Skip to content

Commit

Permalink
Limit the scope of function
Browse files Browse the repository at this point in the history
The static modifier should be used when
the function is used in only one file.
  • Loading branch information
luochunsheng authored and andikleen committed Aug 25, 2022
1 parent e2d6083 commit 75464e7
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 109 deletions.
4 changes: 2 additions & 2 deletions clearcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>
#include "clearcache.h"

unsigned cache_size(void)
static unsigned cache_size(void)
{
unsigned cs = 0;
#ifdef _SC_LEVEL1_DCACHE_SIZE
Expand Down Expand Up @@ -36,7 +36,7 @@ unsigned cache_size(void)
return cs;
}

void fallback_clearcache(void)
static void fallback_clearcache(void)
{
static unsigned char *clearmem;
unsigned cs = cache_size();
Expand Down
7 changes: 5 additions & 2 deletions memhog.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum {
#endif


void usage(void)
static void usage(void)
{
printf("memhog [-fFILE] [-rNUM] size[kmg] [policy [nodeset]]\n");
printf("-f mmap is backed by FILE\n");
Expand All @@ -48,7 +48,7 @@ void usage(void)

long length;

void hog(void *map)
static void hog(void *map)
{
long i;
for (i = 0; i < length; i += UNIT) {
Expand Down Expand Up @@ -104,6 +104,9 @@ int main(int ac, char **av)
} else
loose = 1;
policy = parse_policy(av[2], av[3]);
if (policy == MPOL_MAX)
usage();

if (policy != MPOL_DEFAULT)
nodes = numa_parse_nodestring(av[3]);
if (!nodes) {
Expand Down
4 changes: 2 additions & 2 deletions migratepages.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static struct option opts[] = {
{ 0 }
};

void usage(void)
static void usage(void)
{
fprintf(stderr,
"usage: migratepages pid from-nodes to-nodes\n"
Expand All @@ -46,7 +46,7 @@ void usage(void)
exit(1);
}

void checknuma(void)
static void checknuma(void)
{
static int numa = -1;
if (numa < 0) {
Expand Down
4 changes: 2 additions & 2 deletions migspeed.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static char *cmd;
static int verbose;
static unsigned long pages = 1000;

void usage(void)
static void usage(void)
{
printf("usage %s [-p pages] [-h] [-v] from-nodes to-nodes\n", cmd);
printf(" from and to nodes may specified in form N or N-N\n");
Expand All @@ -30,7 +30,7 @@ void usage(void)
exit(1);
}

void displaymap(void)
static void displaymap(void)
{
FILE *f = fopen("/proc/self/numa_maps","r");

Expand Down
36 changes: 18 additions & 18 deletions numactl.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static struct option opts[] = {
{ 0 }
};

void usage(void)
static void usage(void)
{
fprintf(stderr,
"usage: numactl [--all | -a] [--balancing | -b] [--interleave= | -i <nodes>]\n"
Expand Down Expand Up @@ -100,7 +100,7 @@ void usage(void)
exit(1);
}

void usage_msg(char *msg, ...)
static void usage_msg(char *msg, ...)
{
va_list ap;
va_start(ap,msg);
Expand All @@ -111,7 +111,7 @@ void usage_msg(char *msg, ...)
va_end(ap);
}

void show_physcpubind(void)
static void show_physcpubind(void)
{
int ncpus = numa_num_configured_cpus();

Expand All @@ -132,7 +132,7 @@ void show_physcpubind(void)
}
}

void show(void)
static void show(void)
{
struct bitmask *membind, *interleave, *cpubind, *preferred;
unsigned long cur;
Expand Down Expand Up @@ -189,7 +189,7 @@ void show(void)
printmask("preferred", preferred);
}

char *fmt_mem(unsigned long long mem, char *buf)
static char *fmt_mem(unsigned long long mem, char *buf)
{
if (mem == -1L)
sprintf(buf, "<not available>");
Expand Down Expand Up @@ -230,7 +230,7 @@ static void print_distances(int maxnode)
}
}

void print_node_cpus(int node)
static void print_node_cpus(int node)
{
int i, err;
struct bitmask *cpus;
Expand All @@ -245,7 +245,7 @@ void print_node_cpus(int node)
putchar('\n');
}

void hardware(void)
static void hardware(void)
{
int i;
int numnodes=0;
Expand Down Expand Up @@ -309,15 +309,15 @@ void hardware(void)
print_distances(maxnode);
}

void checkerror(char *s)
static void checkerror(char *s)
{
if (errno) {
perror(s);
exit(1);
}
}

void checknuma(void)
static void checknuma(void)
{
static int numa = -1;
if (numa < 0) {
Expand All @@ -329,14 +329,14 @@ void checknuma(void)

int set_policy = -1;

void setpolicy(int pol)
static inline void setpolicy(int pol)
{
if (set_policy != -1)
usage_msg("Conflicting policies");
set_policy = pol;
}

void nopolicy(void)
static inline void nopolicy(void)
{
if (set_policy >= 0)
usage_msg("specify policy after --shm/--file");
Expand All @@ -347,38 +347,38 @@ static int shmattached = 0;
static int did_node_cpu_parse = 0;
static char *shmoption;

void check_cpubind(int flag)
static inline void check_cpubind(int flag)
{
if (flag)
usage_msg("cannot do --cpubind on shared memory\n");
}

void noshm(char *opt)
static inline void noshm(char *opt)
{
if (shmattached)
usage_msg("%s must be before shared memory specification", opt);
shmoption = opt;
}

void dontshm(char *opt)
static inline void dontshm(char *opt)
{
if (shmoption)
usage_msg("%s shm option is not allowed before %s", shmoption, opt);
}

void needshm(char *opt)
static inline void needshm(char *opt)
{
if (!shmattached)
usage_msg("%s must be after shared memory specification", opt);
}

void check_all_parse(int flag)
static inline void check_all_parse(int flag)
{
if (did_node_cpu_parse)
usage_msg("--all/-a option must be before all cpu/node specifications");
}

void get_short_opts(struct option *o, char *s)
static void get_short_opts(struct option *o, char *s)
{
*s++ = '+';
while (o->name) {
Expand All @@ -392,7 +392,7 @@ void get_short_opts(struct option *o, char *s)
*s = '\0';
}

void check_shmbeyond(char *msg)
static void check_shmbeyond(char *msg)
{
if (shmoffset >= shmlen) {
fprintf(stderr,
Expand Down
16 changes: 8 additions & 8 deletions numademo.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static char *testname[] = {
NULL,
};

void output(char *title, char *result)
static void output(char *title, char *result)
{
if (!isspace(delim[0]))
printf("%s%s%s\n", title,delim, result);
Expand All @@ -84,7 +84,7 @@ void output(char *title, char *result)
}

#ifdef HAVE_STREAM_LIB
void do_stream(char *name, unsigned char *mem)
static void do_stream(char *name, unsigned char *mem)
{
int i;
char title[100], buf[100];
Expand Down Expand Up @@ -122,7 +122,7 @@ static int cmp_node(const void *ap, const void *bp)
return a->val - b->val;
}

void **ptrchase_init(unsigned char *mem)
static void **ptrchase_init(unsigned char *mem)
{
long i;
union node *nodes = (union node *)mem;
Expand All @@ -147,7 +147,7 @@ static inline unsigned long long timerfold(struct timeval *tv)

#define LOOPS 10

void memtest(char *name, unsigned char *mem)
static void memtest(char *name, unsigned char *mem)
{
long k;
struct timeval start, end, res;
Expand Down Expand Up @@ -285,7 +285,7 @@ void memtest(char *name, unsigned char *mem)
numa_free(mem, msize);
}

int popcnt(unsigned long val)
static int popcnt(unsigned long val)
{
int i = 0, cnt = 0;
while (val >> i) {
Expand All @@ -298,7 +298,7 @@ int popcnt(unsigned long val)

static int numnodes;

int get_node_list(void)
static int get_node_list(void)
{
int a, got_nodes = 0;
long long free_node_sizes;
Expand All @@ -316,7 +316,7 @@ int get_node_list(void)
return got_nodes;
}

void test(enum test type)
static void test(enum test type)
{
unsigned long mask;
int i, k;
Expand Down Expand Up @@ -482,7 +482,7 @@ void test(enum test type)
/* numa_run_on_node_mask is not tested */
}

void usage(void)
static void usage(void)
{
int i;
printf("usage: numademo [-S] [-f] [-c] [-e] [-t] msize[kmg] {tests}\nNo tests means run all.\n");
Expand Down
Loading

0 comments on commit 75464e7

Please sign in to comment.