]> git.proxmox.com Git - ovs.git/blob - lib/stress.h
ofproto-dpif: Print slow-path actions instead of "drop" in dump-flows.
[ovs.git] / lib / stress.h
1 /*
2 * Copyright (c) 2010, 2011 Nicira, Inc.
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 extern struct stress_option *stress_option_ptr_##NAME; \
64 struct stress_option *stress_option_ptr_##NAME \
65 __attribute__((section("stress_options"))) = &stress_##NAME
66 #else
67 #define STRESS_OPTION(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
68 extern struct stress_option stress_##NAME
69 #endif
70
71 /* Yields true if stress option NAME should be triggered,
72 * false otherwise. */
73 #define STRESS(NAME) stress_sample__(&stress_##NAME)
74
75 void stress_init_command(void);
76 \f
77 /* Implementation details. */
78
79 #define STRESS_OPTION__(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
80 extern struct stress_option stress_##NAME; \
81 struct stress_option stress_##NAME = \
82 { #NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT, \
83 DEFAULT ? DEFAULT : 0, /* period */ \
84 false, /* random */ \
85 UINT_MAX, /* counter */ \
86 0 } /* hits */
87
88 bool stress_sample_slowpath__(struct stress_option *);
89 static inline bool stress_sample__(struct stress_option *option)
90 {
91 return --option->counter == 0 && stress_sample_slowpath__(option);
92 }
93
94 #endif /* STRESS_H */