lockmeter: fix lock counter roll over issue
When I collected lockmeter data for a longer duration, sometimes the locks counter could roll over. I'm sure someone else maybe meet the same situation. So I wrote the below patch, could you have a look?
diff -Nraup linux/include/linux/lockmeter.h linux.lockmeter/include/linux/lockmeter.h
--- linux/include/linux/lockmeter.h 2005-08-09 10:46:53.302083832 +0800
+++ linux.lockmeter/include/linux/lockmeter.h 2005-08-05
17:22:37.000000000 +0800
@@ -150,7 +150,7 @@ typedef struct {
uint32_t max_wait_ww_ticks; /* max wait time writer vs writer */
/* prev 2 only used for write locks*/
uint32_t acquire_time; /* time lock acquired this CPU */ - uint32_t count[LSTAT_ACT_MAX_VALUES]; + uint64_t count[LSTAT_ACT_MAX_VALUES];
} lstat_lock_counts_t;
typedef lstat_lock_counts_t lstat_cpu_counts_t[LSTAT_MAX_STAT_INDEX];
@@ -167,7 +167,7 @@ typedef lstat_lock_counts_t lstat_cpu_co
#define LSTAT_MAX_READ_LOCK_INDEX 1000
typedef struct {
POINTER lock_ptr; /* address of lock for output stats */ - uint32_t read_lock_count; + uint64_t read_lock_count; int64_t cum_hold_ticks; /* sum of read lock hold times over */
/* all callers. ....................*/
uint32_t write_index; /* last write lock hash table index */
I also modified lockstat to compliant with this modification against lockstat 1.4.11 version.
diff -Nraup lockstat/include/linux/lockmeter.hlockstat.fix/include/linux/lockmeter.h
include/linux/lockmeter.h +2 -2
@@ -150,7 +150,7 @@ typedef struct {uint32_t max_wait_ww_ticks;/* max wait time writer vs writer */ /* prev 2 only used for write locks*/ uint32_t acquire_time;/* time lock acquired this CPU */ -uint32_t count[LSTAT_ACT_MAX_VALUES ]; +uint64_t count[LSTAT_ACT_MAX_VALUES ]; } lstat_lock_counts_t;typedef lstat_lock_counts_t lstat_cpu_counts_t [LSTAT_MAX_STAT_INDEX ];
@@ -167,7 +167,7 @@ typedef lstat_lock_counts_t lstat_cpu_co#define LSTAT_MAX_READ_LOCK_INDEX 1000 typedef struct { POINTER lock_ptr; /* address of lock for output stats */ - uint32_t read_lock_count; + uint64_t read_lock_count; int64_t cum_hold_ticks; /* sum of read lock hold times over */ /* all callers. ....................*/ uint32_t write_index; /* last write lock hash table index */
lockstat.c +4 -3
@@ -36,7 +36,7 @@ static char lockstat_version[] = "1.4.1#include <stdlib.h> #include <string.h> #include <errno.h> -#include <sys/time.h> +#include <time.h> #include <linux/lockmeter.h> extern void closeFiles (void );
@@ -267,7 +267,7 @@ typedef enum {Null_Entry, Spin_Entry, RL typedef struct { lstat_lock_counts_t counts; - uint32_t total; + uint64_t total; double contention; double persec; double utilization;
@@ -999,7 +999,8 @@ add_counts(lock_summary_t *sump, lstat_lint sum_counts (lock_summary_t *sump,entry_type_enum entry_type) { -int total, i, j; +int i, j; +uint64_t total;double contention;double utilization;
@@ -1171,7 +1172,7 @@ print_lock(char *name, lock_summary_t *sfloat mean_hold_time, max_hold_time; float wait_time, mean_wait_time, max_wait_time, mean_wait_ww_time,
max_wait_ww_time;
double temp_time;
- uint32_t total_spin_count = 0;
+ uint64_t total_spin_count = 0;
print_header();
@@ -1317,7 +1318,7 @@ print_lock(char *name, lock_summary_t *s
}
/* following done for ALL types of locks, except as indicated */
- printf(" %9d", sump->total);
+ printf(" %20ld", sump->total);
print_percentage('
',100.0*(double)sump->counts.count[LSTAT_ACT_NO_WAIT]/(double)sump->total,0);
print_percentage('
',100.0*(double)sump->counts.count[LSTAT_ACT_SPIN]/(double)sump->total,0);
if (entry_type == WLspin_Entry) {
@@ -1325,7 +1326,7 @@ print_lock(char *name, lock_summary_t *s
')');
}
#ifdef notyet
- printf("%9d", sump->counts.count[LSTAT_ACT_SLEPT]);
+ printf("%20ld", sump->counts.count[LSTAT_ACT_SLEPT]);
#endif
if (entry_type == Spin_Entry) {
/* We only see these for spinlock_t, and even then it's rare. */
Any comments?
Does anyone have inputs?
Quoted 117 lines · Xuekun Hu
When I collected lockmeter data for a longer duration, sometimes the locks counter could roll over. I'm sure someone else maybe meet the same situation. So I wrote the below patch, could you have a look?
diff -Nraup
linux/include/linux/lockmeter.hlinux.lockmeter/include/linux/lockmeter.hinclude/linux/lockmeter.h 2005-08-05 renamed from include/linux/lockmeter.h 2005-08-09 10:46:53.302083832 +0800 +0
-017:22:37.000000000 +0800
include/linux/lockmeter.h 2005-08-05 renamed from include/linux/lockmeter.h 2005-08-09 10:46:53.302083832 +0800 +2
-2@@ -150,7 +150,7 @@ typedef struct { uint32_t max_wait_ww_ticks; /* max wait time writer vs writer */ /* prev 2 only used for write locks*/ uint32_t acquire_time; /* time lock acquired this CPU */ - uint32_t count[LSTAT_ACT_MAX_VALUES]; + uint64_t count[LSTAT_ACT_MAX_VALUES]; } lstat_lock_counts_t; typedef lstat_lock_counts_t lstat_cpu_counts_t[LSTAT_MAX_STAT_INDEX];@@ -167,7 +167,7 @@ typedef lstat_lock_counts_t lstat_cpu_co #define LSTAT_MAX_READ_LOCK_INDEX 1000 typedef struct { POINTER lock_ptr; /* address of lock for output stats */ - uint32_t read_lock_count; + uint64_t read_lock_count; int64_t cum_hold_ticks; /* sum of read lock hold times over */ /* all callers. ....................*/ uint32_t write_index; /* last write lock hash table index */I also modified lockstat to compliant with this modification against lockstat 1.4.11 version.
diff -Nraup
lockstat/include/linux/lockmeter.hlockstat.fix/include/linux/lockmeter.hinclude/linux/lockmeter.h 2005-08-05 17:38:46.000000000 +0800 renamed from include/linux/lockmeter.h 2004-09-14 07:02:05.000000000 +0800 +2
-2@@ -150,7 +150,7 @@ typedef struct { uint32_t max_wait_ww_ticks; /* max wait time writer vs writer */ /* prev 2 only used for write locks*/ uint32_t acquire_time; /* time lock acquired this CPU */ - uint32_t count[LSTAT_ACT_MAX_VALUES]; + uint64_t count[LSTAT_ACT_MAX_VALUES]; } lstat_lock_counts_t; typedef lstat_lock_counts_t lstat_cpu_counts_t[LSTAT_MAX_STAT_INDEX];@@ -167,7 +167,7 @@ typedef lstat_lock_counts_t lstat_cpu_co #define LSTAT_MAX_READ_LOCK_INDEX 1000 typedef struct { POINTER lock_ptr; /* address of lock for output stats */ - uint32_t read_lock_count; + uint64_t read_lock_count; int64_t cum_hold_ticks; /* sum of read lock hold times over */ /* all callers. ....................*/ uint32_t write_index; /* last write lock hash table index */diff -Nraup
lockstat/lockstat.clockstat.fix/lockstat.clockstat.c 2005-08-09 10:35:18.305356776 +0800 renamed from lockstat.c 2004-09-14 07:01:41.000000000 +0800 +6
-5@@ -36,7 +36,7 @@ static char lockstat_version[] = "1.4.1 #include <stdlib.h> #include <string.h> #include <errno.h> -#include <sys/time.h> +#include <time.h> #include <linux/lockmeter.h> extern void closeFiles(void);@@ -267,7 +267,7 @@ typedef enum {Null_Entry, Spin_Entry, RL typedef struct { lstat_lock_counts_t counts; - uint32_t total; + uint64_t total; double contention; double persec; double utilization;@@ -999,7 +999,8 @@ add_counts(lock_summary_t *sump, lstat_l int sum_counts(lock_summary_t *sump, entry_type_enum entry_type) { - int total, i, j; + int i, j; + uint64_t total; double contention; double utilization;@@ -1171,7 +1172,7 @@ print_lock(char *name, lock_summary_t *s float mean_hold_time, max_hold_time; float wait_time, mean_wait_time, max_wait_time, mean_wait_ww_time, max_wait_ww_time; double temp_time; - uint32_t total_spin_count = 0; + uint64_t total_spin_count = 0; print_header();@@ -1317,7 +1318,7 @@ print_lock(char *name, lock_summary_t *s } /* following done for ALL types of locks, except as indicated */ - printf(" %9d", sump->total); + printf(" %20ld", sump->total); print_percentage(' ',100.0*(double)sump->counts.count[LSTAT_ACT_NO_WAIT]/(double)sump->total,0); print_percentage('',100.0*(double)sump->counts.count[LSTAT_ACT_SPIN]/(double)sump->total,0); if (entry_type == WLspin_Entry) {lockstat.c 2005-08-09 10:35:18.305356776 +0800 renamed from lockstat.c 2004-09-14 07:01:41.000000000 +0800 +1
-1@@ -1325,7 +1326,7 @@ print_lock(char *name, lock_summary_t *s ')'); } #ifdef notyet - printf("%9d", sump->counts.count[LSTAT_ACT_SLEPT]); + printf("%20ld", sump->counts.count[LSTAT_ACT_SLEPT]); #endif if (entry_type == Spin_Entry) { /* We only see these for spinlock_t, and even then it's rare. */Any comments?
Quoted 2 lines · Xuekun Hu
Does anyone have inputs?
Xuekun ,
I was on vacation last week. I just saw your patch yesterday. It looks
reasonable, but I will test it later today.
You should also cc John Hawkes ([email protected]).
Also, please note my email address change: my current email address is [email protected].
Andrew is not so much interested in these changes as the lockmeter patch is not in -mm.
Signature · 3 lines
Ray Bryant AMD Performance Labs Austin, Tx 512-602-0038 (o) 512-507-7807 (c)
Hi, Ray
Did you test the patch? Any updates?
I have tested the patch and no errors were found.
Thx, Xuekun
Quoted 22 lines · Ray Bryant
Quoted 2 lines · Xuekun Hu
Does anyone have inputs?
Xuekun ,
I was on vacation last week. I just saw your patch yesterday. It looks
reasonable, but I will test it later today.You should also cc John Hawkes ([email protected]).
Also, please note my email address change: my current email address is [email protected].
Andrew is not so much interested in these changes as the lockmeter patch is not in -mm.
--
Ray Bryant
AMD Performance Labs Austin, Tx
512-602-0038 (o) 512-507-7807 (c)