@@ -48,7 +48,7 @@ static struct target target;
48
48
#define LOCKHASH_BITS 12
49
49
#define LOCKHASH_SIZE (1UL << LOCKHASH_BITS)
50
50
51
- static struct hlist_head lockhash_table [ LOCKHASH_SIZE ] ;
51
+ static struct hlist_head * lockhash_table ;
52
52
53
53
#define __lockhashfn (key ) hash_long((unsigned long)key, LOCKHASH_BITS)
54
54
#define lockhashentry (key ) (lockhash_table + __lockhashfn((key)))
@@ -1871,7 +1871,6 @@ static int __cmd_contention(int argc, const char **argv)
1871
1871
};
1872
1872
struct lock_contention con = {
1873
1873
.target = & target ,
1874
- .result = & lockhash_table [0 ],
1875
1874
.map_nr_entries = bpf_map_entries ,
1876
1875
.max_stack = max_stack_depth ,
1877
1876
.stack_skip = stack_skip ,
@@ -1880,10 +1879,17 @@ static int __cmd_contention(int argc, const char **argv)
1880
1879
.owner = show_lock_owner ,
1881
1880
};
1882
1881
1882
+ lockhash_table = calloc (LOCKHASH_SIZE , sizeof (* lockhash_table ));
1883
+ if (!lockhash_table )
1884
+ return - ENOMEM ;
1885
+
1886
+ con .result = & lockhash_table [0 ];
1887
+
1883
1888
session = perf_session__new (use_bpf ? NULL : & data , & eops );
1884
1889
if (IS_ERR (session )) {
1885
1890
pr_err ("Initializing perf session failed\n" );
1886
- return PTR_ERR (session );
1891
+ err = PTR_ERR (session );
1892
+ goto out_delete ;
1887
1893
}
1888
1894
1889
1895
con .machine = & session -> machines .host ;
@@ -1983,6 +1989,7 @@ static int __cmd_contention(int argc, const char **argv)
1983
1989
evlist__delete (con .evlist );
1984
1990
lock_contention_finish ();
1985
1991
perf_session__delete (session );
1992
+ zfree (& lockhash_table );
1986
1993
return err ;
1987
1994
}
1988
1995
@@ -2348,6 +2355,10 @@ int cmd_lock(int argc, const char **argv)
2348
2355
unsigned int i ;
2349
2356
int rc = 0 ;
2350
2357
2358
+ lockhash_table = calloc (LOCKHASH_SIZE , sizeof (* lockhash_table ));
2359
+ if (!lockhash_table )
2360
+ return - ENOMEM ;
2361
+
2351
2362
for (i = 0 ; i < LOCKHASH_SIZE ; i ++ )
2352
2363
INIT_HLIST_HEAD (lockhash_table + i );
2353
2364
@@ -2369,7 +2380,7 @@ int cmd_lock(int argc, const char **argv)
2369
2380
rc = __cmd_report (false);
2370
2381
} else if (!strcmp (argv [0 ], "script" )) {
2371
2382
/* Aliased to 'perf script' */
2372
- return cmd_script (argc , argv );
2383
+ rc = cmd_script (argc , argv );
2373
2384
} else if (!strcmp (argv [0 ], "info" )) {
2374
2385
if (argc ) {
2375
2386
argc = parse_options (argc , argv ,
@@ -2403,5 +2414,6 @@ int cmd_lock(int argc, const char **argv)
2403
2414
usage_with_options (lock_usage , lock_options );
2404
2415
}
2405
2416
2417
+ zfree (& lockhash_table );
2406
2418
return rc ;
2407
2419
}
0 commit comments