2
* Copyright (c) 2010 Nicira Networks.
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:
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
22
struct stress_option {
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. */
32
unsigned int period; /* Desired period for firing, 0 to disable. */
33
bool random; /* Fire randomly or exactly at period? */
36
unsigned int counter; /* Number of hits before next firing. */
37
unsigned long long int hits; /* Hits since last reset. */
40
/* Creates and initializes a global instance of a stress option.
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.
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.
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.
52
* MIN and MAX are the minimum and maximum values allowed for the option.
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.
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
66
#define STRESS_OPTION(NAME, DESCRIPTION, RECOMMENDED, MIN, MAX, DEFAULT) \
67
extern struct stress_option stress_##NAME
70
/* Yields true if stress option NAME should be triggered,
72
#define STRESS(NAME) stress_sample__(&stress_##NAME)
74
void stress_init_command(void);
76
/* Implementation details. */
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 */ \
83
UINT_MAX, /* counter */ \
86
bool stress_sample_slowpath__(struct stress_option *);
87
static inline bool stress_sample__(struct stress_option *option)
89
return --option->counter == 0 && stress_sample_slowpath__(option);