@@ -1468,8 +1468,13 @@ static void sort_result(void)
1468
1468
1469
1469
static const struct {
1470
1470
unsigned int flags ;
1471
- const char * str ;
1472
- const char * name ;
1471
+ /*
1472
+ * Name of the lock flags (access), with delimeter ':'.
1473
+ * For example, rwsem:R of rwsem:W.
1474
+ */
1475
+ const char * flags_name ;
1476
+ /* Name of the lock (type), for example, rwlock or rwsem. */
1477
+ const char * lock_name ;
1473
1478
} lock_type_table [] = {
1474
1479
{ 0 , "semaphore" , "semaphore" },
1475
1480
{ LCB_F_SPIN , "spinlock" , "spinlock" },
@@ -1488,24 +1493,24 @@ static const struct {
1488
1493
{ LCB_F_MUTEX | LCB_F_SPIN , "mutex:spin" , "mutex-spin" },
1489
1494
};
1490
1495
1491
- static const char * get_type_str (unsigned int flags )
1496
+ static const char * get_type_flags_name (unsigned int flags )
1492
1497
{
1493
1498
flags &= LCB_F_TYPE_MASK ;
1494
1499
1495
1500
for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
1496
1501
if (lock_type_table [i ].flags == flags )
1497
- return lock_type_table [i ].str ;
1502
+ return lock_type_table [i ].flags_name ;
1498
1503
}
1499
1504
return "unknown" ;
1500
1505
}
1501
1506
1502
- static const char * get_type_name (unsigned int flags )
1507
+ static const char * get_type_lock_name (unsigned int flags )
1503
1508
{
1504
1509
flags &= LCB_F_TYPE_MASK ;
1505
1510
1506
1511
for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
1507
1512
if (lock_type_table [i ].flags == flags )
1508
- return lock_type_table [i ].name ;
1513
+ return lock_type_table [i ].lock_name ;
1509
1514
}
1510
1515
return "unknown" ;
1511
1516
}
@@ -1618,7 +1623,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
1618
1623
1619
1624
switch (aggr_mode ) {
1620
1625
case LOCK_AGGR_CALLER :
1621
- fprintf (lock_output , " %10s %s\n" , get_type_str (st -> flags ), st -> name );
1626
+ fprintf (lock_output , " %10s %s\n" , get_type_flags_name (st -> flags ), st -> name );
1622
1627
break ;
1623
1628
case LOCK_AGGR_TASK :
1624
1629
pid = st -> addr ;
@@ -1628,7 +1633,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
1628
1633
break ;
1629
1634
case LOCK_AGGR_ADDR :
1630
1635
fprintf (lock_output , " %016llx %s (%s)\n" , (unsigned long long )st -> addr ,
1631
- st -> name , get_type_name (st -> flags ));
1636
+ st -> name , get_type_lock_name (st -> flags ));
1632
1637
break ;
1633
1638
case LOCK_AGGR_CGROUP :
1634
1639
fprintf (lock_output , " %s\n" , st -> name );
@@ -1669,7 +1674,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
1669
1674
1670
1675
switch (aggr_mode ) {
1671
1676
case LOCK_AGGR_CALLER :
1672
- fprintf (lock_output , "%s%s %s" , get_type_str (st -> flags ), sep , st -> name );
1677
+ fprintf (lock_output , "%s%s %s" , get_type_flags_name (st -> flags ), sep , st -> name );
1673
1678
if (verbose <= 0 )
1674
1679
fprintf (lock_output , "\n" );
1675
1680
break ;
@@ -1681,7 +1686,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
1681
1686
break ;
1682
1687
case LOCK_AGGR_ADDR :
1683
1688
fprintf (lock_output , "%llx%s %s%s %s\n" , (unsigned long long )st -> addr , sep ,
1684
- st -> name , sep , get_type_name (st -> flags ));
1689
+ st -> name , sep , get_type_lock_name (st -> flags ));
1685
1690
break ;
1686
1691
case LOCK_AGGR_CGROUP :
1687
1692
fprintf (lock_output , "%s\n" ,st -> name );
@@ -2249,10 +2254,10 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
2249
2254
for (tok = strtok_r (s , ", " , & tmp ); tok ; tok = strtok_r (NULL , ", " , & tmp )) {
2250
2255
bool found = false;
2251
2256
2252
- /* `tok` is `str` in `lock_type_table` if it contains ':'. */
2257
+ /* `tok` is a flags name if it contains ':'. */
2253
2258
if (strchr (tok , ':' )) {
2254
2259
for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
2255
- if (!strcmp (lock_type_table [i ].str , tok ) &&
2260
+ if (!strcmp (lock_type_table [i ].flags_name , tok ) &&
2256
2261
add_lock_type (lock_type_table [i ].flags )) {
2257
2262
found = true;
2258
2263
break ;
@@ -2269,14 +2274,14 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
2269
2274
}
2270
2275
2271
2276
/*
2272
- * Otherwise `tok` is `name` in `lock_type_table` .
2277
+ * Otherwise `tok` is a lock name .
2273
2278
* Single lock name could contain multiple flags.
2274
2279
* Replace alias `pcpu-sem` with actual name `percpu-rwsem.
2275
2280
*/
2276
2281
if (!strcmp (tok , "pcpu-sem" ))
2277
2282
tok = (char * )"percpu-rwsem" ;
2278
2283
for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
2279
- if (!strcmp (lock_type_table [i ].name , tok )) {
2284
+ if (!strcmp (lock_type_table [i ].lock_name , tok )) {
2280
2285
if (add_lock_type (lock_type_table [i ].flags )) {
2281
2286
found = true;
2282
2287
} else {
0 commit comments