Merge lp:~timg-tpi/ureadahead/LP491943 into lp:ureadahead

Proposed by Tim Gardner
Status: Needs review
Proposed branch: lp:~timg-tpi/ureadahead/LP491943
Merge into: lp:ureadahead
Diff against target: 78 lines (+34/-2)
1 file modified
src/trace.c (+34/-2)
To merge this branch: bzr merge lp:~timg-tpi/ureadahead/LP491943
Reviewer Review Type Date Requested Status
Scott James Remnant (Canonical) Pending
Review via email: mp+33251@code.launchpad.net

Description of the change

+ * Count the number of CPUs and divide buffer_size_kb by the number of CPUs.
+ Users should watch for instances of "mmiotrace has lost events" in dmesg to make
+ sure the trace buffers are not too small. The original value for
+ buffer_size_kb was chosen somewhat arbitrarily. Empirical testing
+ has shown that its large enough, so we don't actually know where the lower
+ boundary lies.
+ -LP: #491943

To post a comment you must log in.

Unmerged revisions

115. By Tim Gardner

Count the number of CPUs

Count the number of CPUs and divide buffer_size_kb by the number of CPUs.
Users should watch for instances of "mmiotrace has lost events" in dmesg to make
sure the trace buffers are not too small. The original value for
buffer_size_kb was chosen somewhat arbitrarily. Empirical testing
has shown that its large enough, so we don't actually know where the lower
boundary lies.
-LP: #491943

114. By Tim Gardner

Restore buffer_size_kb, LP501715

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/trace.c'
2--- src/trace.c 2009-11-29 15:04:36 +0000
3+++ src/trace.c 2010-08-20 18:49:39 +0000
4@@ -117,17 +117,20 @@
5 int timeout)
6 {
7 int dfd;
8+ FILE *fp;
9 int unmount = FALSE;
10 int old_sys_open_enabled = 0;
11 int old_open_exec_enabled = 0;
12 int old_uselib_enabled = 0;
13 int old_tracing_enabled = 0;
14+ int old_buffer_size_kb = 0;
15 struct sigaction act;
16 struct sigaction old_sigterm;
17 struct sigaction old_sigint;
18 struct timeval tv;
19 nih_local PackFile *files = NULL;
20 size_t num_files = 0;
21+ size_t num_cpus = 0;
22
23 /* Mount debugfs if not already mounted */
24 dfd = open (PATH_DEBUGFS "/tracing", O_RDONLY | O_NOATIME);
25@@ -148,7 +151,29 @@
26 unmount = TRUE;
27 }
28
29- /* Enable tracing of open() syscalls */
30+ /*
31+ * Count the number of CPUs, default to 1 on error.
32+ */
33+ fp = fopen("/proc/cpuinfo", "r");
34+ if (fp) {
35+ int line_size=1024;
36+ char *processor="processor";
37+ char *line = malloc(line_size);
38+ if (line) {
39+ num_cpus = 0;
40+ while (fgets(line,line_size,fp) != NULL) {
41+ if (!strncmp(line,processor,strlen(processor)))
42+ num_cpus++;
43+ }
44+ free(line);
45+ nih_message("Counted %d CPUs\n",num_cpus);
46+ }
47+ fclose(fp);
48+ }
49+ if (!num_cpus)
50+ num_cpus = 1;
51+
52+ /* Enable tracing of open() syscalls */
53 if (set_value (dfd, "events/fs/do_sys_open/enable",
54 TRUE, &old_sys_open_enabled) < 0)
55 goto error;
56@@ -165,7 +190,7 @@
57
58 old_uselib_enabled = -1;
59 }
60- if (set_value (dfd, "buffer_size_kb", 128000, NULL) < 0)
61+ if (set_value (dfd, "buffer_size_kb", 128000/num_cpus, &old_buffer_size_kb) < 0)
62 goto error;
63 if (set_value (dfd, "tracing_enabled",
64 TRUE, &old_tracing_enabled) < 0)
65@@ -226,6 +251,13 @@
66 if (read_trace (NULL, dfd, "trace", &files, &num_files) < 0)
67 goto error;
68
69+ /*
70+ * Restore the trace buffer size (which has just been read) and free
71+ * a bunch of memory.
72+ */
73+ if (set_value (dfd, "buffer_size_kb", old_buffer_size_kb, NULL) < 0)
74+ goto error;
75+
76 /* Unmount the temporary debugfs mount if we mounted it */
77 if (close (dfd)) {
78 nih_error_raise_system ();

Subscribers

People subscribed via source and target branches