Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Allow to reset open files counter

I hit a bug when running test suite without forking
each test (-F option):

$ perf test -F dso
8: Test dso data read : Ok
9: Test dso data cache : FAILED!
10: Test dso data reopen : FAILED!

The reason the session file limit is set just once for
perf process so we need to reset it for each test,
otherwise wrong limit is taken into account.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Nilay Vaish <nilayvaish@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1467113345-12669-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
f3069249 3be28870

+24 -6
+6
tools/perf/tests/dso-data.c
··· 251 251 long nr_end, nr = open_files_cnt(); 252 252 int dso_cnt, limit, i, fd; 253 253 254 + /* Rest the internal dso open counter limit. */ 255 + reset_fd_limit(); 256 + 254 257 memset(&machine, 0, sizeof(machine)); 255 258 256 259 /* set as system limit */ ··· 314 311 #define dso_0 (dsos[0]) 315 312 #define dso_1 (dsos[1]) 316 313 #define dso_2 (dsos[2]) 314 + 315 + /* Rest the internal dso open counter limit. */ 316 + reset_fd_limit(); 317 317 318 318 memset(&machine, 0, sizeof(machine)); 319 319
+16 -6
tools/perf/util/dso.c
··· 442 442 return limit; 443 443 } 444 444 445 + static rlim_t fd_limit; 446 + 447 + /* 448 + * Used only by tests/dso-data.c to reset the environment 449 + * for tests. I dont expect we should change this during 450 + * standard runtime. 451 + */ 452 + void reset_fd_limit(void) 453 + { 454 + fd_limit = 0; 455 + } 456 + 445 457 static bool may_cache_fd(void) 446 458 { 447 - static rlim_t limit; 459 + if (!fd_limit) 460 + fd_limit = get_fd_limit(); 448 461 449 - if (!limit) 450 - limit = get_fd_limit(); 451 - 452 - if (limit == RLIM_INFINITY) 462 + if (fd_limit == RLIM_INFINITY) 453 463 return true; 454 464 455 - return limit > (rlim_t) dso__data_open_cnt; 465 + return fd_limit > (rlim_t) dso__data_open_cnt; 456 466 } 457 467 458 468 /*
+2
tools/perf/util/dso.h
··· 360 360 361 361 int dso__strerror_load(struct dso *dso, char *buf, size_t buflen); 362 362 363 + void reset_fd_limit(void); 364 + 363 365 #endif /* __PERF_DSO */