/proc/loadavg and locking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

In this thread[1] we've been discussing whether you can
get an invalid answer if you open /proc/loadavg because
of a context switch in the kernel.

I read your howto about the seq_fs[2], but the callback of
the /proc/loadavg uses the old method.

I read the function and I notice that it expects to write all
the data at one (and doesn't honor count, ie: uses sprintf
instead of snprintf).

So, my questions are:

- Is the following call of sprintf atomic?

- Is there a non-zero probability of getting wrong
  data from this call or a similar one?

Thanks.

linux-2.6.13.2/fs/proc/proc_misc.c:
--------------------------------------------------
static int loadavg_read_proc(char *page, char **start, off_t off,
         int count, int *eof, void *data)
{
  int a, b, c;
  int len;

  a = avenrun[0] + (FIXED_1/200);
  b = avenrun[1] + (FIXED_1/200);
  c = avenrun[2] + (FIXED_1/200);
  len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
    LOAD_INT(a), LOAD_FRAC(a),
    LOAD_INT(b), LOAD_FRAC(b),
    LOAD_INT(c), LOAD_FRAC(c),
    nr_running(), nr_threads, last_pid);
  return proc_calc_metrics(page, start, off, count, eof, len);
}

[1]http://lists.debian.org/debian-isp/2005/10/threads.html#00011
[2]http://www.kernelnewbies.org/documents/seq_file_howto.txt

--
Homepage : http://geocities.com/arhuaco

The first principle is that you must not fool yourself
and you are the easiest person to fool.
     -- Richard Feynman.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux