]> git.proxmox.com Git - ovs.git/blob - lib/stress.h
ovs-ofctl: Fix small typo about nw_tos in man page.
[ovs.git] / lib / stress.h
1 /*
2 * Copyright (c) 2010 Nicira Networks.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef STRESS_H
18 #define STRESS_H 1
19
20 #include <stdbool.h>
21
22 struct stress_option {
23 /* Properties. */
24 char *name; /* Short identifier string */
25 char *description; /* Description of what the option stresses. */
26 unsigned int recommended; /* Recommended period. */
27 unsigned int min; /* Minimum period that can be set. */
28 unsigned int max; /* Maximum period that can be set. */
29 unsigned int def; /* Default value. */
30
31 /* Configuration. */
32 unsigned int period; /* Desired period for firing, 0 to disable. */
33 bool random; /* Fire randomly or exactly at period? */
34
35 /* State. */
36 unsigned int counter; /* Number of hits before next firing. */
37 unsigned long long int hits; /* Hits since last reset. */
38 };
39
40 /* Creates and initializes a global instance of a stress option.
41 *
42 * NAME is a single word descriptive identifier for the option. This is the
43 * token to pass in to the STRESS() macro at the sites where exectution is to
44 * be controlled by the option.
45 *
46 * DESCRIPTION is a quoted string that should describe to a person unfamiliar
47 * with the detailed internals of the code what behavior the option affects.
48 *
49 * RECOMMENDED is a suggested value for a person unfamiliar with the internals.
50 * It should put reasonable stress on the system without crippling it.
51 *
52 * MIN and MAX are the minimum and maximum values allowed for the option.
53 *
54 * DEFAULT is the default value for the option. Specify 0 to disable the
55 * option by default, which should be the usual choice. But some options can
56 * be left on at low levels without noticable impact to the end user. An
57 * example would be failing to allocate a buffer for every 100000th packet
58 * processed by the system.
59 */
60 #if USE_LINKER_SECTIONS
61 #define STRESS_OPTION(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
62 STRESS_OPTION__(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT); \
63 struct stress_option *stress_option_ptr_##NAME \
64 __attribute__((section("stress_options"))) = &stress_##NAME
65 #else
66 #define STRESS_OPTION(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
67 extern struct stress_option stress_##NAME
68 #endif
69
70 /* Yields true if stress option NAME should be triggered,
71 * false otherwise. */
72 #define STRESS(NAME) stress_sample__(&stress_##NAME)
73
74 void stress_init_command(void);
75 \f
76 /* Implementation details. */
77
78 #define STRESS_OPTION__(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
79 struct stress_option stress_##NAME = \
80 { #NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT, \
81 DEFAULT ? DEFAULT : 0, /* period */ \
82 false, /* random */ \
83 UINT_MAX, /* counter */ \
84 0 } /* hits */
85
86 bool stress_sample_slowpath__(struct stress_option *);
87 static inline bool stress_sample__(struct stress_option *option)
88 {
89 return --option->counter == 0 && stress_sample_slowpath__(option);
90 }
91
92 #endif /* STRESS_H */