From 99f9f72be1165d7b54d4d82093aa14210f74e15c99fad88ac8321eb134ad0a30 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Tue, 7 Sep 2010 16:39:24 +0000 Subject: [PATCH] . OBS-URL: https://build.opensuse.org/package/show/Base:System/procps?expand=0&rev=27 --- boot.sysctl | 4 +- bug-634071_procstat2.diff | 114 ++++++++++++++++++++++++ procps-3.2.7-btime-from-proc-stat.patch | 68 +++++++++++--- procps.changes | 6 ++ procps.spec | 2 + 5 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 bug-634071_procstat2.diff diff --git a/boot.sysctl b/boot.sysctl index 311f49f..044af16 100644 --- a/boot.sysctl +++ b/boot.sysctl @@ -6,9 +6,9 @@ # ### BEGIN INIT INFO # Provides: boot.sysctl -# Required-Start: $local_fs +# Required-Start: boot.proc $local_fs # Should-Start: setserial boot.isapnp -# Required-Stop: $local_fs +# Required-Stop: boot.proc $local_fs # Should-Stop: $null # Default-Start: B # Default-Stop: diff --git a/bug-634071_procstat2.diff b/bug-634071_procstat2.diff new file mode 100644 index 0000000..f990817 --- /dev/null +++ b/bug-634071_procstat2.diff @@ -0,0 +1,114 @@ +--- procps-3.2.7/proc/sysinfo.c 2010-08-20 15:59:36.991845322 -0500 ++++ procps-3.2.7/proc/sysinfo.c 2010-08-25 09:01:49.867972887 -0500 +@@ -26,8 +26,6 @@ + #include /* htons */ + #endif + +-long smp_num_cpus; /* number of CPUs */ +- + #define BAD_OPEN_MESSAGE \ + "Error: /proc must be mounted\n" \ + " To mount /proc at boot you need an /etc/fstab line like:\n" \ +@@ -169,7 +167,7 @@ + setlocale(LC_NUMERIC, savelocale); + jiffies = user_j + nice_j + sys_j + other_j; + seconds = (up_1 + up_2) / 2; +- h = (unsigned)( (double)jiffies/seconds/smp_num_cpus ); ++ h = (unsigned)( (double)jiffies/seconds/smp_num_cpus() ); + /* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */ + switch(h){ + case 9 ... 11 : Hertz = 10; break; /* S/390 (sometimes) */ +@@ -234,9 +232,13 @@ + return !!rc; + } + +-static void init_libproc(void) __attribute__((constructor)); +-static void init_libproc(void){ +- have_privs = check_for_privs(); ++long smp_num_cpus(void) ++{ ++ static long _smp_num_cpus=-1; /* number of CPUs */ ++ ++ if (_smp_num_cpus != -1) ++ return(_smp_num_cpus); ++ + // ought to count CPUs in /proc/stat instead of relying + // on glibc, which foolishly tries to parse /proc/cpuinfo + // +@@ -244,8 +247,15 @@ + // appears to have a non-SMP kernel on a 2-way SMP box. + // _SC_NPROCESSORS_CONF returns 2, resulting in HZ=512 + // _SC_NPROCESSORS_ONLN returns 1, which should work OK +- smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN); +- if(smp_num_cpus<1) smp_num_cpus=1; /* SPARC glibc is buggy */ ++ _smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN); ++ if(_smp_num_cpus<1) _smp_num_cpus=1; /* SPARC glibc is buggy */ ++ ++ return(_smp_num_cpus); ++} ++ ++static void init_libproc(void) __attribute__((constructor)); ++static void init_libproc(void){ ++ have_privs = check_for_privs(); + + if(linux_version_code > LINUX_VERSION(2, 4, 0)){ + Hertz = find_elf_note(AT_CLKTCK); +--- procps-3.2.7/proc/sysinfo.h 2010-08-20 15:59:37.011847000 -0500 ++++ procps-3.2.7/proc/sysinfo.h 2010-08-25 08:58:17.557096693 -0500 +@@ -7,7 +7,7 @@ + EXTERN_C_BEGIN + + extern unsigned long long Hertz; /* clock tick frequency */ +-extern long smp_num_cpus; /* number of CPUs */ ++extern long smp_num_cpus(void); /* number of CPUs */ + extern int have_privs; /* boolean, true if setuid or similar */ + + #if 0 +--- procps-3.2.7/top.c 2010-08-20 15:59:37.507910544 -0500 ++++ procps-3.2.7/top.c 2010-08-20 16:24:36.623565229 -0500 +@@ -1656,7 +1656,7 @@ + if (Myname) ++Myname; else Myname = me; + + /* establish cpu particulars -- even bigger! */ +- Cpu_tot = smp_num_cpus; ++ Cpu_tot = smp_num_cpus(); + if (linux_version_code > LINUX_VERSION(2, 5, 41)) + States_fmts = STATES_line2x5; + if (linux_version_code >= LINUX_VERSION(2, 6, 0)) // grrr... only some 2.6.0-testX :-( +@@ -1676,15 +1676,15 @@ + + Fieldstab[P_CPN].head = " P"; + Fieldstab[P_CPN].fmts = " %1u"; +- if(smp_num_cpus>9){ ++ if(smp_num_cpus()>9){ + Fieldstab[P_CPN].head = " P"; + Fieldstab[P_CPN].fmts = " %2u"; + } +- if(smp_num_cpus>99){ ++ if(smp_num_cpus()>99){ + Fieldstab[P_CPN].head = " P"; + Fieldstab[P_CPN].fmts = " %3u"; + } +- if(smp_num_cpus>999){ ++ if(smp_num_cpus()>999){ + Fieldstab[P_CPN].head = " P"; + Fieldstab[P_CPN].fmts = " %4u"; + } +@@ -1831,7 +1831,7 @@ + confighlp(Winstk[i].rc.fieldscur); + } + +- if(Rc.mode_irixps && smp_num_cpus>1){ ++ if(Rc.mode_irixps && smp_num_cpus()>1){ + // good for 100 CPUs per process + pcpu_max_value = 9999.0; + Fieldstab[P_CPU].fmts = " %4.0f"; +@@ -2677,7 +2677,7 @@ + Rc.mode_irixps = !Rc.mode_irixps; + show_msg(fmtmk("Irix mode %s", Rc.mode_irixps ? "On" : "Off")); + #endif +- if(Rc.mode_irixps && smp_num_cpus>1){ ++ if(Rc.mode_irixps && smp_num_cpus()>1){ + // good for 100 CPUs per process + pcpu_max_value = 9999.0; + Fieldstab[P_CPU].fmts = " %4.0f"; diff --git a/procps-3.2.7-btime-from-proc-stat.patch b/procps-3.2.7-btime-from-proc-stat.patch index 52fc575..927e155 100644 --- a/procps-3.2.7-btime-from-proc-stat.patch +++ b/procps-3.2.7-btime-from-proc-stat.patch @@ -18,16 +18,19 @@ Signed-off-by: Jean Delvare ps/output.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) ---- procps-3.2.7.orig/proc/sysinfo.c 2007-08-31 10:18:07.000000000 +0200 -+++ procps-3.2.7/proc/sysinfo.c 2007-08-31 13:55:32.000000000 +0200 -@@ -88,6 +88,32 @@ int uptime(double *restrict uptime_secs, +--- procps-3.2.7/proc/sysinfo.c ++++ procps-3.2.7/proc/sysinfo.c 2007-08-31 11:55:32.000000000 +0000 +@@ -90,6 +90,35 @@ int uptime(double *restrict uptime_secs, return up; /* assume never be zero seconds in practice */ } +unsigned long getbtime(void) { -+ unsigned long btime = 0; ++ static unsigned long btime = 0; + FILE *f; + ++ if (btime) ++ return btime; ++ + /* /proc/stat can get very large on multi-CPU systems so we + can't use FILE_TO_BUF */ + if (!(f = fopen(STAT_FILE, "r"))) { @@ -53,9 +56,9 @@ Signed-off-by: Jean Delvare /*********************************************************************** * Some values in /proc are expressed in units of 1/HZ seconds, where HZ * is the kernel clock tick rate. One of these units is called a jiffy. ---- procps-3.2.7.orig/proc/sysinfo.h 2007-08-31 10:18:07.000000000 +0200 -+++ procps-3.2.7/proc/sysinfo.h 2007-08-31 10:18:58.000000000 +0200 -@@ -17,6 +17,7 @@ extern void eight_cpu_numbers(JT *uret, +--- procps-3.2.7/proc/sysinfo.h ++++ procps-3.2.7/proc/sysinfo.h 2007-08-31 08:18:58.000000000 +0000 +@@ -17,6 +17,7 @@ extern void eight_cpu_numbers(JT *uret, #endif extern int uptime (double *uptime_secs, double *idle_secs); @@ -63,14 +66,57 @@ Signed-off-by: Jean Delvare extern void loadavg(double *av1, double *av5, double *av15); ---- procps-3.2.7.orig/ps/output.c 2007-08-31 10:18:22.000000000 +0200 -+++ procps-3.2.7/ps/output.c 2007-08-31 10:18:58.000000000 +0200 -@@ -1952,7 +1952,7 @@ void init_output(void){ +--- procps-3.2.7/ps/output.c ++++ procps-3.2.7/ps/output.c 2010-09-07 16:31:59.776958123 +0000 +@@ -77,7 +77,6 @@ static unsigned max_leftward = 0x1234567 + static int wide_signals; /* true if we have room */ + + static unsigned long seconds_since_1970; +-static unsigned long time_of_boot; + static unsigned long page_shift; + + +@@ -793,7 +792,7 @@ static int pr_bsdtime(char *restrict con + static int pr_bsdstart(char *restrict const outbuf, const proc_t *restrict const pp){ + time_t start; + time_t seconds_ago; +- start = time_of_boot + pp->start_time / Hertz; ++ start = getbtime() + pp->start_time / Hertz; + seconds_ago = seconds_since_1970 - start; + if(seconds_ago < 0) seconds_ago=0; + if(seconds_ago > 3600*24) strcpy(outbuf, ctime(&start)+4); +@@ -907,7 +906,7 @@ static int pr_pmem(char *restrict const + + static int pr_lstart(char *restrict const outbuf, const proc_t *restrict const pp){ + time_t t; +- t = time_of_boot + pp->start_time / Hertz; ++ t = getbtime() + pp->start_time / Hertz; + return snprintf(outbuf, COLWID, "%24.24s", ctime(&t)); + } + +@@ -930,7 +929,7 @@ static int pr_stime(char *restrict const + our_time = localtime(&seconds_since_1970); /* not reentrant */ + tm_year = our_time->tm_year; + tm_yday = our_time->tm_yday; +- t = time_of_boot + pp->start_time / Hertz; ++ t = getbtime() + pp->start_time / Hertz; + proc_time = localtime(&t); /* not reentrant, this corrupts our_time */ + fmt = "%H:%M"; /* 03:02 23:59 */ + if(tm_yday != proc_time->tm_yday) fmt = "%b%d"; /* Jun06 Aug27 */ +@@ -941,7 +940,7 @@ static int pr_stime(char *restrict const + static int pr_start(char *restrict const outbuf, const proc_t *restrict const pp){ + time_t t; + char *str; +- t = time_of_boot + pp->start_time / Hertz; ++ t = getbtime() + pp->start_time / Hertz; + str = ctime(&t); + if(str[8]==' ') str[8]='0'; + if(str[11]==' ') str[11]='0'; +@@ -1961,7 +1960,6 @@ void init_output(void){ // available space: page_size*outbuf_pages-SPACE_AMOUNT seconds_since_1970 = time(NULL); - time_of_boot = seconds_since_1970 - seconds_since_boot; -+ time_of_boot = getbtime(); meminfo(); diff --git a/procps.changes b/procps.changes index 8b5c2d5..93e6a03 100644 --- a/procps.changes +++ b/procps.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Sep 7 18:34:50 CEST 2010 - werner@suse.de + +- Add change to avoid repeated read of /proc/stat (bnc#634071) +- Add change to avoid repeated call of sysconf() (bnc#634071) + ------------------------------------------------------------------- Mon Jun 28 06:38:35 UTC 2010 - jengelh@medozas.de diff --git a/procps.spec b/procps.spec index bf23800..8d67ca2 100644 --- a/procps.spec +++ b/procps.spec @@ -68,6 +68,7 @@ Patch30: procps-3.2.8-sysctlerr.dif Patch31: procps-3.2.8-columns.dif Patch32: procps-3.2.7-oom.diff Patch33: procps-3.2.8-integer-overflow.patch +Patch34: bug-634071_procstat2.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -129,6 +130,7 @@ Authors: %patch31 %patch32 -p1 %patch33 -p1 +%patch34 -p1 %build make %{?_smp_mflags} CFLAGS="-Wall -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $RPM_OPT_FLAGS -pipe" \