@@ -1468,8 +1468,13 @@ static void sort_result(void)
14681468
14691469static const struct {
14701470 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 ;
14731478} lock_type_table [] = {
14741479 { 0 , "semaphore" , "semaphore" },
14751480 { LCB_F_SPIN , "spinlock" , "spinlock" },
@@ -1488,24 +1493,24 @@ static const struct {
14881493 { LCB_F_MUTEX | LCB_F_SPIN , "mutex:spin" , "mutex-spin" },
14891494};
14901495
1491- static const char * get_type_str (unsigned int flags )
1496+ static const char * get_type_flags_name (unsigned int flags )
14921497{
14931498 flags &= LCB_F_TYPE_MASK ;
14941499
14951500 for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
14961501 if (lock_type_table [i ].flags == flags )
1497- return lock_type_table [i ].str ;
1502+ return lock_type_table [i ].flags_name ;
14981503 }
14991504 return "unknown" ;
15001505}
15011506
1502- static const char * get_type_name (unsigned int flags )
1507+ static const char * get_type_lock_name (unsigned int flags )
15031508{
15041509 flags &= LCB_F_TYPE_MASK ;
15051510
15061511 for (unsigned int i = 0 ; i < ARRAY_SIZE (lock_type_table ); i ++ ) {
15071512 if (lock_type_table [i ].flags == flags )
1508- return lock_type_table [i ].name ;
1513+ return lock_type_table [i ].lock_name ;
15091514 }
15101515 return "unknown" ;
15111516}
@@ -1618,7 +1623,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
16181623
16191624 switch (aggr_mode ) {
16201625 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 );
16221627 break ;
16231628 case LOCK_AGGR_TASK :
16241629 pid = st -> addr ;
@@ -1628,7 +1633,7 @@ static void print_lock_stat_stdio(struct lock_contention *con, struct lock_stat
16281633 break ;
16291634 case LOCK_AGGR_ADDR :
16301635 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 ));
16321637 break ;
16331638 case LOCK_AGGR_CGROUP :
16341639 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
16691674
16701675 switch (aggr_mode ) {
16711676 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 );
16731678 if (verbose <= 0 )
16741679 fprintf (lock_output , "\n" );
16751680 break ;
@@ -1681,7 +1686,7 @@ static void print_lock_stat_csv(struct lock_contention *con, struct lock_stat *s
16811686 break ;
16821687 case LOCK_AGGR_ADDR :
16831688 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 ));
16851690 break ;
16861691 case LOCK_AGGR_CGROUP :
16871692 fprintf (lock_output , "%s\n" ,st -> name );
@@ -2249,10 +2254,10 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
22492254 for (tok = strtok_r (s , ", " , & tmp ); tok ; tok = strtok_r (NULL , ", " , & tmp )) {
22502255 bool found = false;
22512256
2252- /* `tok` is `str` in `lock_type_table` if it contains ':'. */
2257+ /* `tok` is a flags name if it contains ':'. */
22532258 if (strchr (tok , ':' )) {
22542259 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 ) &&
22562261 add_lock_type (lock_type_table [i ].flags )) {
22572262 found = true;
22582263 break ;
@@ -2269,14 +2274,14 @@ static int parse_lock_type(const struct option *opt __maybe_unused, const char *
22692274 }
22702275
22712276 /*
2272- * Otherwise `tok` is `name` in `lock_type_table` .
2277+ * Otherwise `tok` is a lock name .
22732278 * Single lock name could contain multiple flags.
22742279 * Replace alias `pcpu-sem` with actual name `percpu-rwsem.
22752280 */
22762281 if (!strcmp (tok , "pcpu-sem" ))
22772282 tok = (char * )"percpu-rwsem" ;
22782283 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 )) {
22802285 if (add_lock_type (lock_type_table [i ].flags )) {
22812286 found = true;
22822287 } else {
0 commit comments