svn commit: r205683 - head/sys/compat/linprocfs
John Baldwin
jhb at freebsd.org
Fri Mar 26 13:37:50 UTC 2010
On Friday 26 March 2010 7:43:15 am Alexander Leidinger wrote:
> Author: netchild
> Date: Fri Mar 26 11:43:15 2010
> New Revision: 205683
> URL: http://svn.freebsd.org/changeset/base/205683
>
> Log:
> Fix some bogus values in linprocfs.
>
> Submitted by: Petr Salinger <Petr.Salinger at seznam.cz>
> Verified on: GNU/kFreeBSD debian 8.0-1-686 (by submitter)
> PR: 144584
>
> Modified:
> head/sys/compat/linprocfs/linprocfs.c
>
> Modified: head/sys/compat/linprocfs/linprocfs.c
>
==============================================================================
> --- head/sys/compat/linprocfs/linprocfs.c Fri Mar 26 11:33:12 2010 (r205682)
> +++ head/sys/compat/linprocfs/linprocfs.c Fri Mar 26 11:43:15 2010 (r205683)
> @@ -110,13 +110,36 @@ __FBSDID("$FreeBSD$");
> /*
> * Various conversion macros
> */
> +
> +/* The LINUX_USER_HZ is assumed 100 for now */
> +
> +#if defined(__i386__) && defined(__GNUCLIKE_ASM)
> +/* we need intermediate result as 64 bit, otherwise it overflows too early
*/
> +#define DO64_MULDIV(v,m,d) \
> +({ \
> + unsigned long rv0; \
> + unsigned long rv1; \
> + __asm__ __volatile__( \
> + "mull %1\n\t" \
> + "divl %2\n\t" \
> + :"=a" (rv0), "=d" (rv1) \
> + :"r" (d), "0" (v), "1" (m) \
> + :"cc" ); \
> + rv0; \
> +})
> +
> +#define T2J(x) DO64_MULDIV((x), 100UL, (stathz ? stathz : hz)) /* ticks to
jiffies */
> +#else
> #define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz)) /* ticks to jiffies
*/
> +#endif
This is very bogus. Just use a uint64_t cast or the like.
Extraneous ()'s around (x)->tv_sec and (x)->tv_usec in TV2J() as well.
> @@ -502,12 +525,24 @@ linprocfs_douptime(PFS_FILL_ARGS)
> {
> long cp_time[CPUSTATES];
> struct timeval tv;
> + int cnt, i;
>
> getmicrouptime(&tv);
> read_cpu_time(cp_time);
> - sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n",
> +
> + for (cnt = 0, i = 0; i <= mp_maxid; ++i)
> + if (!(CPU_ABSENT(i)))
> + cnt++;
> +
> + if (!cnt)
> + cnt = 1;
> +
> + i = ((cp_time[CP_IDLE])/cnt) % (stathz ? stathz : hz);
> + i = (i * 100) / (stathz ? stathz : hz);
> +
> + sbuf_printf(sb, "%lld.%02ld %ld.%02d\n",
> (long long)tv.tv_sec, tv.tv_usec / 10000,
> - T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100);
> + T2S((cp_time[CP_IDLE]/cnt)), i);
> return (0);
What's wrong with mp_ncpus?
Also, I don't understand how the machinations for i vs the original code
(assuming you add in a divisor of the raw cp_time by mp_ncpus) give a
different value.
> @@ -613,9 +648,17 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
> struct kinfo_proc kp;
> char state;
> static int ratelimit = 0;
> + unsigned long startcode, startdata;
Why not make these a vm_offset_t and then print them with %j?
--
John Baldwin
More information about the svn-src-head
mailing list