diff options
577 files changed, 24542 insertions, 14740 deletions
diff --git a/Documentation/RCU/stallwarn.txt b/Documentation/RCU/stallwarn.txt index 1423d2570d78..44c6dcc93d6d 100644 --- a/Documentation/RCU/stallwarn.txt +++ b/Documentation/RCU/stallwarn.txt | |||
@@ -3,35 +3,79 @@ Using RCU's CPU Stall Detector | |||
3 | The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables | 3 | The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables |
4 | RCU's CPU stall detector, which detects conditions that unduly delay | 4 | RCU's CPU stall detector, which detects conditions that unduly delay |
5 | RCU grace periods. The stall detector's idea of what constitutes | 5 | RCU grace periods. The stall detector's idea of what constitutes |
6 | "unduly delayed" is controlled by a pair of C preprocessor macros: | 6 | "unduly delayed" is controlled by a set of C preprocessor macros: |
7 | 7 | ||
8 | RCU_SECONDS_TILL_STALL_CHECK | 8 | RCU_SECONDS_TILL_STALL_CHECK |
9 | 9 | ||
10 | This macro defines the period of time that RCU will wait from | 10 | This macro defines the period of time that RCU will wait from |
11 | the beginning of a grace period until it issues an RCU CPU | 11 | the beginning of a grace period until it issues an RCU CPU |
12 | stall warning. It is normally ten seconds. | 12 | stall warning. This time period is normally ten seconds. |
13 | 13 | ||
14 | RCU_SECONDS_TILL_STALL_RECHECK | 14 | RCU_SECONDS_TILL_STALL_RECHECK |
15 | 15 | ||
16 | This macro defines the period of time that RCU will wait after | 16 | This macro defines the period of time that RCU will wait after |
17 | issuing a stall warning until it issues another stall warning. | 17 | issuing a stall warning until it issues another stall warning |
18 | It is normally set to thirty seconds. | 18 | for the same stall. This time period is normally set to thirty |
19 | seconds. | ||
19 | 20 | ||
20 | RCU_STALL_RAT_DELAY | 21 | RCU_STALL_RAT_DELAY |
21 | 22 | ||
22 | The CPU stall detector tries to make the offending CPU rat on itself, | 23 | The CPU stall detector tries to make the offending CPU print its |
23 | as this often gives better-quality stack traces. However, if | 24 | own warnings, as this often gives better-quality stack traces. |
24 | the offending CPU does not detect its own stall in the number | 25 | However, if the offending CPU does not detect its own stall in |
25 | of jiffies specified by RCU_STALL_RAT_DELAY, then other CPUs will | 26 | the number of jiffies specified by RCU_STALL_RAT_DELAY, then |
26 | complain. This is normally set to two jiffies. | 27 | some other CPU will complain. This delay is normally set to |
28 | two jiffies. | ||
27 | 29 | ||
28 | The following problems can result in an RCU CPU stall warning: | 30 | When a CPU detects that it is stalling, it will print a message similar |
31 | to the following: | ||
32 | |||
33 | INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies) | ||
34 | |||
35 | This message indicates that CPU 5 detected that it was causing a stall, | ||
36 | and that the stall was affecting RCU-sched. This message will normally be | ||
37 | followed by a stack dump of the offending CPU. On TREE_RCU kernel builds, | ||
38 | RCU and RCU-sched are implemented by the same underlying mechanism, | ||
39 | while on TREE_PREEMPT_RCU kernel builds, RCU is instead implemented | ||
40 | by rcu_preempt_state. | ||
41 | |||
42 | On the other hand, if the offending CPU fails to print out a stall-warning | ||
43 | message quickly enough, some other CPU will print a message similar to | ||
44 | the following: | ||
45 | |||
46 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies) | ||
47 | |||
48 | This message indicates that CPU 2 detected that CPUs 3 and 5 were both | ||
49 | causing stalls, and that the stall was affecting RCU-bh. This message | ||
50 | will normally be followed by stack dumps for each CPU. Please note that | ||
51 | TREE_PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, | ||
52 | and that the tasks will be indicated by PID, for example, "P3421". | ||
53 | It is even possible for a rcu_preempt_state stall to be caused by both | ||
54 | CPUs -and- tasks, in which case the offending CPUs and tasks will all | ||
55 | be called out in the list. | ||
56 | |||
57 | Finally, if the grace period ends just as the stall warning starts | ||
58 | printing, there will be a spurious stall-warning message: | ||
59 | |||
60 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies) | ||
61 | |||
62 | This is rare, but does happen from time to time in real life. | ||
63 | |||
64 | So your kernel printed an RCU CPU stall warning. The next question is | ||
65 | "What caused it?" The following problems can result in RCU CPU stall | ||
66 | warnings: | ||
29 | 67 | ||
30 | o A CPU looping in an RCU read-side critical section. | 68 | o A CPU looping in an RCU read-side critical section. |
31 | 69 | ||
32 | o A CPU looping with interrupts disabled. | 70 | o A CPU looping with interrupts disabled. This condition can |
71 | result in RCU-sched and RCU-bh stalls. | ||
33 | 72 | ||
34 | o A CPU looping with preemption disabled. | 73 | o A CPU looping with preemption disabled. This condition can |
74 | result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh | ||
75 | stalls. | ||
76 | |||
77 | o A CPU looping with bottom halves disabled. This condition can | ||
78 | result in RCU-sched and RCU-bh stalls. | ||
35 | 79 | ||
36 | o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel | 80 | o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel |
37 | without invoking schedule(). | 81 | without invoking schedule(). |
@@ -39,20 +83,24 @@ o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel | |||
39 | o A bug in the RCU implementation. | 83 | o A bug in the RCU implementation. |
40 | 84 | ||
41 | o A hardware failure. This is quite unlikely, but has occurred | 85 | o A hardware failure. This is quite unlikely, but has occurred |
42 | at least once in a former life. A CPU failed in a running system, | 86 | at least once in real life. A CPU failed in a running system, |
43 | becoming unresponsive, but not causing an immediate crash. | 87 | becoming unresponsive, but not causing an immediate crash. |
44 | This resulted in a series of RCU CPU stall warnings, eventually | 88 | This resulted in a series of RCU CPU stall warnings, eventually |
45 | leading the realization that the CPU had failed. | 89 | leading the realization that the CPU had failed. |
46 | 90 | ||
47 | The RCU, RCU-sched, and RCU-bh implementations have CPU stall warning. | 91 | The RCU, RCU-sched, and RCU-bh implementations have CPU stall |
48 | SRCU does not do so directly, but its calls to synchronize_sched() will | 92 | warning. SRCU does not have its own CPU stall warnings, but its |
49 | result in RCU-sched detecting any CPU stalls that might be occurring. | 93 | calls to synchronize_sched() will result in RCU-sched detecting |
50 | 94 | RCU-sched-related CPU stalls. Please note that RCU only detects | |
51 | To diagnose the cause of the stall, inspect the stack traces. The offending | 95 | CPU stalls when there is a grace period in progress. No grace period, |
52 | function will usually be near the top of the stack. If you have a series | 96 | no CPU stall warnings. |
53 | of stall warnings from a single extended stall, comparing the stack traces | 97 | |
54 | can often help determine where the stall is occurring, which will usually | 98 | To diagnose the cause of the stall, inspect the stack traces. |
55 | be in the function nearest the top of the stack that stays the same from | 99 | The offending function will usually be near the top of the stack. |
56 | trace to trace. | 100 | If you have a series of stall warnings from a single extended stall, |
101 | comparing the stack traces can often help determine where the stall | ||
102 | is occurring, which will usually be in the function nearest the top of | ||
103 | that portion of the stack which remains the same from trace to trace. | ||
104 | If you can reliably trigger the stall, ftrace can be quite helpful. | ||
57 | 105 | ||
58 | RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE. | 106 | RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE. |
diff --git a/Documentation/RCU/torture.txt b/Documentation/RCU/torture.txt index 0e50bc2aa1e2..5d9016795fd8 100644 --- a/Documentation/RCU/torture.txt +++ b/Documentation/RCU/torture.txt | |||
@@ -182,16 +182,6 @@ Similarly, sched_expedited RCU provides the following: | |||
182 | sched_expedited-torture: Reader Pipe: 12660320201 95875 0 0 0 0 0 0 0 0 0 | 182 | sched_expedited-torture: Reader Pipe: 12660320201 95875 0 0 0 0 0 0 0 0 0 |
183 | sched_expedited-torture: Reader Batch: 12660424885 0 0 0 0 0 0 0 0 0 0 | 183 | sched_expedited-torture: Reader Batch: 12660424885 0 0 0 0 0 0 0 0 0 0 |
184 | sched_expedited-torture: Free-Block Circulation: 1090795 1090795 1090794 1090793 1090792 1090791 1090790 1090789 1090788 1090787 0 | 184 | sched_expedited-torture: Free-Block Circulation: 1090795 1090795 1090794 1090793 1090792 1090791 1090790 1090789 1090788 1090787 0 |
185 | state: -1 / 0:0 3:0 4:0 | ||
186 | |||
187 | As before, the first four lines are similar to those for RCU. | ||
188 | The last line shows the task-migration state. The first number is | ||
189 | -1 if synchronize_sched_expedited() is idle, -2 if in the process of | ||
190 | posting wakeups to the migration kthreads, and N when waiting on CPU N. | ||
191 | Each of the colon-separated fields following the "/" is a CPU:state pair. | ||
192 | Valid states are "0" for idle, "1" for waiting for quiescent state, | ||
193 | "2" for passed through quiescent state, and "3" when a race with a | ||
194 | CPU-hotplug event forces use of the synchronize_sched() primitive. | ||
195 | 185 | ||
196 | 186 | ||
197 | USAGE | 187 | USAGE |
diff --git a/Documentation/RCU/trace.txt b/Documentation/RCU/trace.txt index 8608fd85e921..efd8cc95c06b 100644 --- a/Documentation/RCU/trace.txt +++ b/Documentation/RCU/trace.txt | |||
@@ -256,23 +256,23 @@ o Each element of the form "1/1 0:127 ^0" represents one struct | |||
256 | The output of "cat rcu/rcu_pending" looks as follows: | 256 | The output of "cat rcu/rcu_pending" looks as follows: |
257 | 257 | ||
258 | rcu_sched: | 258 | rcu_sched: |
259 | 0 np=255892 qsp=53936 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741 | 259 | 0 np=255892 qsp=53936 rpq=85 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741 |
260 | 1 np=261224 qsp=54638 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792 | 260 | 1 np=261224 qsp=54638 rpq=33 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792 |
261 | 2 np=237496 qsp=49664 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629 | 261 | 2 np=237496 qsp=49664 rpq=23 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629 |
262 | 3 np=236249 qsp=48766 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723 | 262 | 3 np=236249 qsp=48766 rpq=98 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723 |
263 | 4 np=221310 qsp=46850 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110 | 263 | 4 np=221310 qsp=46850 rpq=7 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110 |
264 | 5 np=237332 qsp=48449 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456 | 264 | 5 np=237332 qsp=48449 rpq=9 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456 |
265 | 6 np=219995 qsp=46718 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834 | 265 | 6 np=219995 qsp=46718 rpq=12 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834 |
266 | 7 np=249893 qsp=49390 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888 | 266 | 7 np=249893 qsp=49390 rpq=42 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888 |
267 | rcu_bh: | 267 | rcu_bh: |
268 | 0 np=146741 qsp=1419 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314 | 268 | 0 np=146741 qsp=1419 rpq=6 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314 |
269 | 1 np=155792 qsp=12597 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180 | 269 | 1 np=155792 qsp=12597 rpq=3 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180 |
270 | 2 np=136629 qsp=18680 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936 | 270 | 2 np=136629 qsp=18680 rpq=1 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936 |
271 | 3 np=137723 qsp=2843 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863 | 271 | 3 np=137723 qsp=2843 rpq=0 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863 |
272 | 4 np=123110 qsp=12433 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671 | 272 | 4 np=123110 qsp=12433 rpq=0 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671 |
273 | 5 np=137456 qsp=4210 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235 | 273 | 5 np=137456 qsp=4210 rpq=1 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235 |
274 | 6 np=120834 qsp=9902 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921 | 274 | 6 np=120834 qsp=9902 rpq=2 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921 |
275 | 7 np=144888 qsp=26336 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542 | 275 | 7 np=144888 qsp=26336 rpq=0 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542 |
276 | 276 | ||
277 | As always, this is once again split into "rcu_sched" and "rcu_bh" | 277 | As always, this is once again split into "rcu_sched" and "rcu_bh" |
278 | portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional | 278 | portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional |
@@ -284,6 +284,9 @@ o "np" is the number of times that __rcu_pending() has been invoked | |||
284 | o "qsp" is the number of times that the RCU was waiting for a | 284 | o "qsp" is the number of times that the RCU was waiting for a |
285 | quiescent state from this CPU. | 285 | quiescent state from this CPU. |
286 | 286 | ||
287 | o "rpq" is the number of times that the CPU had passed through | ||
288 | a quiescent state, but not yet reported it to RCU. | ||
289 | |||
287 | o "cbr" is the number of times that this CPU had RCU callbacks | 290 | o "cbr" is the number of times that this CPU had RCU callbacks |
288 | that had passed through a grace period, and were thus ready | 291 | that had passed through a grace period, and were thus ready |
289 | to be invoked. | 292 | to be invoked. |
diff --git a/Documentation/intel_txt.txt b/Documentation/intel_txt.txt index f40a1f030019..87c8990dbbd9 100644 --- a/Documentation/intel_txt.txt +++ b/Documentation/intel_txt.txt | |||
@@ -161,13 +161,15 @@ o In order to put a system into any of the sleep states after a TXT | |||
161 | has been restored, it will restore the TPM PCRs and then | 161 | has been restored, it will restore the TPM PCRs and then |
162 | transfer control back to the kernel's S3 resume vector. | 162 | transfer control back to the kernel's S3 resume vector. |
163 | In order to preserve system integrity across S3, the kernel | 163 | In order to preserve system integrity across S3, the kernel |
164 | provides tboot with a set of memory ranges (kernel | 164 | provides tboot with a set of memory ranges (RAM and RESERVED_KERN |
165 | code/data/bss, S3 resume code, and AP trampoline) that tboot | 165 | in the e820 table, but not any memory that BIOS might alter over |
166 | will calculate a MAC (message authentication code) over and then | 166 | the S3 transition) that tboot will calculate a MAC (message |
167 | seal with the TPM. On resume and once the measured environment | 167 | authentication code) over and then seal with the TPM. On resume |
168 | has been re-established, tboot will re-calculate the MAC and | 168 | and once the measured environment has been re-established, tboot |
169 | verify it against the sealed value. Tboot's policy determines | 169 | will re-calculate the MAC and verify it against the sealed value. |
170 | what happens if the verification fails. | 170 | Tboot's policy determines what happens if the verification fails. |
171 | Note that the c/s 194 of tboot which has the new MAC code supports | ||
172 | this. | ||
171 | 173 | ||
172 | That's pretty much it for TXT support. | 174 | That's pretty much it for TXT support. |
173 | 175 | ||
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 839b21b0699a..567b7a8eb878 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt | |||
@@ -324,6 +324,8 @@ and is between 256 and 4096 characters. It is defined in the file | |||
324 | they are unmapped. Otherwise they are | 324 | they are unmapped. Otherwise they are |
325 | flushed before they will be reused, which | 325 | flushed before they will be reused, which |
326 | is a lot of faster | 326 | is a lot of faster |
327 | off - do not initialize any AMD IOMMU found in | ||
328 | the system | ||
327 | 329 | ||
328 | amijoy.map= [HW,JOY] Amiga joystick support | 330 | amijoy.map= [HW,JOY] Amiga joystick support |
329 | Map of devices attached to JOY0DAT and JOY1DAT | 331 | Map of devices attached to JOY0DAT and JOY1DAT |
@@ -784,8 +786,12 @@ and is between 256 and 4096 characters. It is defined in the file | |||
784 | as early as possible in order to facilitate early | 786 | as early as possible in order to facilitate early |
785 | boot debugging. | 787 | boot debugging. |
786 | 788 | ||
787 | ftrace_dump_on_oops | 789 | ftrace_dump_on_oops[=orig_cpu] |
788 | [FTRACE] will dump the trace buffers on oops. | 790 | [FTRACE] will dump the trace buffers on oops. |
791 | If no parameter is passed, ftrace will dump | ||
792 | buffers of all CPUs, but if you pass orig_cpu, it will | ||
793 | dump only the buffer of the CPU that triggered the | ||
794 | oops. | ||
789 | 795 | ||
790 | ftrace_filter=[function-list] | 796 | ftrace_filter=[function-list] |
791 | [FTRACE] Limit the functions traced by the function | 797 | [FTRACE] Limit the functions traced by the function |
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt index 2f9115c0ae62..61c291cddf18 100644 --- a/Documentation/kprobes.txt +++ b/Documentation/kprobes.txt | |||
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped. | |||
165 | 165 | ||
166 | 1.4 How Does Jump Optimization Work? | 166 | 1.4 How Does Jump Optimization Work? |
167 | 167 | ||
168 | If you configured your kernel with CONFIG_OPTPROBES=y (currently | 168 | If your kernel is built with CONFIG_OPTPROBES=y (currently this flag |
169 | this option is supported on x86/x86-64, non-preemptive kernel) and | 169 | is automatically set 'y' on x86/x86-64, non-preemptive kernel) and |
170 | the "debug.kprobes_optimization" kernel parameter is set to 1 (see | 170 | the "debug.kprobes_optimization" kernel parameter is set to 1 (see |
171 | sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump | 171 | sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump |
172 | instruction instead of a breakpoint instruction at each probepoint. | 172 | instruction instead of a breakpoint instruction at each probepoint. |
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization, | |||
271 | using one of the following techniques: | 271 | using one of the following techniques: |
272 | - Specify an empty function for the kprobe's post_handler or break_handler. | 272 | - Specify an empty function for the kprobe's post_handler or break_handler. |
273 | or | 273 | or |
274 | - Config CONFIG_OPTPROBES=n. | ||
275 | or | ||
276 | - Execute 'sysctl -w debug.kprobes_optimization=n' | 274 | - Execute 'sysctl -w debug.kprobes_optimization=n' |
277 | 275 | ||
278 | 2. Architectures Supported | 276 | 2. Architectures Supported |
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO), | |||
307 | so you can use "objdump -d -l vmlinux" to see the source-to-object | 305 | so you can use "objdump -d -l vmlinux" to see the source-to-object |
308 | code mapping. | 306 | code mapping. |
309 | 307 | ||
310 | If you want to reduce probing overhead, set "Kprobes jump optimization | ||
311 | support" (CONFIG_OPTPROBES) to "y". You can find this option under the | ||
312 | "Kprobes" line. | ||
313 | |||
314 | 4. API Reference | 308 | 4. API Reference |
315 | 309 | ||
316 | The Kprobes API includes a "register" function and an "unregister" | 310 | The Kprobes API includes a "register" function and an "unregister" |
diff --git a/Documentation/rbtree.txt b/Documentation/rbtree.txt index aae8355d3166..221f38be98f4 100644 --- a/Documentation/rbtree.txt +++ b/Documentation/rbtree.txt | |||
@@ -190,3 +190,61 @@ Example: | |||
190 | for (node = rb_first(&mytree); node; node = rb_next(node)) | 190 | for (node = rb_first(&mytree); node; node = rb_next(node)) |
191 | printk("key=%s\n", rb_entry(node, struct mytype, node)->keystring); | 191 | printk("key=%s\n", rb_entry(node, struct mytype, node)->keystring); |
192 | 192 | ||
193 | Support for Augmented rbtrees | ||
194 | ----------------------------- | ||
195 | |||
196 | Augmented rbtree is an rbtree with "some" additional data stored in each node. | ||
197 | This data can be used to augment some new functionality to rbtree. | ||
198 | Augmented rbtree is an optional feature built on top of basic rbtree | ||
199 | infrastructure. rbtree user who wants this feature will have an augment | ||
200 | callback function in rb_root initialized. | ||
201 | |||
202 | This callback function will be called from rbtree core routines whenever | ||
203 | a node has a change in one or both of its children. It is the responsibility | ||
204 | of the callback function to recalculate the additional data that is in the | ||
205 | rb node using new children information. Note that if this new additional | ||
206 | data affects the parent node's additional data, then callback function has | ||
207 | to handle it and do the recursive updates. | ||
208 | |||
209 | |||
210 | Interval tree is an example of augmented rb tree. Reference - | ||
211 | "Introduction to Algorithms" by Cormen, Leiserson, Rivest and Stein. | ||
212 | More details about interval trees: | ||
213 | |||
214 | Classical rbtree has a single key and it cannot be directly used to store | ||
215 | interval ranges like [lo:hi] and do a quick lookup for any overlap with a new | ||
216 | lo:hi or to find whether there is an exact match for a new lo:hi. | ||
217 | |||
218 | However, rbtree can be augmented to store such interval ranges in a structured | ||
219 | way making it possible to do efficient lookup and exact match. | ||
220 | |||
221 | This "extra information" stored in each node is the maximum hi | ||
222 | (max_hi) value among all the nodes that are its descendents. This | ||
223 | information can be maintained at each node just be looking at the node | ||
224 | and its immediate children. And this will be used in O(log n) lookup | ||
225 | for lowest match (lowest start address among all possible matches) | ||
226 | with something like: | ||
227 | |||
228 | find_lowest_match(lo, hi, node) | ||
229 | { | ||
230 | lowest_match = NULL; | ||
231 | while (node) { | ||
232 | if (max_hi(node->left) > lo) { | ||
233 | // Lowest overlap if any must be on left side | ||
234 | node = node->left; | ||
235 | } else if (overlap(lo, hi, node)) { | ||
236 | lowest_match = node; | ||
237 | break; | ||
238 | } else if (lo > node->lo) { | ||
239 | // Lowest overlap if any must be on right side | ||
240 | node = node->right; | ||
241 | } else { | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | return lowest_match; | ||
246 | } | ||
247 | |||
248 | Finding exact match will be to first find lowest match and then to follow | ||
249 | successor nodes looking for exact match, until the start of a node is beyond | ||
250 | the hi value we are looking for. | ||
diff --git a/Documentation/scheduler/sched-design-CFS.txt b/Documentation/scheduler/sched-design-CFS.txt index 6f33593e59e2..8239ebbcddce 100644 --- a/Documentation/scheduler/sched-design-CFS.txt +++ b/Documentation/scheduler/sched-design-CFS.txt | |||
@@ -211,7 +211,7 @@ provide fair CPU time to each such task group. For example, it may be | |||
211 | desirable to first provide fair CPU time to each user on the system and then to | 211 | desirable to first provide fair CPU time to each user on the system and then to |
212 | each task belonging to a user. | 212 | each task belonging to a user. |
213 | 213 | ||
214 | CONFIG_GROUP_SCHED strives to achieve exactly that. It lets tasks to be | 214 | CONFIG_CGROUP_SCHED strives to achieve exactly that. It lets tasks to be |
215 | grouped and divides CPU time fairly among such groups. | 215 | grouped and divides CPU time fairly among such groups. |
216 | 216 | ||
217 | CONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and | 217 | CONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and |
@@ -220,38 +220,11 @@ SCHED_RR) tasks. | |||
220 | CONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and | 220 | CONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and |
221 | SCHED_BATCH) tasks. | 221 | SCHED_BATCH) tasks. |
222 | 222 | ||
223 | At present, there are two (mutually exclusive) mechanisms to group tasks for | 223 | These options need CONFIG_CGROUPS to be defined, and let the administrator |
224 | CPU bandwidth control purposes: | ||
225 | |||
226 | - Based on user id (CONFIG_USER_SCHED) | ||
227 | |||
228 | With this option, tasks are grouped according to their user id. | ||
229 | |||
230 | - Based on "cgroup" pseudo filesystem (CONFIG_CGROUP_SCHED) | ||
231 | |||
232 | This options needs CONFIG_CGROUPS to be defined, and lets the administrator | ||
233 | create arbitrary groups of tasks, using the "cgroup" pseudo filesystem. See | 224 | create arbitrary groups of tasks, using the "cgroup" pseudo filesystem. See |
234 | Documentation/cgroups/cgroups.txt for more information about this filesystem. | 225 | Documentation/cgroups/cgroups.txt for more information about this filesystem. |
235 | 226 | ||
236 | Only one of these options to group tasks can be chosen and not both. | 227 | When CONFIG_FAIR_GROUP_SCHED is defined, a "cpu.shares" file is created for each |
237 | |||
238 | When CONFIG_USER_SCHED is defined, a directory is created in sysfs for each new | ||
239 | user and a "cpu_share" file is added in that directory. | ||
240 | |||
241 | # cd /sys/kernel/uids | ||
242 | # cat 512/cpu_share # Display user 512's CPU share | ||
243 | 1024 | ||
244 | # echo 2048 > 512/cpu_share # Modify user 512's CPU share | ||
245 | # cat 512/cpu_share # Display user 512's CPU share | ||
246 | 2048 | ||
247 | # | ||
248 | |||
249 | CPU bandwidth between two users is divided in the ratio of their CPU shares. | ||
250 | For example: if you would like user "root" to get twice the bandwidth of user | ||
251 | "guest," then set the cpu_share for both the users such that "root"'s cpu_share | ||
252 | is twice "guest"'s cpu_share. | ||
253 | |||
254 | When CONFIG_CGROUP_SCHED is defined, a "cpu.shares" file is created for each | ||
255 | group created using the pseudo filesystem. See example steps below to create | 228 | group created using the pseudo filesystem. See example steps below to create |
256 | task groups and modify their CPU share using the "cgroups" pseudo filesystem. | 229 | task groups and modify their CPU share using the "cgroups" pseudo filesystem. |
257 | 230 | ||
@@ -273,24 +246,3 @@ task groups and modify their CPU share using the "cgroups" pseudo filesystem. | |||
273 | 246 | ||
274 | # #Launch gmplayer (or your favourite movie player) | 247 | # #Launch gmplayer (or your favourite movie player) |
275 | # echo <movie_player_pid> > multimedia/tasks | 248 | # echo <movie_player_pid> > multimedia/tasks |
276 | |||
277 | 8. Implementation note: user namespaces | ||
278 | |||
279 | User namespaces are intended to be hierarchical. But they are currently | ||
280 | only partially implemented. Each of those has ramifications for CFS. | ||
281 | |||
282 | First, since user namespaces are hierarchical, the /sys/kernel/uids | ||
283 | presentation is inadequate. Eventually we will likely want to use sysfs | ||
284 | tagging to provide private views of /sys/kernel/uids within each user | ||
285 | namespace. | ||
286 | |||
287 | Second, the hierarchical nature is intended to support completely | ||
288 | unprivileged use of user namespaces. So if using user groups, then | ||
289 | we want the users in a user namespace to be children of the user | ||
290 | who created it. | ||
291 | |||
292 | That is currently unimplemented. So instead, every user in a new | ||
293 | user namespace will receive 1024 shares just like any user in the | ||
294 | initial user namespace. Note that at the moment creation of a new | ||
295 | user namespace requires each of CAP_SYS_ADMIN, CAP_SETUID, and | ||
296 | CAP_SETGID. | ||
diff --git a/Documentation/scheduler/sched-rt-group.txt b/Documentation/scheduler/sched-rt-group.txt index 86eabe6c3419..605b0d40329d 100644 --- a/Documentation/scheduler/sched-rt-group.txt +++ b/Documentation/scheduler/sched-rt-group.txt | |||
@@ -126,23 +126,12 @@ priority! | |||
126 | 2.3 Basis for grouping tasks | 126 | 2.3 Basis for grouping tasks |
127 | ---------------------------- | 127 | ---------------------------- |
128 | 128 | ||
129 | There are two compile-time settings for allocating CPU bandwidth. These are | 129 | Enabling CONFIG_RT_GROUP_SCHED lets you explicitly allocate real |
130 | configured using the "Basis for grouping tasks" multiple choice menu under | 130 | CPU bandwidth to task groups. |
131 | General setup > Group CPU Scheduler: | ||
132 | |||
133 | a. CONFIG_USER_SCHED (aka "Basis for grouping tasks" = "user id") | ||
134 | |||
135 | This lets you use the virtual files under | ||
136 | "/sys/kernel/uids/<uid>/cpu_rt_runtime_us" to control he CPU time reserved for | ||
137 | each user . | ||
138 | |||
139 | The other option is: | ||
140 | |||
141 | .o CONFIG_CGROUP_SCHED (aka "Basis for grouping tasks" = "Control groups") | ||
142 | 131 | ||
143 | This uses the /cgroup virtual file system and | 132 | This uses the /cgroup virtual file system and |
144 | "/cgroup/<cgroup>/cpu.rt_runtime_us" to control the CPU time reserved for each | 133 | "/cgroup/<cgroup>/cpu.rt_runtime_us" to control the CPU time reserved for each |
145 | control group instead. | 134 | control group. |
146 | 135 | ||
147 | For more information on working with control groups, you should read | 136 | For more information on working with control groups, you should read |
148 | Documentation/cgroups/cgroups.txt as well. | 137 | Documentation/cgroups/cgroups.txt as well. |
@@ -161,8 +150,7 @@ For now, this can be simplified to just the following (but see Future plans): | |||
161 | =============== | 150 | =============== |
162 | 151 | ||
163 | There is work in progress to make the scheduling period for each group | 152 | There is work in progress to make the scheduling period for each group |
164 | ("/sys/kernel/uids/<uid>/cpu_rt_period_us" or | 153 | ("/cgroup/<cgroup>/cpu.rt_period_us") configurable as well. |
165 | "/cgroup/<cgroup>/cpu.rt_period_us" respectively) configurable as well. | ||
166 | 154 | ||
167 | The constraint on the period is that a subgroup must have a smaller or | 155 | The constraint on the period is that a subgroup must have a smaller or |
168 | equal period to its parent. But realistically its not very useful _yet_ | 156 | equal period to its parent. But realistically its not very useful _yet_ |
diff --git a/Documentation/trace/events.txt b/Documentation/trace/events.txt index 02ac6ed38b2d..778ddf38b82c 100644 --- a/Documentation/trace/events.txt +++ b/Documentation/trace/events.txt | |||
@@ -90,7 +90,8 @@ In order to facilitate early boot debugging, use boot option: | |||
90 | 90 | ||
91 | trace_event=[event-list] | 91 | trace_event=[event-list] |
92 | 92 | ||
93 | The format of this boot option is the same as described in section 2.1. | 93 | event-list is a comma separated list of events. See section 2.1 for event |
94 | format. | ||
94 | 95 | ||
95 | 3. Defining an event-enabled tracepoint | 96 | 3. Defining an event-enabled tracepoint |
96 | ======================================= | 97 | ======================================= |
diff --git a/Documentation/trace/ftrace.txt b/Documentation/trace/ftrace.txt index 03485bfbd797..557c1edeccaf 100644 --- a/Documentation/trace/ftrace.txt +++ b/Documentation/trace/ftrace.txt | |||
@@ -155,6 +155,9 @@ of ftrace. Here is a list of some of the key files: | |||
155 | to be traced. Echoing names of functions into this file | 155 | to be traced. Echoing names of functions into this file |
156 | will limit the trace to only those functions. | 156 | will limit the trace to only those functions. |
157 | 157 | ||
158 | This interface also allows for commands to be used. See the | ||
159 | "Filter commands" section for more details. | ||
160 | |||
158 | set_ftrace_notrace: | 161 | set_ftrace_notrace: |
159 | 162 | ||
160 | This has an effect opposite to that of | 163 | This has an effect opposite to that of |
@@ -1337,12 +1340,14 @@ ftrace_dump_on_oops must be set. To set ftrace_dump_on_oops, one | |||
1337 | can either use the sysctl function or set it via the proc system | 1340 | can either use the sysctl function or set it via the proc system |
1338 | interface. | 1341 | interface. |
1339 | 1342 | ||
1340 | sysctl kernel.ftrace_dump_on_oops=1 | 1343 | sysctl kernel.ftrace_dump_on_oops=n |
1341 | 1344 | ||
1342 | or | 1345 | or |
1343 | 1346 | ||
1344 | echo 1 > /proc/sys/kernel/ftrace_dump_on_oops | 1347 | echo n > /proc/sys/kernel/ftrace_dump_on_oops |
1345 | 1348 | ||
1349 | If n = 1, ftrace will dump buffers of all CPUs, if n = 2 ftrace will | ||
1350 | only dump the buffer of the CPU that triggered the oops. | ||
1346 | 1351 | ||
1347 | Here's an example of such a dump after a null pointer | 1352 | Here's an example of such a dump after a null pointer |
1348 | dereference in a kernel module: | 1353 | dereference in a kernel module: |
@@ -1822,6 +1827,47 @@ this special filter via: | |||
1822 | echo > set_graph_function | 1827 | echo > set_graph_function |
1823 | 1828 | ||
1824 | 1829 | ||
1830 | Filter commands | ||
1831 | --------------- | ||
1832 | |||
1833 | A few commands are supported by the set_ftrace_filter interface. | ||
1834 | Trace commands have the following format: | ||
1835 | |||
1836 | <function>:<command>:<parameter> | ||
1837 | |||
1838 | The following commands are supported: | ||
1839 | |||
1840 | - mod | ||
1841 | This command enables function filtering per module. The | ||
1842 | parameter defines the module. For example, if only the write* | ||
1843 | functions in the ext3 module are desired, run: | ||
1844 | |||
1845 | echo 'write*:mod:ext3' > set_ftrace_filter | ||
1846 | |||
1847 | This command interacts with the filter in the same way as | ||
1848 | filtering based on function names. Thus, adding more functions | ||
1849 | in a different module is accomplished by appending (>>) to the | ||
1850 | filter file. Remove specific module functions by prepending | ||
1851 | '!': | ||
1852 | |||
1853 | echo '!writeback*:mod:ext3' >> set_ftrace_filter | ||
1854 | |||
1855 | - traceon/traceoff | ||
1856 | These commands turn tracing on and off when the specified | ||
1857 | functions are hit. The parameter determines how many times the | ||
1858 | tracing system is turned on and off. If unspecified, there is | ||
1859 | no limit. For example, to disable tracing when a schedule bug | ||
1860 | is hit the first 5 times, run: | ||
1861 | |||
1862 | echo '__schedule_bug:traceoff:5' > set_ftrace_filter | ||
1863 | |||
1864 | These commands are cumulative whether or not they are appended | ||
1865 | to set_ftrace_filter. To remove a command, prepend it by '!' | ||
1866 | and drop the parameter: | ||
1867 | |||
1868 | echo '!__schedule_bug:traceoff' > set_ftrace_filter | ||
1869 | |||
1870 | |||
1825 | trace_pipe | 1871 | trace_pipe |
1826 | ---------- | 1872 | ---------- |
1827 | 1873 | ||
diff --git a/Documentation/trace/kprobetrace.txt b/Documentation/trace/kprobetrace.txt index a9100b28eb84..ec94748ae65b 100644 --- a/Documentation/trace/kprobetrace.txt +++ b/Documentation/trace/kprobetrace.txt | |||
@@ -40,7 +40,9 @@ Synopsis of kprobe_events | |||
40 | $stack : Fetch stack address. | 40 | $stack : Fetch stack address. |
41 | $retval : Fetch return value.(*) | 41 | $retval : Fetch return value.(*) |
42 | +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) | 42 | +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) |
43 | NAME=FETCHARG: Set NAME as the argument name of FETCHARG. | 43 | NAME=FETCHARG : Set NAME as the argument name of FETCHARG. |
44 | FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types | ||
45 | (u8/u16/u32/u64/s8/s16/s32/s64) are supported. | ||
44 | 46 | ||
45 | (*) only for return probe. | 47 | (*) only for return probe. |
46 | (**) this is useful for fetching a field of data structures. | 48 | (**) this is useful for fetching a field of data structures. |
diff --git a/MAINTAINERS b/MAINTAINERS index 9372c742c3bc..b375bf9f4e2c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -2954,6 +2954,17 @@ S: Odd Fixes | |||
2954 | F: Documentation/networking/README.ipw2200 | 2954 | F: Documentation/networking/README.ipw2200 |
2955 | F: drivers/net/wireless/ipw2x00/ipw2200.* | 2955 | F: drivers/net/wireless/ipw2x00/ipw2200.* |
2956 | 2956 | ||
2957 | INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT) | ||
2958 | M: Joseph Cihula <joseph.cihula@intel.com> | ||
2959 | M: Shane Wang <shane.wang@intel.com> | ||
2960 | L: tboot-devel@lists.sourceforge.net | ||
2961 | W: http://tboot.sourceforge.net | ||
2962 | T: Mercurial http://www.bughost.org/repos.hg/tboot.hg | ||
2963 | S: Supported | ||
2964 | F: Documentation/intel_txt.txt | ||
2965 | F: include/linux/tboot.h | ||
2966 | F: arch/x86/kernel/tboot.c | ||
2967 | |||
2957 | INTEL WIRELESS WIMAX CONNECTION 2400 | 2968 | INTEL WIRELESS WIMAX CONNECTION 2400 |
2958 | M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> | 2969 | M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
2959 | M: linux-wimax@intel.com | 2970 | M: linux-wimax@intel.com |
@@ -4165,6 +4176,7 @@ OPROFILE | |||
4165 | M: Robert Richter <robert.richter@amd.com> | 4176 | M: Robert Richter <robert.richter@amd.com> |
4166 | L: oprofile-list@lists.sf.net | 4177 | L: oprofile-list@lists.sf.net |
4167 | S: Maintained | 4178 | S: Maintained |
4179 | F: arch/*/include/asm/oprofile*.h | ||
4168 | F: arch/*/oprofile/ | 4180 | F: arch/*/oprofile/ |
4169 | F: drivers/oprofile/ | 4181 | F: drivers/oprofile/ |
4170 | F: include/linux/oprofile.h | 4182 | F: include/linux/oprofile.h |
@@ -4353,13 +4365,13 @@ M: Paul Mackerras <paulus@samba.org> | |||
4353 | M: Ingo Molnar <mingo@elte.hu> | 4365 | M: Ingo Molnar <mingo@elte.hu> |
4354 | M: Arnaldo Carvalho de Melo <acme@redhat.com> | 4366 | M: Arnaldo Carvalho de Melo <acme@redhat.com> |
4355 | S: Supported | 4367 | S: Supported |
4356 | F: kernel/perf_event.c | 4368 | F: kernel/perf_event*.c |
4357 | F: include/linux/perf_event.h | 4369 | F: include/linux/perf_event.h |
4358 | F: arch/*/kernel/perf_event.c | 4370 | F: arch/*/kernel/perf_event*.c |
4359 | F: arch/*/kernel/*/perf_event.c | 4371 | F: arch/*/kernel/*/perf_event*.c |
4360 | F: arch/*/kernel/*/*/perf_event.c | 4372 | F: arch/*/kernel/*/*/perf_event*.c |
4361 | F: arch/*/include/asm/perf_event.h | 4373 | F: arch/*/include/asm/perf_event.h |
4362 | F: arch/*/lib/perf_event.c | 4374 | F: arch/*/lib/perf_event*.c |
4363 | F: arch/*/kernel/perf_callchain.c | 4375 | F: arch/*/kernel/perf_callchain.c |
4364 | F: tools/perf/ | 4376 | F: tools/perf/ |
4365 | 4377 | ||
@@ -5493,7 +5505,7 @@ S: Maintained | |||
5493 | F: drivers/mmc/host/tmio_mmc.* | 5505 | F: drivers/mmc/host/tmio_mmc.* |
5494 | 5506 | ||
5495 | TMPFS (SHMEM FILESYSTEM) | 5507 | TMPFS (SHMEM FILESYSTEM) |
5496 | M: Hugh Dickins <hugh.dickins@tiscali.co.uk> | 5508 | M: Hugh Dickins <hughd@google.com> |
5497 | L: linux-mm@kvack.org | 5509 | L: linux-mm@kvack.org |
5498 | S: Maintained | 5510 | S: Maintained |
5499 | F: include/linux/shmem_fs.h | 5511 | F: include/linux/shmem_fs.h |
@@ -1,7 +1,7 @@ | |||
1 | VERSION = 2 | 1 | VERSION = 2 |
2 | PATCHLEVEL = 6 | 2 | PATCHLEVEL = 6 |
3 | SUBLEVEL = 34 | 3 | SUBLEVEL = 34 |
4 | EXTRAVERSION = -rc7 | 4 | EXTRAVERSION = |
5 | NAME = Sheep on Meth | 5 | NAME = Sheep on Meth |
6 | 6 | ||
7 | # *DOCUMENTATION* | 7 | # *DOCUMENTATION* |
diff --git a/arch/Kconfig b/arch/Kconfig index e5eb1337a537..acda512da2e2 100644 --- a/arch/Kconfig +++ b/arch/Kconfig | |||
@@ -42,15 +42,10 @@ config KPROBES | |||
42 | If in doubt, say "N". | 42 | If in doubt, say "N". |
43 | 43 | ||
44 | config OPTPROBES | 44 | config OPTPROBES |
45 | bool "Kprobes jump optimization support (EXPERIMENTAL)" | 45 | def_bool y |
46 | default y | 46 | depends on KPROBES && HAVE_OPTPROBES |
47 | depends on KPROBES | ||
48 | depends on !PREEMPT | 47 | depends on !PREEMPT |
49 | depends on HAVE_OPTPROBES | ||
50 | select KALLSYMS_ALL | 48 | select KALLSYMS_ALL |
51 | help | ||
52 | This option will allow kprobes to optimize breakpoint to | ||
53 | a jump for reducing its overhead. | ||
54 | 49 | ||
55 | config HAVE_EFFICIENT_UNALIGNED_ACCESS | 50 | config HAVE_EFFICIENT_UNALIGNED_ACCESS |
56 | bool | 51 | bool |
@@ -142,6 +137,17 @@ config HAVE_HW_BREAKPOINT | |||
142 | bool | 137 | bool |
143 | depends on PERF_EVENTS | 138 | depends on PERF_EVENTS |
144 | 139 | ||
140 | config HAVE_MIXED_BREAKPOINTS_REGS | ||
141 | bool | ||
142 | depends on HAVE_HW_BREAKPOINT | ||
143 | help | ||
144 | Depending on the arch implementation of hardware breakpoints, | ||
145 | some of them have separate registers for data and instruction | ||
146 | breakpoints addresses, others have mixed registers to store | ||
147 | them but define the access type in a control register. | ||
148 | Select this option if your arch implements breakpoints under the | ||
149 | latter fashion. | ||
150 | |||
145 | config HAVE_USER_RETURN_NOTIFIER | 151 | config HAVE_USER_RETURN_NOTIFIER |
146 | bool | 152 | bool |
147 | 153 | ||
diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h index 610dff44d94b..e756d04b6cd5 100644 --- a/arch/alpha/include/asm/atomic.h +++ b/arch/alpha/include/asm/atomic.h | |||
@@ -17,8 +17,8 @@ | |||
17 | #define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) | 17 | #define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) |
18 | #define ATOMIC64_INIT(i) ( (atomic64_t) { (i) } ) | 18 | #define ATOMIC64_INIT(i) ( (atomic64_t) { (i) } ) |
19 | 19 | ||
20 | #define atomic_read(v) ((v)->counter + 0) | 20 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
21 | #define atomic64_read(v) ((v)->counter + 0) | 21 | #define atomic64_read(v) (*(volatile long *)&(v)->counter) |
22 | 22 | ||
23 | #define atomic_set(v,i) ((v)->counter = (i)) | 23 | #define atomic_set(v,i) ((v)->counter = (i)) |
24 | #define atomic64_set(v,i) ((v)->counter = (i)) | 24 | #define atomic64_set(v,i) ((v)->counter = (i)) |
diff --git a/arch/alpha/include/asm/bitops.h b/arch/alpha/include/asm/bitops.h index 15f3ae25c511..296da1d5ed57 100644 --- a/arch/alpha/include/asm/bitops.h +++ b/arch/alpha/include/asm/bitops.h | |||
@@ -405,29 +405,31 @@ static inline int fls(int x) | |||
405 | 405 | ||
406 | #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67) | 406 | #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67) |
407 | /* Whee. EV67 can calculate it directly. */ | 407 | /* Whee. EV67 can calculate it directly. */ |
408 | static inline unsigned long hweight64(unsigned long w) | 408 | static inline unsigned long __arch_hweight64(unsigned long w) |
409 | { | 409 | { |
410 | return __kernel_ctpop(w); | 410 | return __kernel_ctpop(w); |
411 | } | 411 | } |
412 | 412 | ||
413 | static inline unsigned int hweight32(unsigned int w) | 413 | static inline unsigned int __arch_weight32(unsigned int w) |
414 | { | 414 | { |
415 | return hweight64(w); | 415 | return __arch_hweight64(w); |
416 | } | 416 | } |
417 | 417 | ||
418 | static inline unsigned int hweight16(unsigned int w) | 418 | static inline unsigned int __arch_hweight16(unsigned int w) |
419 | { | 419 | { |
420 | return hweight64(w & 0xffff); | 420 | return __arch_hweight64(w & 0xffff); |
421 | } | 421 | } |
422 | 422 | ||
423 | static inline unsigned int hweight8(unsigned int w) | 423 | static inline unsigned int __arch_hweight8(unsigned int w) |
424 | { | 424 | { |
425 | return hweight64(w & 0xff); | 425 | return __arch_hweight64(w & 0xff); |
426 | } | 426 | } |
427 | #else | 427 | #else |
428 | #include <asm-generic/bitops/hweight.h> | 428 | #include <asm-generic/bitops/arch_hweight.h> |
429 | #endif | 429 | #endif |
430 | 430 | ||
431 | #include <asm-generic/bitops/const_hweight.h> | ||
432 | |||
431 | #endif /* __KERNEL__ */ | 433 | #endif /* __KERNEL__ */ |
432 | 434 | ||
433 | #include <asm-generic/bitops/find.h> | 435 | #include <asm-generic/bitops/find.h> |
diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h index e8ddec2cb158..a0162fa94564 100644 --- a/arch/arm/include/asm/atomic.h +++ b/arch/arm/include/asm/atomic.h | |||
@@ -24,7 +24,7 @@ | |||
24 | * strex/ldrex monitor on some implementations. The reason we can use it for | 24 | * strex/ldrex monitor on some implementations. The reason we can use it for |
25 | * atomic_set() is the clrex or dummy strex done on every exception return. | 25 | * atomic_set() is the clrex or dummy strex done on every exception return. |
26 | */ | 26 | */ |
27 | #define atomic_read(v) ((v)->counter) | 27 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
28 | #define atomic_set(v,i) (((v)->counter) = (i)) | 28 | #define atomic_set(v,i) (((v)->counter) = (i)) |
29 | 29 | ||
30 | #if __LINUX_ARM_ARCH__ >= 6 | 30 | #if __LINUX_ARM_ARCH__ >= 6 |
diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h index 0d08d4170b64..4656a24058d2 100644 --- a/arch/arm/include/asm/cacheflush.h +++ b/arch/arm/include/asm/cacheflush.h | |||
@@ -371,6 +371,10 @@ static inline void __flush_icache_all(void) | |||
371 | #ifdef CONFIG_ARM_ERRATA_411920 | 371 | #ifdef CONFIG_ARM_ERRATA_411920 |
372 | extern void v6_icache_inval_all(void); | 372 | extern void v6_icache_inval_all(void); |
373 | v6_icache_inval_all(); | 373 | v6_icache_inval_all(); |
374 | #elif defined(CONFIG_SMP) && __LINUX_ARM_ARCH__ >= 7 | ||
375 | asm("mcr p15, 0, %0, c7, c1, 0 @ invalidate I-cache inner shareable\n" | ||
376 | : | ||
377 | : "r" (0)); | ||
374 | #else | 378 | #else |
375 | asm("mcr p15, 0, %0, c7, c5, 0 @ invalidate I-cache\n" | 379 | asm("mcr p15, 0, %0, c7, c5, 0 @ invalidate I-cache\n" |
376 | : | 380 | : |
diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h index 7be0978b2625..634f357be6bb 100644 --- a/arch/arm/include/asm/smp_twd.h +++ b/arch/arm/include/asm/smp_twd.h | |||
@@ -1,6 +1,23 @@ | |||
1 | #ifndef __ASMARM_SMP_TWD_H | 1 | #ifndef __ASMARM_SMP_TWD_H |
2 | #define __ASMARM_SMP_TWD_H | 2 | #define __ASMARM_SMP_TWD_H |
3 | 3 | ||
4 | #define TWD_TIMER_LOAD 0x00 | ||
5 | #define TWD_TIMER_COUNTER 0x04 | ||
6 | #define TWD_TIMER_CONTROL 0x08 | ||
7 | #define TWD_TIMER_INTSTAT 0x0C | ||
8 | |||
9 | #define TWD_WDOG_LOAD 0x20 | ||
10 | #define TWD_WDOG_COUNTER 0x24 | ||
11 | #define TWD_WDOG_CONTROL 0x28 | ||
12 | #define TWD_WDOG_INTSTAT 0x2C | ||
13 | #define TWD_WDOG_RESETSTAT 0x30 | ||
14 | #define TWD_WDOG_DISABLE 0x34 | ||
15 | |||
16 | #define TWD_TIMER_CONTROL_ENABLE (1 << 0) | ||
17 | #define TWD_TIMER_CONTROL_ONESHOT (0 << 1) | ||
18 | #define TWD_TIMER_CONTROL_PERIODIC (1 << 1) | ||
19 | #define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2) | ||
20 | |||
4 | struct clock_event_device; | 21 | struct clock_event_device; |
5 | 22 | ||
6 | extern void __iomem *twd_base; | 23 | extern void __iomem *twd_base; |
diff --git a/arch/arm/include/asm/tlbflush.h b/arch/arm/include/asm/tlbflush.h index e085e2c545eb..bd863d8608cd 100644 --- a/arch/arm/include/asm/tlbflush.h +++ b/arch/arm/include/asm/tlbflush.h | |||
@@ -46,6 +46,9 @@ | |||
46 | #define TLB_V7_UIS_FULL (1 << 20) | 46 | #define TLB_V7_UIS_FULL (1 << 20) |
47 | #define TLB_V7_UIS_ASID (1 << 21) | 47 | #define TLB_V7_UIS_ASID (1 << 21) |
48 | 48 | ||
49 | /* Inner Shareable BTB operation (ARMv7 MP extensions) */ | ||
50 | #define TLB_V7_IS_BTB (1 << 22) | ||
51 | |||
49 | #define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */ | 52 | #define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */ |
50 | #define TLB_DCLEAN (1 << 30) | 53 | #define TLB_DCLEAN (1 << 30) |
51 | #define TLB_WB (1 << 31) | 54 | #define TLB_WB (1 << 31) |
@@ -183,7 +186,7 @@ | |||
183 | #endif | 186 | #endif |
184 | 187 | ||
185 | #ifdef CONFIG_SMP | 188 | #ifdef CONFIG_SMP |
186 | #define v7wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BTB | \ | 189 | #define v7wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_V7_IS_BTB | \ |
187 | TLB_V7_UIS_FULL | TLB_V7_UIS_PAGE | TLB_V7_UIS_ASID) | 190 | TLB_V7_UIS_FULL | TLB_V7_UIS_PAGE | TLB_V7_UIS_ASID) |
188 | #else | 191 | #else |
189 | #define v7wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BTB | \ | 192 | #define v7wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BTB | \ |
@@ -339,6 +342,12 @@ static inline void local_flush_tlb_all(void) | |||
339 | dsb(); | 342 | dsb(); |
340 | isb(); | 343 | isb(); |
341 | } | 344 | } |
345 | if (tlb_flag(TLB_V7_IS_BTB)) { | ||
346 | /* flush the branch target cache */ | ||
347 | asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero) : "cc"); | ||
348 | dsb(); | ||
349 | isb(); | ||
350 | } | ||
342 | } | 351 | } |
343 | 352 | ||
344 | static inline void local_flush_tlb_mm(struct mm_struct *mm) | 353 | static inline void local_flush_tlb_mm(struct mm_struct *mm) |
@@ -376,6 +385,12 @@ static inline void local_flush_tlb_mm(struct mm_struct *mm) | |||
376 | asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc"); | 385 | asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc"); |
377 | dsb(); | 386 | dsb(); |
378 | } | 387 | } |
388 | if (tlb_flag(TLB_V7_IS_BTB)) { | ||
389 | /* flush the branch target cache */ | ||
390 | asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero) : "cc"); | ||
391 | dsb(); | ||
392 | isb(); | ||
393 | } | ||
379 | } | 394 | } |
380 | 395 | ||
381 | static inline void | 396 | static inline void |
@@ -416,6 +431,12 @@ local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) | |||
416 | asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc"); | 431 | asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc"); |
417 | dsb(); | 432 | dsb(); |
418 | } | 433 | } |
434 | if (tlb_flag(TLB_V7_IS_BTB)) { | ||
435 | /* flush the branch target cache */ | ||
436 | asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero) : "cc"); | ||
437 | dsb(); | ||
438 | isb(); | ||
439 | } | ||
419 | } | 440 | } |
420 | 441 | ||
421 | static inline void local_flush_tlb_kernel_page(unsigned long kaddr) | 442 | static inline void local_flush_tlb_kernel_page(unsigned long kaddr) |
@@ -454,6 +475,12 @@ static inline void local_flush_tlb_kernel_page(unsigned long kaddr) | |||
454 | dsb(); | 475 | dsb(); |
455 | isb(); | 476 | isb(); |
456 | } | 477 | } |
478 | if (tlb_flag(TLB_V7_IS_BTB)) { | ||
479 | /* flush the branch target cache */ | ||
480 | asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero) : "cc"); | ||
481 | dsb(); | ||
482 | isb(); | ||
483 | } | ||
457 | } | 484 | } |
458 | 485 | ||
459 | /* | 486 | /* |
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index ea02a7b1c244..7c5f0c024db7 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c | |||
@@ -21,23 +21,6 @@ | |||
21 | #include <asm/smp_twd.h> | 21 | #include <asm/smp_twd.h> |
22 | #include <asm/hardware/gic.h> | 22 | #include <asm/hardware/gic.h> |
23 | 23 | ||
24 | #define TWD_TIMER_LOAD 0x00 | ||
25 | #define TWD_TIMER_COUNTER 0x04 | ||
26 | #define TWD_TIMER_CONTROL 0x08 | ||
27 | #define TWD_TIMER_INTSTAT 0x0C | ||
28 | |||
29 | #define TWD_WDOG_LOAD 0x20 | ||
30 | #define TWD_WDOG_COUNTER 0x24 | ||
31 | #define TWD_WDOG_CONTROL 0x28 | ||
32 | #define TWD_WDOG_INTSTAT 0x2C | ||
33 | #define TWD_WDOG_RESETSTAT 0x30 | ||
34 | #define TWD_WDOG_DISABLE 0x34 | ||
35 | |||
36 | #define TWD_TIMER_CONTROL_ENABLE (1 << 0) | ||
37 | #define TWD_TIMER_CONTROL_ONESHOT (0 << 1) | ||
38 | #define TWD_TIMER_CONTROL_PERIODIC (1 << 1) | ||
39 | #define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2) | ||
40 | |||
41 | /* set up by the platform code */ | 24 | /* set up by the platform code */ |
42 | void __iomem *twd_base; | 25 | void __iomem *twd_base; |
43 | 26 | ||
diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S index 5e3f99620c04..14a0d988c82c 100644 --- a/arch/arm/lib/clear_user.S +++ b/arch/arm/lib/clear_user.S | |||
@@ -45,6 +45,7 @@ USER( strnebt r2, [r0]) | |||
45 | mov r0, #0 | 45 | mov r0, #0 |
46 | ldmfd sp!, {r1, pc} | 46 | ldmfd sp!, {r1, pc} |
47 | ENDPROC(__clear_user) | 47 | ENDPROC(__clear_user) |
48 | ENDPROC(__clear_user_std) | ||
48 | 49 | ||
49 | .pushsection .fixup,"ax" | 50 | .pushsection .fixup,"ax" |
50 | .align 0 | 51 | .align 0 |
diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S index 027b69bdbad1..d066df686e17 100644 --- a/arch/arm/lib/copy_to_user.S +++ b/arch/arm/lib/copy_to_user.S | |||
@@ -93,6 +93,7 @@ WEAK(__copy_to_user) | |||
93 | #include "copy_template.S" | 93 | #include "copy_template.S" |
94 | 94 | ||
95 | ENDPROC(__copy_to_user) | 95 | ENDPROC(__copy_to_user) |
96 | ENDPROC(__copy_to_user_std) | ||
96 | 97 | ||
97 | .pushsection .fixup,"ax" | 98 | .pushsection .fixup,"ax" |
98 | .align 0 | 99 | .align 0 |
diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c index 122e61a9f505..e8cb982f5e8e 100644 --- a/arch/arm/mach-davinci/da830.c +++ b/arch/arm/mach-davinci/da830.c | |||
@@ -410,7 +410,7 @@ static struct clk_lookup da830_clks[] = { | |||
410 | CLK("davinci-mcasp.0", NULL, &mcasp0_clk), | 410 | CLK("davinci-mcasp.0", NULL, &mcasp0_clk), |
411 | CLK("davinci-mcasp.1", NULL, &mcasp1_clk), | 411 | CLK("davinci-mcasp.1", NULL, &mcasp1_clk), |
412 | CLK("davinci-mcasp.2", NULL, &mcasp2_clk), | 412 | CLK("davinci-mcasp.2", NULL, &mcasp2_clk), |
413 | CLK("musb_hdrc", NULL, &usb20_clk), | 413 | CLK(NULL, "usb20", &usb20_clk), |
414 | CLK(NULL, "aemif", &aemif_clk), | 414 | CLK(NULL, "aemif", &aemif_clk), |
415 | CLK(NULL, "aintc", &aintc_clk), | 415 | CLK(NULL, "aintc", &aintc_clk), |
416 | CLK(NULL, "secu_mgr", &secu_mgr_clk), | 416 | CLK(NULL, "secu_mgr", &secu_mgr_clk), |
diff --git a/arch/arm/mm/cache-v6.S b/arch/arm/mm/cache-v6.S index 9d89c67a1cc3..e46ecd847138 100644 --- a/arch/arm/mm/cache-v6.S +++ b/arch/arm/mm/cache-v6.S | |||
@@ -211,6 +211,9 @@ v6_dma_inv_range: | |||
211 | mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line | 211 | mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line |
212 | #endif | 212 | #endif |
213 | 1: | 213 | 1: |
214 | #ifdef CONFIG_SMP | ||
215 | str r0, [r0] @ write for ownership | ||
216 | #endif | ||
214 | #ifdef HARVARD_CACHE | 217 | #ifdef HARVARD_CACHE |
215 | mcr p15, 0, r0, c7, c6, 1 @ invalidate D line | 218 | mcr p15, 0, r0, c7, c6, 1 @ invalidate D line |
216 | #else | 219 | #else |
@@ -231,6 +234,9 @@ v6_dma_inv_range: | |||
231 | v6_dma_clean_range: | 234 | v6_dma_clean_range: |
232 | bic r0, r0, #D_CACHE_LINE_SIZE - 1 | 235 | bic r0, r0, #D_CACHE_LINE_SIZE - 1 |
233 | 1: | 236 | 1: |
237 | #ifdef CONFIG_SMP | ||
238 | ldr r2, [r0] @ read for ownership | ||
239 | #endif | ||
234 | #ifdef HARVARD_CACHE | 240 | #ifdef HARVARD_CACHE |
235 | mcr p15, 0, r0, c7, c10, 1 @ clean D line | 241 | mcr p15, 0, r0, c7, c10, 1 @ clean D line |
236 | #else | 242 | #else |
@@ -251,6 +257,10 @@ v6_dma_clean_range: | |||
251 | ENTRY(v6_dma_flush_range) | 257 | ENTRY(v6_dma_flush_range) |
252 | bic r0, r0, #D_CACHE_LINE_SIZE - 1 | 258 | bic r0, r0, #D_CACHE_LINE_SIZE - 1 |
253 | 1: | 259 | 1: |
260 | #ifdef CONFIG_SMP | ||
261 | ldr r2, [r0] @ read for ownership | ||
262 | str r2, [r0] @ write for ownership | ||
263 | #endif | ||
254 | #ifdef HARVARD_CACHE | 264 | #ifdef HARVARD_CACHE |
255 | mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line | 265 | mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line |
256 | #else | 266 | #else |
@@ -273,7 +283,9 @@ ENTRY(v6_dma_map_area) | |||
273 | add r1, r1, r0 | 283 | add r1, r1, r0 |
274 | teq r2, #DMA_FROM_DEVICE | 284 | teq r2, #DMA_FROM_DEVICE |
275 | beq v6_dma_inv_range | 285 | beq v6_dma_inv_range |
276 | b v6_dma_clean_range | 286 | teq r2, #DMA_TO_DEVICE |
287 | beq v6_dma_clean_range | ||
288 | b v6_dma_flush_range | ||
277 | ENDPROC(v6_dma_map_area) | 289 | ENDPROC(v6_dma_map_area) |
278 | 290 | ||
279 | /* | 291 | /* |
@@ -283,9 +295,6 @@ ENDPROC(v6_dma_map_area) | |||
283 | * - dir - DMA direction | 295 | * - dir - DMA direction |
284 | */ | 296 | */ |
285 | ENTRY(v6_dma_unmap_area) | 297 | ENTRY(v6_dma_unmap_area) |
286 | add r1, r1, r0 | ||
287 | teq r2, #DMA_TO_DEVICE | ||
288 | bne v6_dma_inv_range | ||
289 | mov pc, lr | 298 | mov pc, lr |
290 | ENDPROC(v6_dma_unmap_area) | 299 | ENDPROC(v6_dma_unmap_area) |
291 | 300 | ||
diff --git a/arch/arm/mm/cache-v7.S b/arch/arm/mm/cache-v7.S index bcd64f265870..06a90dcfc60a 100644 --- a/arch/arm/mm/cache-v7.S +++ b/arch/arm/mm/cache-v7.S | |||
@@ -167,7 +167,11 @@ ENTRY(v7_coherent_user_range) | |||
167 | cmp r0, r1 | 167 | cmp r0, r1 |
168 | blo 1b | 168 | blo 1b |
169 | mov r0, #0 | 169 | mov r0, #0 |
170 | #ifdef CONFIG_SMP | ||
171 | mcr p15, 0, r0, c7, c1, 6 @ invalidate BTB Inner Shareable | ||
172 | #else | ||
170 | mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB | 173 | mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB |
174 | #endif | ||
171 | dsb | 175 | dsb |
172 | isb | 176 | isb |
173 | mov pc, lr | 177 | mov pc, lr |
diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index 9bfeb6b9509a..33b327379f07 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c | |||
@@ -65,6 +65,15 @@ void flush_dcache_page(struct page *page) | |||
65 | } | 65 | } |
66 | EXPORT_SYMBOL(flush_dcache_page); | 66 | EXPORT_SYMBOL(flush_dcache_page); |
67 | 67 | ||
68 | void copy_to_user_page(struct vm_area_struct *vma, struct page *page, | ||
69 | unsigned long uaddr, void *dst, const void *src, | ||
70 | unsigned long len) | ||
71 | { | ||
72 | memcpy(dst, src, len); | ||
73 | if (vma->vm_flags & VM_EXEC) | ||
74 | __cpuc_coherent_user_range(uaddr, uaddr + len); | ||
75 | } | ||
76 | |||
68 | void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset, | 77 | void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset, |
69 | size_t size, unsigned int mtype) | 78 | size_t size, unsigned int mtype) |
70 | { | 79 | { |
@@ -87,8 +96,8 @@ void __iomem *__arm_ioremap(unsigned long phys_addr, size_t size, | |||
87 | } | 96 | } |
88 | EXPORT_SYMBOL(__arm_ioremap); | 97 | EXPORT_SYMBOL(__arm_ioremap); |
89 | 98 | ||
90 | void __iomem *__arm_ioremap(unsigned long phys_addr, size_t size, | 99 | void __iomem *__arm_ioremap_caller(unsigned long phys_addr, size_t size, |
91 | unsigned int mtype, void *caller) | 100 | unsigned int mtype, void *caller) |
92 | { | 101 | { |
93 | return __arm_ioremap(phys_addr, size, mtype); | 102 | return __arm_ioremap(phys_addr, size, mtype); |
94 | } | 103 | } |
diff --git a/arch/arm/mm/tlb-v7.S b/arch/arm/mm/tlb-v7.S index 0cb1848bd876..f3f288a9546d 100644 --- a/arch/arm/mm/tlb-v7.S +++ b/arch/arm/mm/tlb-v7.S | |||
@@ -50,7 +50,11 @@ ENTRY(v7wbi_flush_user_tlb_range) | |||
50 | cmp r0, r1 | 50 | cmp r0, r1 |
51 | blo 1b | 51 | blo 1b |
52 | mov ip, #0 | 52 | mov ip, #0 |
53 | #ifdef CONFIG_SMP | ||
54 | mcr p15, 0, ip, c7, c1, 6 @ flush BTAC/BTB Inner Shareable | ||
55 | #else | ||
53 | mcr p15, 0, ip, c7, c5, 6 @ flush BTAC/BTB | 56 | mcr p15, 0, ip, c7, c5, 6 @ flush BTAC/BTB |
57 | #endif | ||
54 | dsb | 58 | dsb |
55 | mov pc, lr | 59 | mov pc, lr |
56 | ENDPROC(v7wbi_flush_user_tlb_range) | 60 | ENDPROC(v7wbi_flush_user_tlb_range) |
@@ -79,7 +83,11 @@ ENTRY(v7wbi_flush_kern_tlb_range) | |||
79 | cmp r0, r1 | 83 | cmp r0, r1 |
80 | blo 1b | 84 | blo 1b |
81 | mov r2, #0 | 85 | mov r2, #0 |
86 | #ifdef CONFIG_SMP | ||
87 | mcr p15, 0, r2, c7, c1, 6 @ flush BTAC/BTB Inner Shareable | ||
88 | #else | ||
82 | mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB | 89 | mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB |
90 | #endif | ||
83 | dsb | 91 | dsb |
84 | isb | 92 | isb |
85 | mov pc, lr | 93 | mov pc, lr |
diff --git a/arch/avr32/include/asm/atomic.h b/arch/avr32/include/asm/atomic.h index b131c27ddf57..bbce6a1c6bb6 100644 --- a/arch/avr32/include/asm/atomic.h +++ b/arch/avr32/include/asm/atomic.h | |||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | #define ATOMIC_INIT(i) { (i) } | 20 | #define ATOMIC_INIT(i) { (i) } |
21 | 21 | ||
22 | #define atomic_read(v) ((v)->counter) | 22 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
23 | #define atomic_set(v, i) (((v)->counter) = i) | 23 | #define atomic_set(v, i) (((v)->counter) = i) |
24 | 24 | ||
25 | /* | 25 | /* |
diff --git a/arch/cris/include/asm/atomic.h b/arch/cris/include/asm/atomic.h index a6aca819e9f3..88dc9b9c4ba0 100644 --- a/arch/cris/include/asm/atomic.h +++ b/arch/cris/include/asm/atomic.h | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #define ATOMIC_INIT(i) { (i) } | 16 | #define ATOMIC_INIT(i) { (i) } |
17 | 17 | ||
18 | #define atomic_read(v) ((v)->counter) | 18 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
19 | #define atomic_set(v,i) (((v)->counter) = (i)) | 19 | #define atomic_set(v,i) (((v)->counter) = (i)) |
20 | 20 | ||
21 | /* These should be written in asm but we do it in C for now. */ | 21 | /* These should be written in asm but we do it in C for now. */ |
diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h index 00a57af79afc..fae32c7fdcb6 100644 --- a/arch/frv/include/asm/atomic.h +++ b/arch/frv/include/asm/atomic.h | |||
@@ -36,7 +36,7 @@ | |||
36 | #define smp_mb__after_atomic_inc() barrier() | 36 | #define smp_mb__after_atomic_inc() barrier() |
37 | 37 | ||
38 | #define ATOMIC_INIT(i) { (i) } | 38 | #define ATOMIC_INIT(i) { (i) } |
39 | #define atomic_read(v) ((v)->counter) | 39 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
40 | #define atomic_set(v, i) (((v)->counter) = (i)) | 40 | #define atomic_set(v, i) (((v)->counter) = (i)) |
41 | 41 | ||
42 | #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS | 42 | #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS |
diff --git a/arch/h8300/include/asm/atomic.h b/arch/h8300/include/asm/atomic.h index 33c8c0fa9583..e936804b7508 100644 --- a/arch/h8300/include/asm/atomic.h +++ b/arch/h8300/include/asm/atomic.h | |||
@@ -10,7 +10,7 @@ | |||
10 | 10 | ||
11 | #define ATOMIC_INIT(i) { (i) } | 11 | #define ATOMIC_INIT(i) { (i) } |
12 | 12 | ||
13 | #define atomic_read(v) ((v)->counter) | 13 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
14 | #define atomic_set(v, i) (((v)->counter) = i) | 14 | #define atomic_set(v, i) (((v)->counter) = i) |
15 | 15 | ||
16 | #include <asm/system.h> | 16 | #include <asm/system.h> |
diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h index 88405cb0832a..4e1948447a00 100644 --- a/arch/ia64/include/asm/atomic.h +++ b/arch/ia64/include/asm/atomic.h | |||
@@ -21,8 +21,8 @@ | |||
21 | #define ATOMIC_INIT(i) ((atomic_t) { (i) }) | 21 | #define ATOMIC_INIT(i) ((atomic_t) { (i) }) |
22 | #define ATOMIC64_INIT(i) ((atomic64_t) { (i) }) | 22 | #define ATOMIC64_INIT(i) ((atomic64_t) { (i) }) |
23 | 23 | ||
24 | #define atomic_read(v) ((v)->counter) | 24 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
25 | #define atomic64_read(v) ((v)->counter) | 25 | #define atomic64_read(v) (*(volatile long *)&(v)->counter) |
26 | 26 | ||
27 | #define atomic_set(v,i) (((v)->counter) = (i)) | 27 | #define atomic_set(v,i) (((v)->counter) = (i)) |
28 | #define atomic64_set(v,i) (((v)->counter) = (i)) | 28 | #define atomic64_set(v,i) (((v)->counter) = (i)) |
diff --git a/arch/ia64/include/asm/bitops.h b/arch/ia64/include/asm/bitops.h index 6ebc229a1c51..9da3df6f1a52 100644 --- a/arch/ia64/include/asm/bitops.h +++ b/arch/ia64/include/asm/bitops.h | |||
@@ -437,17 +437,18 @@ __fls (unsigned long x) | |||
437 | * hweightN: returns the hamming weight (i.e. the number | 437 | * hweightN: returns the hamming weight (i.e. the number |
438 | * of bits set) of a N-bit word | 438 | * of bits set) of a N-bit word |
439 | */ | 439 | */ |
440 | static __inline__ unsigned long | 440 | static __inline__ unsigned long __arch_hweight64(unsigned long x) |
441 | hweight64 (unsigned long x) | ||
442 | { | 441 | { |
443 | unsigned long result; | 442 | unsigned long result; |
444 | result = ia64_popcnt(x); | 443 | result = ia64_popcnt(x); |
445 | return result; | 444 | return result; |
446 | } | 445 | } |
447 | 446 | ||
448 | #define hweight32(x) (unsigned int) hweight64((x) & 0xfffffffful) | 447 | #define __arch_hweight32(x) ((unsigned int) __arch_hweight64((x) & 0xfffffffful)) |
449 | #define hweight16(x) (unsigned int) hweight64((x) & 0xfffful) | 448 | #define __arch_hweight16(x) ((unsigned int) __arch_hweight64((x) & 0xfffful)) |
450 | #define hweight8(x) (unsigned int) hweight64((x) & 0xfful) | 449 | #define __arch_hweight8(x) ((unsigned int) __arch_hweight64((x) & 0xfful)) |
450 | |||
451 | #include <asm-generic/bitops/const_hweight.h> | ||
451 | 452 | ||
452 | #endif /* __KERNEL__ */ | 453 | #endif /* __KERNEL__ */ |
453 | 454 | ||
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c index 4d1a7e9314cf..c6c90f39f4d9 100644 --- a/arch/ia64/kernel/acpi.c +++ b/arch/ia64/kernel/acpi.c | |||
@@ -785,6 +785,14 @@ int acpi_gsi_to_irq(u32 gsi, unsigned int *irq) | |||
785 | return 0; | 785 | return 0; |
786 | } | 786 | } |
787 | 787 | ||
788 | int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi) | ||
789 | { | ||
790 | if (isa_irq >= 16) | ||
791 | return -1; | ||
792 | *gsi = isa_irq; | ||
793 | return 0; | ||
794 | } | ||
795 | |||
788 | /* | 796 | /* |
789 | * ACPI based hotplug CPU support | 797 | * ACPI based hotplug CPU support |
790 | */ | 798 | */ |
diff --git a/arch/m32r/include/asm/atomic.h b/arch/m32r/include/asm/atomic.h index 63f0cf0f50dd..d44a51e5271b 100644 --- a/arch/m32r/include/asm/atomic.h +++ b/arch/m32r/include/asm/atomic.h | |||
@@ -26,7 +26,7 @@ | |||
26 | * | 26 | * |
27 | * Atomically reads the value of @v. | 27 | * Atomically reads the value of @v. |
28 | */ | 28 | */ |
29 | #define atomic_read(v) ((v)->counter) | 29 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * atomic_set - set atomic variable | 32 | * atomic_set - set atomic variable |
diff --git a/arch/m68k/amiga/Makefile b/arch/m68k/amiga/Makefile index 6a0d7650f980..11dd30b16b3b 100644 --- a/arch/m68k/amiga/Makefile +++ b/arch/m68k/amiga/Makefile | |||
@@ -2,6 +2,6 @@ | |||
2 | # Makefile for Linux arch/m68k/amiga source directory | 2 | # Makefile for Linux arch/m68k/amiga source directory |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y := config.o amiints.o cia.o chipram.o amisound.o | 5 | obj-y := config.o amiints.o cia.o chipram.o amisound.o platform.o |
6 | 6 | ||
7 | obj-$(CONFIG_AMIGA_PCMCIA) += pcmcia.o | 7 | obj-$(CONFIG_AMIGA_PCMCIA) += pcmcia.o |
diff --git a/arch/m68k/amiga/platform.c b/arch/m68k/amiga/platform.c new file mode 100644 index 000000000000..38f18bf14737 --- /dev/null +++ b/arch/m68k/amiga/platform.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2009 Geert Uytterhoeven | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file COPYING in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/platform_device.h> | ||
11 | #include <linux/zorro.h> | ||
12 | |||
13 | #include <asm/amigahw.h> | ||
14 | |||
15 | |||
16 | #ifdef CONFIG_ZORRO | ||
17 | |||
18 | static const struct resource zorro_resources[] __initconst = { | ||
19 | /* Zorro II regions (on Zorro II/III) */ | ||
20 | { | ||
21 | .name = "Zorro II exp", | ||
22 | .start = 0x00e80000, | ||
23 | .end = 0x00efffff, | ||
24 | .flags = IORESOURCE_MEM, | ||
25 | }, { | ||
26 | .name = "Zorro II mem", | ||
27 | .start = 0x00200000, | ||
28 | .end = 0x009fffff, | ||
29 | .flags = IORESOURCE_MEM, | ||
30 | }, | ||
31 | /* Zorro III regions (on Zorro III only) */ | ||
32 | { | ||
33 | .name = "Zorro III exp", | ||
34 | .start = 0xff000000, | ||
35 | .end = 0xffffffff, | ||
36 | .flags = IORESOURCE_MEM, | ||
37 | }, { | ||
38 | .name = "Zorro III cfg", | ||
39 | .start = 0x40000000, | ||
40 | .end = 0x7fffffff, | ||
41 | .flags = IORESOURCE_MEM, | ||
42 | } | ||
43 | }; | ||
44 | |||
45 | |||
46 | static int __init amiga_init_bus(void) | ||
47 | { | ||
48 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) | ||
49 | return -ENODEV; | ||
50 | |||
51 | platform_device_register_simple("amiga-zorro", -1, zorro_resources, | ||
52 | AMIGAHW_PRESENT(ZORRO3) ? 4 : 2); | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | subsys_initcall(amiga_init_bus); | ||
57 | |||
58 | #endif /* CONFIG_ZORRO */ | ||
59 | |||
60 | |||
61 | static int __init amiga_init_devices(void) | ||
62 | { | ||
63 | if (!MACH_IS_AMIGA) | ||
64 | return -ENODEV; | ||
65 | |||
66 | /* video hardware */ | ||
67 | if (AMIGAHW_PRESENT(AMI_VIDEO)) | ||
68 | platform_device_register_simple("amiga-video", -1, NULL, 0); | ||
69 | |||
70 | |||
71 | /* sound hardware */ | ||
72 | if (AMIGAHW_PRESENT(AMI_AUDIO)) | ||
73 | platform_device_register_simple("amiga-audio", -1, NULL, 0); | ||
74 | |||
75 | |||
76 | /* storage interfaces */ | ||
77 | if (AMIGAHW_PRESENT(AMI_FLOPPY)) | ||
78 | platform_device_register_simple("amiga-floppy", -1, NULL, 0); | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | device_initcall(amiga_init_devices); | ||
diff --git a/arch/m68k/bvme6000/rtc.c b/arch/m68k/bvme6000/rtc.c index b46ea1714a89..cb8617bb194b 100644 --- a/arch/m68k/bvme6000/rtc.c +++ b/arch/m68k/bvme6000/rtc.c | |||
@@ -9,7 +9,6 @@ | |||
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/errno.h> | 10 | #include <linux/errno.h> |
11 | #include <linux/miscdevice.h> | 11 | #include <linux/miscdevice.h> |
12 | #include <linux/smp_lock.h> | ||
13 | #include <linux/ioport.h> | 12 | #include <linux/ioport.h> |
14 | #include <linux/capability.h> | 13 | #include <linux/capability.h> |
15 | #include <linux/fcntl.h> | 14 | #include <linux/fcntl.h> |
@@ -35,10 +34,9 @@ | |||
35 | static unsigned char days_in_mo[] = | 34 | static unsigned char days_in_mo[] = |
36 | {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 35 | {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
37 | 36 | ||
38 | static char rtc_status; | 37 | static atomic_t rtc_status = ATOMIC_INIT(1); |
39 | 38 | ||
40 | static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 39 | static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
41 | unsigned long arg) | ||
42 | { | 40 | { |
43 | volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; | 41 | volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE; |
44 | unsigned char msr; | 42 | unsigned char msr; |
@@ -132,29 +130,20 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
132 | } | 130 | } |
133 | 131 | ||
134 | /* | 132 | /* |
135 | * We enforce only one user at a time here with the open/close. | 133 | * We enforce only one user at a time here with the open/close. |
136 | * Also clear the previous interrupt data on an open, and clean | ||
137 | * up things on a close. | ||
138 | */ | 134 | */ |
139 | |||
140 | static int rtc_open(struct inode *inode, struct file *file) | 135 | static int rtc_open(struct inode *inode, struct file *file) |
141 | { | 136 | { |
142 | lock_kernel(); | 137 | if (!atomic_dec_and_test(&rtc_status)) { |
143 | if(rtc_status) { | 138 | atomic_inc(&rtc_status); |
144 | unlock_kernel(); | ||
145 | return -EBUSY; | 139 | return -EBUSY; |
146 | } | 140 | } |
147 | |||
148 | rtc_status = 1; | ||
149 | unlock_kernel(); | ||
150 | return 0; | 141 | return 0; |
151 | } | 142 | } |
152 | 143 | ||
153 | static int rtc_release(struct inode *inode, struct file *file) | 144 | static int rtc_release(struct inode *inode, struct file *file) |
154 | { | 145 | { |
155 | lock_kernel(); | 146 | atomic_inc(&rtc_status); |
156 | rtc_status = 0; | ||
157 | unlock_kernel(); | ||
158 | return 0; | 147 | return 0; |
159 | } | 148 | } |
160 | 149 | ||
@@ -163,9 +152,9 @@ static int rtc_release(struct inode *inode, struct file *file) | |||
163 | */ | 152 | */ |
164 | 153 | ||
165 | static const struct file_operations rtc_fops = { | 154 | static const struct file_operations rtc_fops = { |
166 | .ioctl = rtc_ioctl, | 155 | .unlocked_ioctl = rtc_ioctl, |
167 | .open = rtc_open, | 156 | .open = rtc_open, |
168 | .release = rtc_release, | 157 | .release = rtc_release, |
169 | }; | 158 | }; |
170 | 159 | ||
171 | static struct miscdevice rtc_dev = { | 160 | static struct miscdevice rtc_dev = { |
diff --git a/arch/m68k/hp300/time.h b/arch/m68k/hp300/time.h index f5b3d098b0f5..7b98242960de 100644 --- a/arch/m68k/hp300/time.h +++ b/arch/m68k/hp300/time.h | |||
@@ -1,4 +1,2 @@ | |||
1 | extern void hp300_sched_init(irq_handler_t vector); | 1 | extern void hp300_sched_init(irq_handler_t vector); |
2 | extern unsigned long hp300_gettimeoffset (void); | 2 | extern unsigned long hp300_gettimeoffset(void); |
3 | |||
4 | |||
diff --git a/arch/m68k/include/asm/atomic_mm.h b/arch/m68k/include/asm/atomic_mm.h index d9d2ed647435..6a223b3f7e74 100644 --- a/arch/m68k/include/asm/atomic_mm.h +++ b/arch/m68k/include/asm/atomic_mm.h | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #define ATOMIC_INIT(i) { (i) } | 16 | #define ATOMIC_INIT(i) { (i) } |
17 | 17 | ||
18 | #define atomic_read(v) ((v)->counter) | 18 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
19 | #define atomic_set(v, i) (((v)->counter) = i) | 19 | #define atomic_set(v, i) (((v)->counter) = i) |
20 | 20 | ||
21 | static inline void atomic_add(int i, atomic_t *v) | 21 | static inline void atomic_add(int i, atomic_t *v) |
diff --git a/arch/m68k/include/asm/atomic_no.h b/arch/m68k/include/asm/atomic_no.h index 5674cb9449bd..289310c63a8a 100644 --- a/arch/m68k/include/asm/atomic_no.h +++ b/arch/m68k/include/asm/atomic_no.h | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #define ATOMIC_INIT(i) { (i) } | 16 | #define ATOMIC_INIT(i) { (i) } |
17 | 17 | ||
18 | #define atomic_read(v) ((v)->counter) | 18 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
19 | #define atomic_set(v, i) (((v)->counter) = i) | 19 | #define atomic_set(v, i) (((v)->counter) = i) |
20 | 20 | ||
21 | static __inline__ void atomic_add(int i, atomic_t *v) | 21 | static __inline__ void atomic_add(int i, atomic_t *v) |
diff --git a/arch/m68k/include/asm/bitops_mm.h b/arch/m68k/include/asm/bitops_mm.h index 9bde784e7bad..b4ecdaada520 100644 --- a/arch/m68k/include/asm/bitops_mm.h +++ b/arch/m68k/include/asm/bitops_mm.h | |||
@@ -365,6 +365,10 @@ static inline int minix_test_bit(int nr, const void *vaddr) | |||
365 | #define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) | 365 | #define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) |
366 | #define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | 366 | #define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) |
367 | #define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | 367 | #define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) |
368 | #define ext2_find_next_zero_bit(addr, size, offset) \ | ||
369 | generic_find_next_zero_le_bit((unsigned long *)addr, size, offset) | ||
370 | #define ext2_find_next_bit(addr, size, offset) \ | ||
371 | generic_find_next_le_bit((unsigned long *)addr, size, offset) | ||
368 | 372 | ||
369 | static inline int ext2_test_bit(int nr, const void *vaddr) | 373 | static inline int ext2_test_bit(int nr, const void *vaddr) |
370 | { | 374 | { |
@@ -394,10 +398,9 @@ static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size) | |||
394 | return (p - addr) * 32 + res; | 398 | return (p - addr) * 32 + res; |
395 | } | 399 | } |
396 | 400 | ||
397 | static inline int ext2_find_next_zero_bit(const void *vaddr, unsigned size, | 401 | static inline unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, |
398 | unsigned offset) | 402 | unsigned long size, unsigned long offset) |
399 | { | 403 | { |
400 | const unsigned long *addr = vaddr; | ||
401 | const unsigned long *p = addr + (offset >> 5); | 404 | const unsigned long *p = addr + (offset >> 5); |
402 | int bit = offset & 31UL, res; | 405 | int bit = offset & 31UL, res; |
403 | 406 | ||
@@ -437,10 +440,9 @@ static inline int ext2_find_first_bit(const void *vaddr, unsigned size) | |||
437 | return (p - addr) * 32 + res; | 440 | return (p - addr) * 32 + res; |
438 | } | 441 | } |
439 | 442 | ||
440 | static inline int ext2_find_next_bit(const void *vaddr, unsigned size, | 443 | static inline unsigned long generic_find_next_le_bit(const unsigned long *addr, |
441 | unsigned offset) | 444 | unsigned long size, unsigned long offset) |
442 | { | 445 | { |
443 | const unsigned long *addr = vaddr; | ||
444 | const unsigned long *p = addr + (offset >> 5); | 446 | const unsigned long *p = addr + (offset >> 5); |
445 | int bit = offset & 31UL, res; | 447 | int bit = offset & 31UL, res; |
446 | 448 | ||
diff --git a/arch/m68k/include/asm/param.h b/arch/m68k/include/asm/param.h index 85c41b75aa78..36265ccf5c7b 100644 --- a/arch/m68k/include/asm/param.h +++ b/arch/m68k/include/asm/param.h | |||
@@ -1,26 +1,12 @@ | |||
1 | #ifndef _M68K_PARAM_H | 1 | #ifndef _M68K_PARAM_H |
2 | #define _M68K_PARAM_H | 2 | #define _M68K_PARAM_H |
3 | 3 | ||
4 | #ifdef __KERNEL__ | ||
5 | # define HZ CONFIG_HZ /* Internal kernel timer frequency */ | ||
6 | # define USER_HZ 100 /* .. some user interfaces are in "ticks" */ | ||
7 | # define CLOCKS_PER_SEC (USER_HZ) /* like times() */ | ||
8 | #endif | ||
9 | |||
10 | #ifndef HZ | ||
11 | #define HZ 100 | ||
12 | #endif | ||
13 | |||
14 | #ifdef __uClinux__ | 4 | #ifdef __uClinux__ |
15 | #define EXEC_PAGESIZE 4096 | 5 | #define EXEC_PAGESIZE 4096 |
16 | #else | 6 | #else |
17 | #define EXEC_PAGESIZE 8192 | 7 | #define EXEC_PAGESIZE 8192 |
18 | #endif | 8 | #endif |
19 | 9 | ||
20 | #ifndef NOGROUP | 10 | #include <asm-generic/param.h> |
21 | #define NOGROUP (-1) | ||
22 | #endif | ||
23 | |||
24 | #define MAXHOSTNAMELEN 64 /* max length of hostname */ | ||
25 | 11 | ||
26 | #endif /* _M68K_PARAM_H */ | 12 | #endif /* _M68K_PARAM_H */ |
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c index aacd6d17b833..ada4f4cca811 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c | |||
@@ -455,7 +455,7 @@ static inline void access_error040(struct frame *fp) | |||
455 | 455 | ||
456 | if (do_page_fault(&fp->ptregs, addr, errorcode)) { | 456 | if (do_page_fault(&fp->ptregs, addr, errorcode)) { |
457 | #ifdef DEBUG | 457 | #ifdef DEBUG |
458 | printk("do_page_fault() !=0 \n"); | 458 | printk("do_page_fault() !=0\n"); |
459 | #endif | 459 | #endif |
460 | if (user_mode(&fp->ptregs)){ | 460 | if (user_mode(&fp->ptregs)){ |
461 | /* delay writebacks after signal delivery */ | 461 | /* delay writebacks after signal delivery */ |
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c index 0356da9bf763..1c16b1baf8db 100644 --- a/arch/m68k/mac/config.c +++ b/arch/m68k/mac/config.c | |||
@@ -148,7 +148,7 @@ static void mac_cache_card_flush(int writeback) | |||
148 | void __init config_mac(void) | 148 | void __init config_mac(void) |
149 | { | 149 | { |
150 | if (!MACH_IS_MAC) | 150 | if (!MACH_IS_MAC) |
151 | printk(KERN_ERR "ERROR: no Mac, but config_mac() called!! \n"); | 151 | printk(KERN_ERR "ERROR: no Mac, but config_mac() called!!\n"); |
152 | 152 | ||
153 | mach_sched_init = mac_sched_init; | 153 | mach_sched_init = mac_sched_init; |
154 | mach_init_IRQ = mac_init_IRQ; | 154 | mach_init_IRQ = mac_init_IRQ; |
@@ -867,7 +867,7 @@ static void __init mac_identify(void) | |||
867 | */ | 867 | */ |
868 | iop_preinit(); | 868 | iop_preinit(); |
869 | 869 | ||
870 | printk(KERN_INFO "Detected Macintosh model: %d \n", model); | 870 | printk(KERN_INFO "Detected Macintosh model: %d\n", model); |
871 | 871 | ||
872 | /* | 872 | /* |
873 | * Report booter data: | 873 | * Report booter data: |
@@ -878,12 +878,12 @@ static void __init mac_identify(void) | |||
878 | mac_bi_data.videoaddr, mac_bi_data.videorow, | 878 | mac_bi_data.videoaddr, mac_bi_data.videorow, |
879 | mac_bi_data.videodepth, mac_bi_data.dimensions & 0xFFFF, | 879 | mac_bi_data.videodepth, mac_bi_data.dimensions & 0xFFFF, |
880 | mac_bi_data.dimensions >> 16); | 880 | mac_bi_data.dimensions >> 16); |
881 | printk(KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx \n", | 881 | printk(KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx\n", |
882 | mac_bi_data.videological, mac_orig_videoaddr, | 882 | mac_bi_data.videological, mac_orig_videoaddr, |
883 | mac_bi_data.sccbase); | 883 | mac_bi_data.sccbase); |
884 | printk(KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx \n", | 884 | printk(KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx\n", |
885 | mac_bi_data.boottime, mac_bi_data.gmtbias); | 885 | mac_bi_data.boottime, mac_bi_data.gmtbias); |
886 | printk(KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx \n", | 886 | printk(KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx\n", |
887 | mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize); | 887 | mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize); |
888 | 888 | ||
889 | iop_init(); | 889 | iop_init(); |
diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c index d0e35cf99fc6..a96394a0333d 100644 --- a/arch/m68k/mm/fault.c +++ b/arch/m68k/mm/fault.c | |||
@@ -154,7 +154,6 @@ good_area: | |||
154 | * the fault. | 154 | * the fault. |
155 | */ | 155 | */ |
156 | 156 | ||
157 | survive: | ||
158 | fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0); | 157 | fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0); |
159 | #ifdef DEBUG | 158 | #ifdef DEBUG |
160 | printk("handle_mm_fault returns %d\n",fault); | 159 | printk("handle_mm_fault returns %d\n",fault); |
@@ -180,15 +179,10 @@ good_area: | |||
180 | */ | 179 | */ |
181 | out_of_memory: | 180 | out_of_memory: |
182 | up_read(&mm->mmap_sem); | 181 | up_read(&mm->mmap_sem); |
183 | if (is_global_init(current)) { | 182 | if (!user_mode(regs)) |
184 | yield(); | 183 | goto no_context; |
185 | down_read(&mm->mmap_sem); | 184 | pagefault_out_of_memory(); |
186 | goto survive; | 185 | return 0; |
187 | } | ||
188 | |||
189 | printk("VM: killing process %s\n", current->comm); | ||
190 | if (user_mode(regs)) | ||
191 | do_group_exit(SIGKILL); | ||
192 | 186 | ||
193 | no_context: | 187 | no_context: |
194 | current->thread.signo = SIGBUS; | 188 | current->thread.signo = SIGBUS; |
diff --git a/arch/m68k/mvme16x/rtc.c b/arch/m68k/mvme16x/rtc.c index 8da9c250d3e1..11ac6f63967a 100644 --- a/arch/m68k/mvme16x/rtc.c +++ b/arch/m68k/mvme16x/rtc.c | |||
@@ -9,7 +9,6 @@ | |||
9 | #include <linux/types.h> | 9 | #include <linux/types.h> |
10 | #include <linux/errno.h> | 10 | #include <linux/errno.h> |
11 | #include <linux/miscdevice.h> | 11 | #include <linux/miscdevice.h> |
12 | #include <linux/smp_lock.h> | ||
13 | #include <linux/ioport.h> | 12 | #include <linux/ioport.h> |
14 | #include <linux/capability.h> | 13 | #include <linux/capability.h> |
15 | #include <linux/fcntl.h> | 14 | #include <linux/fcntl.h> |
@@ -36,8 +35,7 @@ static const unsigned char days_in_mo[] = | |||
36 | 35 | ||
37 | static atomic_t rtc_ready = ATOMIC_INIT(1); | 36 | static atomic_t rtc_ready = ATOMIC_INIT(1); |
38 | 37 | ||
39 | static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 38 | static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
40 | unsigned long arg) | ||
41 | { | 39 | { |
42 | volatile MK48T08ptr_t rtc = (MK48T08ptr_t)MVME_RTC_BASE; | 40 | volatile MK48T08ptr_t rtc = (MK48T08ptr_t)MVME_RTC_BASE; |
43 | unsigned long flags; | 41 | unsigned long flags; |
@@ -120,22 +118,15 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
120 | } | 118 | } |
121 | 119 | ||
122 | /* | 120 | /* |
123 | * We enforce only one user at a time here with the open/close. | 121 | * We enforce only one user at a time here with the open/close. |
124 | * Also clear the previous interrupt data on an open, and clean | ||
125 | * up things on a close. | ||
126 | */ | 122 | */ |
127 | |||
128 | static int rtc_open(struct inode *inode, struct file *file) | 123 | static int rtc_open(struct inode *inode, struct file *file) |
129 | { | 124 | { |
130 | lock_kernel(); | ||
131 | if( !atomic_dec_and_test(&rtc_ready) ) | 125 | if( !atomic_dec_and_test(&rtc_ready) ) |
132 | { | 126 | { |
133 | atomic_inc( &rtc_ready ); | 127 | atomic_inc( &rtc_ready ); |
134 | unlock_kernel(); | ||
135 | return -EBUSY; | 128 | return -EBUSY; |
136 | } | 129 | } |
137 | unlock_kernel(); | ||
138 | |||
139 | return 0; | 130 | return 0; |
140 | } | 131 | } |
141 | 132 | ||
@@ -150,9 +141,9 @@ static int rtc_release(struct inode *inode, struct file *file) | |||
150 | */ | 141 | */ |
151 | 142 | ||
152 | static const struct file_operations rtc_fops = { | 143 | static const struct file_operations rtc_fops = { |
153 | .ioctl = rtc_ioctl, | 144 | .unlocked_ioctl = rtc_ioctl, |
154 | .open = rtc_open, | 145 | .open = rtc_open, |
155 | .release = rtc_release, | 146 | .release = rtc_release, |
156 | }; | 147 | }; |
157 | 148 | ||
158 | static struct miscdevice rtc_dev= | 149 | static struct miscdevice rtc_dev= |
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c index 31ab3f08bbda..ad10fecec2fe 100644 --- a/arch/m68k/q40/config.c +++ b/arch/m68k/q40/config.c | |||
@@ -126,7 +126,7 @@ static void q40_reset(void) | |||
126 | { | 126 | { |
127 | halted = 1; | 127 | halted = 1; |
128 | printk("\n\n*******************************************\n" | 128 | printk("\n\n*******************************************\n" |
129 | "Called q40_reset : press the RESET button!! \n" | 129 | "Called q40_reset : press the RESET button!!\n" |
130 | "*******************************************\n"); | 130 | "*******************************************\n"); |
131 | Q40_LED_ON(); | 131 | Q40_LED_ON(); |
132 | while (1) | 132 | while (1) |
diff --git a/arch/microblaze/include/asm/uaccess.h b/arch/microblaze/include/asm/uaccess.h index 446bec29b142..26460d15b338 100644 --- a/arch/microblaze/include/asm/uaccess.h +++ b/arch/microblaze/include/asm/uaccess.h | |||
@@ -182,6 +182,39 @@ extern long __user_bad(void); | |||
182 | * Returns zero on success, or -EFAULT on error. | 182 | * Returns zero on success, or -EFAULT on error. |
183 | * On error, the variable @x is set to zero. | 183 | * On error, the variable @x is set to zero. |
184 | */ | 184 | */ |
185 | #define get_user(x, ptr) \ | ||
186 | __get_user_check((x), (ptr), sizeof(*(ptr))) | ||
187 | |||
188 | #define __get_user_check(x, ptr, size) \ | ||
189 | ({ \ | ||
190 | unsigned long __gu_val = 0; \ | ||
191 | const typeof(*(ptr)) __user *__gu_addr = (ptr); \ | ||
192 | int __gu_err = 0; \ | ||
193 | \ | ||
194 | if (access_ok(VERIFY_READ, __gu_addr, size)) { \ | ||
195 | switch (size) { \ | ||
196 | case 1: \ | ||
197 | __get_user_asm("lbu", __gu_addr, __gu_val, \ | ||
198 | __gu_err); \ | ||
199 | break; \ | ||
200 | case 2: \ | ||
201 | __get_user_asm("lhu", __gu_addr, __gu_val, \ | ||
202 | __gu_err); \ | ||
203 | break; \ | ||
204 | case 4: \ | ||
205 | __get_user_asm("lw", __gu_addr, __gu_val, \ | ||
206 | __gu_err); \ | ||
207 | break; \ | ||
208 | default: \ | ||
209 | __gu_err = __user_bad(); \ | ||
210 | break; \ | ||
211 | } \ | ||
212 | } else { \ | ||
213 | __gu_err = -EFAULT; \ | ||
214 | } \ | ||
215 | x = (typeof(*(ptr)))__gu_val; \ | ||
216 | __gu_err; \ | ||
217 | }) | ||
185 | 218 | ||
186 | #define __get_user(x, ptr) \ | 219 | #define __get_user(x, ptr) \ |
187 | ({ \ | 220 | ({ \ |
@@ -206,12 +239,6 @@ extern long __user_bad(void); | |||
206 | }) | 239 | }) |
207 | 240 | ||
208 | 241 | ||
209 | #define get_user(x, ptr) \ | ||
210 | ({ \ | ||
211 | access_ok(VERIFY_READ, (ptr), sizeof(*(ptr))) \ | ||
212 | ? __get_user((x), (ptr)) : -EFAULT; \ | ||
213 | }) | ||
214 | |||
215 | #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ | 242 | #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ |
216 | ({ \ | 243 | ({ \ |
217 | __asm__ __volatile__ ( \ | 244 | __asm__ __volatile__ ( \ |
@@ -266,6 +293,42 @@ extern long __user_bad(void); | |||
266 | * | 293 | * |
267 | * Returns zero on success, or -EFAULT on error. | 294 | * Returns zero on success, or -EFAULT on error. |
268 | */ | 295 | */ |
296 | #define put_user(x, ptr) \ | ||
297 | __put_user_check((x), (ptr), sizeof(*(ptr))) | ||
298 | |||
299 | #define __put_user_check(x, ptr, size) \ | ||
300 | ({ \ | ||
301 | typeof(*(ptr)) __pu_val; \ | ||
302 | typeof(*(ptr)) __user *__pu_addr = (ptr); \ | ||
303 | int __pu_err = 0; \ | ||
304 | \ | ||
305 | __pu_val = (x); \ | ||
306 | if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \ | ||
307 | switch (size) { \ | ||
308 | case 1: \ | ||
309 | __put_user_asm("sb", __pu_addr, __pu_val, \ | ||
310 | __pu_err); \ | ||
311 | break; \ | ||
312 | case 2: \ | ||
313 | __put_user_asm("sh", __pu_addr, __pu_val, \ | ||
314 | __pu_err); \ | ||
315 | break; \ | ||
316 | case 4: \ | ||
317 | __put_user_asm("sw", __pu_addr, __pu_val, \ | ||
318 | __pu_err); \ | ||
319 | break; \ | ||
320 | case 8: \ | ||
321 | __put_user_asm_8(__pu_addr, __pu_val, __pu_err);\ | ||
322 | break; \ | ||
323 | default: \ | ||
324 | __pu_err = __user_bad(); \ | ||
325 | break; \ | ||
326 | } \ | ||
327 | } else { \ | ||
328 | __pu_err = -EFAULT; \ | ||
329 | } \ | ||
330 | __pu_err; \ | ||
331 | }) | ||
269 | 332 | ||
270 | #define __put_user(x, ptr) \ | 333 | #define __put_user(x, ptr) \ |
271 | ({ \ | 334 | ({ \ |
@@ -290,18 +353,6 @@ extern long __user_bad(void); | |||
290 | __gu_err; \ | 353 | __gu_err; \ |
291 | }) | 354 | }) |
292 | 355 | ||
293 | #ifndef CONFIG_MMU | ||
294 | |||
295 | #define put_user(x, ptr) __put_user((x), (ptr)) | ||
296 | |||
297 | #else /* CONFIG_MMU */ | ||
298 | |||
299 | #define put_user(x, ptr) \ | ||
300 | ({ \ | ||
301 | access_ok(VERIFY_WRITE, (ptr), sizeof(*(ptr))) \ | ||
302 | ? __put_user((x), (ptr)) : -EFAULT; \ | ||
303 | }) | ||
304 | #endif /* CONFIG_MMU */ | ||
305 | 356 | ||
306 | /* copy_to_from_user */ | 357 | /* copy_to_from_user */ |
307 | #define __copy_from_user(to, from, n) \ | 358 | #define __copy_from_user(to, from, n) \ |
diff --git a/arch/microblaze/kernel/cpu/cache.c b/arch/microblaze/kernel/cpu/cache.c index 21c3a92394de..109876e8d643 100644 --- a/arch/microblaze/kernel/cpu/cache.c +++ b/arch/microblaze/kernel/cpu/cache.c | |||
@@ -137,8 +137,9 @@ do { \ | |||
137 | do { \ | 137 | do { \ |
138 | int step = -line_length; \ | 138 | int step = -line_length; \ |
139 | int align = ~(line_length - 1); \ | 139 | int align = ~(line_length - 1); \ |
140 | int count; \ | ||
140 | end = ((end & align) == end) ? end - line_length : end & align; \ | 141 | end = ((end & align) == end) ? end - line_length : end & align; \ |
141 | int count = end - start; \ | 142 | count = end - start; \ |
142 | WARN_ON(count < 0); \ | 143 | WARN_ON(count < 0); \ |
143 | \ | 144 | \ |
144 | __asm__ __volatile__ (" 1: " #op " %0, %1; \ | 145 | __asm__ __volatile__ (" 1: " #op " %0, %1; \ |
diff --git a/arch/microblaze/kernel/entry-nommu.S b/arch/microblaze/kernel/entry-nommu.S index 391d6197fc3b..8cc18cd2cce6 100644 --- a/arch/microblaze/kernel/entry-nommu.S +++ b/arch/microblaze/kernel/entry-nommu.S | |||
@@ -476,6 +476,8 @@ ENTRY(ret_from_fork) | |||
476 | nop | 476 | nop |
477 | 477 | ||
478 | work_pending: | 478 | work_pending: |
479 | enable_irq | ||
480 | |||
479 | andi r11, r19, _TIF_NEED_RESCHED | 481 | andi r11, r19, _TIF_NEED_RESCHED |
480 | beqi r11, 1f | 482 | beqi r11, 1f |
481 | bralid r15, schedule | 483 | bralid r15, schedule |
diff --git a/arch/microblaze/kernel/microblaze_ksyms.c b/arch/microblaze/kernel/microblaze_ksyms.c index bc4dcb7d3861..ff85f7718035 100644 --- a/arch/microblaze/kernel/microblaze_ksyms.c +++ b/arch/microblaze/kernel/microblaze_ksyms.c | |||
@@ -52,3 +52,14 @@ EXPORT_SYMBOL_GPL(_ebss); | |||
52 | extern void _mcount(void); | 52 | extern void _mcount(void); |
53 | EXPORT_SYMBOL(_mcount); | 53 | EXPORT_SYMBOL(_mcount); |
54 | #endif | 54 | #endif |
55 | |||
56 | /* | ||
57 | * Assembly functions that may be used (directly or indirectly) by modules | ||
58 | */ | ||
59 | EXPORT_SYMBOL(__copy_tofrom_user); | ||
60 | EXPORT_SYMBOL(__strncpy_user); | ||
61 | |||
62 | #ifdef CONFIG_OPT_LIB_ASM | ||
63 | EXPORT_SYMBOL(memcpy); | ||
64 | EXPORT_SYMBOL(memmove); | ||
65 | #endif | ||
diff --git a/arch/microblaze/kernel/module.c b/arch/microblaze/kernel/module.c index cbecf110dc30..0e73f6606547 100644 --- a/arch/microblaze/kernel/module.c +++ b/arch/microblaze/kernel/module.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | 17 | ||
18 | #include <asm/pgtable.h> | 18 | #include <asm/pgtable.h> |
19 | #include <asm/cacheflush.h> | ||
19 | 20 | ||
20 | void *module_alloc(unsigned long size) | 21 | void *module_alloc(unsigned long size) |
21 | { | 22 | { |
@@ -151,6 +152,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, | |||
151 | int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs, | 152 | int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs, |
152 | struct module *module) | 153 | struct module *module) |
153 | { | 154 | { |
155 | flush_dcache(); | ||
154 | return 0; | 156 | return 0; |
155 | } | 157 | } |
156 | 158 | ||
diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c index f42c2dde8b1c..cca3579d4268 100644 --- a/arch/microblaze/mm/init.c +++ b/arch/microblaze/mm/init.c | |||
@@ -47,6 +47,7 @@ unsigned long memory_start; | |||
47 | EXPORT_SYMBOL(memory_start); | 47 | EXPORT_SYMBOL(memory_start); |
48 | unsigned long memory_end; /* due to mm/nommu.c */ | 48 | unsigned long memory_end; /* due to mm/nommu.c */ |
49 | unsigned long memory_size; | 49 | unsigned long memory_size; |
50 | EXPORT_SYMBOL(memory_size); | ||
50 | 51 | ||
51 | /* | 52 | /* |
52 | * paging_init() sets up the page tables - in fact we've already done this. | 53 | * paging_init() sets up the page tables - in fact we've already done this. |
diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c index 784557fb28cf..59bf2335a4ce 100644 --- a/arch/microblaze/mm/pgtable.c +++ b/arch/microblaze/mm/pgtable.c | |||
@@ -42,6 +42,7 @@ | |||
42 | 42 | ||
43 | unsigned long ioremap_base; | 43 | unsigned long ioremap_base; |
44 | unsigned long ioremap_bot; | 44 | unsigned long ioremap_bot; |
45 | EXPORT_SYMBOL(ioremap_bot); | ||
45 | 46 | ||
46 | /* The maximum lowmem defaults to 768Mb, but this can be configured to | 47 | /* The maximum lowmem defaults to 768Mb, but this can be configured to |
47 | * another value. | 48 | * another value. |
diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index 01c8c97c15b7..9cb782b8e036 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c | |||
@@ -1507,7 +1507,7 @@ void pcibios_finish_adding_to_bus(struct pci_bus *bus) | |||
1507 | pci_bus_add_devices(bus); | 1507 | pci_bus_add_devices(bus); |
1508 | 1508 | ||
1509 | /* Fixup EEH */ | 1509 | /* Fixup EEH */ |
1510 | eeh_add_device_tree_late(bus); | 1510 | /* eeh_add_device_tree_late(bus); */ |
1511 | } | 1511 | } |
1512 | EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus); | 1512 | EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus); |
1513 | 1513 | ||
diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h index 519197ede089..59dc0c7ef733 100644 --- a/arch/mips/include/asm/atomic.h +++ b/arch/mips/include/asm/atomic.h | |||
@@ -29,7 +29,7 @@ | |||
29 | * | 29 | * |
30 | * Atomically reads the value of @v. | 30 | * Atomically reads the value of @v. |
31 | */ | 31 | */ |
32 | #define atomic_read(v) ((v)->counter) | 32 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
33 | 33 | ||
34 | /* | 34 | /* |
35 | * atomic_set - set atomic variable | 35 | * atomic_set - set atomic variable |
@@ -410,7 +410,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u) | |||
410 | * @v: pointer of type atomic64_t | 410 | * @v: pointer of type atomic64_t |
411 | * | 411 | * |
412 | */ | 412 | */ |
413 | #define atomic64_read(v) ((v)->counter) | 413 | #define atomic64_read(v) (*(volatile long *)&(v)->counter) |
414 | 414 | ||
415 | /* | 415 | /* |
416 | * atomic64_set - set atomic variable | 416 | * atomic64_set - set atomic variable |
diff --git a/arch/mips/include/asm/i8253.h b/arch/mips/include/asm/i8253.h index 032ca73f181b..48bb82372994 100644 --- a/arch/mips/include/asm/i8253.h +++ b/arch/mips/include/asm/i8253.h | |||
@@ -12,7 +12,7 @@ | |||
12 | #define PIT_CH0 0x40 | 12 | #define PIT_CH0 0x40 |
13 | #define PIT_CH2 0x42 | 13 | #define PIT_CH2 0x42 |
14 | 14 | ||
15 | extern spinlock_t i8253_lock; | 15 | extern raw_spinlock_t i8253_lock; |
16 | 16 | ||
17 | extern void setup_pit_timer(void); | 17 | extern void setup_pit_timer(void); |
18 | 18 | ||
diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h index 49382d5e891a..c6e3c93ce7c7 100644 --- a/arch/mips/include/asm/mipsregs.h +++ b/arch/mips/include/asm/mipsregs.h | |||
@@ -135,6 +135,12 @@ | |||
135 | #define FPU_CSR_COND7 0x80000000 /* $fcc7 */ | 135 | #define FPU_CSR_COND7 0x80000000 /* $fcc7 */ |
136 | 136 | ||
137 | /* | 137 | /* |
138 | * Bits 18 - 20 of the FPU Status Register will be read as 0, | ||
139 | * and should be written as zero. | ||
140 | */ | ||
141 | #define FPU_CSR_RSVD 0x001c0000 | ||
142 | |||
143 | /* | ||
138 | * X the exception cause indicator | 144 | * X the exception cause indicator |
139 | * E the exception enable | 145 | * E the exception enable |
140 | * S the sticky/flag bit | 146 | * S the sticky/flag bit |
@@ -161,7 +167,8 @@ | |||
161 | #define FPU_CSR_UDF_S 0x00000008 | 167 | #define FPU_CSR_UDF_S 0x00000008 |
162 | #define FPU_CSR_INE_S 0x00000004 | 168 | #define FPU_CSR_INE_S 0x00000004 |
163 | 169 | ||
164 | /* rounding mode */ | 170 | /* Bits 0 and 1 of FPU Status Register specify the rounding mode */ |
171 | #define FPU_CSR_RM 0x00000003 | ||
165 | #define FPU_CSR_RN 0x0 /* nearest */ | 172 | #define FPU_CSR_RN 0x0 /* nearest */ |
166 | #define FPU_CSR_RZ 0x1 /* towards zero */ | 173 | #define FPU_CSR_RZ 0x1 /* towards zero */ |
167 | #define FPU_CSR_RU 0x2 /* towards +Infinity */ | 174 | #define FPU_CSR_RU 0x2 /* towards +Infinity */ |
diff --git a/arch/mips/kernel/i8253.c b/arch/mips/kernel/i8253.c index ed5c441615e4..94794062a177 100644 --- a/arch/mips/kernel/i8253.c +++ b/arch/mips/kernel/i8253.c | |||
@@ -15,7 +15,7 @@ | |||
15 | #include <asm/io.h> | 15 | #include <asm/io.h> |
16 | #include <asm/time.h> | 16 | #include <asm/time.h> |
17 | 17 | ||
18 | DEFINE_SPINLOCK(i8253_lock); | 18 | DEFINE_RAW_SPINLOCK(i8253_lock); |
19 | EXPORT_SYMBOL(i8253_lock); | 19 | EXPORT_SYMBOL(i8253_lock); |
20 | 20 | ||
21 | /* | 21 | /* |
@@ -26,7 +26,7 @@ EXPORT_SYMBOL(i8253_lock); | |||
26 | static void init_pit_timer(enum clock_event_mode mode, | 26 | static void init_pit_timer(enum clock_event_mode mode, |
27 | struct clock_event_device *evt) | 27 | struct clock_event_device *evt) |
28 | { | 28 | { |
29 | spin_lock(&i8253_lock); | 29 | raw_spin_lock(&i8253_lock); |
30 | 30 | ||
31 | switch(mode) { | 31 | switch(mode) { |
32 | case CLOCK_EVT_MODE_PERIODIC: | 32 | case CLOCK_EVT_MODE_PERIODIC: |
@@ -55,7 +55,7 @@ static void init_pit_timer(enum clock_event_mode mode, | |||
55 | /* Nothing to do here */ | 55 | /* Nothing to do here */ |
56 | break; | 56 | break; |
57 | } | 57 | } |
58 | spin_unlock(&i8253_lock); | 58 | raw_spin_unlock(&i8253_lock); |
59 | } | 59 | } |
60 | 60 | ||
61 | /* | 61 | /* |
@@ -65,10 +65,10 @@ static void init_pit_timer(enum clock_event_mode mode, | |||
65 | */ | 65 | */ |
66 | static int pit_next_event(unsigned long delta, struct clock_event_device *evt) | 66 | static int pit_next_event(unsigned long delta, struct clock_event_device *evt) |
67 | { | 67 | { |
68 | spin_lock(&i8253_lock); | 68 | raw_spin_lock(&i8253_lock); |
69 | outb_p(delta & 0xff , PIT_CH0); /* LSB */ | 69 | outb_p(delta & 0xff , PIT_CH0); /* LSB */ |
70 | outb(delta >> 8 , PIT_CH0); /* MSB */ | 70 | outb(delta >> 8 , PIT_CH0); /* MSB */ |
71 | spin_unlock(&i8253_lock); | 71 | raw_spin_unlock(&i8253_lock); |
72 | 72 | ||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
@@ -137,7 +137,7 @@ static cycle_t pit_read(struct clocksource *cs) | |||
137 | static int old_count; | 137 | static int old_count; |
138 | static u32 old_jifs; | 138 | static u32 old_jifs; |
139 | 139 | ||
140 | spin_lock_irqsave(&i8253_lock, flags); | 140 | raw_spin_lock_irqsave(&i8253_lock, flags); |
141 | /* | 141 | /* |
142 | * Although our caller may have the read side of xtime_lock, | 142 | * Although our caller may have the read side of xtime_lock, |
143 | * this is now a seqlock, and we are cheating in this routine | 143 | * this is now a seqlock, and we are cheating in this routine |
@@ -183,7 +183,7 @@ static cycle_t pit_read(struct clocksource *cs) | |||
183 | old_count = count; | 183 | old_count = count; |
184 | old_jifs = jifs; | 184 | old_jifs = jifs; |
185 | 185 | ||
186 | spin_unlock_irqrestore(&i8253_lock, flags); | 186 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
187 | 187 | ||
188 | count = (LATCH - 1) - count; | 188 | count = (LATCH - 1) - count; |
189 | 189 | ||
diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S index 44337ba03717..a5297e2a353a 100644 --- a/arch/mips/kernel/scall64-n32.S +++ b/arch/mips/kernel/scall64-n32.S | |||
@@ -385,7 +385,7 @@ EXPORT(sysn32_call_table) | |||
385 | PTR sys_fchmodat | 385 | PTR sys_fchmodat |
386 | PTR sys_faccessat | 386 | PTR sys_faccessat |
387 | PTR compat_sys_pselect6 | 387 | PTR compat_sys_pselect6 |
388 | PTR sys_ppoll /* 6265 */ | 388 | PTR compat_sys_ppoll /* 6265 */ |
389 | PTR sys_unshare | 389 | PTR sys_unshare |
390 | PTR sys_splice | 390 | PTR sys_splice |
391 | PTR sys_sync_file_range | 391 | PTR sys_sync_file_range |
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c index 8f2f8e9d8b21..f2338d1c0b48 100644 --- a/arch/mips/math-emu/cp1emu.c +++ b/arch/mips/math-emu/cp1emu.c | |||
@@ -78,6 +78,9 @@ DEFINE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats); | |||
78 | #define FPCREG_RID 0 /* $0 = revision id */ | 78 | #define FPCREG_RID 0 /* $0 = revision id */ |
79 | #define FPCREG_CSR 31 /* $31 = csr */ | 79 | #define FPCREG_CSR 31 /* $31 = csr */ |
80 | 80 | ||
81 | /* Determine rounding mode from the RM bits of the FCSR */ | ||
82 | #define modeindex(v) ((v) & FPU_CSR_RM) | ||
83 | |||
81 | /* Convert Mips rounding mode (0..3) to IEEE library modes. */ | 84 | /* Convert Mips rounding mode (0..3) to IEEE library modes. */ |
82 | static const unsigned char ieee_rm[4] = { | 85 | static const unsigned char ieee_rm[4] = { |
83 | [FPU_CSR_RN] = IEEE754_RN, | 86 | [FPU_CSR_RN] = IEEE754_RN, |
@@ -384,10 +387,14 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx) | |||
384 | (void *) (xcp->cp0_epc), | 387 | (void *) (xcp->cp0_epc), |
385 | MIPSInst_RT(ir), value); | 388 | MIPSInst_RT(ir), value); |
386 | #endif | 389 | #endif |
387 | value &= (FPU_CSR_FLUSH | FPU_CSR_ALL_E | FPU_CSR_ALL_S | 0x03); | 390 | |
388 | ctx->fcr31 &= ~(FPU_CSR_FLUSH | FPU_CSR_ALL_E | FPU_CSR_ALL_S | 0x03); | 391 | /* |
389 | /* convert to ieee library modes */ | 392 | * Don't write reserved bits, |
390 | ctx->fcr31 |= (value & ~0x3) | ieee_rm[value & 0x3]; | 393 | * and convert to ieee library modes |
394 | */ | ||
395 | ctx->fcr31 = (value & | ||
396 | ~(FPU_CSR_RSVD | FPU_CSR_RM)) | | ||
397 | ieee_rm[modeindex(value)]; | ||
391 | } | 398 | } |
392 | if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) { | 399 | if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) { |
393 | return SIGFPE; | 400 | return SIGFPE; |
diff --git a/arch/mips/oprofile/op_model_loongson2.c b/arch/mips/oprofile/op_model_loongson2.c index 29e2326b6257..fa3bf661ae29 100644 --- a/arch/mips/oprofile/op_model_loongson2.c +++ b/arch/mips/oprofile/op_model_loongson2.c | |||
@@ -122,7 +122,7 @@ static irqreturn_t loongson2_perfcount_handler(int irq, void *dev_id) | |||
122 | */ | 122 | */ |
123 | 123 | ||
124 | /* Check whether the irq belongs to me */ | 124 | /* Check whether the irq belongs to me */ |
125 | enabled = read_c0_perfcnt() & LOONGSON2_PERFCNT_INT_EN; | 125 | enabled = read_c0_perfctrl() & LOONGSON2_PERFCNT_INT_EN; |
126 | if (!enabled) | 126 | if (!enabled) |
127 | return IRQ_NONE; | 127 | return IRQ_NONE; |
128 | enabled = reg.cnt1_enabled | reg.cnt2_enabled; | 128 | enabled = reg.cnt1_enabled | reg.cnt2_enabled; |
diff --git a/arch/mn10300/include/asm/atomic.h b/arch/mn10300/include/asm/atomic.h index 5bf5be9566de..e41222d6c2fd 100644 --- a/arch/mn10300/include/asm/atomic.h +++ b/arch/mn10300/include/asm/atomic.h | |||
@@ -31,7 +31,7 @@ | |||
31 | * Atomically reads the value of @v. Note that the guaranteed | 31 | * Atomically reads the value of @v. Note that the guaranteed |
32 | * useful range of an atomic_t is only 24 bits. | 32 | * useful range of an atomic_t is only 24 bits. |
33 | */ | 33 | */ |
34 | #define atomic_read(v) ((v)->counter) | 34 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * atomic_set - set atomic variable | 37 | * atomic_set - set atomic variable |
diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h index 716634d1f546..f81955934aeb 100644 --- a/arch/parisc/include/asm/atomic.h +++ b/arch/parisc/include/asm/atomic.h | |||
@@ -189,7 +189,7 @@ static __inline__ void atomic_set(atomic_t *v, int i) | |||
189 | 189 | ||
190 | static __inline__ int atomic_read(const atomic_t *v) | 190 | static __inline__ int atomic_read(const atomic_t *v) |
191 | { | 191 | { |
192 | return v->counter; | 192 | return (*(volatile int *)&(v)->counter); |
193 | } | 193 | } |
194 | 194 | ||
195 | /* exported interface */ | 195 | /* exported interface */ |
@@ -286,7 +286,7 @@ atomic64_set(atomic64_t *v, s64 i) | |||
286 | static __inline__ s64 | 286 | static __inline__ s64 |
287 | atomic64_read(const atomic64_t *v) | 287 | atomic64_read(const atomic64_t *v) |
288 | { | 288 | { |
289 | return v->counter; | 289 | return (*(volatile long *)&(v)->counter); |
290 | } | 290 | } |
291 | 291 | ||
292 | #define atomic64_add(i,v) ((void)(__atomic64_add_return( ((s64)(i)),(v)))) | 292 | #define atomic64_add(i,v) ((void)(__atomic64_add_return( ((s64)(i)),(v)))) |
diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h index 9f4c9d4f5803..bd100fcf40d0 100644 --- a/arch/powerpc/include/asm/hw_irq.h +++ b/arch/powerpc/include/asm/hw_irq.h | |||
@@ -130,43 +130,5 @@ static inline int irqs_disabled_flags(unsigned long flags) | |||
130 | */ | 130 | */ |
131 | struct irq_chip; | 131 | struct irq_chip; |
132 | 132 | ||
133 | #ifdef CONFIG_PERF_EVENTS | ||
134 | |||
135 | #ifdef CONFIG_PPC64 | ||
136 | static inline unsigned long test_perf_event_pending(void) | ||
137 | { | ||
138 | unsigned long x; | ||
139 | |||
140 | asm volatile("lbz %0,%1(13)" | ||
141 | : "=r" (x) | ||
142 | : "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
143 | return x; | ||
144 | } | ||
145 | |||
146 | static inline void set_perf_event_pending(void) | ||
147 | { | ||
148 | asm volatile("stb %0,%1(13)" : : | ||
149 | "r" (1), | ||
150 | "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
151 | } | ||
152 | |||
153 | static inline void clear_perf_event_pending(void) | ||
154 | { | ||
155 | asm volatile("stb %0,%1(13)" : : | ||
156 | "r" (0), | ||
157 | "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
158 | } | ||
159 | #endif /* CONFIG_PPC64 */ | ||
160 | |||
161 | #else /* CONFIG_PERF_EVENTS */ | ||
162 | |||
163 | static inline unsigned long test_perf_event_pending(void) | ||
164 | { | ||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static inline void clear_perf_event_pending(void) {} | ||
169 | #endif /* CONFIG_PERF_EVENTS */ | ||
170 | |||
171 | #endif /* __KERNEL__ */ | 133 | #endif /* __KERNEL__ */ |
172 | #endif /* _ASM_POWERPC_HW_IRQ_H */ | 134 | #endif /* _ASM_POWERPC_HW_IRQ_H */ |
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 957ceb7059c5..c09138d150d4 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c | |||
@@ -133,7 +133,6 @@ int main(void) | |||
133 | DEFINE(PACAKMSR, offsetof(struct paca_struct, kernel_msr)); | 133 | DEFINE(PACAKMSR, offsetof(struct paca_struct, kernel_msr)); |
134 | DEFINE(PACASOFTIRQEN, offsetof(struct paca_struct, soft_enabled)); | 134 | DEFINE(PACASOFTIRQEN, offsetof(struct paca_struct, soft_enabled)); |
135 | DEFINE(PACAHARDIRQEN, offsetof(struct paca_struct, hard_enabled)); | 135 | DEFINE(PACAHARDIRQEN, offsetof(struct paca_struct, hard_enabled)); |
136 | DEFINE(PACAPERFPEND, offsetof(struct paca_struct, perf_event_pending)); | ||
137 | DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id)); | 136 | DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id)); |
138 | #ifdef CONFIG_PPC_MM_SLICES | 137 | #ifdef CONFIG_PPC_MM_SLICES |
139 | DEFINE(PACALOWSLICESPSIZE, offsetof(struct paca_struct, | 138 | DEFINE(PACALOWSLICESPSIZE, offsetof(struct paca_struct, |
diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c index 59c928564a03..4ff4da2c238b 100644 --- a/arch/powerpc/kernel/dma-swiotlb.c +++ b/arch/powerpc/kernel/dma-swiotlb.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Contains routines needed to support swiotlb for ppc. | 2 | * Contains routines needed to support swiotlb for ppc. |
3 | * | 3 | * |
4 | * Copyright (C) 2009 Becky Bruce, Freescale Semiconductor | 4 | * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. |
5 | * Author: Becky Bruce | ||
5 | * | 6 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License as published by the | 8 | * under the terms of the GNU General Public License as published by the |
@@ -70,7 +71,7 @@ static int ppc_swiotlb_bus_notify(struct notifier_block *nb, | |||
70 | sd->max_direct_dma_addr = 0; | 71 | sd->max_direct_dma_addr = 0; |
71 | 72 | ||
72 | /* May need to bounce if the device can't address all of DRAM */ | 73 | /* May need to bounce if the device can't address all of DRAM */ |
73 | if (dma_get_mask(dev) < lmb_end_of_DRAM()) | 74 | if ((dma_get_mask(dev) + 1) < lmb_end_of_DRAM()) |
74 | set_dma_ops(dev, &swiotlb_dma_ops); | 75 | set_dma_ops(dev, &swiotlb_dma_ops); |
75 | 76 | ||
76 | return NOTIFY_DONE; | 77 | return NOTIFY_DONE; |
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 07109d843787..42e9d908914a 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S | |||
@@ -556,15 +556,6 @@ ALT_FW_FTR_SECTION_END_IFCLR(FW_FEATURE_ISERIES) | |||
556 | 2: | 556 | 2: |
557 | TRACE_AND_RESTORE_IRQ(r5); | 557 | TRACE_AND_RESTORE_IRQ(r5); |
558 | 558 | ||
559 | #ifdef CONFIG_PERF_EVENTS | ||
560 | /* check paca->perf_event_pending if we're enabling ints */ | ||
561 | lbz r3,PACAPERFPEND(r13) | ||
562 | and. r3,r3,r5 | ||
563 | beq 27f | ||
564 | bl .perf_event_do_pending | ||
565 | 27: | ||
566 | #endif /* CONFIG_PERF_EVENTS */ | ||
567 | |||
568 | /* extract EE bit and use it to restore paca->hard_enabled */ | 559 | /* extract EE bit and use it to restore paca->hard_enabled */ |
569 | ld r3,_MSR(r1) | 560 | ld r3,_MSR(r1) |
570 | rldicl r4,r3,49,63 /* r0 = (r3 >> 15) & 1 */ | 561 | rldicl r4,r3,49,63 /* r0 = (r3 >> 15) & 1 */ |
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index 64f6f2031c22..066bd31551d5 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c | |||
@@ -53,7 +53,6 @@ | |||
53 | #include <linux/bootmem.h> | 53 | #include <linux/bootmem.h> |
54 | #include <linux/pci.h> | 54 | #include <linux/pci.h> |
55 | #include <linux/debugfs.h> | 55 | #include <linux/debugfs.h> |
56 | #include <linux/perf_event.h> | ||
57 | 56 | ||
58 | #include <asm/uaccess.h> | 57 | #include <asm/uaccess.h> |
59 | #include <asm/system.h> | 58 | #include <asm/system.h> |
@@ -145,11 +144,6 @@ notrace void raw_local_irq_restore(unsigned long en) | |||
145 | } | 144 | } |
146 | #endif /* CONFIG_PPC_STD_MMU_64 */ | 145 | #endif /* CONFIG_PPC_STD_MMU_64 */ |
147 | 146 | ||
148 | if (test_perf_event_pending()) { | ||
149 | clear_perf_event_pending(); | ||
150 | perf_event_do_pending(); | ||
151 | } | ||
152 | |||
153 | /* | 147 | /* |
154 | * if (get_paca()->hard_enabled) return; | 148 | * if (get_paca()->hard_enabled) return; |
155 | * But again we need to take care that gcc gets hard_enabled directly | 149 | * But again we need to take care that gcc gets hard_enabled directly |
diff --git a/arch/powerpc/kernel/perf_event.c b/arch/powerpc/kernel/perf_event.c index 08460a2e9f41..43b83c35cf54 100644 --- a/arch/powerpc/kernel/perf_event.c +++ b/arch/powerpc/kernel/perf_event.c | |||
@@ -35,6 +35,9 @@ struct cpu_hw_events { | |||
35 | u64 alternatives[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; | 35 | u64 alternatives[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; |
36 | unsigned long amasks[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; | 36 | unsigned long amasks[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; |
37 | unsigned long avalues[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; | 37 | unsigned long avalues[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES]; |
38 | |||
39 | unsigned int group_flag; | ||
40 | int n_txn_start; | ||
38 | }; | 41 | }; |
39 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events); | 42 | DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events); |
40 | 43 | ||
@@ -718,66 +721,6 @@ static int collect_events(struct perf_event *group, int max_count, | |||
718 | return n; | 721 | return n; |
719 | } | 722 | } |
720 | 723 | ||
721 | static void event_sched_in(struct perf_event *event) | ||
722 | { | ||
723 | event->state = PERF_EVENT_STATE_ACTIVE; | ||
724 | event->oncpu = smp_processor_id(); | ||
725 | event->tstamp_running += event->ctx->time - event->tstamp_stopped; | ||
726 | if (is_software_event(event)) | ||
727 | event->pmu->enable(event); | ||
728 | } | ||
729 | |||
730 | /* | ||
731 | * Called to enable a whole group of events. | ||
732 | * Returns 1 if the group was enabled, or -EAGAIN if it could not be. | ||
733 | * Assumes the caller has disabled interrupts and has | ||
734 | * frozen the PMU with hw_perf_save_disable. | ||
735 | */ | ||
736 | int hw_perf_group_sched_in(struct perf_event *group_leader, | ||
737 | struct perf_cpu_context *cpuctx, | ||
738 | struct perf_event_context *ctx) | ||
739 | { | ||
740 | struct cpu_hw_events *cpuhw; | ||
741 | long i, n, n0; | ||
742 | struct perf_event *sub; | ||
743 | |||
744 | if (!ppmu) | ||
745 | return 0; | ||
746 | cpuhw = &__get_cpu_var(cpu_hw_events); | ||
747 | n0 = cpuhw->n_events; | ||
748 | n = collect_events(group_leader, ppmu->n_counter - n0, | ||
749 | &cpuhw->event[n0], &cpuhw->events[n0], | ||
750 | &cpuhw->flags[n0]); | ||
751 | if (n < 0) | ||
752 | return -EAGAIN; | ||
753 | if (check_excludes(cpuhw->event, cpuhw->flags, n0, n)) | ||
754 | return -EAGAIN; | ||
755 | i = power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n + n0); | ||
756 | if (i < 0) | ||
757 | return -EAGAIN; | ||
758 | cpuhw->n_events = n0 + n; | ||
759 | cpuhw->n_added += n; | ||
760 | |||
761 | /* | ||
762 | * OK, this group can go on; update event states etc., | ||
763 | * and enable any software events | ||
764 | */ | ||
765 | for (i = n0; i < n0 + n; ++i) | ||
766 | cpuhw->event[i]->hw.config = cpuhw->events[i]; | ||
767 | cpuctx->active_oncpu += n; | ||
768 | n = 1; | ||
769 | event_sched_in(group_leader); | ||
770 | list_for_each_entry(sub, &group_leader->sibling_list, group_entry) { | ||
771 | if (sub->state != PERF_EVENT_STATE_OFF) { | ||
772 | event_sched_in(sub); | ||
773 | ++n; | ||
774 | } | ||
775 | } | ||
776 | ctx->nr_active += n; | ||
777 | |||
778 | return 1; | ||
779 | } | ||
780 | |||
781 | /* | 724 | /* |
782 | * Add a event to the PMU. | 725 | * Add a event to the PMU. |
783 | * If all events are not already frozen, then we disable and | 726 | * If all events are not already frozen, then we disable and |
@@ -805,12 +748,22 @@ static int power_pmu_enable(struct perf_event *event) | |||
805 | cpuhw->event[n0] = event; | 748 | cpuhw->event[n0] = event; |
806 | cpuhw->events[n0] = event->hw.config; | 749 | cpuhw->events[n0] = event->hw.config; |
807 | cpuhw->flags[n0] = event->hw.event_base; | 750 | cpuhw->flags[n0] = event->hw.event_base; |
751 | |||
752 | /* | ||
753 | * If group events scheduling transaction was started, | ||
754 | * skip the schedulability test here, it will be peformed | ||
755 | * at commit time(->commit_txn) as a whole | ||
756 | */ | ||
757 | if (cpuhw->group_flag & PERF_EVENT_TXN_STARTED) | ||
758 | goto nocheck; | ||
759 | |||
808 | if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1)) | 760 | if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1)) |
809 | goto out; | 761 | goto out; |
810 | if (power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n0 + 1)) | 762 | if (power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n0 + 1)) |
811 | goto out; | 763 | goto out; |
812 | |||
813 | event->hw.config = cpuhw->events[n0]; | 764 | event->hw.config = cpuhw->events[n0]; |
765 | |||
766 | nocheck: | ||
814 | ++cpuhw->n_events; | 767 | ++cpuhw->n_events; |
815 | ++cpuhw->n_added; | 768 | ++cpuhw->n_added; |
816 | 769 | ||
@@ -896,11 +849,65 @@ static void power_pmu_unthrottle(struct perf_event *event) | |||
896 | local_irq_restore(flags); | 849 | local_irq_restore(flags); |
897 | } | 850 | } |
898 | 851 | ||
852 | /* | ||
853 | * Start group events scheduling transaction | ||
854 | * Set the flag to make pmu::enable() not perform the | ||
855 | * schedulability test, it will be performed at commit time | ||
856 | */ | ||
857 | void power_pmu_start_txn(const struct pmu *pmu) | ||
858 | { | ||
859 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
860 | |||
861 | cpuhw->group_flag |= PERF_EVENT_TXN_STARTED; | ||
862 | cpuhw->n_txn_start = cpuhw->n_events; | ||
863 | } | ||
864 | |||
865 | /* | ||
866 | * Stop group events scheduling transaction | ||
867 | * Clear the flag and pmu::enable() will perform the | ||
868 | * schedulability test. | ||
869 | */ | ||
870 | void power_pmu_cancel_txn(const struct pmu *pmu) | ||
871 | { | ||
872 | struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events); | ||
873 | |||
874 | cpuhw->group_flag &= ~PERF_EVENT_TXN_STARTED; | ||
875 | } | ||
876 | |||
877 | /* | ||
878 | * Commit group events scheduling transaction | ||
879 | * Perform the group schedulability test as a whole | ||
880 | * Return 0 if success | ||
881 | */ | ||
882 | int power_pmu_commit_txn(const struct pmu *pmu) | ||
883 | { | ||
884 | struct cpu_hw_events *cpuhw; | ||
885 | long i, n; | ||
886 | |||
887 | if (!ppmu) | ||
888 | return -EAGAIN; | ||
889 | cpuhw = &__get_cpu_var(cpu_hw_events); | ||
890 | n = cpuhw->n_events; | ||
891 | if (check_excludes(cpuhw->event, cpuhw->flags, 0, n)) | ||
892 | return -EAGAIN; | ||
893 | i = power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n); | ||
894 | if (i < 0) | ||
895 | return -EAGAIN; | ||
896 | |||
897 | for (i = cpuhw->n_txn_start; i < n; ++i) | ||
898 | cpuhw->event[i]->hw.config = cpuhw->events[i]; | ||
899 | |||
900 | return 0; | ||
901 | } | ||
902 | |||
899 | struct pmu power_pmu = { | 903 | struct pmu power_pmu = { |
900 | .enable = power_pmu_enable, | 904 | .enable = power_pmu_enable, |
901 | .disable = power_pmu_disable, | 905 | .disable = power_pmu_disable, |
902 | .read = power_pmu_read, | 906 | .read = power_pmu_read, |
903 | .unthrottle = power_pmu_unthrottle, | 907 | .unthrottle = power_pmu_unthrottle, |
908 | .start_txn = power_pmu_start_txn, | ||
909 | .cancel_txn = power_pmu_cancel_txn, | ||
910 | .commit_txn = power_pmu_commit_txn, | ||
904 | }; | 911 | }; |
905 | 912 | ||
906 | /* | 913 | /* |
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 1b16b9a3e49a..0441bbdadbd1 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c | |||
@@ -532,25 +532,60 @@ void __init iSeries_time_init_early(void) | |||
532 | } | 532 | } |
533 | #endif /* CONFIG_PPC_ISERIES */ | 533 | #endif /* CONFIG_PPC_ISERIES */ |
534 | 534 | ||
535 | #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_PPC32) | 535 | #ifdef CONFIG_PERF_EVENTS |
536 | DEFINE_PER_CPU(u8, perf_event_pending); | ||
537 | 536 | ||
538 | void set_perf_event_pending(void) | 537 | /* |
538 | * 64-bit uses a byte in the PACA, 32-bit uses a per-cpu variable... | ||
539 | */ | ||
540 | #ifdef CONFIG_PPC64 | ||
541 | static inline unsigned long test_perf_event_pending(void) | ||
539 | { | 542 | { |
540 | get_cpu_var(perf_event_pending) = 1; | 543 | unsigned long x; |
541 | set_dec(1); | 544 | |
542 | put_cpu_var(perf_event_pending); | 545 | asm volatile("lbz %0,%1(13)" |
546 | : "=r" (x) | ||
547 | : "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
548 | return x; | ||
543 | } | 549 | } |
544 | 550 | ||
551 | static inline void set_perf_event_pending_flag(void) | ||
552 | { | ||
553 | asm volatile("stb %0,%1(13)" : : | ||
554 | "r" (1), | ||
555 | "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
556 | } | ||
557 | |||
558 | static inline void clear_perf_event_pending(void) | ||
559 | { | ||
560 | asm volatile("stb %0,%1(13)" : : | ||
561 | "r" (0), | ||
562 | "i" (offsetof(struct paca_struct, perf_event_pending))); | ||
563 | } | ||
564 | |||
565 | #else /* 32-bit */ | ||
566 | |||
567 | DEFINE_PER_CPU(u8, perf_event_pending); | ||
568 | |||
569 | #define set_perf_event_pending_flag() __get_cpu_var(perf_event_pending) = 1 | ||
545 | #define test_perf_event_pending() __get_cpu_var(perf_event_pending) | 570 | #define test_perf_event_pending() __get_cpu_var(perf_event_pending) |
546 | #define clear_perf_event_pending() __get_cpu_var(perf_event_pending) = 0 | 571 | #define clear_perf_event_pending() __get_cpu_var(perf_event_pending) = 0 |
547 | 572 | ||
548 | #else /* CONFIG_PERF_EVENTS && CONFIG_PPC32 */ | 573 | #endif /* 32 vs 64 bit */ |
574 | |||
575 | void set_perf_event_pending(void) | ||
576 | { | ||
577 | preempt_disable(); | ||
578 | set_perf_event_pending_flag(); | ||
579 | set_dec(1); | ||
580 | preempt_enable(); | ||
581 | } | ||
582 | |||
583 | #else /* CONFIG_PERF_EVENTS */ | ||
549 | 584 | ||
550 | #define test_perf_event_pending() 0 | 585 | #define test_perf_event_pending() 0 |
551 | #define clear_perf_event_pending() | 586 | #define clear_perf_event_pending() |
552 | 587 | ||
553 | #endif /* CONFIG_PERF_EVENTS && CONFIG_PPC32 */ | 588 | #endif /* CONFIG_PERF_EVENTS */ |
554 | 589 | ||
555 | /* | 590 | /* |
556 | * For iSeries shared processors, we have to let the hypervisor | 591 | * For iSeries shared processors, we have to let the hypervisor |
@@ -582,10 +617,6 @@ void timer_interrupt(struct pt_regs * regs) | |||
582 | set_dec(DECREMENTER_MAX); | 617 | set_dec(DECREMENTER_MAX); |
583 | 618 | ||
584 | #ifdef CONFIG_PPC32 | 619 | #ifdef CONFIG_PPC32 |
585 | if (test_perf_event_pending()) { | ||
586 | clear_perf_event_pending(); | ||
587 | perf_event_do_pending(); | ||
588 | } | ||
589 | if (atomic_read(&ppc_n_lost_interrupts) != 0) | 620 | if (atomic_read(&ppc_n_lost_interrupts) != 0) |
590 | do_IRQ(regs); | 621 | do_IRQ(regs); |
591 | #endif | 622 | #endif |
@@ -604,6 +635,11 @@ void timer_interrupt(struct pt_regs * regs) | |||
604 | 635 | ||
605 | calculate_steal_time(); | 636 | calculate_steal_time(); |
606 | 637 | ||
638 | if (test_perf_event_pending()) { | ||
639 | clear_perf_event_pending(); | ||
640 | perf_event_do_pending(); | ||
641 | } | ||
642 | |||
607 | #ifdef CONFIG_PPC_ISERIES | 643 | #ifdef CONFIG_PPC_ISERIES |
608 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | 644 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
609 | get_lppaca()->int_dword.fields.decr_int = 0; | 645 | get_lppaca()->int_dword.fields.decr_int = 0; |
diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c index 2570fcc7665d..812312542e50 100644 --- a/arch/powerpc/kvm/44x_tlb.c +++ b/arch/powerpc/kvm/44x_tlb.c | |||
@@ -440,7 +440,7 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws) | |||
440 | unsigned int gtlb_index; | 440 | unsigned int gtlb_index; |
441 | 441 | ||
442 | gtlb_index = kvmppc_get_gpr(vcpu, ra); | 442 | gtlb_index = kvmppc_get_gpr(vcpu, ra); |
443 | if (gtlb_index > KVM44x_GUEST_TLB_SIZE) { | 443 | if (gtlb_index >= KVM44x_GUEST_TLB_SIZE) { |
444 | printk("%s: index %d\n", __func__, gtlb_index); | 444 | printk("%s: index %d\n", __func__, gtlb_index); |
445 | kvmppc_dump_vcpu(vcpu); | 445 | kvmppc_dump_vcpu(vcpu); |
446 | return EMULATE_FAIL; | 446 | return EMULATE_FAIL; |
diff --git a/arch/s390/kernel/head31.S b/arch/s390/kernel/head31.S index 1bbcc499d455..b8f8dc126102 100644 --- a/arch/s390/kernel/head31.S +++ b/arch/s390/kernel/head31.S | |||
@@ -82,7 +82,7 @@ startup_continue: | |||
82 | _ehead: | 82 | _ehead: |
83 | 83 | ||
84 | #ifdef CONFIG_SHARED_KERNEL | 84 | #ifdef CONFIG_SHARED_KERNEL |
85 | .org 0x100000 | 85 | .org 0x100000 - 0x11000 # head.o ends at 0x11000 |
86 | #endif | 86 | #endif |
87 | 87 | ||
88 | # | 88 | # |
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S index 1f70970de0aa..cdef68717416 100644 --- a/arch/s390/kernel/head64.S +++ b/arch/s390/kernel/head64.S | |||
@@ -80,7 +80,7 @@ startup_continue: | |||
80 | _ehead: | 80 | _ehead: |
81 | 81 | ||
82 | #ifdef CONFIG_SHARED_KERNEL | 82 | #ifdef CONFIG_SHARED_KERNEL |
83 | .org 0x100000 | 83 | .org 0x100000 - 0x11000 # head.o ends at 0x11000 |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | # | 86 | # |
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c index 33fdc5a79764..9f654da4cecc 100644 --- a/arch/s390/kernel/ptrace.c +++ b/arch/s390/kernel/ptrace.c | |||
@@ -640,7 +640,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
640 | 640 | ||
641 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) | 641 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
642 | { | 642 | { |
643 | long ret; | 643 | long ret = 0; |
644 | 644 | ||
645 | /* Do the secure computing check first. */ | 645 | /* Do the secure computing check first. */ |
646 | secure_computing(regs->gprs[2]); | 646 | secure_computing(regs->gprs[2]); |
@@ -649,7 +649,6 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) | |||
649 | * The sysc_tracesys code in entry.S stored the system | 649 | * The sysc_tracesys code in entry.S stored the system |
650 | * call number to gprs[2]. | 650 | * call number to gprs[2]. |
651 | */ | 651 | */ |
652 | ret = regs->gprs[2]; | ||
653 | if (test_thread_flag(TIF_SYSCALL_TRACE) && | 652 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
654 | (tracehook_report_syscall_entry(regs) || | 653 | (tracehook_report_syscall_entry(regs) || |
655 | regs->gprs[2] >= NR_syscalls)) { | 654 | regs->gprs[2] >= NR_syscalls)) { |
@@ -671,7 +670,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) | |||
671 | regs->gprs[2], regs->orig_gpr2, | 670 | regs->gprs[2], regs->orig_gpr2, |
672 | regs->gprs[3], regs->gprs[4], | 671 | regs->gprs[3], regs->gprs[4], |
673 | regs->gprs[5]); | 672 | regs->gprs[5]); |
674 | return ret; | 673 | return ret ?: regs->gprs[2]; |
675 | } | 674 | } |
676 | 675 | ||
677 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) | 676 | asmlinkage void do_syscall_trace_exit(struct pt_regs *regs) |
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c index d906bf19c14a..a2163c95eb98 100644 --- a/arch/s390/kernel/time.c +++ b/arch/s390/kernel/time.c | |||
@@ -391,7 +391,6 @@ static void __init time_init_wq(void) | |||
391 | if (time_sync_wq) | 391 | if (time_sync_wq) |
392 | return; | 392 | return; |
393 | time_sync_wq = create_singlethread_workqueue("timesync"); | 393 | time_sync_wq = create_singlethread_workqueue("timesync"); |
394 | stop_machine_create(); | ||
395 | } | 394 | } |
396 | 395 | ||
397 | /* | 396 | /* |
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 8d90564c2bcf..e6d8ab5cfa9d 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
@@ -44,6 +44,7 @@ config SUPERH32 | |||
44 | select HAVE_FUNCTION_GRAPH_TRACER | 44 | select HAVE_FUNCTION_GRAPH_TRACER |
45 | select HAVE_ARCH_KGDB | 45 | select HAVE_ARCH_KGDB |
46 | select HAVE_HW_BREAKPOINT | 46 | select HAVE_HW_BREAKPOINT |
47 | select HAVE_MIXED_BREAKPOINTS_REGS | ||
47 | select PERF_EVENTS if HAVE_HW_BREAKPOINT | 48 | select PERF_EVENTS if HAVE_HW_BREAKPOINT |
48 | select ARCH_HIBERNATION_POSSIBLE if MMU | 49 | select ARCH_HIBERNATION_POSSIBLE if MMU |
49 | 50 | ||
diff --git a/arch/sh/include/asm/atomic.h b/arch/sh/include/asm/atomic.h index 275a448ae8c2..c7983124d99d 100644 --- a/arch/sh/include/asm/atomic.h +++ b/arch/sh/include/asm/atomic.h | |||
@@ -13,7 +13,7 @@ | |||
13 | 13 | ||
14 | #define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) | 14 | #define ATOMIC_INIT(i) ( (atomic_t) { (i) } ) |
15 | 15 | ||
16 | #define atomic_read(v) ((v)->counter) | 16 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
17 | #define atomic_set(v,i) ((v)->counter = (i)) | 17 | #define atomic_set(v,i) ((v)->counter = (i)) |
18 | 18 | ||
19 | #if defined(CONFIG_GUSA_RB) | 19 | #if defined(CONFIG_GUSA_RB) |
diff --git a/arch/sh/include/asm/hw_breakpoint.h b/arch/sh/include/asm/hw_breakpoint.h index 965dd780d51b..e14cad96798f 100644 --- a/arch/sh/include/asm/hw_breakpoint.h +++ b/arch/sh/include/asm/hw_breakpoint.h | |||
@@ -46,10 +46,14 @@ struct pmu; | |||
46 | /* Maximum number of UBC channels */ | 46 | /* Maximum number of UBC channels */ |
47 | #define HBP_NUM 2 | 47 | #define HBP_NUM 2 |
48 | 48 | ||
49 | static inline int hw_breakpoint_slots(int type) | ||
50 | { | ||
51 | return HBP_NUM; | ||
52 | } | ||
53 | |||
49 | /* arch/sh/kernel/hw_breakpoint.c */ | 54 | /* arch/sh/kernel/hw_breakpoint.c */ |
50 | extern int arch_check_va_in_userspace(unsigned long va, u16 hbp_len); | 55 | extern int arch_check_bp_in_kernelspace(struct perf_event *bp); |
51 | extern int arch_validate_hwbkpt_settings(struct perf_event *bp, | 56 | extern int arch_validate_hwbkpt_settings(struct perf_event *bp); |
52 | struct task_struct *tsk); | ||
53 | extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, | 57 | extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, |
54 | unsigned long val, void *data); | 58 | unsigned long val, void *data); |
55 | 59 | ||
diff --git a/arch/sh/kernel/hw_breakpoint.c b/arch/sh/kernel/hw_breakpoint.c index 675eea7785d9..1f2cf6229862 100644 --- a/arch/sh/kernel/hw_breakpoint.c +++ b/arch/sh/kernel/hw_breakpoint.c | |||
@@ -120,25 +120,16 @@ static int get_hbp_len(u16 hbp_len) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | /* | 122 | /* |
123 | * Check for virtual address in user space. | ||
124 | */ | ||
125 | int arch_check_va_in_userspace(unsigned long va, u16 hbp_len) | ||
126 | { | ||
127 | unsigned int len; | ||
128 | |||
129 | len = get_hbp_len(hbp_len); | ||
130 | |||
131 | return (va <= TASK_SIZE - len); | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Check for virtual address in kernel space. | 123 | * Check for virtual address in kernel space. |
136 | */ | 124 | */ |
137 | static int arch_check_va_in_kernelspace(unsigned long va, u8 hbp_len) | 125 | int arch_check_bp_in_kernelspace(struct perf_event *bp) |
138 | { | 126 | { |
139 | unsigned int len; | 127 | unsigned int len; |
128 | unsigned long va; | ||
129 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | ||
140 | 130 | ||
141 | len = get_hbp_len(hbp_len); | 131 | va = info->address; |
132 | len = get_hbp_len(info->len); | ||
142 | 133 | ||
143 | return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE); | 134 | return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE); |
144 | } | 135 | } |
@@ -226,8 +217,7 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
226 | /* | 217 | /* |
227 | * Validate the arch-specific HW Breakpoint register settings | 218 | * Validate the arch-specific HW Breakpoint register settings |
228 | */ | 219 | */ |
229 | int arch_validate_hwbkpt_settings(struct perf_event *bp, | 220 | int arch_validate_hwbkpt_settings(struct perf_event *bp) |
230 | struct task_struct *tsk) | ||
231 | { | 221 | { |
232 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | 222 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); |
233 | unsigned int align; | 223 | unsigned int align; |
@@ -270,15 +260,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp, | |||
270 | if (info->address & align) | 260 | if (info->address & align) |
271 | return -EINVAL; | 261 | return -EINVAL; |
272 | 262 | ||
273 | /* Check that the virtual address is in the proper range */ | ||
274 | if (tsk) { | ||
275 | if (!arch_check_va_in_userspace(info->address, info->len)) | ||
276 | return -EFAULT; | ||
277 | } else { | ||
278 | if (!arch_check_va_in_kernelspace(info->address, info->len)) | ||
279 | return -EFAULT; | ||
280 | } | ||
281 | |||
282 | return 0; | 263 | return 0; |
283 | } | 264 | } |
284 | 265 | ||
@@ -363,8 +344,7 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args) | |||
363 | perf_bp_event(bp, args->regs); | 344 | perf_bp_event(bp, args->regs); |
364 | 345 | ||
365 | /* Deliver the signal to userspace */ | 346 | /* Deliver the signal to userspace */ |
366 | if (arch_check_va_in_userspace(bp->attr.bp_addr, | 347 | if (!arch_check_bp_in_kernelspace(bp)) { |
367 | bp->attr.bp_len)) { | ||
368 | siginfo_t info; | 348 | siginfo_t info; |
369 | 349 | ||
370 | info.si_signo = args->signr; | 350 | info.si_signo = args->signr; |
diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c index 7759a9a93211..d4104ce9fe53 100644 --- a/arch/sh/kernel/ptrace_32.c +++ b/arch/sh/kernel/ptrace_32.c | |||
@@ -85,7 +85,7 @@ static int set_single_step(struct task_struct *tsk, unsigned long addr) | |||
85 | 85 | ||
86 | bp = thread->ptrace_bps[0]; | 86 | bp = thread->ptrace_bps[0]; |
87 | if (!bp) { | 87 | if (!bp) { |
88 | hw_breakpoint_init(&attr); | 88 | ptrace_breakpoint_init(&attr); |
89 | 89 | ||
90 | attr.bp_addr = addr; | 90 | attr.bp_addr = addr; |
91 | attr.bp_len = HW_BREAKPOINT_LEN_2; | 91 | attr.bp_len = HW_BREAKPOINT_LEN_2; |
diff --git a/arch/sparc/include/asm/atomic_32.h b/arch/sparc/include/asm/atomic_32.h index f0d343c3b956..7ae128b19d3f 100644 --- a/arch/sparc/include/asm/atomic_32.h +++ b/arch/sparc/include/asm/atomic_32.h | |||
@@ -25,7 +25,7 @@ extern int atomic_cmpxchg(atomic_t *, int, int); | |||
25 | extern int atomic_add_unless(atomic_t *, int, int); | 25 | extern int atomic_add_unless(atomic_t *, int, int); |
26 | extern void atomic_set(atomic_t *, int); | 26 | extern void atomic_set(atomic_t *, int); |
27 | 27 | ||
28 | #define atomic_read(v) ((v)->counter) | 28 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
29 | 29 | ||
30 | #define atomic_add(i, v) ((void)__atomic_add_return( (int)(i), (v))) | 30 | #define atomic_add(i, v) ((void)__atomic_add_return( (int)(i), (v))) |
31 | #define atomic_sub(i, v) ((void)__atomic_add_return(-(int)(i), (v))) | 31 | #define atomic_sub(i, v) ((void)__atomic_add_return(-(int)(i), (v))) |
diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h index f2e48009989e..2050ca02c423 100644 --- a/arch/sparc/include/asm/atomic_64.h +++ b/arch/sparc/include/asm/atomic_64.h | |||
@@ -13,8 +13,8 @@ | |||
13 | #define ATOMIC_INIT(i) { (i) } | 13 | #define ATOMIC_INIT(i) { (i) } |
14 | #define ATOMIC64_INIT(i) { (i) } | 14 | #define ATOMIC64_INIT(i) { (i) } |
15 | 15 | ||
16 | #define atomic_read(v) ((v)->counter) | 16 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
17 | #define atomic64_read(v) ((v)->counter) | 17 | #define atomic64_read(v) (*(volatile long *)&(v)->counter) |
18 | 18 | ||
19 | #define atomic_set(v, i) (((v)->counter) = i) | 19 | #define atomic_set(v, i) (((v)->counter) = i) |
20 | #define atomic64_set(v, i) (((v)->counter) = i) | 20 | #define atomic64_set(v, i) (((v)->counter) = i) |
diff --git a/arch/sparc/include/asm/bitops_64.h b/arch/sparc/include/asm/bitops_64.h index e72ac9cdfb98..766121a67a24 100644 --- a/arch/sparc/include/asm/bitops_64.h +++ b/arch/sparc/include/asm/bitops_64.h | |||
@@ -44,7 +44,7 @@ extern void change_bit(unsigned long nr, volatile unsigned long *addr); | |||
44 | 44 | ||
45 | #ifdef ULTRA_HAS_POPULATION_COUNT | 45 | #ifdef ULTRA_HAS_POPULATION_COUNT |
46 | 46 | ||
47 | static inline unsigned int hweight64(unsigned long w) | 47 | static inline unsigned int __arch_hweight64(unsigned long w) |
48 | { | 48 | { |
49 | unsigned int res; | 49 | unsigned int res; |
50 | 50 | ||
@@ -52,7 +52,7 @@ static inline unsigned int hweight64(unsigned long w) | |||
52 | return res; | 52 | return res; |
53 | } | 53 | } |
54 | 54 | ||
55 | static inline unsigned int hweight32(unsigned int w) | 55 | static inline unsigned int __arch_hweight32(unsigned int w) |
56 | { | 56 | { |
57 | unsigned int res; | 57 | unsigned int res; |
58 | 58 | ||
@@ -60,7 +60,7 @@ static inline unsigned int hweight32(unsigned int w) | |||
60 | return res; | 60 | return res; |
61 | } | 61 | } |
62 | 62 | ||
63 | static inline unsigned int hweight16(unsigned int w) | 63 | static inline unsigned int __arch_hweight16(unsigned int w) |
64 | { | 64 | { |
65 | unsigned int res; | 65 | unsigned int res; |
66 | 66 | ||
@@ -68,7 +68,7 @@ static inline unsigned int hweight16(unsigned int w) | |||
68 | return res; | 68 | return res; |
69 | } | 69 | } |
70 | 70 | ||
71 | static inline unsigned int hweight8(unsigned int w) | 71 | static inline unsigned int __arch_hweight8(unsigned int w) |
72 | { | 72 | { |
73 | unsigned int res; | 73 | unsigned int res; |
74 | 74 | ||
@@ -78,9 +78,10 @@ static inline unsigned int hweight8(unsigned int w) | |||
78 | 78 | ||
79 | #else | 79 | #else |
80 | 80 | ||
81 | #include <asm-generic/bitops/hweight.h> | 81 | #include <asm-generic/bitops/arch_hweight.h> |
82 | 82 | ||
83 | #endif | 83 | #endif |
84 | #include <asm-generic/bitops/const_hweight.h> | ||
84 | #include <asm-generic/bitops/lock.h> | 85 | #include <asm-generic/bitops/lock.h> |
85 | #endif /* __KERNEL__ */ | 86 | #endif /* __KERNEL__ */ |
86 | 87 | ||
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 9458685902bd..a2d3a5fbeeda 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -53,11 +53,15 @@ config X86 | |||
53 | select HAVE_KERNEL_LZMA | 53 | select HAVE_KERNEL_LZMA |
54 | select HAVE_KERNEL_LZO | 54 | select HAVE_KERNEL_LZO |
55 | select HAVE_HW_BREAKPOINT | 55 | select HAVE_HW_BREAKPOINT |
56 | select HAVE_MIXED_BREAKPOINTS_REGS | ||
56 | select PERF_EVENTS | 57 | select PERF_EVENTS |
57 | select ANON_INODES | 58 | select ANON_INODES |
58 | select HAVE_ARCH_KMEMCHECK | 59 | select HAVE_ARCH_KMEMCHECK |
59 | select HAVE_USER_RETURN_NOTIFIER | 60 | select HAVE_USER_RETURN_NOTIFIER |
60 | 61 | ||
62 | config INSTRUCTION_DECODER | ||
63 | def_bool (KPROBES || PERF_EVENTS) | ||
64 | |||
61 | config OUTPUT_FORMAT | 65 | config OUTPUT_FORMAT |
62 | string | 66 | string |
63 | default "elf32-i386" if X86_32 | 67 | default "elf32-i386" if X86_32 |
@@ -197,20 +201,17 @@ config HAVE_INTEL_TXT | |||
197 | 201 | ||
198 | # Use the generic interrupt handling code in kernel/irq/: | 202 | # Use the generic interrupt handling code in kernel/irq/: |
199 | config GENERIC_HARDIRQS | 203 | config GENERIC_HARDIRQS |
200 | bool | 204 | def_bool y |
201 | default y | ||
202 | 205 | ||
203 | config GENERIC_HARDIRQS_NO__DO_IRQ | 206 | config GENERIC_HARDIRQS_NO__DO_IRQ |
204 | def_bool y | 207 | def_bool y |
205 | 208 | ||
206 | config GENERIC_IRQ_PROBE | 209 | config GENERIC_IRQ_PROBE |
207 | bool | 210 | def_bool y |
208 | default y | ||
209 | 211 | ||
210 | config GENERIC_PENDING_IRQ | 212 | config GENERIC_PENDING_IRQ |
211 | bool | 213 | def_bool y |
212 | depends on GENERIC_HARDIRQS && SMP | 214 | depends on GENERIC_HARDIRQS && SMP |
213 | default y | ||
214 | 215 | ||
215 | config USE_GENERIC_SMP_HELPERS | 216 | config USE_GENERIC_SMP_HELPERS |
216 | def_bool y | 217 | def_bool y |
@@ -225,19 +226,22 @@ config X86_64_SMP | |||
225 | depends on X86_64 && SMP | 226 | depends on X86_64 && SMP |
226 | 227 | ||
227 | config X86_HT | 228 | config X86_HT |
228 | bool | 229 | def_bool y |
229 | depends on SMP | 230 | depends on SMP |
230 | default y | ||
231 | 231 | ||
232 | config X86_TRAMPOLINE | 232 | config X86_TRAMPOLINE |
233 | bool | 233 | def_bool y |
234 | depends on SMP || (64BIT && ACPI_SLEEP) | 234 | depends on SMP || (64BIT && ACPI_SLEEP) |
235 | default y | ||
236 | 235 | ||
237 | config X86_32_LAZY_GS | 236 | config X86_32_LAZY_GS |
238 | def_bool y | 237 | def_bool y |
239 | depends on X86_32 && !CC_STACKPROTECTOR | 238 | depends on X86_32 && !CC_STACKPROTECTOR |
240 | 239 | ||
240 | config ARCH_HWEIGHT_CFLAGS | ||
241 | string | ||
242 | default "-fcall-saved-ecx -fcall-saved-edx" if X86_32 | ||
243 | default "-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11" if X86_64 | ||
244 | |||
241 | config KTIME_SCALAR | 245 | config KTIME_SCALAR |
242 | def_bool X86_32 | 246 | def_bool X86_32 |
243 | source "init/Kconfig" | 247 | source "init/Kconfig" |
@@ -447,7 +451,7 @@ config X86_NUMAQ | |||
447 | firmware with - send email to <Martin.Bligh@us.ibm.com>. | 451 | firmware with - send email to <Martin.Bligh@us.ibm.com>. |
448 | 452 | ||
449 | config X86_SUPPORTS_MEMORY_FAILURE | 453 | config X86_SUPPORTS_MEMORY_FAILURE |
450 | bool | 454 | def_bool y |
451 | # MCE code calls memory_failure(): | 455 | # MCE code calls memory_failure(): |
452 | depends on X86_MCE | 456 | depends on X86_MCE |
453 | # On 32-bit this adds too big of NODES_SHIFT and we run out of page flags: | 457 | # On 32-bit this adds too big of NODES_SHIFT and we run out of page flags: |
@@ -455,7 +459,6 @@ config X86_SUPPORTS_MEMORY_FAILURE | |||
455 | # On 32-bit SPARSEMEM adds too big of SECTIONS_WIDTH: | 459 | # On 32-bit SPARSEMEM adds too big of SECTIONS_WIDTH: |
456 | depends on X86_64 || !SPARSEMEM | 460 | depends on X86_64 || !SPARSEMEM |
457 | select ARCH_SUPPORTS_MEMORY_FAILURE | 461 | select ARCH_SUPPORTS_MEMORY_FAILURE |
458 | default y | ||
459 | 462 | ||
460 | config X86_VISWS | 463 | config X86_VISWS |
461 | bool "SGI 320/540 (Visual Workstation)" | 464 | bool "SGI 320/540 (Visual Workstation)" |
@@ -570,7 +573,6 @@ config PARAVIRT_SPINLOCKS | |||
570 | 573 | ||
571 | config PARAVIRT_CLOCK | 574 | config PARAVIRT_CLOCK |
572 | bool | 575 | bool |
573 | default n | ||
574 | 576 | ||
575 | endif | 577 | endif |
576 | 578 | ||
@@ -749,7 +751,6 @@ config MAXSMP | |||
749 | bool "Configure Maximum number of SMP Processors and NUMA Nodes" | 751 | bool "Configure Maximum number of SMP Processors and NUMA Nodes" |
750 | depends on X86_64 && SMP && DEBUG_KERNEL && EXPERIMENTAL | 752 | depends on X86_64 && SMP && DEBUG_KERNEL && EXPERIMENTAL |
751 | select CPUMASK_OFFSTACK | 753 | select CPUMASK_OFFSTACK |
752 | default n | ||
753 | ---help--- | 754 | ---help--- |
754 | Configure maximum number of CPUS and NUMA Nodes for this architecture. | 755 | Configure maximum number of CPUS and NUMA Nodes for this architecture. |
755 | If unsure, say N. | 756 | If unsure, say N. |
@@ -829,7 +830,6 @@ config X86_VISWS_APIC | |||
829 | 830 | ||
830 | config X86_REROUTE_FOR_BROKEN_BOOT_IRQS | 831 | config X86_REROUTE_FOR_BROKEN_BOOT_IRQS |
831 | bool "Reroute for broken boot IRQs" | 832 | bool "Reroute for broken boot IRQs" |
832 | default n | ||
833 | depends on X86_IO_APIC | 833 | depends on X86_IO_APIC |
834 | ---help--- | 834 | ---help--- |
835 | This option enables a workaround that fixes a source of | 835 | This option enables a workaround that fixes a source of |
@@ -876,9 +876,8 @@ config X86_MCE_AMD | |||
876 | the DRAM Error Threshold. | 876 | the DRAM Error Threshold. |
877 | 877 | ||
878 | config X86_ANCIENT_MCE | 878 | config X86_ANCIENT_MCE |
879 | def_bool n | 879 | bool "Support for old Pentium 5 / WinChip machine checks" |
880 | depends on X86_32 && X86_MCE | 880 | depends on X86_32 && X86_MCE |
881 | prompt "Support for old Pentium 5 / WinChip machine checks" | ||
882 | ---help--- | 881 | ---help--- |
883 | Include support for machine check handling on old Pentium 5 or WinChip | 882 | Include support for machine check handling on old Pentium 5 or WinChip |
884 | systems. These typically need to be enabled explicitely on the command | 883 | systems. These typically need to be enabled explicitely on the command |
@@ -886,8 +885,7 @@ config X86_ANCIENT_MCE | |||
886 | 885 | ||
887 | config X86_MCE_THRESHOLD | 886 | config X86_MCE_THRESHOLD |
888 | depends on X86_MCE_AMD || X86_MCE_INTEL | 887 | depends on X86_MCE_AMD || X86_MCE_INTEL |
889 | bool | 888 | def_bool y |
890 | default y | ||
891 | 889 | ||
892 | config X86_MCE_INJECT | 890 | config X86_MCE_INJECT |
893 | depends on X86_MCE | 891 | depends on X86_MCE |
@@ -1026,8 +1024,8 @@ config X86_CPUID | |||
1026 | 1024 | ||
1027 | choice | 1025 | choice |
1028 | prompt "High Memory Support" | 1026 | prompt "High Memory Support" |
1029 | default HIGHMEM4G if !X86_NUMAQ | ||
1030 | default HIGHMEM64G if X86_NUMAQ | 1027 | default HIGHMEM64G if X86_NUMAQ |
1028 | default HIGHMEM4G | ||
1031 | depends on X86_32 | 1029 | depends on X86_32 |
1032 | 1030 | ||
1033 | config NOHIGHMEM | 1031 | config NOHIGHMEM |
@@ -1285,7 +1283,7 @@ source "mm/Kconfig" | |||
1285 | 1283 | ||
1286 | config HIGHPTE | 1284 | config HIGHPTE |
1287 | bool "Allocate 3rd-level pagetables from highmem" | 1285 | bool "Allocate 3rd-level pagetables from highmem" |
1288 | depends on X86_32 && (HIGHMEM4G || HIGHMEM64G) | 1286 | depends on HIGHMEM |
1289 | ---help--- | 1287 | ---help--- |
1290 | The VM uses one page table entry for each page of physical memory. | 1288 | The VM uses one page table entry for each page of physical memory. |
1291 | For systems with a lot of RAM, this can be wasteful of precious | 1289 | For systems with a lot of RAM, this can be wasteful of precious |
@@ -1369,8 +1367,7 @@ config MATH_EMULATION | |||
1369 | kernel, it won't hurt. | 1367 | kernel, it won't hurt. |
1370 | 1368 | ||
1371 | config MTRR | 1369 | config MTRR |
1372 | bool | 1370 | def_bool y |
1373 | default y | ||
1374 | prompt "MTRR (Memory Type Range Register) support" if EMBEDDED | 1371 | prompt "MTRR (Memory Type Range Register) support" if EMBEDDED |
1375 | ---help--- | 1372 | ---help--- |
1376 | On Intel P6 family processors (Pentium Pro, Pentium II and later) | 1373 | On Intel P6 family processors (Pentium Pro, Pentium II and later) |
@@ -1436,8 +1433,7 @@ config MTRR_SANITIZER_SPARE_REG_NR_DEFAULT | |||
1436 | mtrr_spare_reg_nr=N on the kernel command line. | 1433 | mtrr_spare_reg_nr=N on the kernel command line. |
1437 | 1434 | ||
1438 | config X86_PAT | 1435 | config X86_PAT |
1439 | bool | 1436 | def_bool y |
1440 | default y | ||
1441 | prompt "x86 PAT support" if EMBEDDED | 1437 | prompt "x86 PAT support" if EMBEDDED |
1442 | depends on MTRR | 1438 | depends on MTRR |
1443 | ---help--- | 1439 | ---help--- |
@@ -1605,8 +1601,7 @@ config X86_NEED_RELOCS | |||
1605 | depends on X86_32 && RELOCATABLE | 1601 | depends on X86_32 && RELOCATABLE |
1606 | 1602 | ||
1607 | config PHYSICAL_ALIGN | 1603 | config PHYSICAL_ALIGN |
1608 | hex | 1604 | hex "Alignment value to which kernel should be aligned" if X86_32 |
1609 | prompt "Alignment value to which kernel should be aligned" if X86_32 | ||
1610 | default "0x1000000" | 1605 | default "0x1000000" |
1611 | range 0x2000 0x1000000 | 1606 | range 0x2000 0x1000000 |
1612 | ---help--- | 1607 | ---help--- |
@@ -1653,7 +1648,6 @@ config COMPAT_VDSO | |||
1653 | 1648 | ||
1654 | config CMDLINE_BOOL | 1649 | config CMDLINE_BOOL |
1655 | bool "Built-in kernel command line" | 1650 | bool "Built-in kernel command line" |
1656 | default n | ||
1657 | ---help--- | 1651 | ---help--- |
1658 | Allow for specifying boot arguments to the kernel at | 1652 | Allow for specifying boot arguments to the kernel at |
1659 | build time. On some systems (e.g. embedded ones), it is | 1653 | build time. On some systems (e.g. embedded ones), it is |
@@ -1687,7 +1681,6 @@ config CMDLINE | |||
1687 | 1681 | ||
1688 | config CMDLINE_OVERRIDE | 1682 | config CMDLINE_OVERRIDE |
1689 | bool "Built-in command line overrides boot loader arguments" | 1683 | bool "Built-in command line overrides boot loader arguments" |
1690 | default n | ||
1691 | depends on CMDLINE_BOOL | 1684 | depends on CMDLINE_BOOL |
1692 | ---help--- | 1685 | ---help--- |
1693 | Set this option to 'Y' to have the kernel ignore the boot loader | 1686 | Set this option to 'Y' to have the kernel ignore the boot loader |
@@ -1723,8 +1716,7 @@ source "drivers/acpi/Kconfig" | |||
1723 | source "drivers/sfi/Kconfig" | 1716 | source "drivers/sfi/Kconfig" |
1724 | 1717 | ||
1725 | config X86_APM_BOOT | 1718 | config X86_APM_BOOT |
1726 | bool | 1719 | def_bool y |
1727 | default y | ||
1728 | depends on APM || APM_MODULE | 1720 | depends on APM || APM_MODULE |
1729 | 1721 | ||
1730 | menuconfig APM | 1722 | menuconfig APM |
@@ -1953,8 +1945,7 @@ config DMAR_DEFAULT_ON | |||
1953 | experimental. | 1945 | experimental. |
1954 | 1946 | ||
1955 | config DMAR_BROKEN_GFX_WA | 1947 | config DMAR_BROKEN_GFX_WA |
1956 | def_bool n | 1948 | bool "Workaround broken graphics drivers (going away soon)" |
1957 | prompt "Workaround broken graphics drivers (going away soon)" | ||
1958 | depends on DMAR && BROKEN | 1949 | depends on DMAR && BROKEN |
1959 | ---help--- | 1950 | ---help--- |
1960 | Current Graphics drivers tend to use physical address | 1951 | Current Graphics drivers tend to use physical address |
@@ -2052,7 +2043,6 @@ config SCx200HR_TIMER | |||
2052 | config OLPC | 2043 | config OLPC |
2053 | bool "One Laptop Per Child support" | 2044 | bool "One Laptop Per Child support" |
2054 | select GPIOLIB | 2045 | select GPIOLIB |
2055 | default n | ||
2056 | ---help--- | 2046 | ---help--- |
2057 | Add support for detecting the unique features of the OLPC | 2047 | Add support for detecting the unique features of the OLPC |
2058 | XO hardware. | 2048 | XO hardware. |
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu index a19829374e6a..2ac9069890cd 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu | |||
@@ -338,6 +338,10 @@ config X86_F00F_BUG | |||
338 | def_bool y | 338 | def_bool y |
339 | depends on M586MMX || M586TSC || M586 || M486 || M386 | 339 | depends on M586MMX || M586TSC || M586 || M486 || M386 |
340 | 340 | ||
341 | config X86_INVD_BUG | ||
342 | def_bool y | ||
343 | depends on M486 || M386 | ||
344 | |||
341 | config X86_WP_WORKS_OK | 345 | config X86_WP_WORKS_OK |
342 | def_bool y | 346 | def_bool y |
343 | depends on !M386 | 347 | depends on !M386 |
@@ -502,23 +506,3 @@ config CPU_SUP_UMC_32 | |||
502 | CPU might render the kernel unbootable. | 506 | CPU might render the kernel unbootable. |
503 | 507 | ||
504 | If unsure, say N. | 508 | If unsure, say N. |
505 | |||
506 | config X86_DS | ||
507 | def_bool X86_PTRACE_BTS | ||
508 | depends on X86_DEBUGCTLMSR | ||
509 | select HAVE_HW_BRANCH_TRACER | ||
510 | |||
511 | config X86_PTRACE_BTS | ||
512 | bool "Branch Trace Store" | ||
513 | default y | ||
514 | depends on X86_DEBUGCTLMSR | ||
515 | depends on BROKEN | ||
516 | ---help--- | ||
517 | This adds a ptrace interface to the hardware's branch trace store. | ||
518 | |||
519 | Debuggers may use it to collect an execution trace of the debugged | ||
520 | application in order to answer the question 'how did I get here?'. | ||
521 | Debuggers may trace user mode as well as kernel mode. | ||
522 | |||
523 | Say Y unless there is no application development on this machine | ||
524 | and you want to save a small amount of code size. | ||
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug index bc01e3ebfeb2..75085080b63e 100644 --- a/arch/x86/Kconfig.debug +++ b/arch/x86/Kconfig.debug | |||
@@ -45,7 +45,6 @@ config EARLY_PRINTK | |||
45 | 45 | ||
46 | config EARLY_PRINTK_DBGP | 46 | config EARLY_PRINTK_DBGP |
47 | bool "Early printk via EHCI debug port" | 47 | bool "Early printk via EHCI debug port" |
48 | default n | ||
49 | depends on EARLY_PRINTK && PCI | 48 | depends on EARLY_PRINTK && PCI |
50 | ---help--- | 49 | ---help--- |
51 | Write kernel log output directly into the EHCI debug port. | 50 | Write kernel log output directly into the EHCI debug port. |
@@ -76,7 +75,6 @@ config DEBUG_PER_CPU_MAPS | |||
76 | bool "Debug access to per_cpu maps" | 75 | bool "Debug access to per_cpu maps" |
77 | depends on DEBUG_KERNEL | 76 | depends on DEBUG_KERNEL |
78 | depends on SMP | 77 | depends on SMP |
79 | default n | ||
80 | ---help--- | 78 | ---help--- |
81 | Say Y to verify that the per_cpu map being accessed has | 79 | Say Y to verify that the per_cpu map being accessed has |
82 | been setup. Adds a fair amount of code to kernel memory | 80 | been setup. Adds a fair amount of code to kernel memory |
@@ -174,15 +172,6 @@ config IOMMU_LEAK | |||
174 | Add a simple leak tracer to the IOMMU code. This is useful when you | 172 | Add a simple leak tracer to the IOMMU code. This is useful when you |
175 | are debugging a buggy device driver that leaks IOMMU mappings. | 173 | are debugging a buggy device driver that leaks IOMMU mappings. |
176 | 174 | ||
177 | config X86_DS_SELFTEST | ||
178 | bool "DS selftest" | ||
179 | default y | ||
180 | depends on DEBUG_KERNEL | ||
181 | depends on X86_DS | ||
182 | ---help--- | ||
183 | Perform Debug Store selftests at boot time. | ||
184 | If in doubt, say "N". | ||
185 | |||
186 | config HAVE_MMIOTRACE_SUPPORT | 175 | config HAVE_MMIOTRACE_SUPPORT |
187 | def_bool y | 176 | def_bool y |
188 | 177 | ||
diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 0a43dc515e4c..8aa1b59b9074 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile | |||
@@ -95,8 +95,9 @@ sp-$(CONFIG_X86_64) := rsp | |||
95 | cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1) | 95 | cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1) |
96 | # is .cfi_signal_frame supported too? | 96 | # is .cfi_signal_frame supported too? |
97 | cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1) | 97 | cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1) |
98 | KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) | 98 | cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1) |
99 | KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) | 99 | KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) |
100 | KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) | ||
100 | 101 | ||
101 | LDFLAGS := -m elf_$(UTS_MACHINE) | 102 | LDFLAGS := -m elf_$(UTS_MACHINE) |
102 | 103 | ||
diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h index b97f786a48d5..a63a68be1cce 100644 --- a/arch/x86/include/asm/alternative-asm.h +++ b/arch/x86/include/asm/alternative-asm.h | |||
@@ -6,8 +6,8 @@ | |||
6 | .macro LOCK_PREFIX | 6 | .macro LOCK_PREFIX |
7 | 1: lock | 7 | 1: lock |
8 | .section .smp_locks,"a" | 8 | .section .smp_locks,"a" |
9 | _ASM_ALIGN | 9 | .balign 4 |
10 | _ASM_PTR 1b | 10 | .long 1b - . |
11 | .previous | 11 | .previous |
12 | .endm | 12 | .endm |
13 | #else | 13 | #else |
diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index b09ec55650b3..03b6bb5394a0 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h | |||
@@ -28,20 +28,20 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifdef CONFIG_SMP | 30 | #ifdef CONFIG_SMP |
31 | #define LOCK_PREFIX \ | 31 | #define LOCK_PREFIX_HERE \ |
32 | ".section .smp_locks,\"a\"\n" \ | 32 | ".section .smp_locks,\"a\"\n" \ |
33 | _ASM_ALIGN "\n" \ | 33 | ".balign 4\n" \ |
34 | _ASM_PTR "661f\n" /* address */ \ | 34 | ".long 671f - .\n" /* offset */ \ |
35 | ".previous\n" \ | 35 | ".previous\n" \ |
36 | "661:\n\tlock; " | 36 | "671:" |
37 | |||
38 | #define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; " | ||
37 | 39 | ||
38 | #else /* ! CONFIG_SMP */ | 40 | #else /* ! CONFIG_SMP */ |
41 | #define LOCK_PREFIX_HERE "" | ||
39 | #define LOCK_PREFIX "" | 42 | #define LOCK_PREFIX "" |
40 | #endif | 43 | #endif |
41 | 44 | ||
42 | /* This must be included *after* the definition of LOCK_PREFIX */ | ||
43 | #include <asm/cpufeature.h> | ||
44 | |||
45 | struct alt_instr { | 45 | struct alt_instr { |
46 | u8 *instr; /* original instruction */ | 46 | u8 *instr; /* original instruction */ |
47 | u8 *replacement; | 47 | u8 *replacement; |
@@ -96,6 +96,12 @@ static inline int alternatives_text_reserved(void *start, void *end) | |||
96 | ".previous" | 96 | ".previous" |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * This must be included *after* the definition of ALTERNATIVE due to | ||
100 | * <asm/arch_hweight.h> | ||
101 | */ | ||
102 | #include <asm/cpufeature.h> | ||
103 | |||
104 | /* | ||
99 | * Alternative instructions for different CPU types or capabilities. | 105 | * Alternative instructions for different CPU types or capabilities. |
100 | * | 106 | * |
101 | * This allows to use optimized instructions even on generic binary | 107 | * This allows to use optimized instructions even on generic binary |
diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h index 86a0ff0aeac7..7014e88bc779 100644 --- a/arch/x86/include/asm/amd_iommu_types.h +++ b/arch/x86/include/asm/amd_iommu_types.h | |||
@@ -174,6 +174,40 @@ | |||
174 | (~((1ULL << (12 + ((lvl) * 9))) - 1))) | 174 | (~((1ULL << (12 + ((lvl) * 9))) - 1))) |
175 | #define PM_ALIGNED(lvl, addr) ((PM_MAP_MASK(lvl) & (addr)) == (addr)) | 175 | #define PM_ALIGNED(lvl, addr) ((PM_MAP_MASK(lvl) & (addr)) == (addr)) |
176 | 176 | ||
177 | /* | ||
178 | * Returns the page table level to use for a given page size | ||
179 | * Pagesize is expected to be a power-of-two | ||
180 | */ | ||
181 | #define PAGE_SIZE_LEVEL(pagesize) \ | ||
182 | ((__ffs(pagesize) - 12) / 9) | ||
183 | /* | ||
184 | * Returns the number of ptes to use for a given page size | ||
185 | * Pagesize is expected to be a power-of-two | ||
186 | */ | ||
187 | #define PAGE_SIZE_PTE_COUNT(pagesize) \ | ||
188 | (1ULL << ((__ffs(pagesize) - 12) % 9)) | ||
189 | |||
190 | /* | ||
191 | * Aligns a given io-virtual address to a given page size | ||
192 | * Pagesize is expected to be a power-of-two | ||
193 | */ | ||
194 | #define PAGE_SIZE_ALIGN(address, pagesize) \ | ||
195 | ((address) & ~((pagesize) - 1)) | ||
196 | /* | ||
197 | * Creates an IOMMU PTE for an address an a given pagesize | ||
198 | * The PTE has no permission bits set | ||
199 | * Pagesize is expected to be a power-of-two larger than 4096 | ||
200 | */ | ||
201 | #define PAGE_SIZE_PTE(address, pagesize) \ | ||
202 | (((address) | ((pagesize) - 1)) & \ | ||
203 | (~(pagesize >> 1)) & PM_ADDR_MASK) | ||
204 | |||
205 | /* | ||
206 | * Takes a PTE value with mode=0x07 and returns the page size it maps | ||
207 | */ | ||
208 | #define PTE_PAGE_SIZE(pte) \ | ||
209 | (1ULL << (1 + ffz(((pte) | 0xfffULL)))) | ||
210 | |||
177 | #define IOMMU_PTE_P (1ULL << 0) | 211 | #define IOMMU_PTE_P (1ULL << 0) |
178 | #define IOMMU_PTE_TV (1ULL << 1) | 212 | #define IOMMU_PTE_TV (1ULL << 1) |
179 | #define IOMMU_PTE_U (1ULL << 59) | 213 | #define IOMMU_PTE_U (1ULL << 59) |
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index b4ac2cdcb64f..1fa03e04ae44 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h | |||
@@ -373,6 +373,7 @@ extern atomic_t init_deasserted; | |||
373 | extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); | 373 | extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); |
374 | #endif | 374 | #endif |
375 | 375 | ||
376 | #ifdef CONFIG_X86_LOCAL_APIC | ||
376 | static inline u32 apic_read(u32 reg) | 377 | static inline u32 apic_read(u32 reg) |
377 | { | 378 | { |
378 | return apic->read(reg); | 379 | return apic->read(reg); |
@@ -403,10 +404,19 @@ static inline u32 safe_apic_wait_icr_idle(void) | |||
403 | return apic->safe_wait_icr_idle(); | 404 | return apic->safe_wait_icr_idle(); |
404 | } | 405 | } |
405 | 406 | ||
407 | #else /* CONFIG_X86_LOCAL_APIC */ | ||
408 | |||
409 | static inline u32 apic_read(u32 reg) { return 0; } | ||
410 | static inline void apic_write(u32 reg, u32 val) { } | ||
411 | static inline u64 apic_icr_read(void) { return 0; } | ||
412 | static inline void apic_icr_write(u32 low, u32 high) { } | ||
413 | static inline void apic_wait_icr_idle(void) { } | ||
414 | static inline u32 safe_apic_wait_icr_idle(void) { return 0; } | ||
415 | |||
416 | #endif /* CONFIG_X86_LOCAL_APIC */ | ||
406 | 417 | ||
407 | static inline void ack_APIC_irq(void) | 418 | static inline void ack_APIC_irq(void) |
408 | { | 419 | { |
409 | #ifdef CONFIG_X86_LOCAL_APIC | ||
410 | /* | 420 | /* |
411 | * ack_APIC_irq() actually gets compiled as a single instruction | 421 | * ack_APIC_irq() actually gets compiled as a single instruction |
412 | * ... yummie. | 422 | * ... yummie. |
@@ -414,7 +424,6 @@ static inline void ack_APIC_irq(void) | |||
414 | 424 | ||
415 | /* Docs say use 0 for future compatibility */ | 425 | /* Docs say use 0 for future compatibility */ |
416 | apic_write(APIC_EOI, 0); | 426 | apic_write(APIC_EOI, 0); |
417 | #endif | ||
418 | } | 427 | } |
419 | 428 | ||
420 | static inline unsigned default_get_apic_id(unsigned long x) | 429 | static inline unsigned default_get_apic_id(unsigned long x) |
diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h new file mode 100644 index 000000000000..9686c3d9ff73 --- /dev/null +++ b/arch/x86/include/asm/arch_hweight.h | |||
@@ -0,0 +1,61 @@ | |||
1 | #ifndef _ASM_X86_HWEIGHT_H | ||
2 | #define _ASM_X86_HWEIGHT_H | ||
3 | |||
4 | #ifdef CONFIG_64BIT | ||
5 | /* popcnt %edi, %eax -- redundant REX prefix for alignment */ | ||
6 | #define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc7" | ||
7 | /* popcnt %rdi, %rax */ | ||
8 | #define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7" | ||
9 | #define REG_IN "D" | ||
10 | #define REG_OUT "a" | ||
11 | #else | ||
12 | /* popcnt %eax, %eax */ | ||
13 | #define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0" | ||
14 | #define REG_IN "a" | ||
15 | #define REG_OUT "a" | ||
16 | #endif | ||
17 | |||
18 | /* | ||
19 | * __sw_hweightXX are called from within the alternatives below | ||
20 | * and callee-clobbered registers need to be taken care of. See | ||
21 | * ARCH_HWEIGHT_CFLAGS in <arch/x86/Kconfig> for the respective | ||
22 | * compiler switches. | ||
23 | */ | ||
24 | static inline unsigned int __arch_hweight32(unsigned int w) | ||
25 | { | ||
26 | unsigned int res = 0; | ||
27 | |||
28 | asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT) | ||
29 | : "="REG_OUT (res) | ||
30 | : REG_IN (w)); | ||
31 | |||
32 | return res; | ||
33 | } | ||
34 | |||
35 | static inline unsigned int __arch_hweight16(unsigned int w) | ||
36 | { | ||
37 | return __arch_hweight32(w & 0xffff); | ||
38 | } | ||
39 | |||
40 | static inline unsigned int __arch_hweight8(unsigned int w) | ||
41 | { | ||
42 | return __arch_hweight32(w & 0xff); | ||
43 | } | ||
44 | |||
45 | static inline unsigned long __arch_hweight64(__u64 w) | ||
46 | { | ||
47 | unsigned long res = 0; | ||
48 | |||
49 | #ifdef CONFIG_X86_32 | ||
50 | return __arch_hweight32((u32)w) + | ||
51 | __arch_hweight32((u32)(w >> 32)); | ||
52 | #else | ||
53 | asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) | ||
54 | : "="REG_OUT (res) | ||
55 | : REG_IN (w)); | ||
56 | #endif /* CONFIG_X86_32 */ | ||
57 | |||
58 | return res; | ||
59 | } | ||
60 | |||
61 | #endif | ||
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h index 8f8217b9bdac..952a826ac4e5 100644 --- a/arch/x86/include/asm/atomic.h +++ b/arch/x86/include/asm/atomic.h | |||
@@ -22,7 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | static inline int atomic_read(const atomic_t *v) | 23 | static inline int atomic_read(const atomic_t *v) |
24 | { | 24 | { |
25 | return v->counter; | 25 | return (*(volatile int *)&(v)->counter); |
26 | } | 26 | } |
27 | 27 | ||
28 | /** | 28 | /** |
@@ -246,6 +246,29 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u) | |||
246 | 246 | ||
247 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) | 247 | #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) |
248 | 248 | ||
249 | /* | ||
250 | * atomic_dec_if_positive - decrement by 1 if old value positive | ||
251 | * @v: pointer of type atomic_t | ||
252 | * | ||
253 | * The function returns the old value of *v minus 1, even if | ||
254 | * the atomic variable, v, was not decremented. | ||
255 | */ | ||
256 | static inline int atomic_dec_if_positive(atomic_t *v) | ||
257 | { | ||
258 | int c, old, dec; | ||
259 | c = atomic_read(v); | ||
260 | for (;;) { | ||
261 | dec = c - 1; | ||
262 | if (unlikely(dec < 0)) | ||
263 | break; | ||
264 | old = atomic_cmpxchg((v), c, dec); | ||
265 | if (likely(old == c)) | ||
266 | break; | ||
267 | c = old; | ||
268 | } | ||
269 | return dec; | ||
270 | } | ||
271 | |||
249 | /** | 272 | /** |
250 | * atomic_inc_short - increment of a short integer | 273 | * atomic_inc_short - increment of a short integer |
251 | * @v: pointer to type int | 274 | * @v: pointer to type int |
diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h index 03027bf28de5..2a934aa19a43 100644 --- a/arch/x86/include/asm/atomic64_32.h +++ b/arch/x86/include/asm/atomic64_32.h | |||
@@ -14,109 +14,193 @@ typedef struct { | |||
14 | 14 | ||
15 | #define ATOMIC64_INIT(val) { (val) } | 15 | #define ATOMIC64_INIT(val) { (val) } |
16 | 16 | ||
17 | extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val); | 17 | #ifdef CONFIG_X86_CMPXCHG64 |
18 | #define ATOMIC64_ALTERNATIVE_(f, g) "call atomic64_" #g "_cx8" | ||
19 | #else | ||
20 | #define ATOMIC64_ALTERNATIVE_(f, g) ALTERNATIVE("call atomic64_" #f "_386", "call atomic64_" #g "_cx8", X86_FEATURE_CX8) | ||
21 | #endif | ||
22 | |||
23 | #define ATOMIC64_ALTERNATIVE(f) ATOMIC64_ALTERNATIVE_(f, f) | ||
24 | |||
25 | /** | ||
26 | * atomic64_cmpxchg - cmpxchg atomic64 variable | ||
27 | * @p: pointer to type atomic64_t | ||
28 | * @o: expected value | ||
29 | * @n: new value | ||
30 | * | ||
31 | * Atomically sets @v to @n if it was equal to @o and returns | ||
32 | * the old value. | ||
33 | */ | ||
34 | |||
35 | static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n) | ||
36 | { | ||
37 | return cmpxchg64(&v->counter, o, n); | ||
38 | } | ||
18 | 39 | ||
19 | /** | 40 | /** |
20 | * atomic64_xchg - xchg atomic64 variable | 41 | * atomic64_xchg - xchg atomic64 variable |
21 | * @ptr: pointer to type atomic64_t | 42 | * @v: pointer to type atomic64_t |
22 | * @new_val: value to assign | 43 | * @n: value to assign |
23 | * | 44 | * |
24 | * Atomically xchgs the value of @ptr to @new_val and returns | 45 | * Atomically xchgs the value of @v to @n and returns |
25 | * the old value. | 46 | * the old value. |
26 | */ | 47 | */ |
27 | extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val); | 48 | static inline long long atomic64_xchg(atomic64_t *v, long long n) |
49 | { | ||
50 | long long o; | ||
51 | unsigned high = (unsigned)(n >> 32); | ||
52 | unsigned low = (unsigned)n; | ||
53 | asm volatile(ATOMIC64_ALTERNATIVE(xchg) | ||
54 | : "=A" (o), "+b" (low), "+c" (high) | ||
55 | : "S" (v) | ||
56 | : "memory" | ||
57 | ); | ||
58 | return o; | ||
59 | } | ||
28 | 60 | ||
29 | /** | 61 | /** |
30 | * atomic64_set - set atomic64 variable | 62 | * atomic64_set - set atomic64 variable |
31 | * @ptr: pointer to type atomic64_t | 63 | * @v: pointer to type atomic64_t |
32 | * @new_val: value to assign | 64 | * @n: value to assign |
33 | * | 65 | * |
34 | * Atomically sets the value of @ptr to @new_val. | 66 | * Atomically sets the value of @v to @n. |
35 | */ | 67 | */ |
36 | extern void atomic64_set(atomic64_t *ptr, u64 new_val); | 68 | static inline void atomic64_set(atomic64_t *v, long long i) |
69 | { | ||
70 | unsigned high = (unsigned)(i >> 32); | ||
71 | unsigned low = (unsigned)i; | ||
72 | asm volatile(ATOMIC64_ALTERNATIVE(set) | ||
73 | : "+b" (low), "+c" (high) | ||
74 | : "S" (v) | ||
75 | : "eax", "edx", "memory" | ||
76 | ); | ||
77 | } | ||
37 | 78 | ||
38 | /** | 79 | /** |
39 | * atomic64_read - read atomic64 variable | 80 | * atomic64_read - read atomic64 variable |
40 | * @ptr: pointer to type atomic64_t | 81 | * @v: pointer to type atomic64_t |
41 | * | 82 | * |
42 | * Atomically reads the value of @ptr and returns it. | 83 | * Atomically reads the value of @v and returns it. |
43 | */ | 84 | */ |
44 | static inline u64 atomic64_read(atomic64_t *ptr) | 85 | static inline long long atomic64_read(atomic64_t *v) |
45 | { | 86 | { |
46 | u64 res; | 87 | long long r; |
47 | 88 | asm volatile(ATOMIC64_ALTERNATIVE(read) | |
48 | /* | 89 | : "=A" (r), "+c" (v) |
49 | * Note, we inline this atomic64_t primitive because | 90 | : : "memory" |
50 | * it only clobbers EAX/EDX and leaves the others | 91 | ); |
51 | * untouched. We also (somewhat subtly) rely on the | 92 | return r; |
52 | * fact that cmpxchg8b returns the current 64-bit value | 93 | } |
53 | * of the memory location we are touching: | ||
54 | */ | ||
55 | asm volatile( | ||
56 | "mov %%ebx, %%eax\n\t" | ||
57 | "mov %%ecx, %%edx\n\t" | ||
58 | LOCK_PREFIX "cmpxchg8b %1\n" | ||
59 | : "=&A" (res) | ||
60 | : "m" (*ptr) | ||
61 | ); | ||
62 | |||
63 | return res; | ||
64 | } | ||
65 | |||
66 | extern u64 atomic64_read(atomic64_t *ptr); | ||
67 | 94 | ||
68 | /** | 95 | /** |
69 | * atomic64_add_return - add and return | 96 | * atomic64_add_return - add and return |
70 | * @delta: integer value to add | 97 | * @i: integer value to add |
71 | * @ptr: pointer to type atomic64_t | 98 | * @v: pointer to type atomic64_t |
72 | * | 99 | * |
73 | * Atomically adds @delta to @ptr and returns @delta + *@ptr | 100 | * Atomically adds @i to @v and returns @i + *@v |
74 | */ | 101 | */ |
75 | extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr); | 102 | static inline long long atomic64_add_return(long long i, atomic64_t *v) |
103 | { | ||
104 | asm volatile(ATOMIC64_ALTERNATIVE(add_return) | ||
105 | : "+A" (i), "+c" (v) | ||
106 | : : "memory" | ||
107 | ); | ||
108 | return i; | ||
109 | } | ||
76 | 110 | ||
77 | /* | 111 | /* |
78 | * Other variants with different arithmetic operators: | 112 | * Other variants with different arithmetic operators: |
79 | */ | 113 | */ |
80 | extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr); | 114 | static inline long long atomic64_sub_return(long long i, atomic64_t *v) |
81 | extern u64 atomic64_inc_return(atomic64_t *ptr); | 115 | { |
82 | extern u64 atomic64_dec_return(atomic64_t *ptr); | 116 | asm volatile(ATOMIC64_ALTERNATIVE(sub_return) |
117 | : "+A" (i), "+c" (v) | ||
118 | : : "memory" | ||
119 | ); | ||
120 | return i; | ||
121 | } | ||
122 | |||
123 | static inline long long atomic64_inc_return(atomic64_t *v) | ||
124 | { | ||
125 | long long a; | ||
126 | asm volatile(ATOMIC64_ALTERNATIVE(inc_return) | ||
127 | : "=A" (a) | ||
128 | : "S" (v) | ||
129 | : "memory", "ecx" | ||
130 | ); | ||
131 | return a; | ||
132 | } | ||
133 | |||
134 | static inline long long atomic64_dec_return(atomic64_t *v) | ||
135 | { | ||
136 | long long a; | ||
137 | asm volatile(ATOMIC64_ALTERNATIVE(dec_return) | ||
138 | : "=A" (a) | ||
139 | : "S" (v) | ||
140 | : "memory", "ecx" | ||
141 | ); | ||
142 | return a; | ||
143 | } | ||
83 | 144 | ||
84 | /** | 145 | /** |
85 | * atomic64_add - add integer to atomic64 variable | 146 | * atomic64_add - add integer to atomic64 variable |
86 | * @delta: integer value to add | 147 | * @i: integer value to add |
87 | * @ptr: pointer to type atomic64_t | 148 | * @v: pointer to type atomic64_t |
88 | * | 149 | * |
89 | * Atomically adds @delta to @ptr. | 150 | * Atomically adds @i to @v. |
90 | */ | 151 | */ |
91 | extern void atomic64_add(u64 delta, atomic64_t *ptr); | 152 | static inline long long atomic64_add(long long i, atomic64_t *v) |
153 | { | ||
154 | asm volatile(ATOMIC64_ALTERNATIVE_(add, add_return) | ||
155 | : "+A" (i), "+c" (v) | ||
156 | : : "memory" | ||
157 | ); | ||
158 | return i; | ||
159 | } | ||
92 | 160 | ||
93 | /** | 161 | /** |
94 | * atomic64_sub - subtract the atomic64 variable | 162 | * atomic64_sub - subtract the atomic64 variable |
95 | * @delta: integer value to subtract | 163 | * @i: integer value to subtract |
96 | * @ptr: pointer to type atomic64_t | 164 | * @v: pointer to type atomic64_t |
97 | * | 165 | * |
98 | * Atomically subtracts @delta from @ptr. | 166 | * Atomically subtracts @i from @v. |
99 | */ | 167 | */ |
100 | extern void atomic64_sub(u64 delta, atomic64_t *ptr); | 168 | static inline long long atomic64_sub(long long i, atomic64_t *v) |
169 | { | ||
170 | asm volatile(ATOMIC64_ALTERNATIVE_(sub, sub_return) | ||
171 | : "+A" (i), "+c" (v) | ||
172 | : : "memory" | ||
173 | ); | ||
174 | return i; | ||
175 | } | ||
101 | 176 | ||
102 | /** | 177 | /** |
103 | * atomic64_sub_and_test - subtract value from variable and test result | 178 | * atomic64_sub_and_test - subtract value from variable and test result |
104 | * @delta: integer value to subtract | 179 | * @i: integer value to subtract |
105 | * @ptr: pointer to type atomic64_t | 180 | * @v: pointer to type atomic64_t |
106 | * | 181 | * |
107 | * Atomically subtracts @delta from @ptr and returns | 182 | * Atomically subtracts @i from @v and returns |
108 | * true if the result is zero, or false for all | 183 | * true if the result is zero, or false for all |
109 | * other cases. | 184 | * other cases. |
110 | */ | 185 | */ |
111 | extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr); | 186 | static inline int atomic64_sub_and_test(long long i, atomic64_t *v) |
187 | { | ||
188 | return atomic64_sub_return(i, v) == 0; | ||
189 | } | ||
112 | 190 | ||
113 | /** | 191 | /** |
114 | * atomic64_inc - increment atomic64 variable | 192 | * atomic64_inc - increment atomic64 variable |
115 | * @ptr: pointer to type atomic64_t | 193 | * @v: pointer to type atomic64_t |
116 | * | 194 | * |
117 | * Atomically increments @ptr by 1. | 195 | * Atomically increments @v by 1. |
118 | */ | 196 | */ |
119 | extern void atomic64_inc(atomic64_t *ptr); | 197 | static inline void atomic64_inc(atomic64_t *v) |
198 | { | ||
199 | asm volatile(ATOMIC64_ALTERNATIVE_(inc, inc_return) | ||
200 | : : "S" (v) | ||
201 | : "memory", "eax", "ecx", "edx" | ||
202 | ); | ||
203 | } | ||
120 | 204 | ||
121 | /** | 205 | /** |
122 | * atomic64_dec - decrement atomic64 variable | 206 | * atomic64_dec - decrement atomic64 variable |
@@ -124,37 +208,97 @@ extern void atomic64_inc(atomic64_t *ptr); | |||
124 | * | 208 | * |
125 | * Atomically decrements @ptr by 1. | 209 | * Atomically decrements @ptr by 1. |
126 | */ | 210 | */ |
127 | extern void atomic64_dec(atomic64_t *ptr); | 211 | static inline void atomic64_dec(atomic64_t *v) |
212 | { | ||
213 | asm volatile(ATOMIC64_ALTERNATIVE_(dec, dec_return) | ||
214 | : : "S" (v) | ||
215 | : "memory", "eax", "ecx", "edx" | ||
216 | ); | ||
217 | } | ||
128 | 218 | ||
129 | /** | 219 | /** |
130 | * atomic64_dec_and_test - decrement and test | 220 | * atomic64_dec_and_test - decrement and test |
131 | * @ptr: pointer to type atomic64_t | 221 | * @v: pointer to type atomic64_t |
132 | * | 222 | * |
133 | * Atomically decrements @ptr by 1 and | 223 | * Atomically decrements @v by 1 and |
134 | * returns true if the result is 0, or false for all other | 224 | * returns true if the result is 0, or false for all other |
135 | * cases. | 225 | * cases. |
136 | */ | 226 | */ |
137 | extern int atomic64_dec_and_test(atomic64_t *ptr); | 227 | static inline int atomic64_dec_and_test(atomic64_t *v) |
228 | { | ||
229 | return atomic64_dec_return(v) == 0; | ||
230 | } | ||
138 | 231 | ||
139 | /** | 232 | /** |
140 | * atomic64_inc_and_test - increment and test | 233 | * atomic64_inc_and_test - increment and test |
141 | * @ptr: pointer to type atomic64_t | 234 | * @v: pointer to type atomic64_t |
142 | * | 235 | * |
143 | * Atomically increments @ptr by 1 | 236 | * Atomically increments @v by 1 |
144 | * and returns true if the result is zero, or false for all | 237 | * and returns true if the result is zero, or false for all |
145 | * other cases. | 238 | * other cases. |
146 | */ | 239 | */ |
147 | extern int atomic64_inc_and_test(atomic64_t *ptr); | 240 | static inline int atomic64_inc_and_test(atomic64_t *v) |
241 | { | ||
242 | return atomic64_inc_return(v) == 0; | ||
243 | } | ||
148 | 244 | ||
149 | /** | 245 | /** |
150 | * atomic64_add_negative - add and test if negative | 246 | * atomic64_add_negative - add and test if negative |
151 | * @delta: integer value to add | 247 | * @i: integer value to add |
152 | * @ptr: pointer to type atomic64_t | 248 | * @v: pointer to type atomic64_t |
153 | * | 249 | * |
154 | * Atomically adds @delta to @ptr and returns true | 250 | * Atomically adds @i to @v and returns true |
155 | * if the result is negative, or false when | 251 | * if the result is negative, or false when |
156 | * result is greater than or equal to zero. | 252 | * result is greater than or equal to zero. |
157 | */ | 253 | */ |
158 | extern int atomic64_add_negative(u64 delta, atomic64_t *ptr); | 254 | static inline int atomic64_add_negative(long long i, atomic64_t *v) |
255 | { | ||
256 | return atomic64_add_return(i, v) < 0; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * atomic64_add_unless - add unless the number is a given value | ||
261 | * @v: pointer of type atomic64_t | ||
262 | * @a: the amount to add to v... | ||
263 | * @u: ...unless v is equal to u. | ||
264 | * | ||
265 | * Atomically adds @a to @v, so long as it was not @u. | ||
266 | * Returns non-zero if @v was not @u, and zero otherwise. | ||
267 | */ | ||
268 | static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u) | ||
269 | { | ||
270 | unsigned low = (unsigned)u; | ||
271 | unsigned high = (unsigned)(u >> 32); | ||
272 | asm volatile(ATOMIC64_ALTERNATIVE(add_unless) "\n\t" | ||
273 | : "+A" (a), "+c" (v), "+S" (low), "+D" (high) | ||
274 | : : "memory"); | ||
275 | return (int)a; | ||
276 | } | ||
277 | |||
278 | |||
279 | static inline int atomic64_inc_not_zero(atomic64_t *v) | ||
280 | { | ||
281 | int r; | ||
282 | asm volatile(ATOMIC64_ALTERNATIVE(inc_not_zero) | ||
283 | : "=a" (r) | ||
284 | : "S" (v) | ||
285 | : "ecx", "edx", "memory" | ||
286 | ); | ||
287 | return r; | ||
288 | } | ||
289 | |||
290 | static inline long long atomic64_dec_if_positive(atomic64_t *v) | ||
291 | { | ||
292 | long long r; | ||
293 | asm volatile(ATOMIC64_ALTERNATIVE(dec_if_positive) | ||
294 | : "=A" (r) | ||
295 | : "S" (v) | ||
296 | : "ecx", "memory" | ||
297 | ); | ||
298 | return r; | ||
299 | } | ||
300 | |||
301 | #undef ATOMIC64_ALTERNATIVE | ||
302 | #undef ATOMIC64_ALTERNATIVE_ | ||
159 | 303 | ||
160 | #endif /* _ASM_X86_ATOMIC64_32_H */ | 304 | #endif /* _ASM_X86_ATOMIC64_32_H */ |
diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h index 51c5b4056929..49fd1ea22951 100644 --- a/arch/x86/include/asm/atomic64_64.h +++ b/arch/x86/include/asm/atomic64_64.h | |||
@@ -18,7 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | static inline long atomic64_read(const atomic64_t *v) | 19 | static inline long atomic64_read(const atomic64_t *v) |
20 | { | 20 | { |
21 | return v->counter; | 21 | return (*(volatile long *)&(v)->counter); |
22 | } | 22 | } |
23 | 23 | ||
24 | /** | 24 | /** |
@@ -221,4 +221,27 @@ static inline int atomic64_add_unless(atomic64_t *v, long a, long u) | |||
221 | 221 | ||
222 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) | 222 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) |
223 | 223 | ||
224 | /* | ||
225 | * atomic64_dec_if_positive - decrement by 1 if old value positive | ||
226 | * @v: pointer of type atomic_t | ||
227 | * | ||
228 | * The function returns the old value of *v minus 1, even if | ||
229 | * the atomic variable, v, was not decremented. | ||
230 | */ | ||
231 | static inline long atomic64_dec_if_positive(atomic64_t *v) | ||
232 | { | ||
233 | long c, old, dec; | ||
234 | c = atomic64_read(v); | ||
235 | for (;;) { | ||
236 | dec = c - 1; | ||
237 | if (unlikely(dec < 0)) | ||
238 | break; | ||
239 | old = atomic64_cmpxchg((v), c, dec); | ||
240 | if (likely(old == c)) | ||
241 | break; | ||
242 | c = old; | ||
243 | } | ||
244 | return dec; | ||
245 | } | ||
246 | |||
224 | #endif /* _ASM_X86_ATOMIC64_64_H */ | 247 | #endif /* _ASM_X86_ATOMIC64_64_H */ |
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index 02b47a603fc8..545776efeb16 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h | |||
@@ -444,7 +444,9 @@ static inline int fls(int x) | |||
444 | 444 | ||
445 | #define ARCH_HAS_FAST_MULTIPLIER 1 | 445 | #define ARCH_HAS_FAST_MULTIPLIER 1 |
446 | 446 | ||
447 | #include <asm-generic/bitops/hweight.h> | 447 | #include <asm/arch_hweight.h> |
448 | |||
449 | #include <asm-generic/bitops/const_hweight.h> | ||
448 | 450 | ||
449 | #endif /* __KERNEL__ */ | 451 | #endif /* __KERNEL__ */ |
450 | 452 | ||
diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 7a1065958ba9..3b62ab56c7a0 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h | |||
@@ -24,7 +24,7 @@ | |||
24 | #define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2) | 24 | #define MIN_KERNEL_ALIGN (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2) |
25 | 25 | ||
26 | #if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \ | 26 | #if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \ |
27 | (CONFIG_PHYSICAL_ALIGN < (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)) | 27 | (CONFIG_PHYSICAL_ALIGN < MIN_KERNEL_ALIGN) |
28 | #error "Invalid value for CONFIG_PHYSICAL_ALIGN" | 28 | #error "Invalid value for CONFIG_PHYSICAL_ALIGN" |
29 | #endif | 29 | #endif |
30 | 30 | ||
diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h index 634c40a739a6..c70068d05f70 100644 --- a/arch/x86/include/asm/cacheflush.h +++ b/arch/x86/include/asm/cacheflush.h | |||
@@ -44,9 +44,6 @@ static inline void copy_from_user_page(struct vm_area_struct *vma, | |||
44 | memcpy(dst, src, len); | 44 | memcpy(dst, src, len); |
45 | } | 45 | } |
46 | 46 | ||
47 | #define PG_WC PG_arch_1 | ||
48 | PAGEFLAG(WC, WC) | ||
49 | |||
50 | #ifdef CONFIG_X86_PAT | 47 | #ifdef CONFIG_X86_PAT |
51 | /* | 48 | /* |
52 | * X86 PAT uses page flags WC and Uncached together to keep track of | 49 | * X86 PAT uses page flags WC and Uncached together to keep track of |
@@ -55,16 +52,24 @@ PAGEFLAG(WC, WC) | |||
55 | * _PAGE_CACHE_UC_MINUS and fourth state where page's memory type has not | 52 | * _PAGE_CACHE_UC_MINUS and fourth state where page's memory type has not |
56 | * been changed from its default (value of -1 used to denote this). | 53 | * been changed from its default (value of -1 used to denote this). |
57 | * Note we do not support _PAGE_CACHE_UC here. | 54 | * Note we do not support _PAGE_CACHE_UC here. |
58 | * | ||
59 | * Caller must hold memtype_lock for atomicity. | ||
60 | */ | 55 | */ |
56 | |||
57 | #define _PGMT_DEFAULT 0 | ||
58 | #define _PGMT_WC (1UL << PG_arch_1) | ||
59 | #define _PGMT_UC_MINUS (1UL << PG_uncached) | ||
60 | #define _PGMT_WB (1UL << PG_uncached | 1UL << PG_arch_1) | ||
61 | #define _PGMT_MASK (1UL << PG_uncached | 1UL << PG_arch_1) | ||
62 | #define _PGMT_CLEAR_MASK (~_PGMT_MASK) | ||
63 | |||
61 | static inline unsigned long get_page_memtype(struct page *pg) | 64 | static inline unsigned long get_page_memtype(struct page *pg) |
62 | { | 65 | { |
63 | if (!PageUncached(pg) && !PageWC(pg)) | 66 | unsigned long pg_flags = pg->flags & _PGMT_MASK; |
67 | |||
68 | if (pg_flags == _PGMT_DEFAULT) | ||
64 | return -1; | 69 | return -1; |
65 | else if (!PageUncached(pg) && PageWC(pg)) | 70 | else if (pg_flags == _PGMT_WC) |
66 | return _PAGE_CACHE_WC; | 71 | return _PAGE_CACHE_WC; |
67 | else if (PageUncached(pg) && !PageWC(pg)) | 72 | else if (pg_flags == _PGMT_UC_MINUS) |
68 | return _PAGE_CACHE_UC_MINUS; | 73 | return _PAGE_CACHE_UC_MINUS; |
69 | else | 74 | else |
70 | return _PAGE_CACHE_WB; | 75 | return _PAGE_CACHE_WB; |
@@ -72,25 +77,26 @@ static inline unsigned long get_page_memtype(struct page *pg) | |||
72 | 77 | ||
73 | static inline void set_page_memtype(struct page *pg, unsigned long memtype) | 78 | static inline void set_page_memtype(struct page *pg, unsigned long memtype) |
74 | { | 79 | { |
80 | unsigned long memtype_flags = _PGMT_DEFAULT; | ||
81 | unsigned long old_flags; | ||
82 | unsigned long new_flags; | ||
83 | |||
75 | switch (memtype) { | 84 | switch (memtype) { |
76 | case _PAGE_CACHE_WC: | 85 | case _PAGE_CACHE_WC: |
77 | ClearPageUncached(pg); | 86 | memtype_flags = _PGMT_WC; |
78 | SetPageWC(pg); | ||
79 | break; | 87 | break; |
80 | case _PAGE_CACHE_UC_MINUS: | 88 | case _PAGE_CACHE_UC_MINUS: |
81 | SetPageUncached(pg); | 89 | memtype_flags = _PGMT_UC_MINUS; |
82 | ClearPageWC(pg); | ||
83 | break; | 90 | break; |
84 | case _PAGE_CACHE_WB: | 91 | case _PAGE_CACHE_WB: |
85 | SetPageUncached(pg); | 92 | memtype_flags = _PGMT_WB; |
86 | SetPageWC(pg); | ||
87 | break; | ||
88 | default: | ||
89 | case -1: | ||
90 | ClearPageUncached(pg); | ||
91 | ClearPageWC(pg); | ||
92 | break; | 93 | break; |
93 | } | 94 | } |
95 | |||
96 | do { | ||
97 | old_flags = pg->flags; | ||
98 | new_flags = (old_flags & _PGMT_CLEAR_MASK) | memtype_flags; | ||
99 | } while (cmpxchg(&pg->flags, old_flags, new_flags) != old_flags); | ||
94 | } | 100 | } |
95 | #else | 101 | #else |
96 | static inline unsigned long get_page_memtype(struct page *pg) { return -1; } | 102 | static inline unsigned long get_page_memtype(struct page *pg) { return -1; } |
diff --git a/arch/x86/include/asm/cmpxchg_32.h b/arch/x86/include/asm/cmpxchg_32.h index ffb9bb6b6c37..8859e12dd3cf 100644 --- a/arch/x86/include/asm/cmpxchg_32.h +++ b/arch/x86/include/asm/cmpxchg_32.h | |||
@@ -271,7 +271,8 @@ extern unsigned long long cmpxchg_486_u64(volatile void *, u64, u64); | |||
271 | __typeof__(*(ptr)) __ret; \ | 271 | __typeof__(*(ptr)) __ret; \ |
272 | __typeof__(*(ptr)) __old = (o); \ | 272 | __typeof__(*(ptr)) __old = (o); \ |
273 | __typeof__(*(ptr)) __new = (n); \ | 273 | __typeof__(*(ptr)) __new = (n); \ |
274 | alternative_io("call cmpxchg8b_emu", \ | 274 | alternative_io(LOCK_PREFIX_HERE \ |
275 | "call cmpxchg8b_emu", \ | ||
275 | "lock; cmpxchg8b (%%esi)" , \ | 276 | "lock; cmpxchg8b (%%esi)" , \ |
276 | X86_FEATURE_CX8, \ | 277 | X86_FEATURE_CX8, \ |
277 | "=A" (__ret), \ | 278 | "=A" (__ret), \ |
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 0cd82d068613..dca9c545f44e 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h | |||
@@ -161,6 +161,7 @@ | |||
161 | */ | 161 | */ |
162 | #define X86_FEATURE_IDA (7*32+ 0) /* Intel Dynamic Acceleration */ | 162 | #define X86_FEATURE_IDA (7*32+ 0) /* Intel Dynamic Acceleration */ |
163 | #define X86_FEATURE_ARAT (7*32+ 1) /* Always Running APIC Timer */ | 163 | #define X86_FEATURE_ARAT (7*32+ 1) /* Always Running APIC Timer */ |
164 | #define X86_FEATURE_CPB (7*32+ 2) /* AMD Core Performance Boost */ | ||
164 | 165 | ||
165 | /* Virtualization flags: Linux defined */ | 166 | /* Virtualization flags: Linux defined */ |
166 | #define X86_FEATURE_TPR_SHADOW (8*32+ 0) /* Intel TPR Shadow */ | 167 | #define X86_FEATURE_TPR_SHADOW (8*32+ 0) /* Intel TPR Shadow */ |
@@ -175,6 +176,7 @@ | |||
175 | 176 | ||
176 | #if defined(__KERNEL__) && !defined(__ASSEMBLY__) | 177 | #if defined(__KERNEL__) && !defined(__ASSEMBLY__) |
177 | 178 | ||
179 | #include <asm/asm.h> | ||
178 | #include <linux/bitops.h> | 180 | #include <linux/bitops.h> |
179 | 181 | ||
180 | extern const char * const x86_cap_flags[NCAPINTS*32]; | 182 | extern const char * const x86_cap_flags[NCAPINTS*32]; |
@@ -283,6 +285,62 @@ extern const char * const x86_power_flags[32]; | |||
283 | 285 | ||
284 | #endif /* CONFIG_X86_64 */ | 286 | #endif /* CONFIG_X86_64 */ |
285 | 287 | ||
288 | /* | ||
289 | * Static testing of CPU features. Used the same as boot_cpu_has(). | ||
290 | * These are only valid after alternatives have run, but will statically | ||
291 | * patch the target code for additional performance. | ||
292 | * | ||
293 | */ | ||
294 | static __always_inline __pure bool __static_cpu_has(u8 bit) | ||
295 | { | ||
296 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) | ||
297 | asm goto("1: jmp %l[t_no]\n" | ||
298 | "2:\n" | ||
299 | ".section .altinstructions,\"a\"\n" | ||
300 | _ASM_ALIGN "\n" | ||
301 | _ASM_PTR "1b\n" | ||
302 | _ASM_PTR "0\n" /* no replacement */ | ||
303 | " .byte %P0\n" /* feature bit */ | ||
304 | " .byte 2b - 1b\n" /* source len */ | ||
305 | " .byte 0\n" /* replacement len */ | ||
306 | " .byte 0xff + 0 - (2b-1b)\n" /* padding */ | ||
307 | ".previous\n" | ||
308 | : : "i" (bit) : : t_no); | ||
309 | return true; | ||
310 | t_no: | ||
311 | return false; | ||
312 | #else | ||
313 | u8 flag; | ||
314 | /* Open-coded due to __stringify() in ALTERNATIVE() */ | ||
315 | asm volatile("1: movb $0,%0\n" | ||
316 | "2:\n" | ||
317 | ".section .altinstructions,\"a\"\n" | ||
318 | _ASM_ALIGN "\n" | ||
319 | _ASM_PTR "1b\n" | ||
320 | _ASM_PTR "3f\n" | ||
321 | " .byte %P1\n" /* feature bit */ | ||
322 | " .byte 2b - 1b\n" /* source len */ | ||
323 | " .byte 4f - 3f\n" /* replacement len */ | ||
324 | " .byte 0xff + (4f-3f) - (2b-1b)\n" /* padding */ | ||
325 | ".previous\n" | ||
326 | ".section .altinstr_replacement,\"ax\"\n" | ||
327 | "3: movb $1,%0\n" | ||
328 | "4:\n" | ||
329 | ".previous\n" | ||
330 | : "=qm" (flag) : "i" (bit)); | ||
331 | return flag; | ||
332 | #endif | ||
333 | } | ||
334 | |||
335 | #define static_cpu_has(bit) \ | ||
336 | ( \ | ||
337 | __builtin_constant_p(boot_cpu_has(bit)) ? \ | ||
338 | boot_cpu_has(bit) : \ | ||
339 | (__builtin_constant_p(bit) && !((bit) & ~0xff)) ? \ | ||
340 | __static_cpu_has(bit) : \ | ||
341 | boot_cpu_has(bit) \ | ||
342 | ) | ||
343 | |||
286 | #endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ | 344 | #endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ |
287 | 345 | ||
288 | #endif /* _ASM_X86_CPUFEATURE_H */ | 346 | #endif /* _ASM_X86_CPUFEATURE_H */ |
diff --git a/arch/x86/include/asm/ds.h b/arch/x86/include/asm/ds.h deleted file mode 100644 index 70dac199b093..000000000000 --- a/arch/x86/include/asm/ds.h +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store (DS) support | ||
3 | * | ||
4 | * This provides a low-level interface to the hardware's Debug Store | ||
5 | * feature that is used for branch trace store (BTS) and | ||
6 | * precise-event based sampling (PEBS). | ||
7 | * | ||
8 | * It manages: | ||
9 | * - DS and BTS hardware configuration | ||
10 | * - buffer overflow handling (to be done) | ||
11 | * - buffer access | ||
12 | * | ||
13 | * It does not do: | ||
14 | * - security checking (is the caller allowed to trace the task) | ||
15 | * - buffer allocation (memory accounting) | ||
16 | * | ||
17 | * | ||
18 | * Copyright (C) 2007-2009 Intel Corporation. | ||
19 | * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009 | ||
20 | */ | ||
21 | |||
22 | #ifndef _ASM_X86_DS_H | ||
23 | #define _ASM_X86_DS_H | ||
24 | |||
25 | |||
26 | #include <linux/types.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/err.h> | ||
29 | |||
30 | |||
31 | #ifdef CONFIG_X86_DS | ||
32 | |||
33 | struct task_struct; | ||
34 | struct ds_context; | ||
35 | struct ds_tracer; | ||
36 | struct bts_tracer; | ||
37 | struct pebs_tracer; | ||
38 | |||
39 | typedef void (*bts_ovfl_callback_t)(struct bts_tracer *); | ||
40 | typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *); | ||
41 | |||
42 | |||
43 | /* | ||
44 | * A list of features plus corresponding macros to talk about them in | ||
45 | * the ds_request function's flags parameter. | ||
46 | * | ||
47 | * We use the enum to index an array of corresponding control bits; | ||
48 | * we use the macro to index a flags bit-vector. | ||
49 | */ | ||
50 | enum ds_feature { | ||
51 | dsf_bts = 0, | ||
52 | dsf_bts_kernel, | ||
53 | #define BTS_KERNEL (1 << dsf_bts_kernel) | ||
54 | /* trace kernel-mode branches */ | ||
55 | |||
56 | dsf_bts_user, | ||
57 | #define BTS_USER (1 << dsf_bts_user) | ||
58 | /* trace user-mode branches */ | ||
59 | |||
60 | dsf_bts_overflow, | ||
61 | dsf_bts_max, | ||
62 | dsf_pebs = dsf_bts_max, | ||
63 | |||
64 | dsf_pebs_max, | ||
65 | dsf_ctl_max = dsf_pebs_max, | ||
66 | dsf_bts_timestamps = dsf_ctl_max, | ||
67 | #define BTS_TIMESTAMPS (1 << dsf_bts_timestamps) | ||
68 | /* add timestamps into BTS trace */ | ||
69 | |||
70 | #define BTS_USER_FLAGS (BTS_KERNEL | BTS_USER | BTS_TIMESTAMPS) | ||
71 | }; | ||
72 | |||
73 | |||
74 | /* | ||
75 | * Request BTS or PEBS | ||
76 | * | ||
77 | * Due to alignement constraints, the actual buffer may be slightly | ||
78 | * smaller than the requested or provided buffer. | ||
79 | * | ||
80 | * Returns a pointer to a tracer structure on success, or | ||
81 | * ERR_PTR(errcode) on failure. | ||
82 | * | ||
83 | * The interrupt threshold is independent from the overflow callback | ||
84 | * to allow users to use their own overflow interrupt handling mechanism. | ||
85 | * | ||
86 | * The function might sleep. | ||
87 | * | ||
88 | * task: the task to request recording for | ||
89 | * cpu: the cpu to request recording for | ||
90 | * base: the base pointer for the (non-pageable) buffer; | ||
91 | * size: the size of the provided buffer in bytes | ||
92 | * ovfl: pointer to a function to be called on buffer overflow; | ||
93 | * NULL if cyclic buffer requested | ||
94 | * th: the interrupt threshold in records from the end of the buffer; | ||
95 | * -1 if no interrupt threshold is requested. | ||
96 | * flags: a bit-mask of the above flags | ||
97 | */ | ||
98 | extern struct bts_tracer *ds_request_bts_task(struct task_struct *task, | ||
99 | void *base, size_t size, | ||
100 | bts_ovfl_callback_t ovfl, | ||
101 | size_t th, unsigned int flags); | ||
102 | extern struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size, | ||
103 | bts_ovfl_callback_t ovfl, | ||
104 | size_t th, unsigned int flags); | ||
105 | extern struct pebs_tracer *ds_request_pebs_task(struct task_struct *task, | ||
106 | void *base, size_t size, | ||
107 | pebs_ovfl_callback_t ovfl, | ||
108 | size_t th, unsigned int flags); | ||
109 | extern struct pebs_tracer *ds_request_pebs_cpu(int cpu, | ||
110 | void *base, size_t size, | ||
111 | pebs_ovfl_callback_t ovfl, | ||
112 | size_t th, unsigned int flags); | ||
113 | |||
114 | /* | ||
115 | * Release BTS or PEBS resources | ||
116 | * Suspend and resume BTS or PEBS tracing | ||
117 | * | ||
118 | * Must be called with irq's enabled. | ||
119 | * | ||
120 | * tracer: the tracer handle returned from ds_request_~() | ||
121 | */ | ||
122 | extern void ds_release_bts(struct bts_tracer *tracer); | ||
123 | extern void ds_suspend_bts(struct bts_tracer *tracer); | ||
124 | extern void ds_resume_bts(struct bts_tracer *tracer); | ||
125 | extern void ds_release_pebs(struct pebs_tracer *tracer); | ||
126 | extern void ds_suspend_pebs(struct pebs_tracer *tracer); | ||
127 | extern void ds_resume_pebs(struct pebs_tracer *tracer); | ||
128 | |||
129 | /* | ||
130 | * Release BTS or PEBS resources | ||
131 | * Suspend and resume BTS or PEBS tracing | ||
132 | * | ||
133 | * Cpu tracers must call this on the traced cpu. | ||
134 | * Task tracers must call ds_release_~_noirq() for themselves. | ||
135 | * | ||
136 | * May be called with irq's disabled. | ||
137 | * | ||
138 | * Returns 0 if successful; | ||
139 | * -EPERM if the cpu tracer does not trace the current cpu. | ||
140 | * -EPERM if the task tracer does not trace itself. | ||
141 | * | ||
142 | * tracer: the tracer handle returned from ds_request_~() | ||
143 | */ | ||
144 | extern int ds_release_bts_noirq(struct bts_tracer *tracer); | ||
145 | extern int ds_suspend_bts_noirq(struct bts_tracer *tracer); | ||
146 | extern int ds_resume_bts_noirq(struct bts_tracer *tracer); | ||
147 | extern int ds_release_pebs_noirq(struct pebs_tracer *tracer); | ||
148 | extern int ds_suspend_pebs_noirq(struct pebs_tracer *tracer); | ||
149 | extern int ds_resume_pebs_noirq(struct pebs_tracer *tracer); | ||
150 | |||
151 | |||
152 | /* | ||
153 | * The raw DS buffer state as it is used for BTS and PEBS recording. | ||
154 | * | ||
155 | * This is the low-level, arch-dependent interface for working | ||
156 | * directly on the raw trace data. | ||
157 | */ | ||
158 | struct ds_trace { | ||
159 | /* the number of bts/pebs records */ | ||
160 | size_t n; | ||
161 | /* the size of a bts/pebs record in bytes */ | ||
162 | size_t size; | ||
163 | /* pointers into the raw buffer: | ||
164 | - to the first entry */ | ||
165 | void *begin; | ||
166 | /* - one beyond the last entry */ | ||
167 | void *end; | ||
168 | /* - one beyond the newest entry */ | ||
169 | void *top; | ||
170 | /* - the interrupt threshold */ | ||
171 | void *ith; | ||
172 | /* flags given on ds_request() */ | ||
173 | unsigned int flags; | ||
174 | }; | ||
175 | |||
176 | /* | ||
177 | * An arch-independent view on branch trace data. | ||
178 | */ | ||
179 | enum bts_qualifier { | ||
180 | bts_invalid, | ||
181 | #define BTS_INVALID bts_invalid | ||
182 | |||
183 | bts_branch, | ||
184 | #define BTS_BRANCH bts_branch | ||
185 | |||
186 | bts_task_arrives, | ||
187 | #define BTS_TASK_ARRIVES bts_task_arrives | ||
188 | |||
189 | bts_task_departs, | ||
190 | #define BTS_TASK_DEPARTS bts_task_departs | ||
191 | |||
192 | bts_qual_bit_size = 4, | ||
193 | bts_qual_max = (1 << bts_qual_bit_size), | ||
194 | }; | ||
195 | |||
196 | struct bts_struct { | ||
197 | __u64 qualifier; | ||
198 | union { | ||
199 | /* BTS_BRANCH */ | ||
200 | struct { | ||
201 | __u64 from; | ||
202 | __u64 to; | ||
203 | } lbr; | ||
204 | /* BTS_TASK_ARRIVES or BTS_TASK_DEPARTS */ | ||
205 | struct { | ||
206 | __u64 clock; | ||
207 | pid_t pid; | ||
208 | } event; | ||
209 | } variant; | ||
210 | }; | ||
211 | |||
212 | |||
213 | /* | ||
214 | * The BTS state. | ||
215 | * | ||
216 | * This gives access to the raw DS state and adds functions to provide | ||
217 | * an arch-independent view of the BTS data. | ||
218 | */ | ||
219 | struct bts_trace { | ||
220 | struct ds_trace ds; | ||
221 | |||
222 | int (*read)(struct bts_tracer *tracer, const void *at, | ||
223 | struct bts_struct *out); | ||
224 | int (*write)(struct bts_tracer *tracer, const struct bts_struct *in); | ||
225 | }; | ||
226 | |||
227 | |||
228 | /* | ||
229 | * The PEBS state. | ||
230 | * | ||
231 | * This gives access to the raw DS state and the PEBS-specific counter | ||
232 | * reset value. | ||
233 | */ | ||
234 | struct pebs_trace { | ||
235 | struct ds_trace ds; | ||
236 | |||
237 | /* the number of valid counters in the below array */ | ||
238 | unsigned int counters; | ||
239 | |||
240 | #define MAX_PEBS_COUNTERS 4 | ||
241 | /* the counter reset value */ | ||
242 | unsigned long long counter_reset[MAX_PEBS_COUNTERS]; | ||
243 | }; | ||
244 | |||
245 | |||
246 | /* | ||
247 | * Read the BTS or PEBS trace. | ||
248 | * | ||
249 | * Returns a view on the trace collected for the parameter tracer. | ||
250 | * | ||
251 | * The view remains valid as long as the traced task is not running or | ||
252 | * the tracer is suspended. | ||
253 | * Writes into the trace buffer are not reflected. | ||
254 | * | ||
255 | * tracer: the tracer handle returned from ds_request_~() | ||
256 | */ | ||
257 | extern const struct bts_trace *ds_read_bts(struct bts_tracer *tracer); | ||
258 | extern const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer); | ||
259 | |||
260 | |||
261 | /* | ||
262 | * Reset the write pointer of the BTS/PEBS buffer. | ||
263 | * | ||
264 | * Returns 0 on success; -Eerrno on error | ||
265 | * | ||
266 | * tracer: the tracer handle returned from ds_request_~() | ||
267 | */ | ||
268 | extern int ds_reset_bts(struct bts_tracer *tracer); | ||
269 | extern int ds_reset_pebs(struct pebs_tracer *tracer); | ||
270 | |||
271 | /* | ||
272 | * Set the PEBS counter reset value. | ||
273 | * | ||
274 | * Returns 0 on success; -Eerrno on error | ||
275 | * | ||
276 | * tracer: the tracer handle returned from ds_request_pebs() | ||
277 | * counter: the index of the counter | ||
278 | * value: the new counter reset value | ||
279 | */ | ||
280 | extern int ds_set_pebs_reset(struct pebs_tracer *tracer, | ||
281 | unsigned int counter, u64 value); | ||
282 | |||
283 | /* | ||
284 | * Initialization | ||
285 | */ | ||
286 | struct cpuinfo_x86; | ||
287 | extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *); | ||
288 | |||
289 | /* | ||
290 | * Context switch work | ||
291 | */ | ||
292 | extern void ds_switch_to(struct task_struct *prev, struct task_struct *next); | ||
293 | |||
294 | #else /* CONFIG_X86_DS */ | ||
295 | |||
296 | struct cpuinfo_x86; | ||
297 | static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {} | ||
298 | static inline void ds_switch_to(struct task_struct *prev, | ||
299 | struct task_struct *next) {} | ||
300 | |||
301 | #endif /* CONFIG_X86_DS */ | ||
302 | #endif /* _ASM_X86_DS_H */ | ||
diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h index ae6253ab9029..733f7e91e7a9 100644 --- a/arch/x86/include/asm/dwarf2.h +++ b/arch/x86/include/asm/dwarf2.h | |||
@@ -34,6 +34,18 @@ | |||
34 | #define CFI_SIGNAL_FRAME | 34 | #define CFI_SIGNAL_FRAME |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #if defined(CONFIG_AS_CFI_SECTIONS) && defined(__ASSEMBLY__) | ||
38 | /* | ||
39 | * Emit CFI data in .debug_frame sections, not .eh_frame sections. | ||
40 | * The latter we currently just discard since we don't do DWARF | ||
41 | * unwinding at runtime. So only the offline DWARF information is | ||
42 | * useful to anyone. Note we should not use this directive if this | ||
43 | * file is used in the vDSO assembly, or if vmlinux.lds.S gets | ||
44 | * changed so it doesn't discard .eh_frame. | ||
45 | */ | ||
46 | .cfi_sections .debug_frame | ||
47 | #endif | ||
48 | |||
37 | #else | 49 | #else |
38 | 50 | ||
39 | /* | 51 | /* |
diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h index 0e22296790d3..ec8a52d14ab1 100644 --- a/arch/x86/include/asm/e820.h +++ b/arch/x86/include/asm/e820.h | |||
@@ -45,7 +45,12 @@ | |||
45 | #define E820_NVS 4 | 45 | #define E820_NVS 4 |
46 | #define E820_UNUSABLE 5 | 46 | #define E820_UNUSABLE 5 |
47 | 47 | ||
48 | /* reserved RAM used by kernel itself */ | 48 | /* |
49 | * reserved RAM used by kernel itself | ||
50 | * if CONFIG_INTEL_TXT is enabled, memory of this type will be | ||
51 | * included in the S3 integrity calculation and so should not include | ||
52 | * any memory that BIOS might alter over the S3 transition | ||
53 | */ | ||
49 | #define E820_RESERVED_KERN 128 | 54 | #define E820_RESERVED_KERN 128 |
50 | 55 | ||
51 | #ifndef __ASSEMBLY__ | 56 | #ifndef __ASSEMBLY__ |
diff --git a/arch/x86/include/asm/hardirq.h b/arch/x86/include/asm/hardirq.h index 0f8576427cfe..aeab29aee617 100644 --- a/arch/x86/include/asm/hardirq.h +++ b/arch/x86/include/asm/hardirq.h | |||
@@ -35,7 +35,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat); | |||
35 | 35 | ||
36 | #define __ARCH_IRQ_STAT | 36 | #define __ARCH_IRQ_STAT |
37 | 37 | ||
38 | #define inc_irq_stat(member) percpu_add(irq_stat.member, 1) | 38 | #define inc_irq_stat(member) percpu_inc(irq_stat.member) |
39 | 39 | ||
40 | #define local_softirq_pending() percpu_read(irq_stat.__softirq_pending) | 40 | #define local_softirq_pending() percpu_read(irq_stat.__softirq_pending) |
41 | 41 | ||
diff --git a/arch/x86/include/asm/hw_breakpoint.h b/arch/x86/include/asm/hw_breakpoint.h index 2a1bd8f4f23a..942255310e6a 100644 --- a/arch/x86/include/asm/hw_breakpoint.h +++ b/arch/x86/include/asm/hw_breakpoint.h | |||
@@ -41,12 +41,16 @@ struct arch_hw_breakpoint { | |||
41 | /* Total number of available HW breakpoint registers */ | 41 | /* Total number of available HW breakpoint registers */ |
42 | #define HBP_NUM 4 | 42 | #define HBP_NUM 4 |
43 | 43 | ||
44 | static inline int hw_breakpoint_slots(int type) | ||
45 | { | ||
46 | return HBP_NUM; | ||
47 | } | ||
48 | |||
44 | struct perf_event; | 49 | struct perf_event; |
45 | struct pmu; | 50 | struct pmu; |
46 | 51 | ||
47 | extern int arch_check_va_in_userspace(unsigned long va, u8 hbp_len); | 52 | extern int arch_check_bp_in_kernelspace(struct perf_event *bp); |
48 | extern int arch_validate_hwbkpt_settings(struct perf_event *bp, | 53 | extern int arch_validate_hwbkpt_settings(struct perf_event *bp); |
49 | struct task_struct *tsk); | ||
50 | extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, | 54 | extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, |
51 | unsigned long val, void *data); | 55 | unsigned long val, void *data); |
52 | 56 | ||
diff --git a/arch/x86/include/asm/hyperv.h b/arch/x86/include/asm/hyperv.h index e153a2b3889a..5df477ac3af7 100644 --- a/arch/x86/include/asm/hyperv.h +++ b/arch/x86/include/asm/hyperv.h | |||
@@ -1,5 +1,5 @@ | |||
1 | #ifndef _ASM_X86_KVM_HYPERV_H | 1 | #ifndef _ASM_X86_HYPERV_H |
2 | #define _ASM_X86_KVM_HYPERV_H | 2 | #define _ASM_X86_HYPERV_H |
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | 5 | ||
@@ -14,6 +14,10 @@ | |||
14 | #define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004 | 14 | #define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004 |
15 | #define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005 | 15 | #define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005 |
16 | 16 | ||
17 | #define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000 | ||
18 | #define HYPERV_CPUID_MIN 0x40000005 | ||
19 | #define HYPERV_CPUID_MAX 0x4000ffff | ||
20 | |||
17 | /* | 21 | /* |
18 | * Feature identification. EAX indicates which features are available | 22 | * Feature identification. EAX indicates which features are available |
19 | * to the partition based upon the current partition privileges. | 23 | * to the partition based upon the current partition privileges. |
@@ -129,6 +133,9 @@ | |||
129 | /* MSR used to provide vcpu index */ | 133 | /* MSR used to provide vcpu index */ |
130 | #define HV_X64_MSR_VP_INDEX 0x40000002 | 134 | #define HV_X64_MSR_VP_INDEX 0x40000002 |
131 | 135 | ||
136 | /* MSR used to read the per-partition time reference counter */ | ||
137 | #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 | ||
138 | |||
132 | /* Define the virtual APIC registers */ | 139 | /* Define the virtual APIC registers */ |
133 | #define HV_X64_MSR_EOI 0x40000070 | 140 | #define HV_X64_MSR_EOI 0x40000070 |
134 | #define HV_X64_MSR_ICR 0x40000071 | 141 | #define HV_X64_MSR_ICR 0x40000071 |
diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h index b78c0941e422..70abda7058c8 100644 --- a/arch/x86/include/asm/hypervisor.h +++ b/arch/x86/include/asm/hypervisor.h | |||
@@ -17,10 +17,33 @@ | |||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * | 18 | * |
19 | */ | 19 | */ |
20 | #ifndef ASM_X86__HYPERVISOR_H | 20 | #ifndef _ASM_X86_HYPERVISOR_H |
21 | #define ASM_X86__HYPERVISOR_H | 21 | #define _ASM_X86_HYPERVISOR_H |
22 | 22 | ||
23 | extern void init_hypervisor(struct cpuinfo_x86 *c); | 23 | extern void init_hypervisor(struct cpuinfo_x86 *c); |
24 | extern void init_hypervisor_platform(void); | 24 | extern void init_hypervisor_platform(void); |
25 | 25 | ||
26 | /* | ||
27 | * x86 hypervisor information | ||
28 | */ | ||
29 | struct hypervisor_x86 { | ||
30 | /* Hypervisor name */ | ||
31 | const char *name; | ||
32 | |||
33 | /* Detection routine */ | ||
34 | bool (*detect)(void); | ||
35 | |||
36 | /* Adjust CPU feature bits (run once per CPU) */ | ||
37 | void (*set_cpu_features)(struct cpuinfo_x86 *); | ||
38 | |||
39 | /* Platform setup (run once per boot) */ | ||
40 | void (*init_platform)(void); | ||
41 | }; | ||
42 | |||
43 | extern const struct hypervisor_x86 *x86_hyper; | ||
44 | |||
45 | /* Recognized hypervisors */ | ||
46 | extern const struct hypervisor_x86 x86_hyper_vmware; | ||
47 | extern const struct hypervisor_x86 x86_hyper_ms_hyperv; | ||
48 | |||
26 | #endif | 49 | #endif |
diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h index da2930924501..c991b3a7b904 100644 --- a/arch/x86/include/asm/i387.h +++ b/arch/x86/include/asm/i387.h | |||
@@ -16,7 +16,9 @@ | |||
16 | #include <linux/kernel_stat.h> | 16 | #include <linux/kernel_stat.h> |
17 | #include <linux/regset.h> | 17 | #include <linux/regset.h> |
18 | #include <linux/hardirq.h> | 18 | #include <linux/hardirq.h> |
19 | #include <linux/slab.h> | ||
19 | #include <asm/asm.h> | 20 | #include <asm/asm.h> |
21 | #include <asm/cpufeature.h> | ||
20 | #include <asm/processor.h> | 22 | #include <asm/processor.h> |
21 | #include <asm/sigcontext.h> | 23 | #include <asm/sigcontext.h> |
22 | #include <asm/user.h> | 24 | #include <asm/user.h> |
@@ -56,6 +58,11 @@ extern int restore_i387_xstate_ia32(void __user *buf); | |||
56 | 58 | ||
57 | #define X87_FSW_ES (1 << 7) /* Exception Summary */ | 59 | #define X87_FSW_ES (1 << 7) /* Exception Summary */ |
58 | 60 | ||
61 | static __always_inline __pure bool use_xsave(void) | ||
62 | { | ||
63 | return static_cpu_has(X86_FEATURE_XSAVE); | ||
64 | } | ||
65 | |||
59 | #ifdef CONFIG_X86_64 | 66 | #ifdef CONFIG_X86_64 |
60 | 67 | ||
61 | /* Ignore delayed exceptions from user space */ | 68 | /* Ignore delayed exceptions from user space */ |
@@ -91,15 +98,15 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx) | |||
91 | values. The kernel data segment can be sometimes 0 and sometimes | 98 | values. The kernel data segment can be sometimes 0 and sometimes |
92 | new user value. Both should be ok. | 99 | new user value. Both should be ok. |
93 | Use the PDA as safe address because it should be already in L1. */ | 100 | Use the PDA as safe address because it should be already in L1. */ |
94 | static inline void clear_fpu_state(struct task_struct *tsk) | 101 | static inline void fpu_clear(struct fpu *fpu) |
95 | { | 102 | { |
96 | struct xsave_struct *xstate = &tsk->thread.xstate->xsave; | 103 | struct xsave_struct *xstate = &fpu->state->xsave; |
97 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; | 104 | struct i387_fxsave_struct *fx = &fpu->state->fxsave; |
98 | 105 | ||
99 | /* | 106 | /* |
100 | * xsave header may indicate the init state of the FP. | 107 | * xsave header may indicate the init state of the FP. |
101 | */ | 108 | */ |
102 | if ((task_thread_info(tsk)->status & TS_XSAVE) && | 109 | if (use_xsave() && |
103 | !(xstate->xsave_hdr.xstate_bv & XSTATE_FP)) | 110 | !(xstate->xsave_hdr.xstate_bv & XSTATE_FP)) |
104 | return; | 111 | return; |
105 | 112 | ||
@@ -111,6 +118,11 @@ static inline void clear_fpu_state(struct task_struct *tsk) | |||
111 | X86_FEATURE_FXSAVE_LEAK); | 118 | X86_FEATURE_FXSAVE_LEAK); |
112 | } | 119 | } |
113 | 120 | ||
121 | static inline void clear_fpu_state(struct task_struct *tsk) | ||
122 | { | ||
123 | fpu_clear(&tsk->thread.fpu); | ||
124 | } | ||
125 | |||
114 | static inline int fxsave_user(struct i387_fxsave_struct __user *fx) | 126 | static inline int fxsave_user(struct i387_fxsave_struct __user *fx) |
115 | { | 127 | { |
116 | int err; | 128 | int err; |
@@ -135,7 +147,7 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx) | |||
135 | return err; | 147 | return err; |
136 | } | 148 | } |
137 | 149 | ||
138 | static inline void fxsave(struct task_struct *tsk) | 150 | static inline void fpu_fxsave(struct fpu *fpu) |
139 | { | 151 | { |
140 | /* Using "rex64; fxsave %0" is broken because, if the memory operand | 152 | /* Using "rex64; fxsave %0" is broken because, if the memory operand |
141 | uses any extended registers for addressing, a second REX prefix | 153 | uses any extended registers for addressing, a second REX prefix |
@@ -145,42 +157,45 @@ static inline void fxsave(struct task_struct *tsk) | |||
145 | /* Using "fxsaveq %0" would be the ideal choice, but is only supported | 157 | /* Using "fxsaveq %0" would be the ideal choice, but is only supported |
146 | starting with gas 2.16. */ | 158 | starting with gas 2.16. */ |
147 | __asm__ __volatile__("fxsaveq %0" | 159 | __asm__ __volatile__("fxsaveq %0" |
148 | : "=m" (tsk->thread.xstate->fxsave)); | 160 | : "=m" (fpu->state->fxsave)); |
149 | #elif 0 | 161 | #elif 0 |
150 | /* Using, as a workaround, the properly prefixed form below isn't | 162 | /* Using, as a workaround, the properly prefixed form below isn't |
151 | accepted by any binutils version so far released, complaining that | 163 | accepted by any binutils version so far released, complaining that |
152 | the same type of prefix is used twice if an extended register is | 164 | the same type of prefix is used twice if an extended register is |
153 | needed for addressing (fix submitted to mainline 2005-11-21). */ | 165 | needed for addressing (fix submitted to mainline 2005-11-21). */ |
154 | __asm__ __volatile__("rex64/fxsave %0" | 166 | __asm__ __volatile__("rex64/fxsave %0" |
155 | : "=m" (tsk->thread.xstate->fxsave)); | 167 | : "=m" (fpu->state->fxsave)); |
156 | #else | 168 | #else |
157 | /* This, however, we can work around by forcing the compiler to select | 169 | /* This, however, we can work around by forcing the compiler to select |
158 | an addressing mode that doesn't require extended registers. */ | 170 | an addressing mode that doesn't require extended registers. */ |
159 | __asm__ __volatile__("rex64/fxsave (%1)" | 171 | __asm__ __volatile__("rex64/fxsave (%1)" |
160 | : "=m" (tsk->thread.xstate->fxsave) | 172 | : "=m" (fpu->state->fxsave) |
161 | : "cdaSDb" (&tsk->thread.xstate->fxsave)); | 173 | : "cdaSDb" (&fpu->state->fxsave)); |
162 | #endif | 174 | #endif |
163 | } | 175 | } |
164 | 176 | ||
165 | static inline void __save_init_fpu(struct task_struct *tsk) | 177 | static inline void fpu_save_init(struct fpu *fpu) |
166 | { | 178 | { |
167 | if (task_thread_info(tsk)->status & TS_XSAVE) | 179 | if (use_xsave()) |
168 | xsave(tsk); | 180 | fpu_xsave(fpu); |
169 | else | 181 | else |
170 | fxsave(tsk); | 182 | fpu_fxsave(fpu); |
183 | |||
184 | fpu_clear(fpu); | ||
185 | } | ||
171 | 186 | ||
172 | clear_fpu_state(tsk); | 187 | static inline void __save_init_fpu(struct task_struct *tsk) |
188 | { | ||
189 | fpu_save_init(&tsk->thread.fpu); | ||
173 | task_thread_info(tsk)->status &= ~TS_USEDFPU; | 190 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
174 | } | 191 | } |
175 | 192 | ||
176 | #else /* CONFIG_X86_32 */ | 193 | #else /* CONFIG_X86_32 */ |
177 | 194 | ||
178 | #ifdef CONFIG_MATH_EMULATION | 195 | #ifdef CONFIG_MATH_EMULATION |
179 | extern void finit_task(struct task_struct *tsk); | 196 | extern void finit_soft_fpu(struct i387_soft_struct *soft); |
180 | #else | 197 | #else |
181 | static inline void finit_task(struct task_struct *tsk) | 198 | static inline void finit_soft_fpu(struct i387_soft_struct *soft) {} |
182 | { | ||
183 | } | ||
184 | #endif | 199 | #endif |
185 | 200 | ||
186 | static inline void tolerant_fwait(void) | 201 | static inline void tolerant_fwait(void) |
@@ -216,13 +231,13 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx) | |||
216 | /* | 231 | /* |
217 | * These must be called with preempt disabled | 232 | * These must be called with preempt disabled |
218 | */ | 233 | */ |
219 | static inline void __save_init_fpu(struct task_struct *tsk) | 234 | static inline void fpu_save_init(struct fpu *fpu) |
220 | { | 235 | { |
221 | if (task_thread_info(tsk)->status & TS_XSAVE) { | 236 | if (use_xsave()) { |
222 | struct xsave_struct *xstate = &tsk->thread.xstate->xsave; | 237 | struct xsave_struct *xstate = &fpu->state->xsave; |
223 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; | 238 | struct i387_fxsave_struct *fx = &fpu->state->fxsave; |
224 | 239 | ||
225 | xsave(tsk); | 240 | fpu_xsave(fpu); |
226 | 241 | ||
227 | /* | 242 | /* |
228 | * xsave header may indicate the init state of the FP. | 243 | * xsave header may indicate the init state of the FP. |
@@ -246,8 +261,8 @@ static inline void __save_init_fpu(struct task_struct *tsk) | |||
246 | "fxsave %[fx]\n" | 261 | "fxsave %[fx]\n" |
247 | "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:", | 262 | "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:", |
248 | X86_FEATURE_FXSR, | 263 | X86_FEATURE_FXSR, |
249 | [fx] "m" (tsk->thread.xstate->fxsave), | 264 | [fx] "m" (fpu->state->fxsave), |
250 | [fsw] "m" (tsk->thread.xstate->fxsave.swd) : "memory"); | 265 | [fsw] "m" (fpu->state->fxsave.swd) : "memory"); |
251 | clear_state: | 266 | clear_state: |
252 | /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception | 267 | /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception |
253 | is pending. Clear the x87 state here by setting it to fixed | 268 | is pending. Clear the x87 state here by setting it to fixed |
@@ -259,17 +274,34 @@ clear_state: | |||
259 | X86_FEATURE_FXSAVE_LEAK, | 274 | X86_FEATURE_FXSAVE_LEAK, |
260 | [addr] "m" (safe_address)); | 275 | [addr] "m" (safe_address)); |
261 | end: | 276 | end: |
277 | ; | ||
278 | } | ||
279 | |||
280 | static inline void __save_init_fpu(struct task_struct *tsk) | ||
281 | { | ||
282 | fpu_save_init(&tsk->thread.fpu); | ||
262 | task_thread_info(tsk)->status &= ~TS_USEDFPU; | 283 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
263 | } | 284 | } |
264 | 285 | ||
286 | |||
265 | #endif /* CONFIG_X86_64 */ | 287 | #endif /* CONFIG_X86_64 */ |
266 | 288 | ||
267 | static inline int restore_fpu_checking(struct task_struct *tsk) | 289 | static inline int fpu_fxrstor_checking(struct fpu *fpu) |
268 | { | 290 | { |
269 | if (task_thread_info(tsk)->status & TS_XSAVE) | 291 | return fxrstor_checking(&fpu->state->fxsave); |
270 | return xrstor_checking(&tsk->thread.xstate->xsave); | 292 | } |
293 | |||
294 | static inline int fpu_restore_checking(struct fpu *fpu) | ||
295 | { | ||
296 | if (use_xsave()) | ||
297 | return fpu_xrstor_checking(fpu); | ||
271 | else | 298 | else |
272 | return fxrstor_checking(&tsk->thread.xstate->fxsave); | 299 | return fpu_fxrstor_checking(fpu); |
300 | } | ||
301 | |||
302 | static inline int restore_fpu_checking(struct task_struct *tsk) | ||
303 | { | ||
304 | return fpu_restore_checking(&tsk->thread.fpu); | ||
273 | } | 305 | } |
274 | 306 | ||
275 | /* | 307 | /* |
@@ -397,30 +429,59 @@ static inline void clear_fpu(struct task_struct *tsk) | |||
397 | static inline unsigned short get_fpu_cwd(struct task_struct *tsk) | 429 | static inline unsigned short get_fpu_cwd(struct task_struct *tsk) |
398 | { | 430 | { |
399 | if (cpu_has_fxsr) { | 431 | if (cpu_has_fxsr) { |
400 | return tsk->thread.xstate->fxsave.cwd; | 432 | return tsk->thread.fpu.state->fxsave.cwd; |
401 | } else { | 433 | } else { |
402 | return (unsigned short)tsk->thread.xstate->fsave.cwd; | 434 | return (unsigned short)tsk->thread.fpu.state->fsave.cwd; |
403 | } | 435 | } |
404 | } | 436 | } |
405 | 437 | ||
406 | static inline unsigned short get_fpu_swd(struct task_struct *tsk) | 438 | static inline unsigned short get_fpu_swd(struct task_struct *tsk) |
407 | { | 439 | { |
408 | if (cpu_has_fxsr) { | 440 | if (cpu_has_fxsr) { |
409 | return tsk->thread.xstate->fxsave.swd; | 441 | return tsk->thread.fpu.state->fxsave.swd; |
410 | } else { | 442 | } else { |
411 | return (unsigned short)tsk->thread.xstate->fsave.swd; | 443 | return (unsigned short)tsk->thread.fpu.state->fsave.swd; |
412 | } | 444 | } |
413 | } | 445 | } |
414 | 446 | ||
415 | static inline unsigned short get_fpu_mxcsr(struct task_struct *tsk) | 447 | static inline unsigned short get_fpu_mxcsr(struct task_struct *tsk) |
416 | { | 448 | { |
417 | if (cpu_has_xmm) { | 449 | if (cpu_has_xmm) { |
418 | return tsk->thread.xstate->fxsave.mxcsr; | 450 | return tsk->thread.fpu.state->fxsave.mxcsr; |
419 | } else { | 451 | } else { |
420 | return MXCSR_DEFAULT; | 452 | return MXCSR_DEFAULT; |
421 | } | 453 | } |
422 | } | 454 | } |
423 | 455 | ||
456 | static bool fpu_allocated(struct fpu *fpu) | ||
457 | { | ||
458 | return fpu->state != NULL; | ||
459 | } | ||
460 | |||
461 | static inline int fpu_alloc(struct fpu *fpu) | ||
462 | { | ||
463 | if (fpu_allocated(fpu)) | ||
464 | return 0; | ||
465 | fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_KERNEL); | ||
466 | if (!fpu->state) | ||
467 | return -ENOMEM; | ||
468 | WARN_ON((unsigned long)fpu->state & 15); | ||
469 | return 0; | ||
470 | } | ||
471 | |||
472 | static inline void fpu_free(struct fpu *fpu) | ||
473 | { | ||
474 | if (fpu->state) { | ||
475 | kmem_cache_free(task_xstate_cachep, fpu->state); | ||
476 | fpu->state = NULL; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | static inline void fpu_copy(struct fpu *dst, struct fpu *src) | ||
481 | { | ||
482 | memcpy(dst->state, src->state, xstate_size); | ||
483 | } | ||
484 | |||
424 | #endif /* __ASSEMBLY__ */ | 485 | #endif /* __ASSEMBLY__ */ |
425 | 486 | ||
426 | #define PSHUFB_XMM5_XMM0 .byte 0x66, 0x0f, 0x38, 0x00, 0xc5 | 487 | #define PSHUFB_XMM5_XMM0 .byte 0x66, 0x0f, 0x38, 0x00, 0xc5 |
diff --git a/arch/x86/include/asm/i8253.h b/arch/x86/include/asm/i8253.h index 1edbf89680fd..fc1f579fb965 100644 --- a/arch/x86/include/asm/i8253.h +++ b/arch/x86/include/asm/i8253.h | |||
@@ -6,7 +6,7 @@ | |||
6 | #define PIT_CH0 0x40 | 6 | #define PIT_CH0 0x40 |
7 | #define PIT_CH2 0x42 | 7 | #define PIT_CH2 0x42 |
8 | 8 | ||
9 | extern spinlock_t i8253_lock; | 9 | extern raw_spinlock_t i8253_lock; |
10 | 10 | ||
11 | extern struct clock_event_device *global_clock_event; | 11 | extern struct clock_event_device *global_clock_event; |
12 | 12 | ||
diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 96c2e0ad04ca..88c765e16410 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h | |||
@@ -68,6 +68,8 @@ struct insn { | |||
68 | const insn_byte_t *next_byte; | 68 | const insn_byte_t *next_byte; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | #define MAX_INSN_SIZE 16 | ||
72 | |||
71 | #define X86_MODRM_MOD(modrm) (((modrm) & 0xc0) >> 6) | 73 | #define X86_MODRM_MOD(modrm) (((modrm) & 0xc0) >> 6) |
72 | #define X86_MODRM_REG(modrm) (((modrm) & 0x38) >> 3) | 74 | #define X86_MODRM_REG(modrm) (((modrm) & 0x38) >> 3) |
73 | #define X86_MODRM_RM(modrm) ((modrm) & 0x07) | 75 | #define X86_MODRM_RM(modrm) ((modrm) & 0x07) |
diff --git a/arch/x86/include/asm/io_apic.h b/arch/x86/include/asm/io_apic.h index 35832a03a515..63cb4096c3dc 100644 --- a/arch/x86/include/asm/io_apic.h +++ b/arch/x86/include/asm/io_apic.h | |||
@@ -159,7 +159,6 @@ struct io_apic_irq_attr; | |||
159 | extern int io_apic_set_pci_routing(struct device *dev, int irq, | 159 | extern int io_apic_set_pci_routing(struct device *dev, int irq, |
160 | struct io_apic_irq_attr *irq_attr); | 160 | struct io_apic_irq_attr *irq_attr); |
161 | void setup_IO_APIC_irq_extra(u32 gsi); | 161 | void setup_IO_APIC_irq_extra(u32 gsi); |
162 | extern int (*ioapic_renumber_irq)(int ioapic, int irq); | ||
163 | extern void ioapic_init_mappings(void); | 162 | extern void ioapic_init_mappings(void); |
164 | extern void ioapic_insert_resources(void); | 163 | extern void ioapic_insert_resources(void); |
165 | 164 | ||
@@ -180,12 +179,13 @@ extern void ioapic_write_entry(int apic, int pin, | |||
180 | extern void setup_ioapic_ids_from_mpc(void); | 179 | extern void setup_ioapic_ids_from_mpc(void); |
181 | 180 | ||
182 | struct mp_ioapic_gsi{ | 181 | struct mp_ioapic_gsi{ |
183 | int gsi_base; | 182 | u32 gsi_base; |
184 | int gsi_end; | 183 | u32 gsi_end; |
185 | }; | 184 | }; |
186 | extern struct mp_ioapic_gsi mp_gsi_routing[]; | 185 | extern struct mp_ioapic_gsi mp_gsi_routing[]; |
187 | int mp_find_ioapic(int gsi); | 186 | extern u32 gsi_end; |
188 | int mp_find_ioapic_pin(int ioapic, int gsi); | 187 | int mp_find_ioapic(u32 gsi); |
188 | int mp_find_ioapic_pin(int ioapic, u32 gsi); | ||
189 | void __init mp_register_ioapic(int id, u32 address, u32 gsi_base); | 189 | void __init mp_register_ioapic(int id, u32 address, u32 gsi_base); |
190 | extern void __init pre_init_apic_IRQ0(void); | 190 | extern void __init pre_init_apic_IRQ0(void); |
191 | 191 | ||
@@ -197,7 +197,8 @@ static const int timer_through_8259 = 0; | |||
197 | static inline void ioapic_init_mappings(void) { } | 197 | static inline void ioapic_init_mappings(void) { } |
198 | static inline void ioapic_insert_resources(void) { } | 198 | static inline void ioapic_insert_resources(void) { } |
199 | static inline void probe_nr_irqs_gsi(void) { } | 199 | static inline void probe_nr_irqs_gsi(void) { } |
200 | static inline int mp_find_ioapic(int gsi) { return 0; } | 200 | #define gsi_end (NR_IRQS_LEGACY - 1) |
201 | static inline int mp_find_ioapic(u32 gsi) { return 0; } | ||
201 | 202 | ||
202 | struct io_apic_irq_attr; | 203 | struct io_apic_irq_attr; |
203 | static inline int io_apic_set_pci_routing(struct device *dev, int irq, | 204 | static inline int io_apic_set_pci_routing(struct device *dev, int irq, |
diff --git a/arch/x86/include/asm/k8.h b/arch/x86/include/asm/k8.h index f70e60071fe8..af00bd1d2089 100644 --- a/arch/x86/include/asm/k8.h +++ b/arch/x86/include/asm/k8.h | |||
@@ -16,11 +16,16 @@ extern int k8_numa_init(unsigned long start_pfn, unsigned long end_pfn); | |||
16 | extern int k8_scan_nodes(void); | 16 | extern int k8_scan_nodes(void); |
17 | 17 | ||
18 | #ifdef CONFIG_K8_NB | 18 | #ifdef CONFIG_K8_NB |
19 | extern int num_k8_northbridges; | ||
20 | |||
19 | static inline struct pci_dev *node_to_k8_nb_misc(int node) | 21 | static inline struct pci_dev *node_to_k8_nb_misc(int node) |
20 | { | 22 | { |
21 | return (node < num_k8_northbridges) ? k8_northbridges[node] : NULL; | 23 | return (node < num_k8_northbridges) ? k8_northbridges[node] : NULL; |
22 | } | 24 | } |
25 | |||
23 | #else | 26 | #else |
27 | #define num_k8_northbridges 0 | ||
28 | |||
24 | static inline struct pci_dev *node_to_k8_nb_misc(int node) | 29 | static inline struct pci_dev *node_to_k8_nb_misc(int node) |
25 | { | 30 | { |
26 | return NULL; | 31 | return NULL; |
diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h index 4ffa345a8ccb..547882539157 100644 --- a/arch/x86/include/asm/kprobes.h +++ b/arch/x86/include/asm/kprobes.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/types.h> | 24 | #include <linux/types.h> |
25 | #include <linux/ptrace.h> | 25 | #include <linux/ptrace.h> |
26 | #include <linux/percpu.h> | 26 | #include <linux/percpu.h> |
27 | #include <asm/insn.h> | ||
27 | 28 | ||
28 | #define __ARCH_WANT_KPROBES_INSN_SLOT | 29 | #define __ARCH_WANT_KPROBES_INSN_SLOT |
29 | 30 | ||
@@ -36,7 +37,6 @@ typedef u8 kprobe_opcode_t; | |||
36 | #define RELATIVEJUMP_SIZE 5 | 37 | #define RELATIVEJUMP_SIZE 5 |
37 | #define RELATIVECALL_OPCODE 0xe8 | 38 | #define RELATIVECALL_OPCODE 0xe8 |
38 | #define RELATIVE_ADDR_SIZE 4 | 39 | #define RELATIVE_ADDR_SIZE 4 |
39 | #define MAX_INSN_SIZE 16 | ||
40 | #define MAX_STACK_SIZE 64 | 40 | #define MAX_STACK_SIZE 64 |
41 | #define MIN_STACK_SIZE(ADDR) \ | 41 | #define MIN_STACK_SIZE(ADDR) \ |
42 | (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \ | 42 | (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \ |
diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h index d8bf23a88d05..c82868e9f905 100644 --- a/arch/x86/include/asm/mpspec.h +++ b/arch/x86/include/asm/mpspec.h | |||
@@ -105,16 +105,6 @@ extern void mp_config_acpi_legacy_irqs(void); | |||
105 | struct device; | 105 | struct device; |
106 | extern int mp_register_gsi(struct device *dev, u32 gsi, int edge_level, | 106 | extern int mp_register_gsi(struct device *dev, u32 gsi, int edge_level, |
107 | int active_high_low); | 107 | int active_high_low); |
108 | extern int acpi_probe_gsi(void); | ||
109 | #ifdef CONFIG_X86_IO_APIC | ||
110 | extern int mp_find_ioapic(int gsi); | ||
111 | extern int mp_find_ioapic_pin(int ioapic, int gsi); | ||
112 | #endif | ||
113 | #else /* !CONFIG_ACPI: */ | ||
114 | static inline int acpi_probe_gsi(void) | ||
115 | { | ||
116 | return 0; | ||
117 | } | ||
118 | #endif /* CONFIG_ACPI */ | 108 | #endif /* CONFIG_ACPI */ |
119 | 109 | ||
120 | #define PHYSID_ARRAY_SIZE BITS_TO_LONGS(MAX_APICS) | 110 | #define PHYSID_ARRAY_SIZE BITS_TO_LONGS(MAX_APICS) |
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h new file mode 100644 index 000000000000..79ce5685ab64 --- /dev/null +++ b/arch/x86/include/asm/mshyperv.h | |||
@@ -0,0 +1,14 @@ | |||
1 | #ifndef _ASM_X86_MSHYPER_H | ||
2 | #define _ASM_X86_MSHYPER_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | #include <asm/hyperv.h> | ||
6 | |||
7 | struct ms_hyperv_info { | ||
8 | u32 features; | ||
9 | u32 hints; | ||
10 | }; | ||
11 | |||
12 | extern struct ms_hyperv_info ms_hyperv; | ||
13 | |||
14 | #endif | ||
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 4604e6a54d36..bc473acfa7f9 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h | |||
@@ -71,11 +71,14 @@ | |||
71 | #define MSR_IA32_LASTINTTOIP 0x000001de | 71 | #define MSR_IA32_LASTINTTOIP 0x000001de |
72 | 72 | ||
73 | /* DEBUGCTLMSR bits (others vary by model): */ | 73 | /* DEBUGCTLMSR bits (others vary by model): */ |
74 | #define _DEBUGCTLMSR_LBR 0 /* last branch recording */ | 74 | #define DEBUGCTLMSR_LBR (1UL << 0) /* last branch recording */ |
75 | #define _DEBUGCTLMSR_BTF 1 /* single-step on branches */ | 75 | #define DEBUGCTLMSR_BTF (1UL << 1) /* single-step on branches */ |
76 | 76 | #define DEBUGCTLMSR_TR (1UL << 6) | |
77 | #define DEBUGCTLMSR_LBR (1UL << _DEBUGCTLMSR_LBR) | 77 | #define DEBUGCTLMSR_BTS (1UL << 7) |
78 | #define DEBUGCTLMSR_BTF (1UL << _DEBUGCTLMSR_BTF) | 78 | #define DEBUGCTLMSR_BTINT (1UL << 8) |
79 | #define DEBUGCTLMSR_BTS_OFF_OS (1UL << 9) | ||
80 | #define DEBUGCTLMSR_BTS_OFF_USR (1UL << 10) | ||
81 | #define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11) | ||
79 | 82 | ||
80 | #define MSR_IA32_MC0_CTL 0x00000400 | 83 | #define MSR_IA32_MC0_CTL 0x00000400 |
81 | #define MSR_IA32_MC0_STATUS 0x00000401 | 84 | #define MSR_IA32_MC0_STATUS 0x00000401 |
@@ -359,6 +362,8 @@ | |||
359 | #define MSR_P4_U2L_ESCR0 0x000003b0 | 362 | #define MSR_P4_U2L_ESCR0 0x000003b0 |
360 | #define MSR_P4_U2L_ESCR1 0x000003b1 | 363 | #define MSR_P4_U2L_ESCR1 0x000003b1 |
361 | 364 | ||
365 | #define MSR_P4_PEBS_MATRIX_VERT 0x000003f2 | ||
366 | |||
362 | /* Intel Core-based CPU performance counters */ | 367 | /* Intel Core-based CPU performance counters */ |
363 | #define MSR_CORE_PERF_FIXED_CTR0 0x00000309 | 368 | #define MSR_CORE_PERF_FIXED_CTR0 0x00000309 |
364 | #define MSR_CORE_PERF_FIXED_CTR1 0x0000030a | 369 | #define MSR_CORE_PERF_FIXED_CTR1 0x0000030a |
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 66a272dfd8b8..0ec6d12d84e6 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h | |||
@@ -190,6 +190,29 @@ do { \ | |||
190 | pfo_ret__; \ | 190 | pfo_ret__; \ |
191 | }) | 191 | }) |
192 | 192 | ||
193 | #define percpu_unary_op(op, var) \ | ||
194 | ({ \ | ||
195 | switch (sizeof(var)) { \ | ||
196 | case 1: \ | ||
197 | asm(op "b "__percpu_arg(0) \ | ||
198 | : "+m" (var)); \ | ||
199 | break; \ | ||
200 | case 2: \ | ||
201 | asm(op "w "__percpu_arg(0) \ | ||
202 | : "+m" (var)); \ | ||
203 | break; \ | ||
204 | case 4: \ | ||
205 | asm(op "l "__percpu_arg(0) \ | ||
206 | : "+m" (var)); \ | ||
207 | break; \ | ||
208 | case 8: \ | ||
209 | asm(op "q "__percpu_arg(0) \ | ||
210 | : "+m" (var)); \ | ||
211 | break; \ | ||
212 | default: __bad_percpu_size(); \ | ||
213 | } \ | ||
214 | }) | ||
215 | |||
193 | /* | 216 | /* |
194 | * percpu_read() makes gcc load the percpu variable every time it is | 217 | * percpu_read() makes gcc load the percpu variable every time it is |
195 | * accessed while percpu_read_stable() allows the value to be cached. | 218 | * accessed while percpu_read_stable() allows the value to be cached. |
@@ -207,6 +230,7 @@ do { \ | |||
207 | #define percpu_and(var, val) percpu_to_op("and", var, val) | 230 | #define percpu_and(var, val) percpu_to_op("and", var, val) |
208 | #define percpu_or(var, val) percpu_to_op("or", var, val) | 231 | #define percpu_or(var, val) percpu_to_op("or", var, val) |
209 | #define percpu_xor(var, val) percpu_to_op("xor", var, val) | 232 | #define percpu_xor(var, val) percpu_to_op("xor", var, val) |
233 | #define percpu_inc(var) percpu_unary_op("inc", var) | ||
210 | 234 | ||
211 | #define __this_cpu_read_1(pcp) percpu_from_op("mov", (pcp), "m"(pcp)) | 235 | #define __this_cpu_read_1(pcp) percpu_from_op("mov", (pcp), "m"(pcp)) |
212 | #define __this_cpu_read_2(pcp) percpu_from_op("mov", (pcp), "m"(pcp)) | 236 | #define __this_cpu_read_2(pcp) percpu_from_op("mov", (pcp), "m"(pcp)) |
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index db6109a885a7..254883d0c7e0 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h | |||
@@ -5,7 +5,7 @@ | |||
5 | * Performance event hw details: | 5 | * Performance event hw details: |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #define X86_PMC_MAX_GENERIC 8 | 8 | #define X86_PMC_MAX_GENERIC 32 |
9 | #define X86_PMC_MAX_FIXED 3 | 9 | #define X86_PMC_MAX_FIXED 3 |
10 | 10 | ||
11 | #define X86_PMC_IDX_GENERIC 0 | 11 | #define X86_PMC_IDX_GENERIC 0 |
@@ -18,39 +18,31 @@ | |||
18 | #define MSR_ARCH_PERFMON_EVENTSEL0 0x186 | 18 | #define MSR_ARCH_PERFMON_EVENTSEL0 0x186 |
19 | #define MSR_ARCH_PERFMON_EVENTSEL1 0x187 | 19 | #define MSR_ARCH_PERFMON_EVENTSEL1 0x187 |
20 | 20 | ||
21 | #define ARCH_PERFMON_EVENTSEL_ENABLE (1 << 22) | 21 | #define ARCH_PERFMON_EVENTSEL_EVENT 0x000000FFULL |
22 | #define ARCH_PERFMON_EVENTSEL_ANY (1 << 21) | 22 | #define ARCH_PERFMON_EVENTSEL_UMASK 0x0000FF00ULL |
23 | #define ARCH_PERFMON_EVENTSEL_INT (1 << 20) | 23 | #define ARCH_PERFMON_EVENTSEL_USR (1ULL << 16) |
24 | #define ARCH_PERFMON_EVENTSEL_OS (1 << 17) | 24 | #define ARCH_PERFMON_EVENTSEL_OS (1ULL << 17) |
25 | #define ARCH_PERFMON_EVENTSEL_USR (1 << 16) | 25 | #define ARCH_PERFMON_EVENTSEL_EDGE (1ULL << 18) |
26 | 26 | #define ARCH_PERFMON_EVENTSEL_INT (1ULL << 20) | |
27 | /* | 27 | #define ARCH_PERFMON_EVENTSEL_ANY (1ULL << 21) |
28 | * Includes eventsel and unit mask as well: | 28 | #define ARCH_PERFMON_EVENTSEL_ENABLE (1ULL << 22) |
29 | */ | 29 | #define ARCH_PERFMON_EVENTSEL_INV (1ULL << 23) |
30 | 30 | #define ARCH_PERFMON_EVENTSEL_CMASK 0xFF000000ULL | |
31 | 31 | ||
32 | #define INTEL_ARCH_EVTSEL_MASK 0x000000FFULL | 32 | #define AMD64_EVENTSEL_EVENT \ |
33 | #define INTEL_ARCH_UNIT_MASK 0x0000FF00ULL | 33 | (ARCH_PERFMON_EVENTSEL_EVENT | (0x0FULL << 32)) |
34 | #define INTEL_ARCH_EDGE_MASK 0x00040000ULL | 34 | #define INTEL_ARCH_EVENT_MASK \ |
35 | #define INTEL_ARCH_INV_MASK 0x00800000ULL | 35 | (ARCH_PERFMON_EVENTSEL_UMASK | ARCH_PERFMON_EVENTSEL_EVENT) |
36 | #define INTEL_ARCH_CNT_MASK 0xFF000000ULL | 36 | |
37 | #define INTEL_ARCH_EVENT_MASK (INTEL_ARCH_UNIT_MASK|INTEL_ARCH_EVTSEL_MASK) | 37 | #define X86_RAW_EVENT_MASK \ |
38 | 38 | (ARCH_PERFMON_EVENTSEL_EVENT | \ | |
39 | /* | 39 | ARCH_PERFMON_EVENTSEL_UMASK | \ |
40 | * filter mask to validate fixed counter events. | 40 | ARCH_PERFMON_EVENTSEL_EDGE | \ |
41 | * the following filters disqualify for fixed counters: | 41 | ARCH_PERFMON_EVENTSEL_INV | \ |
42 | * - inv | 42 | ARCH_PERFMON_EVENTSEL_CMASK) |
43 | * - edge | 43 | #define AMD64_RAW_EVENT_MASK \ |
44 | * - cnt-mask | 44 | (X86_RAW_EVENT_MASK | \ |
45 | * The other filters are supported by fixed counters. | 45 | AMD64_EVENTSEL_EVENT) |
46 | * The any-thread option is supported starting with v3. | ||
47 | */ | ||
48 | #define INTEL_ARCH_FIXED_MASK \ | ||
49 | (INTEL_ARCH_CNT_MASK| \ | ||
50 | INTEL_ARCH_INV_MASK| \ | ||
51 | INTEL_ARCH_EDGE_MASK|\ | ||
52 | INTEL_ARCH_UNIT_MASK|\ | ||
53 | INTEL_ARCH_EVENT_MASK) | ||
54 | 46 | ||
55 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL 0x3c | 47 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL 0x3c |
56 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) | 48 | #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK (0x00 << 8) |
@@ -67,7 +59,7 @@ | |||
67 | union cpuid10_eax { | 59 | union cpuid10_eax { |
68 | struct { | 60 | struct { |
69 | unsigned int version_id:8; | 61 | unsigned int version_id:8; |
70 | unsigned int num_events:8; | 62 | unsigned int num_counters:8; |
71 | unsigned int bit_width:8; | 63 | unsigned int bit_width:8; |
72 | unsigned int mask_length:8; | 64 | unsigned int mask_length:8; |
73 | } split; | 65 | } split; |
@@ -76,7 +68,7 @@ union cpuid10_eax { | |||
76 | 68 | ||
77 | union cpuid10_edx { | 69 | union cpuid10_edx { |
78 | struct { | 70 | struct { |
79 | unsigned int num_events_fixed:4; | 71 | unsigned int num_counters_fixed:4; |
80 | unsigned int reserved:28; | 72 | unsigned int reserved:28; |
81 | } split; | 73 | } split; |
82 | unsigned int full; | 74 | unsigned int full; |
@@ -136,6 +128,18 @@ extern void perf_events_lapic_init(void); | |||
136 | 128 | ||
137 | #define PERF_EVENT_INDEX_OFFSET 0 | 129 | #define PERF_EVENT_INDEX_OFFSET 0 |
138 | 130 | ||
131 | /* | ||
132 | * Abuse bit 3 of the cpu eflags register to indicate proper PEBS IP fixups. | ||
133 | * This flag is otherwise unused and ABI specified to be 0, so nobody should | ||
134 | * care what we do with it. | ||
135 | */ | ||
136 | #define PERF_EFLAGS_EXACT (1UL << 3) | ||
137 | |||
138 | struct pt_regs; | ||
139 | extern unsigned long perf_instruction_pointer(struct pt_regs *regs); | ||
140 | extern unsigned long perf_misc_flags(struct pt_regs *regs); | ||
141 | #define perf_misc_flags(regs) perf_misc_flags(regs) | ||
142 | |||
139 | #else | 143 | #else |
140 | static inline void init_hw_perf_events(void) { } | 144 | static inline void init_hw_perf_events(void) { } |
141 | static inline void perf_events_lapic_init(void) { } | 145 | static inline void perf_events_lapic_init(void) { } |
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h new file mode 100644 index 000000000000..b05400a542ff --- /dev/null +++ b/arch/x86/include/asm/perf_event_p4.h | |||
@@ -0,0 +1,794 @@ | |||
1 | /* | ||
2 | * Netburst Perfomance Events (P4, old Xeon) | ||
3 | */ | ||
4 | |||
5 | #ifndef PERF_EVENT_P4_H | ||
6 | #define PERF_EVENT_P4_H | ||
7 | |||
8 | #include <linux/cpu.h> | ||
9 | #include <linux/bitops.h> | ||
10 | |||
11 | /* | ||
12 | * NetBurst has perfomance MSRs shared between | ||
13 | * threads if HT is turned on, ie for both logical | ||
14 | * processors (mem: in turn in Atom with HT support | ||
15 | * perf-MSRs are not shared and every thread has its | ||
16 | * own perf-MSRs set) | ||
17 | */ | ||
18 | #define ARCH_P4_TOTAL_ESCR (46) | ||
19 | #define ARCH_P4_RESERVED_ESCR (2) /* IQ_ESCR(0,1) not always present */ | ||
20 | #define ARCH_P4_MAX_ESCR (ARCH_P4_TOTAL_ESCR - ARCH_P4_RESERVED_ESCR) | ||
21 | #define ARCH_P4_MAX_CCCR (18) | ||
22 | #define ARCH_P4_MAX_COUNTER (ARCH_P4_MAX_CCCR / 2) | ||
23 | |||
24 | #define P4_ESCR_EVENT_MASK 0x7e000000U | ||
25 | #define P4_ESCR_EVENT_SHIFT 25 | ||
26 | #define P4_ESCR_EVENTMASK_MASK 0x01fffe00U | ||
27 | #define P4_ESCR_EVENTMASK_SHIFT 9 | ||
28 | #define P4_ESCR_TAG_MASK 0x000001e0U | ||
29 | #define P4_ESCR_TAG_SHIFT 5 | ||
30 | #define P4_ESCR_TAG_ENABLE 0x00000010U | ||
31 | #define P4_ESCR_T0_OS 0x00000008U | ||
32 | #define P4_ESCR_T0_USR 0x00000004U | ||
33 | #define P4_ESCR_T1_OS 0x00000002U | ||
34 | #define P4_ESCR_T1_USR 0x00000001U | ||
35 | |||
36 | #define P4_ESCR_EVENT(v) ((v) << P4_ESCR_EVENT_SHIFT) | ||
37 | #define P4_ESCR_EMASK(v) ((v) << P4_ESCR_EVENTMASK_SHIFT) | ||
38 | #define P4_ESCR_TAG(v) ((v) << P4_ESCR_TAG_SHIFT) | ||
39 | |||
40 | /* Non HT mask */ | ||
41 | #define P4_ESCR_MASK \ | ||
42 | (P4_ESCR_EVENT_MASK | \ | ||
43 | P4_ESCR_EVENTMASK_MASK | \ | ||
44 | P4_ESCR_TAG_MASK | \ | ||
45 | P4_ESCR_TAG_ENABLE | \ | ||
46 | P4_ESCR_T0_OS | \ | ||
47 | P4_ESCR_T0_USR) | ||
48 | |||
49 | /* HT mask */ | ||
50 | #define P4_ESCR_MASK_HT \ | ||
51 | (P4_ESCR_MASK | P4_ESCR_T1_OS | P4_ESCR_T1_USR) | ||
52 | |||
53 | #define P4_CCCR_OVF 0x80000000U | ||
54 | #define P4_CCCR_CASCADE 0x40000000U | ||
55 | #define P4_CCCR_OVF_PMI_T0 0x04000000U | ||
56 | #define P4_CCCR_OVF_PMI_T1 0x08000000U | ||
57 | #define P4_CCCR_FORCE_OVF 0x02000000U | ||
58 | #define P4_CCCR_EDGE 0x01000000U | ||
59 | #define P4_CCCR_THRESHOLD_MASK 0x00f00000U | ||
60 | #define P4_CCCR_THRESHOLD_SHIFT 20 | ||
61 | #define P4_CCCR_COMPLEMENT 0x00080000U | ||
62 | #define P4_CCCR_COMPARE 0x00040000U | ||
63 | #define P4_CCCR_ESCR_SELECT_MASK 0x0000e000U | ||
64 | #define P4_CCCR_ESCR_SELECT_SHIFT 13 | ||
65 | #define P4_CCCR_ENABLE 0x00001000U | ||
66 | #define P4_CCCR_THREAD_SINGLE 0x00010000U | ||
67 | #define P4_CCCR_THREAD_BOTH 0x00020000U | ||
68 | #define P4_CCCR_THREAD_ANY 0x00030000U | ||
69 | #define P4_CCCR_RESERVED 0x00000fffU | ||
70 | |||
71 | #define P4_CCCR_THRESHOLD(v) ((v) << P4_CCCR_THRESHOLD_SHIFT) | ||
72 | #define P4_CCCR_ESEL(v) ((v) << P4_CCCR_ESCR_SELECT_SHIFT) | ||
73 | |||
74 | /* Custom bits in reerved CCCR area */ | ||
75 | #define P4_CCCR_CACHE_OPS_MASK 0x0000003fU | ||
76 | |||
77 | |||
78 | /* Non HT mask */ | ||
79 | #define P4_CCCR_MASK \ | ||
80 | (P4_CCCR_OVF | \ | ||
81 | P4_CCCR_CASCADE | \ | ||
82 | P4_CCCR_OVF_PMI_T0 | \ | ||
83 | P4_CCCR_FORCE_OVF | \ | ||
84 | P4_CCCR_EDGE | \ | ||
85 | P4_CCCR_THRESHOLD_MASK | \ | ||
86 | P4_CCCR_COMPLEMENT | \ | ||
87 | P4_CCCR_COMPARE | \ | ||
88 | P4_CCCR_ESCR_SELECT_MASK | \ | ||
89 | P4_CCCR_ENABLE) | ||
90 | |||
91 | /* HT mask */ | ||
92 | #define P4_CCCR_MASK_HT (P4_CCCR_MASK | P4_CCCR_THREAD_ANY) | ||
93 | |||
94 | #define P4_GEN_ESCR_EMASK(class, name, bit) \ | ||
95 | class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT) | ||
96 | #define P4_ESCR_EMASK_BIT(class, name) class##__##name | ||
97 | |||
98 | /* | ||
99 | * config field is 64bit width and consists of | ||
100 | * HT << 63 | ESCR << 32 | CCCR | ||
101 | * where HT is HyperThreading bit (since ESCR | ||
102 | * has it reserved we may use it for own purpose) | ||
103 | * | ||
104 | * note that this is NOT the addresses of respective | ||
105 | * ESCR and CCCR but rather an only packed value should | ||
106 | * be unpacked and written to a proper addresses | ||
107 | * | ||
108 | * the base idea is to pack as much info as | ||
109 | * possible | ||
110 | */ | ||
111 | #define p4_config_pack_escr(v) (((u64)(v)) << 32) | ||
112 | #define p4_config_pack_cccr(v) (((u64)(v)) & 0xffffffffULL) | ||
113 | #define p4_config_unpack_escr(v) (((u64)(v)) >> 32) | ||
114 | #define p4_config_unpack_cccr(v) (((u64)(v)) & 0xffffffffULL) | ||
115 | |||
116 | #define p4_config_unpack_emask(v) \ | ||
117 | ({ \ | ||
118 | u32 t = p4_config_unpack_escr((v)); \ | ||
119 | t = t & P4_ESCR_EVENTMASK_MASK; \ | ||
120 | t = t >> P4_ESCR_EVENTMASK_SHIFT; \ | ||
121 | t; \ | ||
122 | }) | ||
123 | |||
124 | #define p4_config_unpack_event(v) \ | ||
125 | ({ \ | ||
126 | u32 t = p4_config_unpack_escr((v)); \ | ||
127 | t = t & P4_ESCR_EVENT_MASK; \ | ||
128 | t = t >> P4_ESCR_EVENT_SHIFT; \ | ||
129 | t; \ | ||
130 | }) | ||
131 | |||
132 | #define p4_config_unpack_cache_event(v) (((u64)(v)) & P4_CCCR_CACHE_OPS_MASK) | ||
133 | |||
134 | #define P4_CONFIG_HT_SHIFT 63 | ||
135 | #define P4_CONFIG_HT (1ULL << P4_CONFIG_HT_SHIFT) | ||
136 | |||
137 | static inline bool p4_is_event_cascaded(u64 config) | ||
138 | { | ||
139 | u32 cccr = p4_config_unpack_cccr(config); | ||
140 | return !!(cccr & P4_CCCR_CASCADE); | ||
141 | } | ||
142 | |||
143 | static inline int p4_ht_config_thread(u64 config) | ||
144 | { | ||
145 | return !!(config & P4_CONFIG_HT); | ||
146 | } | ||
147 | |||
148 | static inline u64 p4_set_ht_bit(u64 config) | ||
149 | { | ||
150 | return config | P4_CONFIG_HT; | ||
151 | } | ||
152 | |||
153 | static inline u64 p4_clear_ht_bit(u64 config) | ||
154 | { | ||
155 | return config & ~P4_CONFIG_HT; | ||
156 | } | ||
157 | |||
158 | static inline int p4_ht_active(void) | ||
159 | { | ||
160 | #ifdef CONFIG_SMP | ||
161 | return smp_num_siblings > 1; | ||
162 | #endif | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static inline int p4_ht_thread(int cpu) | ||
167 | { | ||
168 | #ifdef CONFIG_SMP | ||
169 | if (smp_num_siblings == 2) | ||
170 | return cpu != cpumask_first(__get_cpu_var(cpu_sibling_map)); | ||
171 | #endif | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static inline int p4_should_swap_ts(u64 config, int cpu) | ||
176 | { | ||
177 | return p4_ht_config_thread(config) ^ p4_ht_thread(cpu); | ||
178 | } | ||
179 | |||
180 | static inline u32 p4_default_cccr_conf(int cpu) | ||
181 | { | ||
182 | /* | ||
183 | * Note that P4_CCCR_THREAD_ANY is "required" on | ||
184 | * non-HT machines (on HT machines we count TS events | ||
185 | * regardless the state of second logical processor | ||
186 | */ | ||
187 | u32 cccr = P4_CCCR_THREAD_ANY; | ||
188 | |||
189 | if (!p4_ht_thread(cpu)) | ||
190 | cccr |= P4_CCCR_OVF_PMI_T0; | ||
191 | else | ||
192 | cccr |= P4_CCCR_OVF_PMI_T1; | ||
193 | |||
194 | return cccr; | ||
195 | } | ||
196 | |||
197 | static inline u32 p4_default_escr_conf(int cpu, int exclude_os, int exclude_usr) | ||
198 | { | ||
199 | u32 escr = 0; | ||
200 | |||
201 | if (!p4_ht_thread(cpu)) { | ||
202 | if (!exclude_os) | ||
203 | escr |= P4_ESCR_T0_OS; | ||
204 | if (!exclude_usr) | ||
205 | escr |= P4_ESCR_T0_USR; | ||
206 | } else { | ||
207 | if (!exclude_os) | ||
208 | escr |= P4_ESCR_T1_OS; | ||
209 | if (!exclude_usr) | ||
210 | escr |= P4_ESCR_T1_USR; | ||
211 | } | ||
212 | |||
213 | return escr; | ||
214 | } | ||
215 | |||
216 | enum P4_EVENTS { | ||
217 | P4_EVENT_TC_DELIVER_MODE, | ||
218 | P4_EVENT_BPU_FETCH_REQUEST, | ||
219 | P4_EVENT_ITLB_REFERENCE, | ||
220 | P4_EVENT_MEMORY_CANCEL, | ||
221 | P4_EVENT_MEMORY_COMPLETE, | ||
222 | P4_EVENT_LOAD_PORT_REPLAY, | ||
223 | P4_EVENT_STORE_PORT_REPLAY, | ||
224 | P4_EVENT_MOB_LOAD_REPLAY, | ||
225 | P4_EVENT_PAGE_WALK_TYPE, | ||
226 | P4_EVENT_BSQ_CACHE_REFERENCE, | ||
227 | P4_EVENT_IOQ_ALLOCATION, | ||
228 | P4_EVENT_IOQ_ACTIVE_ENTRIES, | ||
229 | P4_EVENT_FSB_DATA_ACTIVITY, | ||
230 | P4_EVENT_BSQ_ALLOCATION, | ||
231 | P4_EVENT_BSQ_ACTIVE_ENTRIES, | ||
232 | P4_EVENT_SSE_INPUT_ASSIST, | ||
233 | P4_EVENT_PACKED_SP_UOP, | ||
234 | P4_EVENT_PACKED_DP_UOP, | ||
235 | P4_EVENT_SCALAR_SP_UOP, | ||
236 | P4_EVENT_SCALAR_DP_UOP, | ||
237 | P4_EVENT_64BIT_MMX_UOP, | ||
238 | P4_EVENT_128BIT_MMX_UOP, | ||
239 | P4_EVENT_X87_FP_UOP, | ||
240 | P4_EVENT_TC_MISC, | ||
241 | P4_EVENT_GLOBAL_POWER_EVENTS, | ||
242 | P4_EVENT_TC_MS_XFER, | ||
243 | P4_EVENT_UOP_QUEUE_WRITES, | ||
244 | P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, | ||
245 | P4_EVENT_RETIRED_BRANCH_TYPE, | ||
246 | P4_EVENT_RESOURCE_STALL, | ||
247 | P4_EVENT_WC_BUFFER, | ||
248 | P4_EVENT_B2B_CYCLES, | ||
249 | P4_EVENT_BNR, | ||
250 | P4_EVENT_SNOOP, | ||
251 | P4_EVENT_RESPONSE, | ||
252 | P4_EVENT_FRONT_END_EVENT, | ||
253 | P4_EVENT_EXECUTION_EVENT, | ||
254 | P4_EVENT_REPLAY_EVENT, | ||
255 | P4_EVENT_INSTR_RETIRED, | ||
256 | P4_EVENT_UOPS_RETIRED, | ||
257 | P4_EVENT_UOP_TYPE, | ||
258 | P4_EVENT_BRANCH_RETIRED, | ||
259 | P4_EVENT_MISPRED_BRANCH_RETIRED, | ||
260 | P4_EVENT_X87_ASSIST, | ||
261 | P4_EVENT_MACHINE_CLEAR, | ||
262 | P4_EVENT_INSTR_COMPLETED, | ||
263 | }; | ||
264 | |||
265 | #define P4_OPCODE(event) event##_OPCODE | ||
266 | #define P4_OPCODE_ESEL(opcode) ((opcode & 0x00ff) >> 0) | ||
267 | #define P4_OPCODE_EVNT(opcode) ((opcode & 0xff00) >> 8) | ||
268 | #define P4_OPCODE_PACK(event, sel) (((event) << 8) | sel) | ||
269 | |||
270 | /* | ||
271 | * Comments below the event represent ESCR restriction | ||
272 | * for this event and counter index per ESCR | ||
273 | * | ||
274 | * MSR_P4_IQ_ESCR0 and MSR_P4_IQ_ESCR1 are available only on early | ||
275 | * processor builds (family 0FH, models 01H-02H). These MSRs | ||
276 | * are not available on later versions, so that we don't use | ||
277 | * them completely | ||
278 | * | ||
279 | * Also note that CCCR1 do not have P4_CCCR_ENABLE bit properly | ||
280 | * working so that we should not use this CCCR and respective | ||
281 | * counter as result | ||
282 | */ | ||
283 | enum P4_EVENT_OPCODES { | ||
284 | P4_OPCODE(P4_EVENT_TC_DELIVER_MODE) = P4_OPCODE_PACK(0x01, 0x01), | ||
285 | /* | ||
286 | * MSR_P4_TC_ESCR0: 4, 5 | ||
287 | * MSR_P4_TC_ESCR1: 6, 7 | ||
288 | */ | ||
289 | |||
290 | P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST) = P4_OPCODE_PACK(0x03, 0x00), | ||
291 | /* | ||
292 | * MSR_P4_BPU_ESCR0: 0, 1 | ||
293 | * MSR_P4_BPU_ESCR1: 2, 3 | ||
294 | */ | ||
295 | |||
296 | P4_OPCODE(P4_EVENT_ITLB_REFERENCE) = P4_OPCODE_PACK(0x18, 0x03), | ||
297 | /* | ||
298 | * MSR_P4_ITLB_ESCR0: 0, 1 | ||
299 | * MSR_P4_ITLB_ESCR1: 2, 3 | ||
300 | */ | ||
301 | |||
302 | P4_OPCODE(P4_EVENT_MEMORY_CANCEL) = P4_OPCODE_PACK(0x02, 0x05), | ||
303 | /* | ||
304 | * MSR_P4_DAC_ESCR0: 8, 9 | ||
305 | * MSR_P4_DAC_ESCR1: 10, 11 | ||
306 | */ | ||
307 | |||
308 | P4_OPCODE(P4_EVENT_MEMORY_COMPLETE) = P4_OPCODE_PACK(0x08, 0x02), | ||
309 | /* | ||
310 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
311 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
312 | */ | ||
313 | |||
314 | P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY) = P4_OPCODE_PACK(0x04, 0x02), | ||
315 | /* | ||
316 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
317 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
318 | */ | ||
319 | |||
320 | P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY) = P4_OPCODE_PACK(0x05, 0x02), | ||
321 | /* | ||
322 | * MSR_P4_SAAT_ESCR0: 8, 9 | ||
323 | * MSR_P4_SAAT_ESCR1: 10, 11 | ||
324 | */ | ||
325 | |||
326 | P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY) = P4_OPCODE_PACK(0x03, 0x02), | ||
327 | /* | ||
328 | * MSR_P4_MOB_ESCR0: 0, 1 | ||
329 | * MSR_P4_MOB_ESCR1: 2, 3 | ||
330 | */ | ||
331 | |||
332 | P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE) = P4_OPCODE_PACK(0x01, 0x04), | ||
333 | /* | ||
334 | * MSR_P4_PMH_ESCR0: 0, 1 | ||
335 | * MSR_P4_PMH_ESCR1: 2, 3 | ||
336 | */ | ||
337 | |||
338 | P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE) = P4_OPCODE_PACK(0x0c, 0x07), | ||
339 | /* | ||
340 | * MSR_P4_BSU_ESCR0: 0, 1 | ||
341 | * MSR_P4_BSU_ESCR1: 2, 3 | ||
342 | */ | ||
343 | |||
344 | P4_OPCODE(P4_EVENT_IOQ_ALLOCATION) = P4_OPCODE_PACK(0x03, 0x06), | ||
345 | /* | ||
346 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
347 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
348 | */ | ||
349 | |||
350 | P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES) = P4_OPCODE_PACK(0x1a, 0x06), | ||
351 | /* | ||
352 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
353 | */ | ||
354 | |||
355 | P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY) = P4_OPCODE_PACK(0x17, 0x06), | ||
356 | /* | ||
357 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
358 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
359 | */ | ||
360 | |||
361 | P4_OPCODE(P4_EVENT_BSQ_ALLOCATION) = P4_OPCODE_PACK(0x05, 0x07), | ||
362 | /* | ||
363 | * MSR_P4_BSU_ESCR0: 0, 1 | ||
364 | */ | ||
365 | |||
366 | P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES) = P4_OPCODE_PACK(0x06, 0x07), | ||
367 | /* | ||
368 | * NOTE: no ESCR name in docs, it's guessed | ||
369 | * MSR_P4_BSU_ESCR1: 2, 3 | ||
370 | */ | ||
371 | |||
372 | P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST) = P4_OPCODE_PACK(0x34, 0x01), | ||
373 | /* | ||
374 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
375 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
376 | */ | ||
377 | |||
378 | P4_OPCODE(P4_EVENT_PACKED_SP_UOP) = P4_OPCODE_PACK(0x08, 0x01), | ||
379 | /* | ||
380 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
381 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
382 | */ | ||
383 | |||
384 | P4_OPCODE(P4_EVENT_PACKED_DP_UOP) = P4_OPCODE_PACK(0x0c, 0x01), | ||
385 | /* | ||
386 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
387 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
388 | */ | ||
389 | |||
390 | P4_OPCODE(P4_EVENT_SCALAR_SP_UOP) = P4_OPCODE_PACK(0x0a, 0x01), | ||
391 | /* | ||
392 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
393 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
394 | */ | ||
395 | |||
396 | P4_OPCODE(P4_EVENT_SCALAR_DP_UOP) = P4_OPCODE_PACK(0x0e, 0x01), | ||
397 | /* | ||
398 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
399 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
400 | */ | ||
401 | |||
402 | P4_OPCODE(P4_EVENT_64BIT_MMX_UOP) = P4_OPCODE_PACK(0x02, 0x01), | ||
403 | /* | ||
404 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
405 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
406 | */ | ||
407 | |||
408 | P4_OPCODE(P4_EVENT_128BIT_MMX_UOP) = P4_OPCODE_PACK(0x1a, 0x01), | ||
409 | /* | ||
410 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
411 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
412 | */ | ||
413 | |||
414 | P4_OPCODE(P4_EVENT_X87_FP_UOP) = P4_OPCODE_PACK(0x04, 0x01), | ||
415 | /* | ||
416 | * MSR_P4_FIRM_ESCR0: 8, 9 | ||
417 | * MSR_P4_FIRM_ESCR1: 10, 11 | ||
418 | */ | ||
419 | |||
420 | P4_OPCODE(P4_EVENT_TC_MISC) = P4_OPCODE_PACK(0x06, 0x01), | ||
421 | /* | ||
422 | * MSR_P4_TC_ESCR0: 4, 5 | ||
423 | * MSR_P4_TC_ESCR1: 6, 7 | ||
424 | */ | ||
425 | |||
426 | P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS) = P4_OPCODE_PACK(0x13, 0x06), | ||
427 | /* | ||
428 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
429 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
430 | */ | ||
431 | |||
432 | P4_OPCODE(P4_EVENT_TC_MS_XFER) = P4_OPCODE_PACK(0x05, 0x00), | ||
433 | /* | ||
434 | * MSR_P4_MS_ESCR0: 4, 5 | ||
435 | * MSR_P4_MS_ESCR1: 6, 7 | ||
436 | */ | ||
437 | |||
438 | P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES) = P4_OPCODE_PACK(0x09, 0x00), | ||
439 | /* | ||
440 | * MSR_P4_MS_ESCR0: 4, 5 | ||
441 | * MSR_P4_MS_ESCR1: 6, 7 | ||
442 | */ | ||
443 | |||
444 | P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE) = P4_OPCODE_PACK(0x05, 0x02), | ||
445 | /* | ||
446 | * MSR_P4_TBPU_ESCR0: 4, 5 | ||
447 | * MSR_P4_TBPU_ESCR1: 6, 7 | ||
448 | */ | ||
449 | |||
450 | P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE) = P4_OPCODE_PACK(0x04, 0x02), | ||
451 | /* | ||
452 | * MSR_P4_TBPU_ESCR0: 4, 5 | ||
453 | * MSR_P4_TBPU_ESCR1: 6, 7 | ||
454 | */ | ||
455 | |||
456 | P4_OPCODE(P4_EVENT_RESOURCE_STALL) = P4_OPCODE_PACK(0x01, 0x01), | ||
457 | /* | ||
458 | * MSR_P4_ALF_ESCR0: 12, 13, 16 | ||
459 | * MSR_P4_ALF_ESCR1: 14, 15, 17 | ||
460 | */ | ||
461 | |||
462 | P4_OPCODE(P4_EVENT_WC_BUFFER) = P4_OPCODE_PACK(0x05, 0x05), | ||
463 | /* | ||
464 | * MSR_P4_DAC_ESCR0: 8, 9 | ||
465 | * MSR_P4_DAC_ESCR1: 10, 11 | ||
466 | */ | ||
467 | |||
468 | P4_OPCODE(P4_EVENT_B2B_CYCLES) = P4_OPCODE_PACK(0x16, 0x03), | ||
469 | /* | ||
470 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
471 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
472 | */ | ||
473 | |||
474 | P4_OPCODE(P4_EVENT_BNR) = P4_OPCODE_PACK(0x08, 0x03), | ||
475 | /* | ||
476 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
477 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
478 | */ | ||
479 | |||
480 | P4_OPCODE(P4_EVENT_SNOOP) = P4_OPCODE_PACK(0x06, 0x03), | ||
481 | /* | ||
482 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
483 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
484 | */ | ||
485 | |||
486 | P4_OPCODE(P4_EVENT_RESPONSE) = P4_OPCODE_PACK(0x04, 0x03), | ||
487 | /* | ||
488 | * MSR_P4_FSB_ESCR0: 0, 1 | ||
489 | * MSR_P4_FSB_ESCR1: 2, 3 | ||
490 | */ | ||
491 | |||
492 | P4_OPCODE(P4_EVENT_FRONT_END_EVENT) = P4_OPCODE_PACK(0x08, 0x05), | ||
493 | /* | ||
494 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
495 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
496 | */ | ||
497 | |||
498 | P4_OPCODE(P4_EVENT_EXECUTION_EVENT) = P4_OPCODE_PACK(0x0c, 0x05), | ||
499 | /* | ||
500 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
501 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
502 | */ | ||
503 | |||
504 | P4_OPCODE(P4_EVENT_REPLAY_EVENT) = P4_OPCODE_PACK(0x09, 0x05), | ||
505 | /* | ||
506 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
507 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
508 | */ | ||
509 | |||
510 | P4_OPCODE(P4_EVENT_INSTR_RETIRED) = P4_OPCODE_PACK(0x02, 0x04), | ||
511 | /* | ||
512 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
513 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
514 | */ | ||
515 | |||
516 | P4_OPCODE(P4_EVENT_UOPS_RETIRED) = P4_OPCODE_PACK(0x01, 0x04), | ||
517 | /* | ||
518 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
519 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
520 | */ | ||
521 | |||
522 | P4_OPCODE(P4_EVENT_UOP_TYPE) = P4_OPCODE_PACK(0x02, 0x02), | ||
523 | /* | ||
524 | * MSR_P4_RAT_ESCR0: 12, 13, 16 | ||
525 | * MSR_P4_RAT_ESCR1: 14, 15, 17 | ||
526 | */ | ||
527 | |||
528 | P4_OPCODE(P4_EVENT_BRANCH_RETIRED) = P4_OPCODE_PACK(0x06, 0x05), | ||
529 | /* | ||
530 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
531 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
532 | */ | ||
533 | |||
534 | P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED) = P4_OPCODE_PACK(0x03, 0x04), | ||
535 | /* | ||
536 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
537 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
538 | */ | ||
539 | |||
540 | P4_OPCODE(P4_EVENT_X87_ASSIST) = P4_OPCODE_PACK(0x03, 0x05), | ||
541 | /* | ||
542 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
543 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
544 | */ | ||
545 | |||
546 | P4_OPCODE(P4_EVENT_MACHINE_CLEAR) = P4_OPCODE_PACK(0x02, 0x05), | ||
547 | /* | ||
548 | * MSR_P4_CRU_ESCR2: 12, 13, 16 | ||
549 | * MSR_P4_CRU_ESCR3: 14, 15, 17 | ||
550 | */ | ||
551 | |||
552 | P4_OPCODE(P4_EVENT_INSTR_COMPLETED) = P4_OPCODE_PACK(0x07, 0x04), | ||
553 | /* | ||
554 | * MSR_P4_CRU_ESCR0: 12, 13, 16 | ||
555 | * MSR_P4_CRU_ESCR1: 14, 15, 17 | ||
556 | */ | ||
557 | }; | ||
558 | |||
559 | /* | ||
560 | * a caller should use P4_ESCR_EMASK_NAME helper to | ||
561 | * pick the EventMask needed, for example | ||
562 | * | ||
563 | * P4_ESCR_EMASK_NAME(P4_EVENT_TC_DELIVER_MODE, DD) | ||
564 | */ | ||
565 | enum P4_ESCR_EMASKS { | ||
566 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DD, 0), | ||
567 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DB, 1), | ||
568 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DI, 2), | ||
569 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BD, 3), | ||
570 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BB, 4), | ||
571 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BI, 5), | ||
572 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, ID, 6), | ||
573 | |||
574 | P4_GEN_ESCR_EMASK(P4_EVENT_BPU_FETCH_REQUEST, TCMISS, 0), | ||
575 | |||
576 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT, 0), | ||
577 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, MISS, 1), | ||
578 | P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT_UK, 2), | ||
579 | |||
580 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, ST_RB_FULL, 2), | ||
581 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, 64K_CONF, 3), | ||
582 | |||
583 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, LSC, 0), | ||
584 | P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, SSC, 1), | ||
585 | |||
586 | P4_GEN_ESCR_EMASK(P4_EVENT_LOAD_PORT_REPLAY, SPLIT_LD, 1), | ||
587 | |||
588 | P4_GEN_ESCR_EMASK(P4_EVENT_STORE_PORT_REPLAY, SPLIT_ST, 1), | ||
589 | |||
590 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STA, 1), | ||
591 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STD, 3), | ||
592 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, PARTIAL_DATA, 4), | ||
593 | P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, UNALGN_ADDR, 5), | ||
594 | |||
595 | P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, DTMISS, 0), | ||
596 | P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, ITMISS, 1), | ||
597 | |||
598 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS, 0), | ||
599 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE, 1), | ||
600 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM, 2), | ||
601 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS, 3), | ||
602 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE, 4), | ||
603 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM, 5), | ||
604 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS, 8), | ||
605 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS, 9), | ||
606 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS, 10), | ||
607 | |||
608 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, DEFAULT, 0), | ||
609 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_READ, 5), | ||
610 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_WRITE, 6), | ||
611 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_UC, 7), | ||
612 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WC, 8), | ||
613 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WT, 9), | ||
614 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WP, 10), | ||
615 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WB, 11), | ||
616 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OWN, 13), | ||
617 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OTHER, 14), | ||
618 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, PREFETCH, 15), | ||
619 | |||
620 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, DEFAULT, 0), | ||
621 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_READ, 5), | ||
622 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_WRITE, 6), | ||
623 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_UC, 7), | ||
624 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WC, 8), | ||
625 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WT, 9), | ||
626 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WP, 10), | ||
627 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WB, 11), | ||
628 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OWN, 13), | ||
629 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OTHER, 14), | ||
630 | P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, PREFETCH, 15), | ||
631 | |||
632 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV, 0), | ||
633 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN, 1), | ||
634 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OTHER, 2), | ||
635 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_DRV, 3), | ||
636 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OWN, 4), | ||
637 | P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OTHER, 5), | ||
638 | |||
639 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE0, 0), | ||
640 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE1, 1), | ||
641 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN0, 2), | ||
642 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN1, 3), | ||
643 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_IO_TYPE, 5), | ||
644 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LOCK_TYPE, 6), | ||
645 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_CACHE_TYPE, 7), | ||
646 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_SPLIT_TYPE, 8), | ||
647 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_DEM_TYPE, 9), | ||
648 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_ORD_TYPE, 10), | ||
649 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE0, 11), | ||
650 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE1, 12), | ||
651 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE2, 13), | ||
652 | |||
653 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE0, 0), | ||
654 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE1, 1), | ||
655 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN0, 2), | ||
656 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN1, 3), | ||
657 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_IO_TYPE, 5), | ||
658 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LOCK_TYPE, 6), | ||
659 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_CACHE_TYPE, 7), | ||
660 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_SPLIT_TYPE, 8), | ||
661 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_DEM_TYPE, 9), | ||
662 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_ORD_TYPE, 10), | ||
663 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE0, 11), | ||
664 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE1, 12), | ||
665 | P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE2, 13), | ||
666 | |||
667 | P4_GEN_ESCR_EMASK(P4_EVENT_SSE_INPUT_ASSIST, ALL, 15), | ||
668 | |||
669 | P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_SP_UOP, ALL, 15), | ||
670 | |||
671 | P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_DP_UOP, ALL, 15), | ||
672 | |||
673 | P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_SP_UOP, ALL, 15), | ||
674 | |||
675 | P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_DP_UOP, ALL, 15), | ||
676 | |||
677 | P4_GEN_ESCR_EMASK(P4_EVENT_64BIT_MMX_UOP, ALL, 15), | ||
678 | |||
679 | P4_GEN_ESCR_EMASK(P4_EVENT_128BIT_MMX_UOP, ALL, 15), | ||
680 | |||
681 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_FP_UOP, ALL, 15), | ||
682 | |||
683 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_MISC, FLUSH, 4), | ||
684 | |||
685 | P4_GEN_ESCR_EMASK(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING, 0), | ||
686 | |||
687 | P4_GEN_ESCR_EMASK(P4_EVENT_TC_MS_XFER, CISC, 0), | ||
688 | |||
689 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_BUILD, 0), | ||
690 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_DELIVER, 1), | ||
691 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_ROM, 2), | ||
692 | |||
693 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CONDITIONAL, 1), | ||
694 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CALL, 2), | ||
695 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, RETURN, 3), | ||
696 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, INDIRECT, 4), | ||
697 | |||
698 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL, 1), | ||
699 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CALL, 2), | ||
700 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN, 3), | ||
701 | P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT, 4), | ||
702 | |||
703 | P4_GEN_ESCR_EMASK(P4_EVENT_RESOURCE_STALL, SBFULL, 5), | ||
704 | |||
705 | P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_EVICTS, 0), | ||
706 | P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_FULL_EVICTS, 1), | ||
707 | |||
708 | P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, NBOGUS, 0), | ||
709 | P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, BOGUS, 1), | ||
710 | |||
711 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS0, 0), | ||
712 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS1, 1), | ||
713 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS2, 2), | ||
714 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS3, 3), | ||
715 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS0, 4), | ||
716 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS1, 5), | ||
717 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS2, 6), | ||
718 | P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS3, 7), | ||
719 | |||
720 | P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, NBOGUS, 0), | ||
721 | P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, BOGUS, 1), | ||
722 | |||
723 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG, 0), | ||
724 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSTAG, 1), | ||
725 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSNTAG, 2), | ||
726 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSTAG, 3), | ||
727 | |||
728 | P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, NBOGUS, 0), | ||
729 | P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, BOGUS, 1), | ||
730 | |||
731 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGLOADS, 1), | ||
732 | P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGSTORES, 2), | ||
733 | |||
734 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNP, 0), | ||
735 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNM, 1), | ||
736 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTP, 2), | ||
737 | P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTM, 3), | ||
738 | |||
739 | P4_GEN_ESCR_EMASK(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS, 0), | ||
740 | |||
741 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSU, 0), | ||
742 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSO, 1), | ||
743 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAO, 2), | ||
744 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAU, 3), | ||
745 | P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, PREA, 4), | ||
746 | |||
747 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, CLEAR, 0), | ||
748 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, MOCLEAR, 1), | ||
749 | P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, SMCLEAR, 2), | ||
750 | |||
751 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, NBOGUS, 0), | ||
752 | P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, BOGUS, 1), | ||
753 | }; | ||
754 | |||
755 | /* P4 PEBS: stale for a while */ | ||
756 | #define P4_PEBS_METRIC_MASK 0x00001fffU | ||
757 | #define P4_PEBS_UOB_TAG 0x01000000U | ||
758 | #define P4_PEBS_ENABLE 0x02000000U | ||
759 | |||
760 | /* Replay metrics for MSR_IA32_PEBS_ENABLE and MSR_P4_PEBS_MATRIX_VERT */ | ||
761 | #define P4_PEBS__1stl_cache_load_miss_retired 0x3000001 | ||
762 | #define P4_PEBS__2ndl_cache_load_miss_retired 0x3000002 | ||
763 | #define P4_PEBS__dtlb_load_miss_retired 0x3000004 | ||
764 | #define P4_PEBS__dtlb_store_miss_retired 0x3000004 | ||
765 | #define P4_PEBS__dtlb_all_miss_retired 0x3000004 | ||
766 | #define P4_PEBS__tagged_mispred_branch 0x3018000 | ||
767 | #define P4_PEBS__mob_load_replay_retired 0x3000200 | ||
768 | #define P4_PEBS__split_load_retired 0x3000400 | ||
769 | #define P4_PEBS__split_store_retired 0x3000400 | ||
770 | |||
771 | #define P4_VERT__1stl_cache_load_miss_retired 0x0000001 | ||
772 | #define P4_VERT__2ndl_cache_load_miss_retired 0x0000001 | ||
773 | #define P4_VERT__dtlb_load_miss_retired 0x0000001 | ||
774 | #define P4_VERT__dtlb_store_miss_retired 0x0000002 | ||
775 | #define P4_VERT__dtlb_all_miss_retired 0x0000003 | ||
776 | #define P4_VERT__tagged_mispred_branch 0x0000010 | ||
777 | #define P4_VERT__mob_load_replay_retired 0x0000001 | ||
778 | #define P4_VERT__split_load_retired 0x0000001 | ||
779 | #define P4_VERT__split_store_retired 0x0000002 | ||
780 | |||
781 | enum P4_CACHE_EVENTS { | ||
782 | P4_CACHE__NONE, | ||
783 | |||
784 | P4_CACHE__1stl_cache_load_miss_retired, | ||
785 | P4_CACHE__2ndl_cache_load_miss_retired, | ||
786 | P4_CACHE__dtlb_load_miss_retired, | ||
787 | P4_CACHE__dtlb_store_miss_retired, | ||
788 | P4_CACHE__itlb_reference_hit, | ||
789 | P4_CACHE__itlb_reference_miss, | ||
790 | |||
791 | P4_CACHE__MAX | ||
792 | }; | ||
793 | |||
794 | #endif /* PERF_EVENT_P4_H */ | ||
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index b753ea59703a..5a51379dcbe4 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h | |||
@@ -21,7 +21,6 @@ struct mm_struct; | |||
21 | #include <asm/msr.h> | 21 | #include <asm/msr.h> |
22 | #include <asm/desc_defs.h> | 22 | #include <asm/desc_defs.h> |
23 | #include <asm/nops.h> | 23 | #include <asm/nops.h> |
24 | #include <asm/ds.h> | ||
25 | 24 | ||
26 | #include <linux/personality.h> | 25 | #include <linux/personality.h> |
27 | #include <linux/cpumask.h> | 26 | #include <linux/cpumask.h> |
@@ -29,6 +28,7 @@ struct mm_struct; | |||
29 | #include <linux/threads.h> | 28 | #include <linux/threads.h> |
30 | #include <linux/math64.h> | 29 | #include <linux/math64.h> |
31 | #include <linux/init.h> | 30 | #include <linux/init.h> |
31 | #include <linux/err.h> | ||
32 | 32 | ||
33 | #define HBP_NUM 4 | 33 | #define HBP_NUM 4 |
34 | /* | 34 | /* |
@@ -113,7 +113,6 @@ struct cpuinfo_x86 { | |||
113 | /* Index into per_cpu list: */ | 113 | /* Index into per_cpu list: */ |
114 | u16 cpu_index; | 114 | u16 cpu_index; |
115 | #endif | 115 | #endif |
116 | unsigned int x86_hyper_vendor; | ||
117 | } __attribute__((__aligned__(SMP_CACHE_BYTES))); | 116 | } __attribute__((__aligned__(SMP_CACHE_BYTES))); |
118 | 117 | ||
119 | #define X86_VENDOR_INTEL 0 | 118 | #define X86_VENDOR_INTEL 0 |
@@ -127,9 +126,6 @@ struct cpuinfo_x86 { | |||
127 | 126 | ||
128 | #define X86_VENDOR_UNKNOWN 0xff | 127 | #define X86_VENDOR_UNKNOWN 0xff |
129 | 128 | ||
130 | #define X86_HYPER_VENDOR_NONE 0 | ||
131 | #define X86_HYPER_VENDOR_VMWARE 1 | ||
132 | |||
133 | /* | 129 | /* |
134 | * capabilities of CPUs | 130 | * capabilities of CPUs |
135 | */ | 131 | */ |
@@ -380,6 +376,10 @@ union thread_xstate { | |||
380 | struct xsave_struct xsave; | 376 | struct xsave_struct xsave; |
381 | }; | 377 | }; |
382 | 378 | ||
379 | struct fpu { | ||
380 | union thread_xstate *state; | ||
381 | }; | ||
382 | |||
383 | #ifdef CONFIG_X86_64 | 383 | #ifdef CONFIG_X86_64 |
384 | DECLARE_PER_CPU(struct orig_ist, orig_ist); | 384 | DECLARE_PER_CPU(struct orig_ist, orig_ist); |
385 | 385 | ||
@@ -457,7 +457,7 @@ struct thread_struct { | |||
457 | unsigned long trap_no; | 457 | unsigned long trap_no; |
458 | unsigned long error_code; | 458 | unsigned long error_code; |
459 | /* floating point and extended processor state */ | 459 | /* floating point and extended processor state */ |
460 | union thread_xstate *xstate; | 460 | struct fpu fpu; |
461 | #ifdef CONFIG_X86_32 | 461 | #ifdef CONFIG_X86_32 |
462 | /* Virtual 86 mode info */ | 462 | /* Virtual 86 mode info */ |
463 | struct vm86_struct __user *vm86_info; | 463 | struct vm86_struct __user *vm86_info; |
@@ -473,10 +473,6 @@ struct thread_struct { | |||
473 | unsigned long iopl; | 473 | unsigned long iopl; |
474 | /* Max allowed port in the bitmap, in bytes: */ | 474 | /* Max allowed port in the bitmap, in bytes: */ |
475 | unsigned io_bitmap_max; | 475 | unsigned io_bitmap_max; |
476 | /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set. */ | ||
477 | unsigned long debugctlmsr; | ||
478 | /* Debug Store context; see asm/ds.h */ | ||
479 | struct ds_context *ds_ctx; | ||
480 | }; | 476 | }; |
481 | 477 | ||
482 | static inline unsigned long native_get_debugreg(int regno) | 478 | static inline unsigned long native_get_debugreg(int regno) |
@@ -803,7 +799,7 @@ extern void cpu_init(void); | |||
803 | 799 | ||
804 | static inline unsigned long get_debugctlmsr(void) | 800 | static inline unsigned long get_debugctlmsr(void) |
805 | { | 801 | { |
806 | unsigned long debugctlmsr = 0; | 802 | unsigned long debugctlmsr = 0; |
807 | 803 | ||
808 | #ifndef CONFIG_X86_DEBUGCTLMSR | 804 | #ifndef CONFIG_X86_DEBUGCTLMSR |
809 | if (boot_cpu_data.x86 < 6) | 805 | if (boot_cpu_data.x86 < 6) |
@@ -811,21 +807,6 @@ static inline unsigned long get_debugctlmsr(void) | |||
811 | #endif | 807 | #endif |
812 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); | 808 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
813 | 809 | ||
814 | return debugctlmsr; | ||
815 | } | ||
816 | |||
817 | static inline unsigned long get_debugctlmsr_on_cpu(int cpu) | ||
818 | { | ||
819 | u64 debugctlmsr = 0; | ||
820 | u32 val1, val2; | ||
821 | |||
822 | #ifndef CONFIG_X86_DEBUGCTLMSR | ||
823 | if (boot_cpu_data.x86 < 6) | ||
824 | return 0; | ||
825 | #endif | ||
826 | rdmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR, &val1, &val2); | ||
827 | debugctlmsr = val1 | ((u64)val2 << 32); | ||
828 | |||
829 | return debugctlmsr; | 810 | return debugctlmsr; |
830 | } | 811 | } |
831 | 812 | ||
@@ -838,18 +819,6 @@ static inline void update_debugctlmsr(unsigned long debugctlmsr) | |||
838 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); | 819 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
839 | } | 820 | } |
840 | 821 | ||
841 | static inline void update_debugctlmsr_on_cpu(int cpu, | ||
842 | unsigned long debugctlmsr) | ||
843 | { | ||
844 | #ifndef CONFIG_X86_DEBUGCTLMSR | ||
845 | if (boot_cpu_data.x86 < 6) | ||
846 | return; | ||
847 | #endif | ||
848 | wrmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR, | ||
849 | (u32)((u64)debugctlmsr), | ||
850 | (u32)((u64)debugctlmsr >> 32)); | ||
851 | } | ||
852 | |||
853 | /* | 822 | /* |
854 | * from system description table in BIOS. Mostly for MCA use, but | 823 | * from system description table in BIOS. Mostly for MCA use, but |
855 | * others may find it useful: | 824 | * others may find it useful: |
diff --git a/arch/x86/include/asm/ptrace-abi.h b/arch/x86/include/asm/ptrace-abi.h index 86723035a515..52b098a6eebb 100644 --- a/arch/x86/include/asm/ptrace-abi.h +++ b/arch/x86/include/asm/ptrace-abi.h | |||
@@ -82,61 +82,6 @@ | |||
82 | 82 | ||
83 | #ifndef __ASSEMBLY__ | 83 | #ifndef __ASSEMBLY__ |
84 | #include <linux/types.h> | 84 | #include <linux/types.h> |
85 | 85 | #endif | |
86 | /* configuration/status structure used in PTRACE_BTS_CONFIG and | ||
87 | PTRACE_BTS_STATUS commands. | ||
88 | */ | ||
89 | struct ptrace_bts_config { | ||
90 | /* requested or actual size of BTS buffer in bytes */ | ||
91 | __u32 size; | ||
92 | /* bitmask of below flags */ | ||
93 | __u32 flags; | ||
94 | /* buffer overflow signal */ | ||
95 | __u32 signal; | ||
96 | /* actual size of bts_struct in bytes */ | ||
97 | __u32 bts_size; | ||
98 | }; | ||
99 | #endif /* __ASSEMBLY__ */ | ||
100 | |||
101 | #define PTRACE_BTS_O_TRACE 0x1 /* branch trace */ | ||
102 | #define PTRACE_BTS_O_SCHED 0x2 /* scheduling events w/ jiffies */ | ||
103 | #define PTRACE_BTS_O_SIGNAL 0x4 /* send SIG<signal> on buffer overflow | ||
104 | instead of wrapping around */ | ||
105 | #define PTRACE_BTS_O_ALLOC 0x8 /* (re)allocate buffer */ | ||
106 | |||
107 | #define PTRACE_BTS_CONFIG 40 | ||
108 | /* Configure branch trace recording. | ||
109 | ADDR points to a struct ptrace_bts_config. | ||
110 | DATA gives the size of that buffer. | ||
111 | A new buffer is allocated, if requested in the flags. | ||
112 | An overflow signal may only be requested for new buffers. | ||
113 | Returns the number of bytes read. | ||
114 | */ | ||
115 | #define PTRACE_BTS_STATUS 41 | ||
116 | /* Return the current configuration in a struct ptrace_bts_config | ||
117 | pointed to by ADDR; DATA gives the size of that buffer. | ||
118 | Returns the number of bytes written. | ||
119 | */ | ||
120 | #define PTRACE_BTS_SIZE 42 | ||
121 | /* Return the number of available BTS records for draining. | ||
122 | DATA and ADDR are ignored. | ||
123 | */ | ||
124 | #define PTRACE_BTS_GET 43 | ||
125 | /* Get a single BTS record. | ||
126 | DATA defines the index into the BTS array, where 0 is the newest | ||
127 | entry, and higher indices refer to older entries. | ||
128 | ADDR is pointing to struct bts_struct (see asm/ds.h). | ||
129 | */ | ||
130 | #define PTRACE_BTS_CLEAR 44 | ||
131 | /* Clear the BTS buffer. | ||
132 | DATA and ADDR are ignored. | ||
133 | */ | ||
134 | #define PTRACE_BTS_DRAIN 45 | ||
135 | /* Read all available BTS records and clear the buffer. | ||
136 | ADDR points to an array of struct bts_struct. | ||
137 | DATA gives the size of that buffer. | ||
138 | BTS records are read from oldest to newest. | ||
139 | Returns number of BTS records drained. | ||
140 | */ | ||
141 | 86 | ||
142 | #endif /* _ASM_X86_PTRACE_ABI_H */ | 87 | #endif /* _ASM_X86_PTRACE_ABI_H */ |
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h index 69a686a7dff0..78cd1ea94500 100644 --- a/arch/x86/include/asm/ptrace.h +++ b/arch/x86/include/asm/ptrace.h | |||
@@ -289,12 +289,6 @@ extern int do_get_thread_area(struct task_struct *p, int idx, | |||
289 | extern int do_set_thread_area(struct task_struct *p, int idx, | 289 | extern int do_set_thread_area(struct task_struct *p, int idx, |
290 | struct user_desc __user *info, int can_allocate); | 290 | struct user_desc __user *info, int can_allocate); |
291 | 291 | ||
292 | #ifdef CONFIG_X86_PTRACE_BTS | ||
293 | extern void ptrace_bts_untrace(struct task_struct *tsk); | ||
294 | |||
295 | #define arch_ptrace_untrace(tsk) ptrace_bts_untrace(tsk) | ||
296 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
297 | |||
298 | #endif /* __KERNEL__ */ | 292 | #endif /* __KERNEL__ */ |
299 | 293 | ||
300 | #endif /* !__ASSEMBLY__ */ | 294 | #endif /* !__ASSEMBLY__ */ |
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h index e0d28901e969..d4092fac226b 100644 --- a/arch/x86/include/asm/thread_info.h +++ b/arch/x86/include/asm/thread_info.h | |||
@@ -92,8 +92,7 @@ struct thread_info { | |||
92 | #define TIF_IO_BITMAP 22 /* uses I/O bitmap */ | 92 | #define TIF_IO_BITMAP 22 /* uses I/O bitmap */ |
93 | #define TIF_FREEZE 23 /* is freezing for suspend */ | 93 | #define TIF_FREEZE 23 /* is freezing for suspend */ |
94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ | 94 | #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */ |
95 | #define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */ | 95 | #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */ |
96 | #define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */ | ||
97 | #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ | 96 | #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */ |
98 | #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */ | 97 | #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */ |
99 | 98 | ||
@@ -115,8 +114,7 @@ struct thread_info { | |||
115 | #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) | 114 | #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) |
116 | #define _TIF_FREEZE (1 << TIF_FREEZE) | 115 | #define _TIF_FREEZE (1 << TIF_FREEZE) |
117 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) | 116 | #define _TIF_FORCED_TF (1 << TIF_FORCED_TF) |
118 | #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR) | 117 | #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) |
119 | #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR) | ||
120 | #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) | 118 | #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES) |
121 | #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) | 119 | #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT) |
122 | 120 | ||
@@ -147,7 +145,7 @@ struct thread_info { | |||
147 | 145 | ||
148 | /* flags to check in __switch_to() */ | 146 | /* flags to check in __switch_to() */ |
149 | #define _TIF_WORK_CTXSW \ | 147 | #define _TIF_WORK_CTXSW \ |
150 | (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC) | 148 | (_TIF_IO_BITMAP|_TIF_NOTSC|_TIF_BLOCKSTEP) |
151 | 149 | ||
152 | #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) | 150 | #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY) |
153 | #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG) | 151 | #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG) |
@@ -244,7 +242,6 @@ static inline struct thread_info *current_thread_info(void) | |||
244 | #define TS_POLLING 0x0004 /* true if in idle loop | 242 | #define TS_POLLING 0x0004 /* true if in idle loop |
245 | and not sleeping */ | 243 | and not sleeping */ |
246 | #define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal() */ | 244 | #define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal() */ |
247 | #define TS_XSAVE 0x0010 /* Use xsave/xrstor */ | ||
248 | 245 | ||
249 | #define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING) | 246 | #define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING) |
250 | 247 | ||
diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index 4da91ad69e0d..f66cda56781d 100644 --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h | |||
@@ -79,7 +79,7 @@ static inline int get_si_code(unsigned long condition) | |||
79 | 79 | ||
80 | extern int panic_on_unrecovered_nmi; | 80 | extern int panic_on_unrecovered_nmi; |
81 | 81 | ||
82 | void math_error(void __user *); | 82 | void math_error(struct pt_regs *, int, int); |
83 | void math_emulate(struct math_emu_info *); | 83 | void math_emulate(struct math_emu_info *); |
84 | #ifndef CONFIG_X86_32 | 84 | #ifndef CONFIG_X86_32 |
85 | asmlinkage void smp_thermal_interrupt(void); | 85 | asmlinkage void smp_thermal_interrupt(void); |
diff --git a/arch/x86/include/asm/uv/uv_bau.h b/arch/x86/include/asm/uv/uv_bau.h index b414d2b401f6..aa558ac0306e 100644 --- a/arch/x86/include/asm/uv/uv_bau.h +++ b/arch/x86/include/asm/uv/uv_bau.h | |||
@@ -27,13 +27,14 @@ | |||
27 | * set 2 is at BASE + 2*512, set 3 at BASE + 3*512, and so on. | 27 | * set 2 is at BASE + 2*512, set 3 at BASE + 3*512, and so on. |
28 | * | 28 | * |
29 | * We will use 31 sets, one for sending BAU messages from each of the 32 | 29 | * We will use 31 sets, one for sending BAU messages from each of the 32 |
30 | * cpu's on the node. | 30 | * cpu's on the uvhub. |
31 | * | 31 | * |
32 | * TLB shootdown will use the first of the 8 descriptors of each set. | 32 | * TLB shootdown will use the first of the 8 descriptors of each set. |
33 | * Each of the descriptors is 64 bytes in size (8*64 = 512 bytes in a set). | 33 | * Each of the descriptors is 64 bytes in size (8*64 = 512 bytes in a set). |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #define UV_ITEMS_PER_DESCRIPTOR 8 | 36 | #define UV_ITEMS_PER_DESCRIPTOR 8 |
37 | #define MAX_BAU_CONCURRENT 3 | ||
37 | #define UV_CPUS_PER_ACT_STATUS 32 | 38 | #define UV_CPUS_PER_ACT_STATUS 32 |
38 | #define UV_ACT_STATUS_MASK 0x3 | 39 | #define UV_ACT_STATUS_MASK 0x3 |
39 | #define UV_ACT_STATUS_SIZE 2 | 40 | #define UV_ACT_STATUS_SIZE 2 |
@@ -45,6 +46,9 @@ | |||
45 | #define UV_PAYLOADQ_PNODE_SHIFT 49 | 46 | #define UV_PAYLOADQ_PNODE_SHIFT 49 |
46 | #define UV_PTC_BASENAME "sgi_uv/ptc_statistics" | 47 | #define UV_PTC_BASENAME "sgi_uv/ptc_statistics" |
47 | #define uv_physnodeaddr(x) ((__pa((unsigned long)(x)) & uv_mmask)) | 48 | #define uv_physnodeaddr(x) ((__pa((unsigned long)(x)) & uv_mmask)) |
49 | #define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15 | ||
50 | #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16 | ||
51 | #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL | ||
48 | 52 | ||
49 | /* | 53 | /* |
50 | * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1 | 54 | * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1 |
@@ -55,15 +59,29 @@ | |||
55 | #define DESC_STATUS_SOURCE_TIMEOUT 3 | 59 | #define DESC_STATUS_SOURCE_TIMEOUT 3 |
56 | 60 | ||
57 | /* | 61 | /* |
58 | * source side thresholds at which message retries print a warning | 62 | * source side threshholds at which message retries print a warning |
59 | */ | 63 | */ |
60 | #define SOURCE_TIMEOUT_LIMIT 20 | 64 | #define SOURCE_TIMEOUT_LIMIT 20 |
61 | #define DESTINATION_TIMEOUT_LIMIT 20 | 65 | #define DESTINATION_TIMEOUT_LIMIT 20 |
62 | 66 | ||
63 | /* | 67 | /* |
68 | * misc. delays, in microseconds | ||
69 | */ | ||
70 | #define THROTTLE_DELAY 10 | ||
71 | #define TIMEOUT_DELAY 10 | ||
72 | #define BIOS_TO 1000 | ||
73 | /* BIOS is assumed to set the destination timeout to 1003520 nanoseconds */ | ||
74 | |||
75 | /* | ||
76 | * threshholds at which to use IPI to free resources | ||
77 | */ | ||
78 | #define PLUGSB4RESET 100 | ||
79 | #define TIMEOUTSB4RESET 100 | ||
80 | |||
81 | /* | ||
64 | * number of entries in the destination side payload queue | 82 | * number of entries in the destination side payload queue |
65 | */ | 83 | */ |
66 | #define DEST_Q_SIZE 17 | 84 | #define DEST_Q_SIZE 20 |
67 | /* | 85 | /* |
68 | * number of destination side software ack resources | 86 | * number of destination side software ack resources |
69 | */ | 87 | */ |
@@ -72,9 +90,10 @@ | |||
72 | /* | 90 | /* |
73 | * completion statuses for sending a TLB flush message | 91 | * completion statuses for sending a TLB flush message |
74 | */ | 92 | */ |
75 | #define FLUSH_RETRY 1 | 93 | #define FLUSH_RETRY_PLUGGED 1 |
76 | #define FLUSH_GIVEUP 2 | 94 | #define FLUSH_RETRY_TIMEOUT 2 |
77 | #define FLUSH_COMPLETE 3 | 95 | #define FLUSH_GIVEUP 3 |
96 | #define FLUSH_COMPLETE 4 | ||
78 | 97 | ||
79 | /* | 98 | /* |
80 | * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor) | 99 | * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor) |
@@ -86,14 +105,14 @@ | |||
86 | * 'base_dest_nodeid' field of the header corresponds to the | 105 | * 'base_dest_nodeid' field of the header corresponds to the |
87 | * destination nodeID associated with that specified bit. | 106 | * destination nodeID associated with that specified bit. |
88 | */ | 107 | */ |
89 | struct bau_target_nodemask { | 108 | struct bau_target_uvhubmask { |
90 | unsigned long bits[BITS_TO_LONGS(256)]; | 109 | unsigned long bits[BITS_TO_LONGS(UV_DISTRIBUTION_SIZE)]; |
91 | }; | 110 | }; |
92 | 111 | ||
93 | /* | 112 | /* |
94 | * mask of cpu's on a node | 113 | * mask of cpu's on a uvhub |
95 | * (during initialization we need to check that unsigned long has | 114 | * (during initialization we need to check that unsigned long has |
96 | * enough bits for max. cpu's per node) | 115 | * enough bits for max. cpu's per uvhub) |
97 | */ | 116 | */ |
98 | struct bau_local_cpumask { | 117 | struct bau_local_cpumask { |
99 | unsigned long bits; | 118 | unsigned long bits; |
@@ -135,8 +154,8 @@ struct bau_msg_payload { | |||
135 | struct bau_msg_header { | 154 | struct bau_msg_header { |
136 | unsigned int dest_subnodeid:6; /* must be 0x10, for the LB */ | 155 | unsigned int dest_subnodeid:6; /* must be 0x10, for the LB */ |
137 | /* bits 5:0 */ | 156 | /* bits 5:0 */ |
138 | unsigned int base_dest_nodeid:15; /* nasid>>1 (pnode) of */ | 157 | unsigned int base_dest_nodeid:15; /* nasid (pnode<<1) of */ |
139 | /* bits 20:6 */ /* first bit in node_map */ | 158 | /* bits 20:6 */ /* first bit in uvhub map */ |
140 | unsigned int command:8; /* message type */ | 159 | unsigned int command:8; /* message type */ |
141 | /* bits 28:21 */ | 160 | /* bits 28:21 */ |
142 | /* 0x38: SN3net EndPoint Message */ | 161 | /* 0x38: SN3net EndPoint Message */ |
@@ -146,26 +165,38 @@ struct bau_msg_header { | |||
146 | unsigned int rsvd_2:9; /* must be zero */ | 165 | unsigned int rsvd_2:9; /* must be zero */ |
147 | /* bits 40:32 */ | 166 | /* bits 40:32 */ |
148 | /* Suppl_A is 56-41 */ | 167 | /* Suppl_A is 56-41 */ |
149 | unsigned int payload_2a:8;/* becomes byte 16 of msg */ | 168 | unsigned int sequence:16;/* message sequence number */ |
150 | /* bits 48:41 */ /* not currently using */ | 169 | /* bits 56:41 */ /* becomes bytes 16-17 of msg */ |
151 | unsigned int payload_2b:8;/* becomes byte 17 of msg */ | ||
152 | /* bits 56:49 */ /* not currently using */ | ||
153 | /* Address field (96:57) is never used as an | 170 | /* Address field (96:57) is never used as an |
154 | address (these are address bits 42:3) */ | 171 | address (these are address bits 42:3) */ |
172 | |||
155 | unsigned int rsvd_3:1; /* must be zero */ | 173 | unsigned int rsvd_3:1; /* must be zero */ |
156 | /* bit 57 */ | 174 | /* bit 57 */ |
157 | /* address bits 27:4 are payload */ | 175 | /* address bits 27:4 are payload */ |
158 | /* these 24 bits become bytes 12-14 of msg */ | 176 | /* these next 24 (58-81) bits become bytes 12-14 of msg */ |
177 | |||
178 | /* bits 65:58 land in byte 12 */ | ||
159 | unsigned int replied_to:1;/* sent as 0 by the source to byte 12 */ | 179 | unsigned int replied_to:1;/* sent as 0 by the source to byte 12 */ |
160 | /* bit 58 */ | 180 | /* bit 58 */ |
161 | 181 | unsigned int msg_type:3; /* software type of the message*/ | |
162 | unsigned int payload_1a:5;/* not currently used */ | 182 | /* bits 61:59 */ |
163 | /* bits 63:59 */ | 183 | unsigned int canceled:1; /* message canceled, resource to be freed*/ |
164 | unsigned int payload_1b:8;/* not currently used */ | 184 | /* bit 62 */ |
165 | /* bits 71:64 */ | 185 | unsigned int payload_1a:1;/* not currently used */ |
166 | unsigned int payload_1c:8;/* not currently used */ | 186 | /* bit 63 */ |
167 | /* bits 79:72 */ | 187 | unsigned int payload_1b:2;/* not currently used */ |
168 | unsigned int payload_1d:2;/* not currently used */ | 188 | /* bits 65:64 */ |
189 | |||
190 | /* bits 73:66 land in byte 13 */ | ||
191 | unsigned int payload_1ca:6;/* not currently used */ | ||
192 | /* bits 71:66 */ | ||
193 | unsigned int payload_1c:2;/* not currently used */ | ||
194 | /* bits 73:72 */ | ||
195 | |||
196 | /* bits 81:74 land in byte 14 */ | ||
197 | unsigned int payload_1d:6;/* not currently used */ | ||
198 | /* bits 79:74 */ | ||
199 | unsigned int payload_1e:2;/* not currently used */ | ||
169 | /* bits 81:80 */ | 200 | /* bits 81:80 */ |
170 | 201 | ||
171 | unsigned int rsvd_4:7; /* must be zero */ | 202 | unsigned int rsvd_4:7; /* must be zero */ |
@@ -178,7 +209,7 @@ struct bau_msg_header { | |||
178 | /* bits 95:90 */ | 209 | /* bits 95:90 */ |
179 | unsigned int rsvd_6:5; /* must be zero */ | 210 | unsigned int rsvd_6:5; /* must be zero */ |
180 | /* bits 100:96 */ | 211 | /* bits 100:96 */ |
181 | unsigned int int_both:1;/* if 1, interrupt both sockets on the blade */ | 212 | unsigned int int_both:1;/* if 1, interrupt both sockets on the uvhub */ |
182 | /* bit 101*/ | 213 | /* bit 101*/ |
183 | unsigned int fairness:3;/* usually zero */ | 214 | unsigned int fairness:3;/* usually zero */ |
184 | /* bits 104:102 */ | 215 | /* bits 104:102 */ |
@@ -191,13 +222,18 @@ struct bau_msg_header { | |||
191 | /* bits 127:107 */ | 222 | /* bits 127:107 */ |
192 | }; | 223 | }; |
193 | 224 | ||
225 | /* see msg_type: */ | ||
226 | #define MSG_NOOP 0 | ||
227 | #define MSG_REGULAR 1 | ||
228 | #define MSG_RETRY 2 | ||
229 | |||
194 | /* | 230 | /* |
195 | * The activation descriptor: | 231 | * The activation descriptor: |
196 | * The format of the message to send, plus all accompanying control | 232 | * The format of the message to send, plus all accompanying control |
197 | * Should be 64 bytes | 233 | * Should be 64 bytes |
198 | */ | 234 | */ |
199 | struct bau_desc { | 235 | struct bau_desc { |
200 | struct bau_target_nodemask distribution; | 236 | struct bau_target_uvhubmask distribution; |
201 | /* | 237 | /* |
202 | * message template, consisting of header and payload: | 238 | * message template, consisting of header and payload: |
203 | */ | 239 | */ |
@@ -237,19 +273,25 @@ struct bau_payload_queue_entry { | |||
237 | unsigned short acknowledge_count; /* filled in by destination */ | 273 | unsigned short acknowledge_count; /* filled in by destination */ |
238 | /* 16 bits, bytes 10-11 */ | 274 | /* 16 bits, bytes 10-11 */ |
239 | 275 | ||
240 | unsigned short replied_to:1; /* sent as 0 by the source */ | 276 | /* these next 3 bytes come from bits 58-81 of the message header */ |
241 | /* 1 bit */ | 277 | unsigned short replied_to:1; /* sent as 0 by the source */ |
242 | unsigned short unused1:7; /* not currently using */ | 278 | unsigned short msg_type:3; /* software message type */ |
243 | /* 7 bits: byte 12) */ | 279 | unsigned short canceled:1; /* sent as 0 by the source */ |
280 | unsigned short unused1:3; /* not currently using */ | ||
281 | /* byte 12 */ | ||
244 | 282 | ||
245 | unsigned char unused2[2]; /* not currently using */ | 283 | unsigned char unused2a; /* not currently using */ |
246 | /* bytes 13-14 */ | 284 | /* byte 13 */ |
285 | unsigned char unused2; /* not currently using */ | ||
286 | /* byte 14 */ | ||
247 | 287 | ||
248 | unsigned char sw_ack_vector; /* filled in by the hardware */ | 288 | unsigned char sw_ack_vector; /* filled in by the hardware */ |
249 | /* byte 15 (bits 127:120) */ | 289 | /* byte 15 (bits 127:120) */ |
250 | 290 | ||
251 | unsigned char unused4[3]; /* not currently using bytes 17-19 */ | 291 | unsigned short sequence; /* message sequence number */ |
252 | /* bytes 17-19 */ | 292 | /* bytes 16-17 */ |
293 | unsigned char unused4[2]; /* not currently using bytes 18-19 */ | ||
294 | /* bytes 18-19 */ | ||
253 | 295 | ||
254 | int number_of_cpus; /* filled in at destination */ | 296 | int number_of_cpus; /* filled in at destination */ |
255 | /* 32 bits, bytes 20-23 (aligned) */ | 297 | /* 32 bits, bytes 20-23 (aligned) */ |
@@ -259,63 +301,93 @@ struct bau_payload_queue_entry { | |||
259 | }; | 301 | }; |
260 | 302 | ||
261 | /* | 303 | /* |
262 | * one for every slot in the destination payload queue | 304 | * one per-cpu; to locate the software tables |
263 | */ | ||
264 | struct bau_msg_status { | ||
265 | struct bau_local_cpumask seen_by; /* map of cpu's */ | ||
266 | }; | ||
267 | |||
268 | /* | ||
269 | * one for every slot in the destination software ack resources | ||
270 | */ | ||
271 | struct bau_sw_ack_status { | ||
272 | struct bau_payload_queue_entry *msg; /* associated message */ | ||
273 | int watcher; /* cpu monitoring, or -1 */ | ||
274 | }; | ||
275 | |||
276 | /* | ||
277 | * one on every node and per-cpu; to locate the software tables | ||
278 | */ | 305 | */ |
279 | struct bau_control { | 306 | struct bau_control { |
280 | struct bau_desc *descriptor_base; | 307 | struct bau_desc *descriptor_base; |
281 | struct bau_payload_queue_entry *bau_msg_head; | ||
282 | struct bau_payload_queue_entry *va_queue_first; | 308 | struct bau_payload_queue_entry *va_queue_first; |
283 | struct bau_payload_queue_entry *va_queue_last; | 309 | struct bau_payload_queue_entry *va_queue_last; |
284 | struct bau_msg_status *msg_statuses; | 310 | struct bau_payload_queue_entry *bau_msg_head; |
285 | int *watching; /* pointer to array */ | 311 | struct bau_control *uvhub_master; |
312 | struct bau_control *socket_master; | ||
313 | unsigned long timeout_interval; | ||
314 | atomic_t active_descriptor_count; | ||
315 | int max_concurrent; | ||
316 | int max_concurrent_constant; | ||
317 | int retry_message_scans; | ||
318 | int plugged_tries; | ||
319 | int timeout_tries; | ||
320 | int ipi_attempts; | ||
321 | int conseccompletes; | ||
322 | short cpu; | ||
323 | short uvhub_cpu; | ||
324 | short uvhub; | ||
325 | short cpus_in_socket; | ||
326 | short cpus_in_uvhub; | ||
327 | unsigned short message_number; | ||
328 | unsigned short uvhub_quiesce; | ||
329 | short socket_acknowledge_count[DEST_Q_SIZE]; | ||
330 | cycles_t send_message; | ||
331 | spinlock_t masks_lock; | ||
332 | spinlock_t uvhub_lock; | ||
333 | spinlock_t queue_lock; | ||
286 | }; | 334 | }; |
287 | 335 | ||
288 | /* | 336 | /* |
289 | * This structure is allocated per_cpu for UV TLB shootdown statistics. | 337 | * This structure is allocated per_cpu for UV TLB shootdown statistics. |
290 | */ | 338 | */ |
291 | struct ptc_stats { | 339 | struct ptc_stats { |
292 | unsigned long ptc_i; /* number of IPI-style flushes */ | 340 | /* sender statistics */ |
293 | unsigned long requestor; /* number of nodes this cpu sent to */ | 341 | unsigned long s_giveup; /* number of fall backs to IPI-style flushes */ |
294 | unsigned long requestee; /* times cpu was remotely requested */ | 342 | unsigned long s_requestor; /* number of shootdown requests */ |
295 | unsigned long alltlb; /* times all tlb's on this cpu were flushed */ | 343 | unsigned long s_stimeout; /* source side timeouts */ |
296 | unsigned long onetlb; /* times just one tlb on this cpu was flushed */ | 344 | unsigned long s_dtimeout; /* destination side timeouts */ |
297 | unsigned long s_retry; /* retries on source side timeouts */ | 345 | unsigned long s_time; /* time spent in sending side */ |
298 | unsigned long d_retry; /* retries on destination side timeouts */ | 346 | unsigned long s_retriesok; /* successful retries */ |
299 | unsigned long sflush; /* cycles spent in uv_flush_tlb_others */ | 347 | unsigned long s_ntargcpu; /* number of cpus targeted */ |
300 | unsigned long dflush; /* cycles spent on destination side */ | 348 | unsigned long s_ntarguvhub; /* number of uvhubs targeted */ |
301 | unsigned long retriesok; /* successes on retries */ | 349 | unsigned long s_ntarguvhub16; /* number of times >= 16 target hubs */ |
302 | unsigned long nomsg; /* interrupts with no message */ | 350 | unsigned long s_ntarguvhub8; /* number of times >= 8 target hubs */ |
303 | unsigned long multmsg; /* interrupts with multiple messages */ | 351 | unsigned long s_ntarguvhub4; /* number of times >= 4 target hubs */ |
304 | unsigned long ntargeted;/* nodes targeted */ | 352 | unsigned long s_ntarguvhub2; /* number of times >= 2 target hubs */ |
353 | unsigned long s_ntarguvhub1; /* number of times == 1 target hub */ | ||
354 | unsigned long s_resets_plug; /* ipi-style resets from plug state */ | ||
355 | unsigned long s_resets_timeout; /* ipi-style resets from timeouts */ | ||
356 | unsigned long s_busy; /* status stayed busy past s/w timer */ | ||
357 | unsigned long s_throttles; /* waits in throttle */ | ||
358 | unsigned long s_retry_messages; /* retry broadcasts */ | ||
359 | /* destination statistics */ | ||
360 | unsigned long d_alltlb; /* times all tlb's on this cpu were flushed */ | ||
361 | unsigned long d_onetlb; /* times just one tlb on this cpu was flushed */ | ||
362 | unsigned long d_multmsg; /* interrupts with multiple messages */ | ||
363 | unsigned long d_nomsg; /* interrupts with no message */ | ||
364 | unsigned long d_time; /* time spent on destination side */ | ||
365 | unsigned long d_requestee; /* number of messages processed */ | ||
366 | unsigned long d_retries; /* number of retry messages processed */ | ||
367 | unsigned long d_canceled; /* number of messages canceled by retries */ | ||
368 | unsigned long d_nocanceled; /* retries that found nothing to cancel */ | ||
369 | unsigned long d_resets; /* number of ipi-style requests processed */ | ||
370 | unsigned long d_rcanceled; /* number of messages canceled by resets */ | ||
305 | }; | 371 | }; |
306 | 372 | ||
307 | static inline int bau_node_isset(int node, struct bau_target_nodemask *dstp) | 373 | static inline int bau_uvhub_isset(int uvhub, struct bau_target_uvhubmask *dstp) |
308 | { | 374 | { |
309 | return constant_test_bit(node, &dstp->bits[0]); | 375 | return constant_test_bit(uvhub, &dstp->bits[0]); |
310 | } | 376 | } |
311 | static inline void bau_node_set(int node, struct bau_target_nodemask *dstp) | 377 | static inline void bau_uvhub_set(int uvhub, struct bau_target_uvhubmask *dstp) |
312 | { | 378 | { |
313 | __set_bit(node, &dstp->bits[0]); | 379 | __set_bit(uvhub, &dstp->bits[0]); |
314 | } | 380 | } |
315 | static inline void bau_nodes_clear(struct bau_target_nodemask *dstp, int nbits) | 381 | static inline void bau_uvhubs_clear(struct bau_target_uvhubmask *dstp, |
382 | int nbits) | ||
316 | { | 383 | { |
317 | bitmap_zero(&dstp->bits[0], nbits); | 384 | bitmap_zero(&dstp->bits[0], nbits); |
318 | } | 385 | } |
386 | static inline int bau_uvhub_weight(struct bau_target_uvhubmask *dstp) | ||
387 | { | ||
388 | return bitmap_weight((unsigned long *)&dstp->bits[0], | ||
389 | UV_DISTRIBUTION_SIZE); | ||
390 | } | ||
319 | 391 | ||
320 | static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits) | 392 | static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits) |
321 | { | 393 | { |
@@ -328,4 +400,35 @@ static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits) | |||
328 | extern void uv_bau_message_intr1(void); | 400 | extern void uv_bau_message_intr1(void); |
329 | extern void uv_bau_timeout_intr1(void); | 401 | extern void uv_bau_timeout_intr1(void); |
330 | 402 | ||
403 | struct atomic_short { | ||
404 | short counter; | ||
405 | }; | ||
406 | |||
407 | /** | ||
408 | * atomic_read_short - read a short atomic variable | ||
409 | * @v: pointer of type atomic_short | ||
410 | * | ||
411 | * Atomically reads the value of @v. | ||
412 | */ | ||
413 | static inline int atomic_read_short(const struct atomic_short *v) | ||
414 | { | ||
415 | return v->counter; | ||
416 | } | ||
417 | |||
418 | /** | ||
419 | * atomic_add_short_return - add and return a short int | ||
420 | * @i: short value to add | ||
421 | * @v: pointer of type atomic_short | ||
422 | * | ||
423 | * Atomically adds @i to @v and returns @i + @v | ||
424 | */ | ||
425 | static inline int atomic_add_short_return(short i, struct atomic_short *v) | ||
426 | { | ||
427 | short __i = i; | ||
428 | asm volatile(LOCK_PREFIX "xaddw %0, %1" | ||
429 | : "+r" (i), "+m" (v->counter) | ||
430 | : : "memory"); | ||
431 | return i + __i; | ||
432 | } | ||
433 | |||
331 | #endif /* _ASM_X86_UV_UV_BAU_H */ | 434 | #endif /* _ASM_X86_UV_UV_BAU_H */ |
diff --git a/arch/x86/include/asm/uv/uv_hub.h b/arch/x86/include/asm/uv/uv_hub.h index 14cc74ba5d23..bf6b88ef8eeb 100644 --- a/arch/x86/include/asm/uv/uv_hub.h +++ b/arch/x86/include/asm/uv/uv_hub.h | |||
@@ -307,7 +307,7 @@ static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset | |||
307 | * Access Global MMR space using the MMR space located at the top of physical | 307 | * Access Global MMR space using the MMR space located at the top of physical |
308 | * memory. | 308 | * memory. |
309 | */ | 309 | */ |
310 | static inline unsigned long *uv_global_mmr64_address(int pnode, unsigned long offset) | 310 | static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset) |
311 | { | 311 | { |
312 | return __va(UV_GLOBAL_MMR64_BASE | | 312 | return __va(UV_GLOBAL_MMR64_BASE | |
313 | UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset); | 313 | UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset); |
diff --git a/arch/x86/include/asm/uv/uv_mmrs.h b/arch/x86/include/asm/uv/uv_mmrs.h index 2cae46c7c8a2..b2f2d2e05cec 100644 --- a/arch/x86/include/asm/uv/uv_mmrs.h +++ b/arch/x86/include/asm/uv/uv_mmrs.h | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | /* | 1 | /* |
3 | * This file is subject to the terms and conditions of the GNU General Public | 2 | * This file is subject to the terms and conditions of the GNU General Public |
4 | * License. See the file "COPYING" in the main directory of this archive | 3 | * License. See the file "COPYING" in the main directory of this archive |
@@ -15,13 +14,25 @@ | |||
15 | #define UV_MMR_ENABLE (1UL << 63) | 14 | #define UV_MMR_ENABLE (1UL << 63) |
16 | 15 | ||
17 | /* ========================================================================= */ | 16 | /* ========================================================================= */ |
17 | /* UVH_BAU_DATA_BROADCAST */ | ||
18 | /* ========================================================================= */ | ||
19 | #define UVH_BAU_DATA_BROADCAST 0x61688UL | ||
20 | #define UVH_BAU_DATA_BROADCAST_32 0x0440 | ||
21 | |||
22 | #define UVH_BAU_DATA_BROADCAST_ENABLE_SHFT 0 | ||
23 | #define UVH_BAU_DATA_BROADCAST_ENABLE_MASK 0x0000000000000001UL | ||
24 | |||
25 | union uvh_bau_data_broadcast_u { | ||
26 | unsigned long v; | ||
27 | struct uvh_bau_data_broadcast_s { | ||
28 | unsigned long enable : 1; /* RW */ | ||
29 | unsigned long rsvd_1_63: 63; /* */ | ||
30 | } s; | ||
31 | }; | ||
32 | |||
33 | /* ========================================================================= */ | ||
18 | /* UVH_BAU_DATA_CONFIG */ | 34 | /* UVH_BAU_DATA_CONFIG */ |
19 | /* ========================================================================= */ | 35 | /* ========================================================================= */ |
20 | #define UVH_LB_BAU_MISC_CONTROL 0x320170UL | ||
21 | #define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15 | ||
22 | #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16 | ||
23 | #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL | ||
24 | /* 1011 timebase 7 (168millisec) * 3 ticks -> 500ms */ | ||
25 | #define UVH_BAU_DATA_CONFIG 0x61680UL | 36 | #define UVH_BAU_DATA_CONFIG 0x61680UL |
26 | #define UVH_BAU_DATA_CONFIG_32 0x0438 | 37 | #define UVH_BAU_DATA_CONFIG_32 0x0438 |
27 | 38 | ||
@@ -604,6 +615,68 @@ union uvh_lb_bau_intd_software_acknowledge_u { | |||
604 | #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS_32 0x0a70 | 615 | #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS_32 0x0a70 |
605 | 616 | ||
606 | /* ========================================================================= */ | 617 | /* ========================================================================= */ |
618 | /* UVH_LB_BAU_MISC_CONTROL */ | ||
619 | /* ========================================================================= */ | ||
620 | #define UVH_LB_BAU_MISC_CONTROL 0x320170UL | ||
621 | #define UVH_LB_BAU_MISC_CONTROL_32 0x00a10 | ||
622 | |||
623 | #define UVH_LB_BAU_MISC_CONTROL_REJECTION_DELAY_SHFT 0 | ||
624 | #define UVH_LB_BAU_MISC_CONTROL_REJECTION_DELAY_MASK 0x00000000000000ffUL | ||
625 | #define UVH_LB_BAU_MISC_CONTROL_APIC_MODE_SHFT 8 | ||
626 | #define UVH_LB_BAU_MISC_CONTROL_APIC_MODE_MASK 0x0000000000000100UL | ||
627 | #define UVH_LB_BAU_MISC_CONTROL_FORCE_BROADCAST_SHFT 9 | ||
628 | #define UVH_LB_BAU_MISC_CONTROL_FORCE_BROADCAST_MASK 0x0000000000000200UL | ||
629 | #define UVH_LB_BAU_MISC_CONTROL_FORCE_LOCK_NOP_SHFT 10 | ||
630 | #define UVH_LB_BAU_MISC_CONTROL_FORCE_LOCK_NOP_MASK 0x0000000000000400UL | ||
631 | #define UVH_LB_BAU_MISC_CONTROL_CSI_AGENT_PRESENCE_VECTOR_SHFT 11 | ||
632 | #define UVH_LB_BAU_MISC_CONTROL_CSI_AGENT_PRESENCE_VECTOR_MASK 0x0000000000003800UL | ||
633 | #define UVH_LB_BAU_MISC_CONTROL_DESCRIPTOR_FETCH_MODE_SHFT 14 | ||
634 | #define UVH_LB_BAU_MISC_CONTROL_DESCRIPTOR_FETCH_MODE_MASK 0x0000000000004000UL | ||
635 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT 15 | ||
636 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_MASK 0x0000000000008000UL | ||
637 | #define UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT 16 | ||
638 | #define UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_MASK 0x00000000000f0000UL | ||
639 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_DUAL_MAPPING_MODE_SHFT 20 | ||
640 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_DUAL_MAPPING_MODE_MASK 0x0000000000100000UL | ||
641 | #define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_DECODE_ENABLE_SHFT 21 | ||
642 | #define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_DECODE_ENABLE_MASK 0x0000000000200000UL | ||
643 | #define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_16_BIT_DECODE_SHFT 22 | ||
644 | #define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_16_BIT_DECODE_MASK 0x0000000000400000UL | ||
645 | #define UVH_LB_BAU_MISC_CONTROL_SUPPRESS_DEST_REGISTRATION_SHFT 23 | ||
646 | #define UVH_LB_BAU_MISC_CONTROL_SUPPRESS_DEST_REGISTRATION_MASK 0x0000000000800000UL | ||
647 | #define UVH_LB_BAU_MISC_CONTROL_PROGRAMMED_INITIAL_PRIORITY_SHFT 24 | ||
648 | #define UVH_LB_BAU_MISC_CONTROL_PROGRAMMED_INITIAL_PRIORITY_MASK 0x0000000007000000UL | ||
649 | #define UVH_LB_BAU_MISC_CONTROL_USE_INCOMING_PRIORITY_SHFT 27 | ||
650 | #define UVH_LB_BAU_MISC_CONTROL_USE_INCOMING_PRIORITY_MASK 0x0000000008000000UL | ||
651 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_PROGRAMMED_INITIAL_PRIORITY_SHFT 28 | ||
652 | #define UVH_LB_BAU_MISC_CONTROL_ENABLE_PROGRAMMED_INITIAL_PRIORITY_MASK 0x0000000010000000UL | ||
653 | #define UVH_LB_BAU_MISC_CONTROL_FUN_SHFT 48 | ||
654 | #define UVH_LB_BAU_MISC_CONTROL_FUN_MASK 0xffff000000000000UL | ||
655 | |||
656 | union uvh_lb_bau_misc_control_u { | ||
657 | unsigned long v; | ||
658 | struct uvh_lb_bau_misc_control_s { | ||
659 | unsigned long rejection_delay : 8; /* RW */ | ||
660 | unsigned long apic_mode : 1; /* RW */ | ||
661 | unsigned long force_broadcast : 1; /* RW */ | ||
662 | unsigned long force_lock_nop : 1; /* RW */ | ||
663 | unsigned long csi_agent_presence_vector : 3; /* RW */ | ||
664 | unsigned long descriptor_fetch_mode : 1; /* RW */ | ||
665 | unsigned long enable_intd_soft_ack_mode : 1; /* RW */ | ||
666 | unsigned long intd_soft_ack_timeout_period : 4; /* RW */ | ||
667 | unsigned long enable_dual_mapping_mode : 1; /* RW */ | ||
668 | unsigned long vga_io_port_decode_enable : 1; /* RW */ | ||
669 | unsigned long vga_io_port_16_bit_decode : 1; /* RW */ | ||
670 | unsigned long suppress_dest_registration : 1; /* RW */ | ||
671 | unsigned long programmed_initial_priority : 3; /* RW */ | ||
672 | unsigned long use_incoming_priority : 1; /* RW */ | ||
673 | unsigned long enable_programmed_initial_priority : 1; /* RW */ | ||
674 | unsigned long rsvd_29_47 : 19; /* */ | ||
675 | unsigned long fun : 16; /* RW */ | ||
676 | } s; | ||
677 | }; | ||
678 | |||
679 | /* ========================================================================= */ | ||
607 | /* UVH_LB_BAU_SB_ACTIVATION_CONTROL */ | 680 | /* UVH_LB_BAU_SB_ACTIVATION_CONTROL */ |
608 | /* ========================================================================= */ | 681 | /* ========================================================================= */ |
609 | #define UVH_LB_BAU_SB_ACTIVATION_CONTROL 0x320020UL | 682 | #define UVH_LB_BAU_SB_ACTIVATION_CONTROL 0x320020UL |
@@ -681,334 +754,6 @@ union uvh_lb_bau_sb_descriptor_base_u { | |||
681 | }; | 754 | }; |
682 | 755 | ||
683 | /* ========================================================================= */ | 756 | /* ========================================================================= */ |
684 | /* UVH_LB_MCAST_AOERR0_RPT_ENABLE */ | ||
685 | /* ========================================================================= */ | ||
686 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE 0x50b20UL | ||
687 | |||
688 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_SHFT 0 | ||
689 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_MASK 0x0000000000000001UL | ||
690 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_SHFT 1 | ||
691 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_MASK 0x0000000000000002UL | ||
692 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_SHFT 2 | ||
693 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_MASK 0x0000000000000004UL | ||
694 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_SHFT 3 | ||
695 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_MASK 0x0000000000000008UL | ||
696 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_SHFT 4 | ||
697 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_MASK 0x0000000000000010UL | ||
698 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_SHFT 5 | ||
699 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_MASK 0x0000000000000020UL | ||
700 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_SHFT 6 | ||
701 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_MASK 0x0000000000000040UL | ||
702 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_SHFT 7 | ||
703 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_MASK 0x0000000000000080UL | ||
704 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_SHFT 8 | ||
705 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_MASK 0x0000000000000100UL | ||
706 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_SHFT 9 | ||
707 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_MASK 0x0000000000000200UL | ||
708 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_SHFT 10 | ||
709 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_MASK 0x0000000000000400UL | ||
710 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_SHFT 11 | ||
711 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_MASK 0x0000000000000800UL | ||
712 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_SHFT 12 | ||
713 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_MASK 0x0000000000001000UL | ||
714 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_SHFT 13 | ||
715 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_MASK 0x0000000000002000UL | ||
716 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_SHFT 14 | ||
717 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_MASK 0x0000000000004000UL | ||
718 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_SHFT 15 | ||
719 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_MASK 0x0000000000008000UL | ||
720 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_SHFT 16 | ||
721 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_MASK 0x0000000000010000UL | ||
722 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_SHFT 17 | ||
723 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_MASK 0x0000000000020000UL | ||
724 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_SHFT 18 | ||
725 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_MASK 0x0000000000040000UL | ||
726 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_SHFT 19 | ||
727 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_MASK 0x0000000000080000UL | ||
728 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_SHFT 20 | ||
729 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_MASK 0x0000000000100000UL | ||
730 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_SHFT 21 | ||
731 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_MASK 0x0000000000200000UL | ||
732 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_SHFT 22 | ||
733 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_MASK 0x0000000000400000UL | ||
734 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_SHFT 23 | ||
735 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_MASK 0x0000000000800000UL | ||
736 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_SHFT 24 | ||
737 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_MASK 0x0000000001000000UL | ||
738 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_SHFT 25 | ||
739 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_MASK 0x0000000002000000UL | ||
740 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_SHFT 26 | ||
741 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_MASK 0x0000000004000000UL | ||
742 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_SHFT 27 | ||
743 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_MASK 0x0000000008000000UL | ||
744 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_SHFT 28 | ||
745 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_MASK 0x0000000010000000UL | ||
746 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_SHFT 29 | ||
747 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_MASK 0x0000000020000000UL | ||
748 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_SHFT 30 | ||
749 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_MASK 0x0000000040000000UL | ||
750 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_SHFT 31 | ||
751 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_MASK 0x0000000080000000UL | ||
752 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_SHFT 32 | ||
753 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_MASK 0x0000000100000000UL | ||
754 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_SHFT 33 | ||
755 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_MASK 0x0000000200000000UL | ||
756 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_SHFT 34 | ||
757 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_MASK 0x0000000400000000UL | ||
758 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_SHFT 35 | ||
759 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_MASK 0x0000000800000000UL | ||
760 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_SHFT 36 | ||
761 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_MASK 0x0000001000000000UL | ||
762 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_SHFT 37 | ||
763 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_MASK 0x0000002000000000UL | ||
764 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_SHFT 38 | ||
765 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_MASK 0x0000004000000000UL | ||
766 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_SHFT 39 | ||
767 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_MASK 0x0000008000000000UL | ||
768 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_SHFT 40 | ||
769 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_MASK 0x0000010000000000UL | ||
770 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_SHFT 41 | ||
771 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_MASK 0x0000020000000000UL | ||
772 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_SHFT 42 | ||
773 | #define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_MASK 0x0000040000000000UL | ||
774 | |||
775 | union uvh_lb_mcast_aoerr0_rpt_enable_u { | ||
776 | unsigned long v; | ||
777 | struct uvh_lb_mcast_aoerr0_rpt_enable_s { | ||
778 | unsigned long mcast_obese_msg : 1; /* RW */ | ||
779 | unsigned long mcast_data_sb_err : 1; /* RW */ | ||
780 | unsigned long mcast_nack_buff_parity : 1; /* RW */ | ||
781 | unsigned long mcast_timeout : 1; /* RW */ | ||
782 | unsigned long mcast_inactive_reply : 1; /* RW */ | ||
783 | unsigned long mcast_upgrade_error : 1; /* RW */ | ||
784 | unsigned long mcast_reg_count_underflow : 1; /* RW */ | ||
785 | unsigned long mcast_rep_obese_msg : 1; /* RW */ | ||
786 | unsigned long ucache_req_runt_msg : 1; /* RW */ | ||
787 | unsigned long ucache_req_obese_msg : 1; /* RW */ | ||
788 | unsigned long ucache_req_data_sb_err : 1; /* RW */ | ||
789 | unsigned long ucache_rep_runt_msg : 1; /* RW */ | ||
790 | unsigned long ucache_rep_obese_msg : 1; /* RW */ | ||
791 | unsigned long ucache_rep_data_sb_err : 1; /* RW */ | ||
792 | unsigned long ucache_rep_command_err : 1; /* RW */ | ||
793 | unsigned long ucache_pend_timeout : 1; /* RW */ | ||
794 | unsigned long macc_req_runt_msg : 1; /* RW */ | ||
795 | unsigned long macc_req_obese_msg : 1; /* RW */ | ||
796 | unsigned long macc_req_data_sb_err : 1; /* RW */ | ||
797 | unsigned long macc_rep_runt_msg : 1; /* RW */ | ||
798 | unsigned long macc_rep_obese_msg : 1; /* RW */ | ||
799 | unsigned long macc_rep_data_sb_err : 1; /* RW */ | ||
800 | unsigned long macc_amo_timeout : 1; /* RW */ | ||
801 | unsigned long macc_put_timeout : 1; /* RW */ | ||
802 | unsigned long macc_spurious_event : 1; /* RW */ | ||
803 | unsigned long ioh_destination_table_parity : 1; /* RW */ | ||
804 | unsigned long get_had_error_reply : 1; /* RW */ | ||
805 | unsigned long get_timeout : 1; /* RW */ | ||
806 | unsigned long lock_manager_had_error_reply : 1; /* RW */ | ||
807 | unsigned long put_had_error_reply : 1; /* RW */ | ||
808 | unsigned long put_timeout : 1; /* RW */ | ||
809 | unsigned long sb_activation_overrun : 1; /* RW */ | ||
810 | unsigned long completed_gb_activation_had_error_reply : 1; /* RW */ | ||
811 | unsigned long completed_gb_activation_timeout : 1; /* RW */ | ||
812 | unsigned long descriptor_buffer_0_parity : 1; /* RW */ | ||
813 | unsigned long descriptor_buffer_1_parity : 1; /* RW */ | ||
814 | unsigned long socket_destination_table_parity : 1; /* RW */ | ||
815 | unsigned long bau_reply_payload_corruption : 1; /* RW */ | ||
816 | unsigned long io_port_destination_table_parity : 1; /* RW */ | ||
817 | unsigned long intd_soft_ack_timeout : 1; /* RW */ | ||
818 | unsigned long int_rep_obese_msg : 1; /* RW */ | ||
819 | unsigned long int_rep_command_err : 1; /* RW */ | ||
820 | unsigned long int_timeout : 1; /* RW */ | ||
821 | unsigned long rsvd_43_63 : 21; /* */ | ||
822 | } s; | ||
823 | }; | ||
824 | |||
825 | /* ========================================================================= */ | ||
826 | /* UVH_LOCAL_INT0_CONFIG */ | ||
827 | /* ========================================================================= */ | ||
828 | #define UVH_LOCAL_INT0_CONFIG 0x61000UL | ||
829 | |||
830 | #define UVH_LOCAL_INT0_CONFIG_VECTOR_SHFT 0 | ||
831 | #define UVH_LOCAL_INT0_CONFIG_VECTOR_MASK 0x00000000000000ffUL | ||
832 | #define UVH_LOCAL_INT0_CONFIG_DM_SHFT 8 | ||
833 | #define UVH_LOCAL_INT0_CONFIG_DM_MASK 0x0000000000000700UL | ||
834 | #define UVH_LOCAL_INT0_CONFIG_DESTMODE_SHFT 11 | ||
835 | #define UVH_LOCAL_INT0_CONFIG_DESTMODE_MASK 0x0000000000000800UL | ||
836 | #define UVH_LOCAL_INT0_CONFIG_STATUS_SHFT 12 | ||
837 | #define UVH_LOCAL_INT0_CONFIG_STATUS_MASK 0x0000000000001000UL | ||
838 | #define UVH_LOCAL_INT0_CONFIG_P_SHFT 13 | ||
839 | #define UVH_LOCAL_INT0_CONFIG_P_MASK 0x0000000000002000UL | ||
840 | #define UVH_LOCAL_INT0_CONFIG_T_SHFT 15 | ||
841 | #define UVH_LOCAL_INT0_CONFIG_T_MASK 0x0000000000008000UL | ||
842 | #define UVH_LOCAL_INT0_CONFIG_M_SHFT 16 | ||
843 | #define UVH_LOCAL_INT0_CONFIG_M_MASK 0x0000000000010000UL | ||
844 | #define UVH_LOCAL_INT0_CONFIG_APIC_ID_SHFT 32 | ||
845 | #define UVH_LOCAL_INT0_CONFIG_APIC_ID_MASK 0xffffffff00000000UL | ||
846 | |||
847 | union uvh_local_int0_config_u { | ||
848 | unsigned long v; | ||
849 | struct uvh_local_int0_config_s { | ||
850 | unsigned long vector_ : 8; /* RW */ | ||
851 | unsigned long dm : 3; /* RW */ | ||
852 | unsigned long destmode : 1; /* RW */ | ||
853 | unsigned long status : 1; /* RO */ | ||
854 | unsigned long p : 1; /* RO */ | ||
855 | unsigned long rsvd_14 : 1; /* */ | ||
856 | unsigned long t : 1; /* RO */ | ||
857 | unsigned long m : 1; /* RW */ | ||
858 | unsigned long rsvd_17_31: 15; /* */ | ||
859 | unsigned long apic_id : 32; /* RW */ | ||
860 | } s; | ||
861 | }; | ||
862 | |||
863 | /* ========================================================================= */ | ||
864 | /* UVH_LOCAL_INT0_ENABLE */ | ||
865 | /* ========================================================================= */ | ||
866 | #define UVH_LOCAL_INT0_ENABLE 0x65000UL | ||
867 | |||
868 | #define UVH_LOCAL_INT0_ENABLE_LB_HCERR_SHFT 0 | ||
869 | #define UVH_LOCAL_INT0_ENABLE_LB_HCERR_MASK 0x0000000000000001UL | ||
870 | #define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_SHFT 1 | ||
871 | #define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_MASK 0x0000000000000002UL | ||
872 | #define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_SHFT 2 | ||
873 | #define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_MASK 0x0000000000000004UL | ||
874 | #define UVH_LOCAL_INT0_ENABLE_LH_HCERR_SHFT 3 | ||
875 | #define UVH_LOCAL_INT0_ENABLE_LH_HCERR_MASK 0x0000000000000008UL | ||
876 | #define UVH_LOCAL_INT0_ENABLE_RH_HCERR_SHFT 4 | ||
877 | #define UVH_LOCAL_INT0_ENABLE_RH_HCERR_MASK 0x0000000000000010UL | ||
878 | #define UVH_LOCAL_INT0_ENABLE_XN_HCERR_SHFT 5 | ||
879 | #define UVH_LOCAL_INT0_ENABLE_XN_HCERR_MASK 0x0000000000000020UL | ||
880 | #define UVH_LOCAL_INT0_ENABLE_SI_HCERR_SHFT 6 | ||
881 | #define UVH_LOCAL_INT0_ENABLE_SI_HCERR_MASK 0x0000000000000040UL | ||
882 | #define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_SHFT 7 | ||
883 | #define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_MASK 0x0000000000000080UL | ||
884 | #define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_SHFT 8 | ||
885 | #define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_MASK 0x0000000000000100UL | ||
886 | #define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_SHFT 9 | ||
887 | #define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_MASK 0x0000000000000200UL | ||
888 | #define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_SHFT 10 | ||
889 | #define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_MASK 0x0000000000000400UL | ||
890 | #define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_SHFT 11 | ||
891 | #define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_MASK 0x0000000000000800UL | ||
892 | #define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_SHFT 12 | ||
893 | #define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_MASK 0x0000000000001000UL | ||
894 | #define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_SHFT 13 | ||
895 | #define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_MASK 0x0000000000002000UL | ||
896 | #define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_SHFT 14 | ||
897 | #define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_MASK 0x0000000000004000UL | ||
898 | #define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_SHFT 15 | ||
899 | #define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_MASK 0x0000000000008000UL | ||
900 | #define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_SHFT 16 | ||
901 | #define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_MASK 0x0000000000010000UL | ||
902 | #define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_SHFT 17 | ||
903 | #define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_MASK 0x0000000000020000UL | ||
904 | #define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_SHFT 18 | ||
905 | #define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_MASK 0x0000000000040000UL | ||
906 | #define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_SHFT 19 | ||
907 | #define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_MASK 0x0000000000080000UL | ||
908 | #define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_SHFT 20 | ||
909 | #define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_MASK 0x0000000000100000UL | ||
910 | #define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_SHFT 21 | ||
911 | #define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_MASK 0x0000000000200000UL | ||
912 | #define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_SHFT 22 | ||
913 | #define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_MASK 0x0000000000400000UL | ||
914 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_SHFT 23 | ||
915 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_MASK 0x0000000000800000UL | ||
916 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_SHFT 24 | ||
917 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_MASK 0x0000000001000000UL | ||
918 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_SHFT 25 | ||
919 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_MASK 0x0000000002000000UL | ||
920 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_SHFT 26 | ||
921 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_MASK 0x0000000004000000UL | ||
922 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_SHFT 27 | ||
923 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_MASK 0x0000000008000000UL | ||
924 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_SHFT 28 | ||
925 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_MASK 0x0000000010000000UL | ||
926 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_SHFT 29 | ||
927 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_MASK 0x0000000020000000UL | ||
928 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_SHFT 30 | ||
929 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_MASK 0x0000000040000000UL | ||
930 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_SHFT 31 | ||
931 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_MASK 0x0000000080000000UL | ||
932 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_SHFT 32 | ||
933 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_MASK 0x0000000100000000UL | ||
934 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_SHFT 33 | ||
935 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_MASK 0x0000000200000000UL | ||
936 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_SHFT 34 | ||
937 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_MASK 0x0000000400000000UL | ||
938 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_SHFT 35 | ||
939 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_MASK 0x0000000800000000UL | ||
940 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_SHFT 36 | ||
941 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_MASK 0x0000001000000000UL | ||
942 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_SHFT 37 | ||
943 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_MASK 0x0000002000000000UL | ||
944 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_SHFT 38 | ||
945 | #define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_MASK 0x0000004000000000UL | ||
946 | #define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_SHFT 39 | ||
947 | #define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_MASK 0x0000008000000000UL | ||
948 | #define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_SHFT 40 | ||
949 | #define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_MASK 0x0000010000000000UL | ||
950 | #define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_SHFT 41 | ||
951 | #define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_MASK 0x0000020000000000UL | ||
952 | #define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_SHFT 42 | ||
953 | #define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_MASK 0x0000040000000000UL | ||
954 | #define UVH_LOCAL_INT0_ENABLE_LTC_INT_SHFT 43 | ||
955 | #define UVH_LOCAL_INT0_ENABLE_LTC_INT_MASK 0x0000080000000000UL | ||
956 | #define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_SHFT 44 | ||
957 | #define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_MASK 0x0000100000000000UL | ||
958 | |||
959 | union uvh_local_int0_enable_u { | ||
960 | unsigned long v; | ||
961 | struct uvh_local_int0_enable_s { | ||
962 | unsigned long lb_hcerr : 1; /* RW */ | ||
963 | unsigned long gr0_hcerr : 1; /* RW */ | ||
964 | unsigned long gr1_hcerr : 1; /* RW */ | ||
965 | unsigned long lh_hcerr : 1; /* RW */ | ||
966 | unsigned long rh_hcerr : 1; /* RW */ | ||
967 | unsigned long xn_hcerr : 1; /* RW */ | ||
968 | unsigned long si_hcerr : 1; /* RW */ | ||
969 | unsigned long lb_aoerr0 : 1; /* RW */ | ||
970 | unsigned long gr0_aoerr0 : 1; /* RW */ | ||
971 | unsigned long gr1_aoerr0 : 1; /* RW */ | ||
972 | unsigned long lh_aoerr0 : 1; /* RW */ | ||
973 | unsigned long rh_aoerr0 : 1; /* RW */ | ||
974 | unsigned long xn_aoerr0 : 1; /* RW */ | ||
975 | unsigned long si_aoerr0 : 1; /* RW */ | ||
976 | unsigned long lb_aoerr1 : 1; /* RW */ | ||
977 | unsigned long gr0_aoerr1 : 1; /* RW */ | ||
978 | unsigned long gr1_aoerr1 : 1; /* RW */ | ||
979 | unsigned long lh_aoerr1 : 1; /* RW */ | ||
980 | unsigned long rh_aoerr1 : 1; /* RW */ | ||
981 | unsigned long xn_aoerr1 : 1; /* RW */ | ||
982 | unsigned long si_aoerr1 : 1; /* RW */ | ||
983 | unsigned long rh_vpi_int : 1; /* RW */ | ||
984 | unsigned long system_shutdown_int : 1; /* RW */ | ||
985 | unsigned long lb_irq_int_0 : 1; /* RW */ | ||
986 | unsigned long lb_irq_int_1 : 1; /* RW */ | ||
987 | unsigned long lb_irq_int_2 : 1; /* RW */ | ||
988 | unsigned long lb_irq_int_3 : 1; /* RW */ | ||
989 | unsigned long lb_irq_int_4 : 1; /* RW */ | ||
990 | unsigned long lb_irq_int_5 : 1; /* RW */ | ||
991 | unsigned long lb_irq_int_6 : 1; /* RW */ | ||
992 | unsigned long lb_irq_int_7 : 1; /* RW */ | ||
993 | unsigned long lb_irq_int_8 : 1; /* RW */ | ||
994 | unsigned long lb_irq_int_9 : 1; /* RW */ | ||
995 | unsigned long lb_irq_int_10 : 1; /* RW */ | ||
996 | unsigned long lb_irq_int_11 : 1; /* RW */ | ||
997 | unsigned long lb_irq_int_12 : 1; /* RW */ | ||
998 | unsigned long lb_irq_int_13 : 1; /* RW */ | ||
999 | unsigned long lb_irq_int_14 : 1; /* RW */ | ||
1000 | unsigned long lb_irq_int_15 : 1; /* RW */ | ||
1001 | unsigned long l1_nmi_int : 1; /* RW */ | ||
1002 | unsigned long stop_clock : 1; /* RW */ | ||
1003 | unsigned long asic_to_l1 : 1; /* RW */ | ||
1004 | unsigned long l1_to_asic : 1; /* RW */ | ||
1005 | unsigned long ltc_int : 1; /* RW */ | ||
1006 | unsigned long la_seq_trigger : 1; /* RW */ | ||
1007 | unsigned long rsvd_45_63 : 19; /* */ | ||
1008 | } s; | ||
1009 | }; | ||
1010 | |||
1011 | /* ========================================================================= */ | ||
1012 | /* UVH_NODE_ID */ | 757 | /* UVH_NODE_ID */ |
1013 | /* ========================================================================= */ | 758 | /* ========================================================================= */ |
1014 | #define UVH_NODE_ID 0x0UL | 759 | #define UVH_NODE_ID 0x0UL |
@@ -1112,26 +857,6 @@ union uvh_rh_gam_alias210_redirect_config_2_mmr_u { | |||
1112 | }; | 857 | }; |
1113 | 858 | ||
1114 | /* ========================================================================= */ | 859 | /* ========================================================================= */ |
1115 | /* UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR */ | ||
1116 | /* ========================================================================= */ | ||
1117 | #define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR 0x1600020UL | ||
1118 | |||
1119 | #define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_SHFT 26 | ||
1120 | #define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffffc000000UL | ||
1121 | #define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63 | ||
1122 | #define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_MASK 0x8000000000000000UL | ||
1123 | |||
1124 | union uvh_rh_gam_cfg_overlay_config_mmr_u { | ||
1125 | unsigned long v; | ||
1126 | struct uvh_rh_gam_cfg_overlay_config_mmr_s { | ||
1127 | unsigned long rsvd_0_25: 26; /* */ | ||
1128 | unsigned long base : 20; /* RW */ | ||
1129 | unsigned long rsvd_46_62: 17; /* */ | ||
1130 | unsigned long enable : 1; /* RW */ | ||
1131 | } s; | ||
1132 | }; | ||
1133 | |||
1134 | /* ========================================================================= */ | ||
1135 | /* UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR */ | 860 | /* UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR */ |
1136 | /* ========================================================================= */ | 861 | /* ========================================================================= */ |
1137 | #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR 0x1600010UL | 862 | #define UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR 0x1600010UL |
@@ -1263,101 +988,6 @@ union uvh_rtc1_int_config_u { | |||
1263 | }; | 988 | }; |
1264 | 989 | ||
1265 | /* ========================================================================= */ | 990 | /* ========================================================================= */ |
1266 | /* UVH_RTC2_INT_CONFIG */ | ||
1267 | /* ========================================================================= */ | ||
1268 | #define UVH_RTC2_INT_CONFIG 0x61600UL | ||
1269 | |||
1270 | #define UVH_RTC2_INT_CONFIG_VECTOR_SHFT 0 | ||
1271 | #define UVH_RTC2_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL | ||
1272 | #define UVH_RTC2_INT_CONFIG_DM_SHFT 8 | ||
1273 | #define UVH_RTC2_INT_CONFIG_DM_MASK 0x0000000000000700UL | ||
1274 | #define UVH_RTC2_INT_CONFIG_DESTMODE_SHFT 11 | ||
1275 | #define UVH_RTC2_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL | ||
1276 | #define UVH_RTC2_INT_CONFIG_STATUS_SHFT 12 | ||
1277 | #define UVH_RTC2_INT_CONFIG_STATUS_MASK 0x0000000000001000UL | ||
1278 | #define UVH_RTC2_INT_CONFIG_P_SHFT 13 | ||
1279 | #define UVH_RTC2_INT_CONFIG_P_MASK 0x0000000000002000UL | ||
1280 | #define UVH_RTC2_INT_CONFIG_T_SHFT 15 | ||
1281 | #define UVH_RTC2_INT_CONFIG_T_MASK 0x0000000000008000UL | ||
1282 | #define UVH_RTC2_INT_CONFIG_M_SHFT 16 | ||
1283 | #define UVH_RTC2_INT_CONFIG_M_MASK 0x0000000000010000UL | ||
1284 | #define UVH_RTC2_INT_CONFIG_APIC_ID_SHFT 32 | ||
1285 | #define UVH_RTC2_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL | ||
1286 | |||
1287 | union uvh_rtc2_int_config_u { | ||
1288 | unsigned long v; | ||
1289 | struct uvh_rtc2_int_config_s { | ||
1290 | unsigned long vector_ : 8; /* RW */ | ||
1291 | unsigned long dm : 3; /* RW */ | ||
1292 | unsigned long destmode : 1; /* RW */ | ||
1293 | unsigned long status : 1; /* RO */ | ||
1294 | unsigned long p : 1; /* RO */ | ||
1295 | unsigned long rsvd_14 : 1; /* */ | ||
1296 | unsigned long t : 1; /* RO */ | ||
1297 | unsigned long m : 1; /* RW */ | ||
1298 | unsigned long rsvd_17_31: 15; /* */ | ||
1299 | unsigned long apic_id : 32; /* RW */ | ||
1300 | } s; | ||
1301 | }; | ||
1302 | |||
1303 | /* ========================================================================= */ | ||
1304 | /* UVH_RTC3_INT_CONFIG */ | ||
1305 | /* ========================================================================= */ | ||
1306 | #define UVH_RTC3_INT_CONFIG 0x61640UL | ||
1307 | |||
1308 | #define UVH_RTC3_INT_CONFIG_VECTOR_SHFT 0 | ||
1309 | #define UVH_RTC3_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL | ||
1310 | #define UVH_RTC3_INT_CONFIG_DM_SHFT 8 | ||
1311 | #define UVH_RTC3_INT_CONFIG_DM_MASK 0x0000000000000700UL | ||
1312 | #define UVH_RTC3_INT_CONFIG_DESTMODE_SHFT 11 | ||
1313 | #define UVH_RTC3_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL | ||
1314 | #define UVH_RTC3_INT_CONFIG_STATUS_SHFT 12 | ||
1315 | #define UVH_RTC3_INT_CONFIG_STATUS_MASK 0x0000000000001000UL | ||
1316 | #define UVH_RTC3_INT_CONFIG_P_SHFT 13 | ||
1317 | #define UVH_RTC3_INT_CONFIG_P_MASK 0x0000000000002000UL | ||
1318 | #define UVH_RTC3_INT_CONFIG_T_SHFT 15 | ||
1319 | #define UVH_RTC3_INT_CONFIG_T_MASK 0x0000000000008000UL | ||
1320 | #define UVH_RTC3_INT_CONFIG_M_SHFT 16 | ||
1321 | #define UVH_RTC3_INT_CONFIG_M_MASK 0x0000000000010000UL | ||
1322 | #define UVH_RTC3_INT_CONFIG_APIC_ID_SHFT 32 | ||
1323 | #define UVH_RTC3_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL | ||
1324 | |||
1325 | union uvh_rtc3_int_config_u { | ||
1326 | unsigned long v; | ||
1327 | struct uvh_rtc3_int_config_s { | ||
1328 | unsigned long vector_ : 8; /* RW */ | ||
1329 | unsigned long dm : 3; /* RW */ | ||
1330 | unsigned long destmode : 1; /* RW */ | ||
1331 | unsigned long status : 1; /* RO */ | ||
1332 | unsigned long p : 1; /* RO */ | ||
1333 | unsigned long rsvd_14 : 1; /* */ | ||
1334 | unsigned long t : 1; /* RO */ | ||
1335 | unsigned long m : 1; /* RW */ | ||
1336 | unsigned long rsvd_17_31: 15; /* */ | ||
1337 | unsigned long apic_id : 32; /* RW */ | ||
1338 | } s; | ||
1339 | }; | ||
1340 | |||
1341 | /* ========================================================================= */ | ||
1342 | /* UVH_RTC_INC_RATIO */ | ||
1343 | /* ========================================================================= */ | ||
1344 | #define UVH_RTC_INC_RATIO 0x350000UL | ||
1345 | |||
1346 | #define UVH_RTC_INC_RATIO_FRACTION_SHFT 0 | ||
1347 | #define UVH_RTC_INC_RATIO_FRACTION_MASK 0x00000000000fffffUL | ||
1348 | #define UVH_RTC_INC_RATIO_RATIO_SHFT 20 | ||
1349 | #define UVH_RTC_INC_RATIO_RATIO_MASK 0x0000000000700000UL | ||
1350 | |||
1351 | union uvh_rtc_inc_ratio_u { | ||
1352 | unsigned long v; | ||
1353 | struct uvh_rtc_inc_ratio_s { | ||
1354 | unsigned long fraction : 20; /* RW */ | ||
1355 | unsigned long ratio : 3; /* RW */ | ||
1356 | unsigned long rsvd_23_63: 41; /* */ | ||
1357 | } s; | ||
1358 | }; | ||
1359 | |||
1360 | /* ========================================================================= */ | ||
1361 | /* UVH_SI_ADDR_MAP_CONFIG */ | 991 | /* UVH_SI_ADDR_MAP_CONFIG */ |
1362 | /* ========================================================================= */ | 992 | /* ========================================================================= */ |
1363 | #define UVH_SI_ADDR_MAP_CONFIG 0xc80000UL | 993 | #define UVH_SI_ADDR_MAP_CONFIG 0xc80000UL |
diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h deleted file mode 100644 index e49ed6d2fd4e..000000000000 --- a/arch/x86/include/asm/vmware.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008, VMware, Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
12 | * NON INFRINGEMENT. See the GNU General Public License for more | ||
13 | * details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | * | ||
19 | */ | ||
20 | #ifndef ASM_X86__VMWARE_H | ||
21 | #define ASM_X86__VMWARE_H | ||
22 | |||
23 | extern void vmware_platform_setup(void); | ||
24 | extern int vmware_platform(void); | ||
25 | extern void vmware_set_feature_bits(struct cpuinfo_x86 *c); | ||
26 | |||
27 | #endif | ||
diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h index ddc04ccad03b..2c4390cae228 100644 --- a/arch/x86/include/asm/xsave.h +++ b/arch/x86/include/asm/xsave.h | |||
@@ -37,8 +37,9 @@ extern int check_for_xstate(struct i387_fxsave_struct __user *buf, | |||
37 | void __user *fpstate, | 37 | void __user *fpstate, |
38 | struct _fpx_sw_bytes *sw); | 38 | struct _fpx_sw_bytes *sw); |
39 | 39 | ||
40 | static inline int xrstor_checking(struct xsave_struct *fx) | 40 | static inline int fpu_xrstor_checking(struct fpu *fpu) |
41 | { | 41 | { |
42 | struct xsave_struct *fx = &fpu->state->xsave; | ||
42 | int err; | 43 | int err; |
43 | 44 | ||
44 | asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" | 45 | asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" |
@@ -110,12 +111,12 @@ static inline void xrstor_state(struct xsave_struct *fx, u64 mask) | |||
110 | : "memory"); | 111 | : "memory"); |
111 | } | 112 | } |
112 | 113 | ||
113 | static inline void xsave(struct task_struct *tsk) | 114 | static inline void fpu_xsave(struct fpu *fpu) |
114 | { | 115 | { |
115 | /* This, however, we can work around by forcing the compiler to select | 116 | /* This, however, we can work around by forcing the compiler to select |
116 | an addressing mode that doesn't require extended registers. */ | 117 | an addressing mode that doesn't require extended registers. */ |
117 | __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27" | 118 | __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27" |
118 | : : "D" (&(tsk->thread.xstate->xsave)), | 119 | : : "D" (&(fpu->state->xsave)), |
119 | "a" (-1), "d"(-1) : "memory"); | 120 | "a" (-1), "d"(-1) : "memory"); |
120 | } | 121 | } |
121 | #endif | 122 | #endif |
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 4c58352209e0..e77b22083721 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -47,8 +47,6 @@ obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o | |||
47 | obj-y += process.o | 47 | obj-y += process.o |
48 | obj-y += i387.o xsave.o | 48 | obj-y += i387.o xsave.o |
49 | obj-y += ptrace.o | 49 | obj-y += ptrace.o |
50 | obj-$(CONFIG_X86_DS) += ds.o | ||
51 | obj-$(CONFIG_X86_DS_SELFTEST) += ds_selftest.o | ||
52 | obj-$(CONFIG_X86_32) += tls.o | 50 | obj-$(CONFIG_X86_32) += tls.o |
53 | obj-$(CONFIG_IA32_EMULATION) += tls.o | 51 | obj-$(CONFIG_IA32_EMULATION) += tls.o |
54 | obj-y += step.o | 52 | obj-y += step.o |
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index cd40aba6aa95..9a5ed58f09dc 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c | |||
@@ -94,6 +94,53 @@ enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC; | |||
94 | 94 | ||
95 | 95 | ||
96 | /* | 96 | /* |
97 | * ISA irqs by default are the first 16 gsis but can be | ||
98 | * any gsi as specified by an interrupt source override. | ||
99 | */ | ||
100 | static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = { | ||
101 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 | ||
102 | }; | ||
103 | |||
104 | static unsigned int gsi_to_irq(unsigned int gsi) | ||
105 | { | ||
106 | unsigned int irq = gsi + NR_IRQS_LEGACY; | ||
107 | unsigned int i; | ||
108 | |||
109 | for (i = 0; i < NR_IRQS_LEGACY; i++) { | ||
110 | if (isa_irq_to_gsi[i] == gsi) { | ||
111 | return i; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /* Provide an identity mapping of gsi == irq | ||
116 | * except on truly weird platforms that have | ||
117 | * non isa irqs in the first 16 gsis. | ||
118 | */ | ||
119 | if (gsi >= NR_IRQS_LEGACY) | ||
120 | irq = gsi; | ||
121 | else | ||
122 | irq = gsi_end + 1 + gsi; | ||
123 | |||
124 | return irq; | ||
125 | } | ||
126 | |||
127 | static u32 irq_to_gsi(int irq) | ||
128 | { | ||
129 | unsigned int gsi; | ||
130 | |||
131 | if (irq < NR_IRQS_LEGACY) | ||
132 | gsi = isa_irq_to_gsi[irq]; | ||
133 | else if (irq <= gsi_end) | ||
134 | gsi = irq; | ||
135 | else if (irq <= (gsi_end + NR_IRQS_LEGACY)) | ||
136 | gsi = irq - gsi_end; | ||
137 | else | ||
138 | gsi = 0xffffffff; | ||
139 | |||
140 | return gsi; | ||
141 | } | ||
142 | |||
143 | /* | ||
97 | * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END, | 144 | * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END, |
98 | * to map the target physical address. The problem is that set_fixmap() | 145 | * to map the target physical address. The problem is that set_fixmap() |
99 | * provides a single page, and it is possible that the page is not | 146 | * provides a single page, and it is possible that the page is not |
@@ -313,7 +360,7 @@ acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end) | |||
313 | /* | 360 | /* |
314 | * Parse Interrupt Source Override for the ACPI SCI | 361 | * Parse Interrupt Source Override for the ACPI SCI |
315 | */ | 362 | */ |
316 | static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger) | 363 | static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi) |
317 | { | 364 | { |
318 | if (trigger == 0) /* compatible SCI trigger is level */ | 365 | if (trigger == 0) /* compatible SCI trigger is level */ |
319 | trigger = 3; | 366 | trigger = 3; |
@@ -333,7 +380,7 @@ static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger) | |||
333 | * If GSI is < 16, this will update its flags, | 380 | * If GSI is < 16, this will update its flags, |
334 | * else it will create a new mp_irqs[] entry. | 381 | * else it will create a new mp_irqs[] entry. |
335 | */ | 382 | */ |
336 | mp_override_legacy_irq(gsi, polarity, trigger, gsi); | 383 | mp_override_legacy_irq(bus_irq, polarity, trigger, gsi); |
337 | 384 | ||
338 | /* | 385 | /* |
339 | * stash over-ride to indicate we've been here | 386 | * stash over-ride to indicate we've been here |
@@ -357,9 +404,10 @@ acpi_parse_int_src_ovr(struct acpi_subtable_header * header, | |||
357 | acpi_table_print_madt_entry(header); | 404 | acpi_table_print_madt_entry(header); |
358 | 405 | ||
359 | if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) { | 406 | if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) { |
360 | acpi_sci_ioapic_setup(intsrc->global_irq, | 407 | acpi_sci_ioapic_setup(intsrc->source_irq, |
361 | intsrc->inti_flags & ACPI_MADT_POLARITY_MASK, | 408 | intsrc->inti_flags & ACPI_MADT_POLARITY_MASK, |
362 | (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2); | 409 | (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2, |
410 | intsrc->global_irq); | ||
363 | return 0; | 411 | return 0; |
364 | } | 412 | } |
365 | 413 | ||
@@ -448,7 +496,7 @@ void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger) | |||
448 | 496 | ||
449 | int acpi_gsi_to_irq(u32 gsi, unsigned int *irq) | 497 | int acpi_gsi_to_irq(u32 gsi, unsigned int *irq) |
450 | { | 498 | { |
451 | *irq = gsi; | 499 | *irq = gsi_to_irq(gsi); |
452 | 500 | ||
453 | #ifdef CONFIG_X86_IO_APIC | 501 | #ifdef CONFIG_X86_IO_APIC |
454 | if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) | 502 | if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) |
@@ -458,6 +506,14 @@ int acpi_gsi_to_irq(u32 gsi, unsigned int *irq) | |||
458 | return 0; | 506 | return 0; |
459 | } | 507 | } |
460 | 508 | ||
509 | int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi) | ||
510 | { | ||
511 | if (isa_irq >= 16) | ||
512 | return -1; | ||
513 | *gsi = irq_to_gsi(isa_irq); | ||
514 | return 0; | ||
515 | } | ||
516 | |||
461 | /* | 517 | /* |
462 | * success: return IRQ number (>=0) | 518 | * success: return IRQ number (>=0) |
463 | * failure: return < 0 | 519 | * failure: return < 0 |
@@ -482,7 +538,7 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity) | |||
482 | plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity); | 538 | plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity); |
483 | } | 539 | } |
484 | #endif | 540 | #endif |
485 | irq = plat_gsi; | 541 | irq = gsi_to_irq(plat_gsi); |
486 | 542 | ||
487 | return irq; | 543 | return irq; |
488 | } | 544 | } |
@@ -867,29 +923,6 @@ static int __init acpi_parse_madt_lapic_entries(void) | |||
867 | extern int es7000_plat; | 923 | extern int es7000_plat; |
868 | #endif | 924 | #endif |
869 | 925 | ||
870 | int __init acpi_probe_gsi(void) | ||
871 | { | ||
872 | int idx; | ||
873 | int gsi; | ||
874 | int max_gsi = 0; | ||
875 | |||
876 | if (acpi_disabled) | ||
877 | return 0; | ||
878 | |||
879 | if (!acpi_ioapic) | ||
880 | return 0; | ||
881 | |||
882 | max_gsi = 0; | ||
883 | for (idx = 0; idx < nr_ioapics; idx++) { | ||
884 | gsi = mp_gsi_routing[idx].gsi_end; | ||
885 | |||
886 | if (gsi > max_gsi) | ||
887 | max_gsi = gsi; | ||
888 | } | ||
889 | |||
890 | return max_gsi + 1; | ||
891 | } | ||
892 | |||
893 | static void assign_to_mp_irq(struct mpc_intsrc *m, | 926 | static void assign_to_mp_irq(struct mpc_intsrc *m, |
894 | struct mpc_intsrc *mp_irq) | 927 | struct mpc_intsrc *mp_irq) |
895 | { | 928 | { |
@@ -947,13 +980,13 @@ void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi) | |||
947 | mp_irq.dstirq = pin; /* INTIN# */ | 980 | mp_irq.dstirq = pin; /* INTIN# */ |
948 | 981 | ||
949 | save_mp_irq(&mp_irq); | 982 | save_mp_irq(&mp_irq); |
983 | |||
984 | isa_irq_to_gsi[bus_irq] = gsi; | ||
950 | } | 985 | } |
951 | 986 | ||
952 | void __init mp_config_acpi_legacy_irqs(void) | 987 | void __init mp_config_acpi_legacy_irqs(void) |
953 | { | 988 | { |
954 | int i; | 989 | int i; |
955 | int ioapic; | ||
956 | unsigned int dstapic; | ||
957 | struct mpc_intsrc mp_irq; | 990 | struct mpc_intsrc mp_irq; |
958 | 991 | ||
959 | #if defined (CONFIG_MCA) || defined (CONFIG_EISA) | 992 | #if defined (CONFIG_MCA) || defined (CONFIG_EISA) |
@@ -974,19 +1007,27 @@ void __init mp_config_acpi_legacy_irqs(void) | |||
974 | #endif | 1007 | #endif |
975 | 1008 | ||
976 | /* | 1009 | /* |
977 | * Locate the IOAPIC that manages the ISA IRQs (0-15). | ||
978 | */ | ||
979 | ioapic = mp_find_ioapic(0); | ||
980 | if (ioapic < 0) | ||
981 | return; | ||
982 | dstapic = mp_ioapics[ioapic].apicid; | ||
983 | |||
984 | /* | ||
985 | * Use the default configuration for the IRQs 0-15. Unless | 1010 | * Use the default configuration for the IRQs 0-15. Unless |
986 | * overridden by (MADT) interrupt source override entries. | 1011 | * overridden by (MADT) interrupt source override entries. |
987 | */ | 1012 | */ |
988 | for (i = 0; i < 16; i++) { | 1013 | for (i = 0; i < 16; i++) { |
1014 | int ioapic, pin; | ||
1015 | unsigned int dstapic; | ||
989 | int idx; | 1016 | int idx; |
1017 | u32 gsi; | ||
1018 | |||
1019 | /* Locate the gsi that irq i maps to. */ | ||
1020 | if (acpi_isa_irq_to_gsi(i, &gsi)) | ||
1021 | continue; | ||
1022 | |||
1023 | /* | ||
1024 | * Locate the IOAPIC that manages the ISA IRQ. | ||
1025 | */ | ||
1026 | ioapic = mp_find_ioapic(gsi); | ||
1027 | if (ioapic < 0) | ||
1028 | continue; | ||
1029 | pin = mp_find_ioapic_pin(ioapic, gsi); | ||
1030 | dstapic = mp_ioapics[ioapic].apicid; | ||
990 | 1031 | ||
991 | for (idx = 0; idx < mp_irq_entries; idx++) { | 1032 | for (idx = 0; idx < mp_irq_entries; idx++) { |
992 | struct mpc_intsrc *irq = mp_irqs + idx; | 1033 | struct mpc_intsrc *irq = mp_irqs + idx; |
@@ -996,7 +1037,7 @@ void __init mp_config_acpi_legacy_irqs(void) | |||
996 | break; | 1037 | break; |
997 | 1038 | ||
998 | /* Do we already have a mapping for this IOAPIC pin */ | 1039 | /* Do we already have a mapping for this IOAPIC pin */ |
999 | if (irq->dstapic == dstapic && irq->dstirq == i) | 1040 | if (irq->dstapic == dstapic && irq->dstirq == pin) |
1000 | break; | 1041 | break; |
1001 | } | 1042 | } |
1002 | 1043 | ||
@@ -1011,7 +1052,7 @@ void __init mp_config_acpi_legacy_irqs(void) | |||
1011 | mp_irq.dstapic = dstapic; | 1052 | mp_irq.dstapic = dstapic; |
1012 | mp_irq.irqtype = mp_INT; | 1053 | mp_irq.irqtype = mp_INT; |
1013 | mp_irq.srcbusirq = i; /* Identity mapped */ | 1054 | mp_irq.srcbusirq = i; /* Identity mapped */ |
1014 | mp_irq.dstirq = i; | 1055 | mp_irq.dstirq = pin; |
1015 | 1056 | ||
1016 | save_mp_irq(&mp_irq); | 1057 | save_mp_irq(&mp_irq); |
1017 | } | 1058 | } |
@@ -1076,11 +1117,6 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity) | |||
1076 | 1117 | ||
1077 | ioapic_pin = mp_find_ioapic_pin(ioapic, gsi); | 1118 | ioapic_pin = mp_find_ioapic_pin(ioapic, gsi); |
1078 | 1119 | ||
1079 | #ifdef CONFIG_X86_32 | ||
1080 | if (ioapic_renumber_irq) | ||
1081 | gsi = ioapic_renumber_irq(ioapic, gsi); | ||
1082 | #endif | ||
1083 | |||
1084 | if (ioapic_pin > MP_MAX_IOAPIC_PIN) { | 1120 | if (ioapic_pin > MP_MAX_IOAPIC_PIN) { |
1085 | printk(KERN_ERR "Invalid reference to IOAPIC pin " | 1121 | printk(KERN_ERR "Invalid reference to IOAPIC pin " |
1086 | "%d-%d\n", mp_ioapics[ioapic].apicid, | 1122 | "%d-%d\n", mp_ioapics[ioapic].apicid, |
@@ -1094,7 +1130,7 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity) | |||
1094 | set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin, | 1130 | set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin, |
1095 | trigger == ACPI_EDGE_SENSITIVE ? 0 : 1, | 1131 | trigger == ACPI_EDGE_SENSITIVE ? 0 : 1, |
1096 | polarity == ACPI_ACTIVE_HIGH ? 0 : 1); | 1132 | polarity == ACPI_ACTIVE_HIGH ? 0 : 1); |
1097 | io_apic_set_pci_routing(dev, gsi, &irq_attr); | 1133 | io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr); |
1098 | 1134 | ||
1099 | return gsi; | 1135 | return gsi; |
1100 | } | 1136 | } |
@@ -1154,7 +1190,8 @@ static int __init acpi_parse_madt_ioapic_entries(void) | |||
1154 | * pretend we got one so we can set the SCI flags. | 1190 | * pretend we got one so we can set the SCI flags. |
1155 | */ | 1191 | */ |
1156 | if (!acpi_sci_override_gsi) | 1192 | if (!acpi_sci_override_gsi) |
1157 | acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0); | 1193 | acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0, |
1194 | acpi_gbl_FADT.sci_interrupt); | ||
1158 | 1195 | ||
1159 | /* Fill in identity legacy mappings where no override */ | 1196 | /* Fill in identity legacy mappings where no override */ |
1160 | mp_config_acpi_legacy_irqs(); | 1197 | mp_config_acpi_legacy_irqs(); |
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 1a160d5d44d0..70237732a6c7 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c | |||
@@ -194,7 +194,7 @@ static void __init_or_module add_nops(void *insns, unsigned int len) | |||
194 | } | 194 | } |
195 | 195 | ||
196 | extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; | 196 | extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; |
197 | extern u8 *__smp_locks[], *__smp_locks_end[]; | 197 | extern s32 __smp_locks[], __smp_locks_end[]; |
198 | static void *text_poke_early(void *addr, const void *opcode, size_t len); | 198 | static void *text_poke_early(void *addr, const void *opcode, size_t len); |
199 | 199 | ||
200 | /* Replace instructions with better alternatives for this CPU type. | 200 | /* Replace instructions with better alternatives for this CPU type. |
@@ -235,37 +235,41 @@ void __init_or_module apply_alternatives(struct alt_instr *start, | |||
235 | 235 | ||
236 | #ifdef CONFIG_SMP | 236 | #ifdef CONFIG_SMP |
237 | 237 | ||
238 | static void alternatives_smp_lock(u8 **start, u8 **end, u8 *text, u8 *text_end) | 238 | static void alternatives_smp_lock(const s32 *start, const s32 *end, |
239 | u8 *text, u8 *text_end) | ||
239 | { | 240 | { |
240 | u8 **ptr; | 241 | const s32 *poff; |
241 | 242 | ||
242 | mutex_lock(&text_mutex); | 243 | mutex_lock(&text_mutex); |
243 | for (ptr = start; ptr < end; ptr++) { | 244 | for (poff = start; poff < end; poff++) { |
244 | if (*ptr < text) | 245 | u8 *ptr = (u8 *)poff + *poff; |
245 | continue; | 246 | |
246 | if (*ptr > text_end) | 247 | if (!*poff || ptr < text || ptr >= text_end) |
247 | continue; | 248 | continue; |
248 | /* turn DS segment override prefix into lock prefix */ | 249 | /* turn DS segment override prefix into lock prefix */ |
249 | text_poke(*ptr, ((unsigned char []){0xf0}), 1); | 250 | if (*ptr == 0x3e) |
251 | text_poke(ptr, ((unsigned char []){0xf0}), 1); | ||
250 | }; | 252 | }; |
251 | mutex_unlock(&text_mutex); | 253 | mutex_unlock(&text_mutex); |
252 | } | 254 | } |
253 | 255 | ||
254 | static void alternatives_smp_unlock(u8 **start, u8 **end, u8 *text, u8 *text_end) | 256 | static void alternatives_smp_unlock(const s32 *start, const s32 *end, |
257 | u8 *text, u8 *text_end) | ||
255 | { | 258 | { |
256 | u8 **ptr; | 259 | const s32 *poff; |
257 | 260 | ||
258 | if (noreplace_smp) | 261 | if (noreplace_smp) |
259 | return; | 262 | return; |
260 | 263 | ||
261 | mutex_lock(&text_mutex); | 264 | mutex_lock(&text_mutex); |
262 | for (ptr = start; ptr < end; ptr++) { | 265 | for (poff = start; poff < end; poff++) { |
263 | if (*ptr < text) | 266 | u8 *ptr = (u8 *)poff + *poff; |
264 | continue; | 267 | |
265 | if (*ptr > text_end) | 268 | if (!*poff || ptr < text || ptr >= text_end) |
266 | continue; | 269 | continue; |
267 | /* turn lock prefix into DS segment override prefix */ | 270 | /* turn lock prefix into DS segment override prefix */ |
268 | text_poke(*ptr, ((unsigned char []){0x3E}), 1); | 271 | if (*ptr == 0xf0) |
272 | text_poke(ptr, ((unsigned char []){0x3E}), 1); | ||
269 | }; | 273 | }; |
270 | mutex_unlock(&text_mutex); | 274 | mutex_unlock(&text_mutex); |
271 | } | 275 | } |
@@ -276,8 +280,8 @@ struct smp_alt_module { | |||
276 | char *name; | 280 | char *name; |
277 | 281 | ||
278 | /* ptrs to lock prefixes */ | 282 | /* ptrs to lock prefixes */ |
279 | u8 **locks; | 283 | const s32 *locks; |
280 | u8 **locks_end; | 284 | const s32 *locks_end; |
281 | 285 | ||
282 | /* .text segment, needed to avoid patching init code ;) */ | 286 | /* .text segment, needed to avoid patching init code ;) */ |
283 | u8 *text; | 287 | u8 *text; |
@@ -398,16 +402,19 @@ void alternatives_smp_switch(int smp) | |||
398 | int alternatives_text_reserved(void *start, void *end) | 402 | int alternatives_text_reserved(void *start, void *end) |
399 | { | 403 | { |
400 | struct smp_alt_module *mod; | 404 | struct smp_alt_module *mod; |
401 | u8 **ptr; | 405 | const s32 *poff; |
402 | u8 *text_start = start; | 406 | u8 *text_start = start; |
403 | u8 *text_end = end; | 407 | u8 *text_end = end; |
404 | 408 | ||
405 | list_for_each_entry(mod, &smp_alt_modules, next) { | 409 | list_for_each_entry(mod, &smp_alt_modules, next) { |
406 | if (mod->text > text_end || mod->text_end < text_start) | 410 | if (mod->text > text_end || mod->text_end < text_start) |
407 | continue; | 411 | continue; |
408 | for (ptr = mod->locks; ptr < mod->locks_end; ptr++) | 412 | for (poff = mod->locks; poff < mod->locks_end; poff++) { |
409 | if (text_start <= *ptr && text_end >= *ptr) | 413 | const u8 *ptr = (const u8 *)poff + *poff; |
414 | |||
415 | if (text_start <= ptr && text_end > ptr) | ||
410 | return 1; | 416 | return 1; |
417 | } | ||
411 | } | 418 | } |
412 | 419 | ||
413 | return 0; | 420 | return 0; |
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index f854d89b7edf..fa5a1474cd18 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -731,18 +731,22 @@ static bool increase_address_space(struct protection_domain *domain, | |||
731 | 731 | ||
732 | static u64 *alloc_pte(struct protection_domain *domain, | 732 | static u64 *alloc_pte(struct protection_domain *domain, |
733 | unsigned long address, | 733 | unsigned long address, |
734 | int end_lvl, | 734 | unsigned long page_size, |
735 | u64 **pte_page, | 735 | u64 **pte_page, |
736 | gfp_t gfp) | 736 | gfp_t gfp) |
737 | { | 737 | { |
738 | int level, end_lvl; | ||
738 | u64 *pte, *page; | 739 | u64 *pte, *page; |
739 | int level; | 740 | |
741 | BUG_ON(!is_power_of_2(page_size)); | ||
740 | 742 | ||
741 | while (address > PM_LEVEL_SIZE(domain->mode)) | 743 | while (address > PM_LEVEL_SIZE(domain->mode)) |
742 | increase_address_space(domain, gfp); | 744 | increase_address_space(domain, gfp); |
743 | 745 | ||
744 | level = domain->mode - 1; | 746 | level = domain->mode - 1; |
745 | pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; | 747 | pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; |
748 | address = PAGE_SIZE_ALIGN(address, page_size); | ||
749 | end_lvl = PAGE_SIZE_LEVEL(page_size); | ||
746 | 750 | ||
747 | while (level > end_lvl) { | 751 | while (level > end_lvl) { |
748 | if (!IOMMU_PTE_PRESENT(*pte)) { | 752 | if (!IOMMU_PTE_PRESENT(*pte)) { |
@@ -752,6 +756,10 @@ static u64 *alloc_pte(struct protection_domain *domain, | |||
752 | *pte = PM_LEVEL_PDE(level, virt_to_phys(page)); | 756 | *pte = PM_LEVEL_PDE(level, virt_to_phys(page)); |
753 | } | 757 | } |
754 | 758 | ||
759 | /* No level skipping support yet */ | ||
760 | if (PM_PTE_LEVEL(*pte) != level) | ||
761 | return NULL; | ||
762 | |||
755 | level -= 1; | 763 | level -= 1; |
756 | 764 | ||
757 | pte = IOMMU_PTE_PAGE(*pte); | 765 | pte = IOMMU_PTE_PAGE(*pte); |
@@ -769,28 +777,47 @@ static u64 *alloc_pte(struct protection_domain *domain, | |||
769 | * This function checks if there is a PTE for a given dma address. If | 777 | * This function checks if there is a PTE for a given dma address. If |
770 | * there is one, it returns the pointer to it. | 778 | * there is one, it returns the pointer to it. |
771 | */ | 779 | */ |
772 | static u64 *fetch_pte(struct protection_domain *domain, | 780 | static u64 *fetch_pte(struct protection_domain *domain, unsigned long address) |
773 | unsigned long address, int map_size) | ||
774 | { | 781 | { |
775 | int level; | 782 | int level; |
776 | u64 *pte; | 783 | u64 *pte; |
777 | 784 | ||
778 | level = domain->mode - 1; | 785 | if (address > PM_LEVEL_SIZE(domain->mode)) |
779 | pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; | 786 | return NULL; |
787 | |||
788 | level = domain->mode - 1; | ||
789 | pte = &domain->pt_root[PM_LEVEL_INDEX(level, address)]; | ||
780 | 790 | ||
781 | while (level > map_size) { | 791 | while (level > 0) { |
792 | |||
793 | /* Not Present */ | ||
782 | if (!IOMMU_PTE_PRESENT(*pte)) | 794 | if (!IOMMU_PTE_PRESENT(*pte)) |
783 | return NULL; | 795 | return NULL; |
784 | 796 | ||
797 | /* Large PTE */ | ||
798 | if (PM_PTE_LEVEL(*pte) == 0x07) { | ||
799 | unsigned long pte_mask, __pte; | ||
800 | |||
801 | /* | ||
802 | * If we have a series of large PTEs, make | ||
803 | * sure to return a pointer to the first one. | ||
804 | */ | ||
805 | pte_mask = PTE_PAGE_SIZE(*pte); | ||
806 | pte_mask = ~((PAGE_SIZE_PTE_COUNT(pte_mask) << 3) - 1); | ||
807 | __pte = ((unsigned long)pte) & pte_mask; | ||
808 | |||
809 | return (u64 *)__pte; | ||
810 | } | ||
811 | |||
812 | /* No level skipping support yet */ | ||
813 | if (PM_PTE_LEVEL(*pte) != level) | ||
814 | return NULL; | ||
815 | |||
785 | level -= 1; | 816 | level -= 1; |
786 | 817 | ||
818 | /* Walk to the next level */ | ||
787 | pte = IOMMU_PTE_PAGE(*pte); | 819 | pte = IOMMU_PTE_PAGE(*pte); |
788 | pte = &pte[PM_LEVEL_INDEX(level, address)]; | 820 | pte = &pte[PM_LEVEL_INDEX(level, address)]; |
789 | |||
790 | if ((PM_PTE_LEVEL(*pte) == 0) && level != map_size) { | ||
791 | pte = NULL; | ||
792 | break; | ||
793 | } | ||
794 | } | 821 | } |
795 | 822 | ||
796 | return pte; | 823 | return pte; |
@@ -807,44 +834,84 @@ static int iommu_map_page(struct protection_domain *dom, | |||
807 | unsigned long bus_addr, | 834 | unsigned long bus_addr, |
808 | unsigned long phys_addr, | 835 | unsigned long phys_addr, |
809 | int prot, | 836 | int prot, |
810 | int map_size) | 837 | unsigned long page_size) |
811 | { | 838 | { |
812 | u64 __pte, *pte; | 839 | u64 __pte, *pte; |
813 | 840 | int i, count; | |
814 | bus_addr = PAGE_ALIGN(bus_addr); | ||
815 | phys_addr = PAGE_ALIGN(phys_addr); | ||
816 | |||
817 | BUG_ON(!PM_ALIGNED(map_size, bus_addr)); | ||
818 | BUG_ON(!PM_ALIGNED(map_size, phys_addr)); | ||
819 | 841 | ||
820 | if (!(prot & IOMMU_PROT_MASK)) | 842 | if (!(prot & IOMMU_PROT_MASK)) |
821 | return -EINVAL; | 843 | return -EINVAL; |
822 | 844 | ||
823 | pte = alloc_pte(dom, bus_addr, map_size, NULL, GFP_KERNEL); | 845 | bus_addr = PAGE_ALIGN(bus_addr); |
846 | phys_addr = PAGE_ALIGN(phys_addr); | ||
847 | count = PAGE_SIZE_PTE_COUNT(page_size); | ||
848 | pte = alloc_pte(dom, bus_addr, page_size, NULL, GFP_KERNEL); | ||
849 | |||
850 | for (i = 0; i < count; ++i) | ||
851 | if (IOMMU_PTE_PRESENT(pte[i])) | ||
852 | return -EBUSY; | ||
824 | 853 | ||
825 | if (IOMMU_PTE_PRESENT(*pte)) | 854 | if (page_size > PAGE_SIZE) { |
826 | return -EBUSY; | 855 | __pte = PAGE_SIZE_PTE(phys_addr, page_size); |
856 | __pte |= PM_LEVEL_ENC(7) | IOMMU_PTE_P | IOMMU_PTE_FC; | ||
857 | } else | ||
858 | __pte = phys_addr | IOMMU_PTE_P | IOMMU_PTE_FC; | ||
827 | 859 | ||
828 | __pte = phys_addr | IOMMU_PTE_P; | ||
829 | if (prot & IOMMU_PROT_IR) | 860 | if (prot & IOMMU_PROT_IR) |
830 | __pte |= IOMMU_PTE_IR; | 861 | __pte |= IOMMU_PTE_IR; |
831 | if (prot & IOMMU_PROT_IW) | 862 | if (prot & IOMMU_PROT_IW) |
832 | __pte |= IOMMU_PTE_IW; | 863 | __pte |= IOMMU_PTE_IW; |
833 | 864 | ||
834 | *pte = __pte; | 865 | for (i = 0; i < count; ++i) |
866 | pte[i] = __pte; | ||
835 | 867 | ||
836 | update_domain(dom); | 868 | update_domain(dom); |
837 | 869 | ||
838 | return 0; | 870 | return 0; |
839 | } | 871 | } |
840 | 872 | ||
841 | static void iommu_unmap_page(struct protection_domain *dom, | 873 | static unsigned long iommu_unmap_page(struct protection_domain *dom, |
842 | unsigned long bus_addr, int map_size) | 874 | unsigned long bus_addr, |
875 | unsigned long page_size) | ||
843 | { | 876 | { |
844 | u64 *pte = fetch_pte(dom, bus_addr, map_size); | 877 | unsigned long long unmap_size, unmapped; |
878 | u64 *pte; | ||
879 | |||
880 | BUG_ON(!is_power_of_2(page_size)); | ||
881 | |||
882 | unmapped = 0; | ||
845 | 883 | ||
846 | if (pte) | 884 | while (unmapped < page_size) { |
847 | *pte = 0; | 885 | |
886 | pte = fetch_pte(dom, bus_addr); | ||
887 | |||
888 | if (!pte) { | ||
889 | /* | ||
890 | * No PTE for this address | ||
891 | * move forward in 4kb steps | ||
892 | */ | ||
893 | unmap_size = PAGE_SIZE; | ||
894 | } else if (PM_PTE_LEVEL(*pte) == 0) { | ||
895 | /* 4kb PTE found for this address */ | ||
896 | unmap_size = PAGE_SIZE; | ||
897 | *pte = 0ULL; | ||
898 | } else { | ||
899 | int count, i; | ||
900 | |||
901 | /* Large PTE found which maps this address */ | ||
902 | unmap_size = PTE_PAGE_SIZE(*pte); | ||
903 | count = PAGE_SIZE_PTE_COUNT(unmap_size); | ||
904 | for (i = 0; i < count; i++) | ||
905 | pte[i] = 0ULL; | ||
906 | } | ||
907 | |||
908 | bus_addr = (bus_addr & ~(unmap_size - 1)) + unmap_size; | ||
909 | unmapped += unmap_size; | ||
910 | } | ||
911 | |||
912 | BUG_ON(!is_power_of_2(unmapped)); | ||
913 | |||
914 | return unmapped; | ||
848 | } | 915 | } |
849 | 916 | ||
850 | /* | 917 | /* |
@@ -878,7 +945,7 @@ static int dma_ops_unity_map(struct dma_ops_domain *dma_dom, | |||
878 | for (addr = e->address_start; addr < e->address_end; | 945 | for (addr = e->address_start; addr < e->address_end; |
879 | addr += PAGE_SIZE) { | 946 | addr += PAGE_SIZE) { |
880 | ret = iommu_map_page(&dma_dom->domain, addr, addr, e->prot, | 947 | ret = iommu_map_page(&dma_dom->domain, addr, addr, e->prot, |
881 | PM_MAP_4k); | 948 | PAGE_SIZE); |
882 | if (ret) | 949 | if (ret) |
883 | return ret; | 950 | return ret; |
884 | /* | 951 | /* |
@@ -1006,7 +1073,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom, | |||
1006 | u64 *pte, *pte_page; | 1073 | u64 *pte, *pte_page; |
1007 | 1074 | ||
1008 | for (i = 0; i < num_ptes; ++i) { | 1075 | for (i = 0; i < num_ptes; ++i) { |
1009 | pte = alloc_pte(&dma_dom->domain, address, PM_MAP_4k, | 1076 | pte = alloc_pte(&dma_dom->domain, address, PAGE_SIZE, |
1010 | &pte_page, gfp); | 1077 | &pte_page, gfp); |
1011 | if (!pte) | 1078 | if (!pte) |
1012 | goto out_free; | 1079 | goto out_free; |
@@ -1042,7 +1109,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom, | |||
1042 | for (i = dma_dom->aperture[index]->offset; | 1109 | for (i = dma_dom->aperture[index]->offset; |
1043 | i < dma_dom->aperture_size; | 1110 | i < dma_dom->aperture_size; |
1044 | i += PAGE_SIZE) { | 1111 | i += PAGE_SIZE) { |
1045 | u64 *pte = fetch_pte(&dma_dom->domain, i, PM_MAP_4k); | 1112 | u64 *pte = fetch_pte(&dma_dom->domain, i); |
1046 | if (!pte || !IOMMU_PTE_PRESENT(*pte)) | 1113 | if (!pte || !IOMMU_PTE_PRESENT(*pte)) |
1047 | continue; | 1114 | continue; |
1048 | 1115 | ||
@@ -1712,7 +1779,7 @@ static u64* dma_ops_get_pte(struct dma_ops_domain *dom, | |||
1712 | 1779 | ||
1713 | pte = aperture->pte_pages[APERTURE_PAGE_INDEX(address)]; | 1780 | pte = aperture->pte_pages[APERTURE_PAGE_INDEX(address)]; |
1714 | if (!pte) { | 1781 | if (!pte) { |
1715 | pte = alloc_pte(&dom->domain, address, PM_MAP_4k, &pte_page, | 1782 | pte = alloc_pte(&dom->domain, address, PAGE_SIZE, &pte_page, |
1716 | GFP_ATOMIC); | 1783 | GFP_ATOMIC); |
1717 | aperture->pte_pages[APERTURE_PAGE_INDEX(address)] = pte_page; | 1784 | aperture->pte_pages[APERTURE_PAGE_INDEX(address)] = pte_page; |
1718 | } else | 1785 | } else |
@@ -2439,12 +2506,11 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, | |||
2439 | return ret; | 2506 | return ret; |
2440 | } | 2507 | } |
2441 | 2508 | ||
2442 | static int amd_iommu_map_range(struct iommu_domain *dom, | 2509 | static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, |
2443 | unsigned long iova, phys_addr_t paddr, | 2510 | phys_addr_t paddr, int gfp_order, int iommu_prot) |
2444 | size_t size, int iommu_prot) | ||
2445 | { | 2511 | { |
2512 | unsigned long page_size = 0x1000UL << gfp_order; | ||
2446 | struct protection_domain *domain = dom->priv; | 2513 | struct protection_domain *domain = dom->priv; |
2447 | unsigned long i, npages = iommu_num_pages(paddr, size, PAGE_SIZE); | ||
2448 | int prot = 0; | 2514 | int prot = 0; |
2449 | int ret; | 2515 | int ret; |
2450 | 2516 | ||
@@ -2453,61 +2519,50 @@ static int amd_iommu_map_range(struct iommu_domain *dom, | |||
2453 | if (iommu_prot & IOMMU_WRITE) | 2519 | if (iommu_prot & IOMMU_WRITE) |
2454 | prot |= IOMMU_PROT_IW; | 2520 | prot |= IOMMU_PROT_IW; |
2455 | 2521 | ||
2456 | iova &= PAGE_MASK; | ||
2457 | paddr &= PAGE_MASK; | ||
2458 | |||
2459 | mutex_lock(&domain->api_lock); | 2522 | mutex_lock(&domain->api_lock); |
2460 | 2523 | ret = iommu_map_page(domain, iova, paddr, prot, page_size); | |
2461 | for (i = 0; i < npages; ++i) { | ||
2462 | ret = iommu_map_page(domain, iova, paddr, prot, PM_MAP_4k); | ||
2463 | if (ret) | ||
2464 | return ret; | ||
2465 | |||
2466 | iova += PAGE_SIZE; | ||
2467 | paddr += PAGE_SIZE; | ||
2468 | } | ||
2469 | |||
2470 | mutex_unlock(&domain->api_lock); | 2524 | mutex_unlock(&domain->api_lock); |
2471 | 2525 | ||
2472 | return 0; | 2526 | return ret; |
2473 | } | 2527 | } |
2474 | 2528 | ||
2475 | static void amd_iommu_unmap_range(struct iommu_domain *dom, | 2529 | static int amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, |
2476 | unsigned long iova, size_t size) | 2530 | int gfp_order) |
2477 | { | 2531 | { |
2478 | |||
2479 | struct protection_domain *domain = dom->priv; | 2532 | struct protection_domain *domain = dom->priv; |
2480 | unsigned long i, npages = iommu_num_pages(iova, size, PAGE_SIZE); | 2533 | unsigned long page_size, unmap_size; |
2481 | 2534 | ||
2482 | iova &= PAGE_MASK; | 2535 | page_size = 0x1000UL << gfp_order; |
2483 | 2536 | ||
2484 | mutex_lock(&domain->api_lock); | 2537 | mutex_lock(&domain->api_lock); |
2485 | 2538 | unmap_size = iommu_unmap_page(domain, iova, page_size); | |
2486 | for (i = 0; i < npages; ++i) { | 2539 | mutex_unlock(&domain->api_lock); |
2487 | iommu_unmap_page(domain, iova, PM_MAP_4k); | ||
2488 | iova += PAGE_SIZE; | ||
2489 | } | ||
2490 | 2540 | ||
2491 | iommu_flush_tlb_pde(domain); | 2541 | iommu_flush_tlb_pde(domain); |
2492 | 2542 | ||
2493 | mutex_unlock(&domain->api_lock); | 2543 | return get_order(unmap_size); |
2494 | } | 2544 | } |
2495 | 2545 | ||
2496 | static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom, | 2546 | static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom, |
2497 | unsigned long iova) | 2547 | unsigned long iova) |
2498 | { | 2548 | { |
2499 | struct protection_domain *domain = dom->priv; | 2549 | struct protection_domain *domain = dom->priv; |
2500 | unsigned long offset = iova & ~PAGE_MASK; | 2550 | unsigned long offset_mask; |
2501 | phys_addr_t paddr; | 2551 | phys_addr_t paddr; |
2502 | u64 *pte; | 2552 | u64 *pte, __pte; |
2503 | 2553 | ||
2504 | pte = fetch_pte(domain, iova, PM_MAP_4k); | 2554 | pte = fetch_pte(domain, iova); |
2505 | 2555 | ||
2506 | if (!pte || !IOMMU_PTE_PRESENT(*pte)) | 2556 | if (!pte || !IOMMU_PTE_PRESENT(*pte)) |
2507 | return 0; | 2557 | return 0; |
2508 | 2558 | ||
2509 | paddr = *pte & IOMMU_PAGE_MASK; | 2559 | if (PM_PTE_LEVEL(*pte) == 0) |
2510 | paddr |= offset; | 2560 | offset_mask = PAGE_SIZE - 1; |
2561 | else | ||
2562 | offset_mask = PTE_PAGE_SIZE(*pte) - 1; | ||
2563 | |||
2564 | __pte = *pte & PM_ADDR_MASK; | ||
2565 | paddr = (__pte & ~offset_mask) | (iova & offset_mask); | ||
2511 | 2566 | ||
2512 | return paddr; | 2567 | return paddr; |
2513 | } | 2568 | } |
@@ -2523,8 +2578,8 @@ static struct iommu_ops amd_iommu_ops = { | |||
2523 | .domain_destroy = amd_iommu_domain_destroy, | 2578 | .domain_destroy = amd_iommu_domain_destroy, |
2524 | .attach_dev = amd_iommu_attach_device, | 2579 | .attach_dev = amd_iommu_attach_device, |
2525 | .detach_dev = amd_iommu_detach_device, | 2580 | .detach_dev = amd_iommu_detach_device, |
2526 | .map = amd_iommu_map_range, | 2581 | .map = amd_iommu_map, |
2527 | .unmap = amd_iommu_unmap_range, | 2582 | .unmap = amd_iommu_unmap, |
2528 | .iova_to_phys = amd_iommu_iova_to_phys, | 2583 | .iova_to_phys = amd_iommu_iova_to_phys, |
2529 | .domain_has_cap = amd_iommu_domain_has_cap, | 2584 | .domain_has_cap = amd_iommu_domain_has_cap, |
2530 | }; | 2585 | }; |
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c index 6360abf993d4..3bacb4d0844c 100644 --- a/arch/x86/kernel/amd_iommu_init.c +++ b/arch/x86/kernel/amd_iommu_init.c | |||
@@ -120,6 +120,7 @@ struct ivmd_header { | |||
120 | bool amd_iommu_dump; | 120 | bool amd_iommu_dump; |
121 | 121 | ||
122 | static int __initdata amd_iommu_detected; | 122 | static int __initdata amd_iommu_detected; |
123 | static bool __initdata amd_iommu_disabled; | ||
123 | 124 | ||
124 | u16 amd_iommu_last_bdf; /* largest PCI device id we have | 125 | u16 amd_iommu_last_bdf; /* largest PCI device id we have |
125 | to handle */ | 126 | to handle */ |
@@ -1372,6 +1373,9 @@ void __init amd_iommu_detect(void) | |||
1372 | if (no_iommu || (iommu_detected && !gart_iommu_aperture)) | 1373 | if (no_iommu || (iommu_detected && !gart_iommu_aperture)) |
1373 | return; | 1374 | return; |
1374 | 1375 | ||
1376 | if (amd_iommu_disabled) | ||
1377 | return; | ||
1378 | |||
1375 | if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) { | 1379 | if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) { |
1376 | iommu_detected = 1; | 1380 | iommu_detected = 1; |
1377 | amd_iommu_detected = 1; | 1381 | amd_iommu_detected = 1; |
@@ -1401,6 +1405,8 @@ static int __init parse_amd_iommu_options(char *str) | |||
1401 | for (; *str; ++str) { | 1405 | for (; *str; ++str) { |
1402 | if (strncmp(str, "fullflush", 9) == 0) | 1406 | if (strncmp(str, "fullflush", 9) == 0) |
1403 | amd_iommu_unmap_flush = true; | 1407 | amd_iommu_unmap_flush = true; |
1408 | if (strncmp(str, "off", 3) == 0) | ||
1409 | amd_iommu_disabled = true; | ||
1404 | } | 1410 | } |
1405 | 1411 | ||
1406 | return 1; | 1412 | return 1; |
diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c index 03ba1b895f5e..425e53a87feb 100644 --- a/arch/x86/kernel/apic/es7000_32.c +++ b/arch/x86/kernel/apic/es7000_32.c | |||
@@ -131,24 +131,6 @@ int es7000_plat; | |||
131 | 131 | ||
132 | static unsigned int base; | 132 | static unsigned int base; |
133 | 133 | ||
134 | static int | ||
135 | es7000_rename_gsi(int ioapic, int gsi) | ||
136 | { | ||
137 | if (es7000_plat == ES7000_ZORRO) | ||
138 | return gsi; | ||
139 | |||
140 | if (!base) { | ||
141 | int i; | ||
142 | for (i = 0; i < nr_ioapics; i++) | ||
143 | base += nr_ioapic_registers[i]; | ||
144 | } | ||
145 | |||
146 | if (!ioapic && (gsi < 16)) | ||
147 | gsi += base; | ||
148 | |||
149 | return gsi; | ||
150 | } | ||
151 | |||
152 | static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip) | 134 | static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip) |
153 | { | 135 | { |
154 | unsigned long vect = 0, psaival = 0; | 136 | unsigned long vect = 0, psaival = 0; |
@@ -190,7 +172,6 @@ static void setup_unisys(void) | |||
190 | es7000_plat = ES7000_ZORRO; | 172 | es7000_plat = ES7000_ZORRO; |
191 | else | 173 | else |
192 | es7000_plat = ES7000_CLASSIC; | 174 | es7000_plat = ES7000_CLASSIC; |
193 | ioapic_renumber_irq = es7000_rename_gsi; | ||
194 | } | 175 | } |
195 | 176 | ||
196 | /* | 177 | /* |
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index eb2789c3f721..33f3563a2a52 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c | |||
@@ -89,6 +89,9 @@ int nr_ioapics; | |||
89 | /* IO APIC gsi routing info */ | 89 | /* IO APIC gsi routing info */ |
90 | struct mp_ioapic_gsi mp_gsi_routing[MAX_IO_APICS]; | 90 | struct mp_ioapic_gsi mp_gsi_routing[MAX_IO_APICS]; |
91 | 91 | ||
92 | /* The last gsi number used */ | ||
93 | u32 gsi_end; | ||
94 | |||
92 | /* MP IRQ source entries */ | 95 | /* MP IRQ source entries */ |
93 | struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES]; | 96 | struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
94 | 97 | ||
@@ -1013,10 +1016,9 @@ static inline int irq_trigger(int idx) | |||
1013 | return MPBIOS_trigger(idx); | 1016 | return MPBIOS_trigger(idx); |
1014 | } | 1017 | } |
1015 | 1018 | ||
1016 | int (*ioapic_renumber_irq)(int ioapic, int irq); | ||
1017 | static int pin_2_irq(int idx, int apic, int pin) | 1019 | static int pin_2_irq(int idx, int apic, int pin) |
1018 | { | 1020 | { |
1019 | int irq, i; | 1021 | int irq; |
1020 | int bus = mp_irqs[idx].srcbus; | 1022 | int bus = mp_irqs[idx].srcbus; |
1021 | 1023 | ||
1022 | /* | 1024 | /* |
@@ -1028,18 +1030,12 @@ static int pin_2_irq(int idx, int apic, int pin) | |||
1028 | if (test_bit(bus, mp_bus_not_pci)) { | 1030 | if (test_bit(bus, mp_bus_not_pci)) { |
1029 | irq = mp_irqs[idx].srcbusirq; | 1031 | irq = mp_irqs[idx].srcbusirq; |
1030 | } else { | 1032 | } else { |
1031 | /* | 1033 | u32 gsi = mp_gsi_routing[apic].gsi_base + pin; |
1032 | * PCI IRQs are mapped in order | 1034 | |
1033 | */ | 1035 | if (gsi >= NR_IRQS_LEGACY) |
1034 | i = irq = 0; | 1036 | irq = gsi; |
1035 | while (i < apic) | 1037 | else |
1036 | irq += nr_ioapic_registers[i++]; | 1038 | irq = gsi_end + 1 + gsi; |
1037 | irq += pin; | ||
1038 | /* | ||
1039 | * For MPS mode, so far only needed by ES7000 platform | ||
1040 | */ | ||
1041 | if (ioapic_renumber_irq) | ||
1042 | irq = ioapic_renumber_irq(apic, irq); | ||
1043 | } | 1039 | } |
1044 | 1040 | ||
1045 | #ifdef CONFIG_X86_32 | 1041 | #ifdef CONFIG_X86_32 |
@@ -1950,20 +1946,8 @@ static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; | |||
1950 | 1946 | ||
1951 | void __init enable_IO_APIC(void) | 1947 | void __init enable_IO_APIC(void) |
1952 | { | 1948 | { |
1953 | union IO_APIC_reg_01 reg_01; | ||
1954 | int i8259_apic, i8259_pin; | 1949 | int i8259_apic, i8259_pin; |
1955 | int apic; | 1950 | int apic; |
1956 | unsigned long flags; | ||
1957 | |||
1958 | /* | ||
1959 | * The number of IO-APIC IRQ registers (== #pins): | ||
1960 | */ | ||
1961 | for (apic = 0; apic < nr_ioapics; apic++) { | ||
1962 | raw_spin_lock_irqsave(&ioapic_lock, flags); | ||
1963 | reg_01.raw = io_apic_read(apic, 1); | ||
1964 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); | ||
1965 | nr_ioapic_registers[apic] = reg_01.bits.entries+1; | ||
1966 | } | ||
1967 | 1951 | ||
1968 | if (!legacy_pic->nr_legacy_irqs) | 1952 | if (!legacy_pic->nr_legacy_irqs) |
1969 | return; | 1953 | return; |
@@ -3858,27 +3842,20 @@ int __init io_apic_get_redir_entries (int ioapic) | |||
3858 | reg_01.raw = io_apic_read(ioapic, 1); | 3842 | reg_01.raw = io_apic_read(ioapic, 1); |
3859 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); | 3843 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
3860 | 3844 | ||
3861 | return reg_01.bits.entries; | 3845 | /* The register returns the maximum index redir index |
3846 | * supported, which is one less than the total number of redir | ||
3847 | * entries. | ||
3848 | */ | ||
3849 | return reg_01.bits.entries + 1; | ||
3862 | } | 3850 | } |
3863 | 3851 | ||
3864 | void __init probe_nr_irqs_gsi(void) | 3852 | void __init probe_nr_irqs_gsi(void) |
3865 | { | 3853 | { |
3866 | int nr = 0; | 3854 | int nr; |
3867 | 3855 | ||
3868 | nr = acpi_probe_gsi(); | 3856 | nr = gsi_end + 1 + NR_IRQS_LEGACY; |
3869 | if (nr > nr_irqs_gsi) { | 3857 | if (nr > nr_irqs_gsi) |
3870 | nr_irqs_gsi = nr; | 3858 | nr_irqs_gsi = nr; |
3871 | } else { | ||
3872 | /* for acpi=off or acpi is not compiled in */ | ||
3873 | int idx; | ||
3874 | |||
3875 | nr = 0; | ||
3876 | for (idx = 0; idx < nr_ioapics; idx++) | ||
3877 | nr += io_apic_get_redir_entries(idx) + 1; | ||
3878 | |||
3879 | if (nr > nr_irqs_gsi) | ||
3880 | nr_irqs_gsi = nr; | ||
3881 | } | ||
3882 | 3859 | ||
3883 | printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi); | 3860 | printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi); |
3884 | } | 3861 | } |
@@ -4085,22 +4062,27 @@ int __init io_apic_get_version(int ioapic) | |||
4085 | return reg_01.bits.version; | 4062 | return reg_01.bits.version; |
4086 | } | 4063 | } |
4087 | 4064 | ||
4088 | int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity) | 4065 | int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity) |
4089 | { | 4066 | { |
4090 | int i; | 4067 | int ioapic, pin, idx; |
4091 | 4068 | ||
4092 | if (skip_ioapic_setup) | 4069 | if (skip_ioapic_setup) |
4093 | return -1; | 4070 | return -1; |
4094 | 4071 | ||
4095 | for (i = 0; i < mp_irq_entries; i++) | 4072 | ioapic = mp_find_ioapic(gsi); |
4096 | if (mp_irqs[i].irqtype == mp_INT && | 4073 | if (ioapic < 0) |
4097 | mp_irqs[i].srcbusirq == bus_irq) | ||
4098 | break; | ||
4099 | if (i >= mp_irq_entries) | ||
4100 | return -1; | 4074 | return -1; |
4101 | 4075 | ||
4102 | *trigger = irq_trigger(i); | 4076 | pin = mp_find_ioapic_pin(ioapic, gsi); |
4103 | *polarity = irq_polarity(i); | 4077 | if (pin < 0) |
4078 | return -1; | ||
4079 | |||
4080 | idx = find_irq_entry(ioapic, pin, mp_INT); | ||
4081 | if (idx < 0) | ||
4082 | return -1; | ||
4083 | |||
4084 | *trigger = irq_trigger(idx); | ||
4085 | *polarity = irq_polarity(idx); | ||
4104 | return 0; | 4086 | return 0; |
4105 | } | 4087 | } |
4106 | 4088 | ||
@@ -4241,7 +4223,7 @@ void __init ioapic_insert_resources(void) | |||
4241 | } | 4223 | } |
4242 | } | 4224 | } |
4243 | 4225 | ||
4244 | int mp_find_ioapic(int gsi) | 4226 | int mp_find_ioapic(u32 gsi) |
4245 | { | 4227 | { |
4246 | int i = 0; | 4228 | int i = 0; |
4247 | 4229 | ||
@@ -4256,7 +4238,7 @@ int mp_find_ioapic(int gsi) | |||
4256 | return -1; | 4238 | return -1; |
4257 | } | 4239 | } |
4258 | 4240 | ||
4259 | int mp_find_ioapic_pin(int ioapic, int gsi) | 4241 | int mp_find_ioapic_pin(int ioapic, u32 gsi) |
4260 | { | 4242 | { |
4261 | if (WARN_ON(ioapic == -1)) | 4243 | if (WARN_ON(ioapic == -1)) |
4262 | return -1; | 4244 | return -1; |
@@ -4284,6 +4266,7 @@ static int bad_ioapic(unsigned long address) | |||
4284 | void __init mp_register_ioapic(int id, u32 address, u32 gsi_base) | 4266 | void __init mp_register_ioapic(int id, u32 address, u32 gsi_base) |
4285 | { | 4267 | { |
4286 | int idx = 0; | 4268 | int idx = 0; |
4269 | int entries; | ||
4287 | 4270 | ||
4288 | if (bad_ioapic(address)) | 4271 | if (bad_ioapic(address)) |
4289 | return; | 4272 | return; |
@@ -4302,9 +4285,17 @@ void __init mp_register_ioapic(int id, u32 address, u32 gsi_base) | |||
4302 | * Build basic GSI lookup table to facilitate gsi->io_apic lookups | 4285 | * Build basic GSI lookup table to facilitate gsi->io_apic lookups |
4303 | * and to prevent reprogramming of IOAPIC pins (PCI GSIs). | 4286 | * and to prevent reprogramming of IOAPIC pins (PCI GSIs). |
4304 | */ | 4287 | */ |
4288 | entries = io_apic_get_redir_entries(idx); | ||
4305 | mp_gsi_routing[idx].gsi_base = gsi_base; | 4289 | mp_gsi_routing[idx].gsi_base = gsi_base; |
4306 | mp_gsi_routing[idx].gsi_end = gsi_base + | 4290 | mp_gsi_routing[idx].gsi_end = gsi_base + entries - 1; |
4307 | io_apic_get_redir_entries(idx); | 4291 | |
4292 | /* | ||
4293 | * The number of IO-APIC IRQ registers (== #pins): | ||
4294 | */ | ||
4295 | nr_ioapic_registers[idx] = entries; | ||
4296 | |||
4297 | if (mp_gsi_routing[idx].gsi_end > gsi_end) | ||
4298 | gsi_end = mp_gsi_routing[idx].gsi_end; | ||
4308 | 4299 | ||
4309 | printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, " | 4300 | printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, " |
4310 | "GSI %d-%d\n", idx, mp_ioapics[idx].apicid, | 4301 | "GSI %d-%d\n", idx, mp_ioapics[idx].apicid, |
diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c index c085d52dbaf2..e46f98f36e31 100644 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c | |||
@@ -735,9 +735,6 @@ void __init uv_system_init(void) | |||
735 | uv_node_to_blade[nid] = blade; | 735 | uv_node_to_blade[nid] = blade; |
736 | uv_cpu_to_blade[cpu] = blade; | 736 | uv_cpu_to_blade[cpu] = blade; |
737 | max_pnode = max(pnode, max_pnode); | 737 | max_pnode = max(pnode, max_pnode); |
738 | |||
739 | printk(KERN_DEBUG "UV: cpu %d, apicid 0x%x, pnode %d, nid %d, lcpu %d, blade %d\n", | ||
740 | cpu, apicid, pnode, nid, lcpu, blade); | ||
741 | } | 738 | } |
742 | 739 | ||
743 | /* Add blade/pnode info for nodes without cpus */ | 740 | /* Add blade/pnode info for nodes without cpus */ |
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c index 031aa887b0eb..c4f9182ca3ac 100644 --- a/arch/x86/kernel/apm_32.c +++ b/arch/x86/kernel/apm_32.c | |||
@@ -1224,7 +1224,7 @@ static void reinit_timer(void) | |||
1224 | #ifdef INIT_TIMER_AFTER_SUSPEND | 1224 | #ifdef INIT_TIMER_AFTER_SUSPEND |
1225 | unsigned long flags; | 1225 | unsigned long flags; |
1226 | 1226 | ||
1227 | spin_lock_irqsave(&i8253_lock, flags); | 1227 | raw_spin_lock_irqsave(&i8253_lock, flags); |
1228 | /* set the clock to HZ */ | 1228 | /* set the clock to HZ */ |
1229 | outb_pit(0x34, PIT_MODE); /* binary, mode 2, LSB/MSB, ch 0 */ | 1229 | outb_pit(0x34, PIT_MODE); /* binary, mode 2, LSB/MSB, ch 0 */ |
1230 | udelay(10); | 1230 | udelay(10); |
@@ -1232,7 +1232,7 @@ static void reinit_timer(void) | |||
1232 | udelay(10); | 1232 | udelay(10); |
1233 | outb_pit(LATCH >> 8, PIT_CH0); /* MSB */ | 1233 | outb_pit(LATCH >> 8, PIT_CH0); /* MSB */ |
1234 | udelay(10); | 1234 | udelay(10); |
1235 | spin_unlock_irqrestore(&i8253_lock, flags); | 1235 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
1236 | #endif | 1236 | #endif |
1237 | } | 1237 | } |
1238 | 1238 | ||
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index c202b62f3671..3a785da34b6f 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile | |||
@@ -14,7 +14,7 @@ CFLAGS_common.o := $(nostackp) | |||
14 | 14 | ||
15 | obj-y := intel_cacheinfo.o addon_cpuid_features.o | 15 | obj-y := intel_cacheinfo.o addon_cpuid_features.o |
16 | obj-y += proc.o capflags.o powerflags.o common.o | 16 | obj-y += proc.o capflags.o powerflags.o common.o |
17 | obj-y += vmware.o hypervisor.o sched.o | 17 | obj-y += vmware.o hypervisor.o sched.o mshyperv.o |
18 | 18 | ||
19 | obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o | 19 | obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o |
20 | obj-$(CONFIG_X86_64) += bugs_64.o | 20 | obj-$(CONFIG_X86_64) += bugs_64.o |
diff --git a/arch/x86/kernel/cpu/addon_cpuid_features.c b/arch/x86/kernel/cpu/addon_cpuid_features.c index 97ad79cdf688..10fa5684a662 100644 --- a/arch/x86/kernel/cpu/addon_cpuid_features.c +++ b/arch/x86/kernel/cpu/addon_cpuid_features.c | |||
@@ -30,12 +30,14 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c) | |||
30 | const struct cpuid_bit *cb; | 30 | const struct cpuid_bit *cb; |
31 | 31 | ||
32 | static const struct cpuid_bit __cpuinitconst cpuid_bits[] = { | 32 | static const struct cpuid_bit __cpuinitconst cpuid_bits[] = { |
33 | { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 }, | 33 | { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 }, |
34 | { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 }, | 34 | { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 }, |
35 | { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a }, | 35 | { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006 }, |
36 | { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a }, | 36 | { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007 }, |
37 | { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a }, | 37 | { X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a }, |
38 | { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a }, | 38 | { X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a }, |
39 | { X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a }, | ||
40 | { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a }, | ||
39 | { 0, 0, 0, 0 } | 41 | { 0, 0, 0, 0 } |
40 | }; | 42 | }; |
41 | 43 | ||
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 01a265212395..c39576cb3018 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c | |||
@@ -86,7 +86,7 @@ static void __init check_fpu(void) | |||
86 | 86 | ||
87 | static void __init check_hlt(void) | 87 | static void __init check_hlt(void) |
88 | { | 88 | { |
89 | if (paravirt_enabled()) | 89 | if (boot_cpu_data.x86 >= 5 || paravirt_enabled()) |
90 | return; | 90 | return; |
91 | 91 | ||
92 | printk(KERN_INFO "Checking 'hlt' instruction... "); | 92 | printk(KERN_INFO "Checking 'hlt' instruction... "); |
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 4868e4a951ee..c1c00d0b1692 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -1243,10 +1243,7 @@ void __cpuinit cpu_init(void) | |||
1243 | /* | 1243 | /* |
1244 | * Force FPU initialization: | 1244 | * Force FPU initialization: |
1245 | */ | 1245 | */ |
1246 | if (cpu_has_xsave) | 1246 | current_thread_info()->status = 0; |
1247 | current_thread_info()->status = TS_XSAVE; | ||
1248 | else | ||
1249 | current_thread_info()->status = 0; | ||
1250 | clear_used_math(); | 1247 | clear_used_math(); |
1251 | mxcsr_feature_mask_init(); | 1248 | mxcsr_feature_mask_init(); |
1252 | 1249 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/Makefile b/arch/x86/kernel/cpu/cpufreq/Makefile index 1840c0a5170b..bd54bf67e6fb 100644 --- a/arch/x86/kernel/cpu/cpufreq/Makefile +++ b/arch/x86/kernel/cpu/cpufreq/Makefile | |||
@@ -2,8 +2,8 @@ | |||
2 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. | 2 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. |
3 | # speedstep-* is preferred over p4-clockmod. | 3 | # speedstep-* is preferred over p4-clockmod. |
4 | 4 | ||
5 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o | 5 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o mperf.o |
6 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o | 6 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o |
7 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o | 7 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o |
8 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o | 8 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o |
9 | obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o | 9 | obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o |
diff --git a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c index 459168083b77..1d3cddaa40ee 100644 --- a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +++ b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <asm/msr.h> | 46 | #include <asm/msr.h> |
47 | #include <asm/processor.h> | 47 | #include <asm/processor.h> |
48 | #include <asm/cpufeature.h> | 48 | #include <asm/cpufeature.h> |
49 | #include "mperf.h" | ||
49 | 50 | ||
50 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ | 51 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \ |
51 | "acpi-cpufreq", msg) | 52 | "acpi-cpufreq", msg) |
@@ -71,8 +72,6 @@ struct acpi_cpufreq_data { | |||
71 | 72 | ||
72 | static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); | 73 | static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); |
73 | 74 | ||
74 | static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf); | ||
75 | |||
76 | /* acpi_perf_data is a pointer to percpu data. */ | 75 | /* acpi_perf_data is a pointer to percpu data. */ |
77 | static struct acpi_processor_performance *acpi_perf_data; | 76 | static struct acpi_processor_performance *acpi_perf_data; |
78 | 77 | ||
@@ -240,45 +239,6 @@ static u32 get_cur_val(const struct cpumask *mask) | |||
240 | return cmd.val; | 239 | return cmd.val; |
241 | } | 240 | } |
242 | 241 | ||
243 | /* Called via smp_call_function_single(), on the target CPU */ | ||
244 | static void read_measured_perf_ctrs(void *_cur) | ||
245 | { | ||
246 | struct aperfmperf *am = _cur; | ||
247 | |||
248 | get_aperfmperf(am); | ||
249 | } | ||
250 | |||
251 | /* | ||
252 | * Return the measured active (C0) frequency on this CPU since last call | ||
253 | * to this function. | ||
254 | * Input: cpu number | ||
255 | * Return: Average CPU frequency in terms of max frequency (zero on error) | ||
256 | * | ||
257 | * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance | ||
258 | * over a period of time, while CPU is in C0 state. | ||
259 | * IA32_MPERF counts at the rate of max advertised frequency | ||
260 | * IA32_APERF counts at the rate of actual CPU frequency | ||
261 | * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and | ||
262 | * no meaning should be associated with absolute values of these MSRs. | ||
263 | */ | ||
264 | static unsigned int get_measured_perf(struct cpufreq_policy *policy, | ||
265 | unsigned int cpu) | ||
266 | { | ||
267 | struct aperfmperf perf; | ||
268 | unsigned long ratio; | ||
269 | unsigned int retval; | ||
270 | |||
271 | if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1)) | ||
272 | return 0; | ||
273 | |||
274 | ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf); | ||
275 | per_cpu(acfreq_old_perf, cpu) = perf; | ||
276 | |||
277 | retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT; | ||
278 | |||
279 | return retval; | ||
280 | } | ||
281 | |||
282 | static unsigned int get_cur_freq_on_cpu(unsigned int cpu) | 242 | static unsigned int get_cur_freq_on_cpu(unsigned int cpu) |
283 | { | 243 | { |
284 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); | 244 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); |
@@ -702,7 +662,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | |||
702 | 662 | ||
703 | /* Check for APERF/MPERF support in hardware */ | 663 | /* Check for APERF/MPERF support in hardware */ |
704 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | 664 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) |
705 | acpi_cpufreq_driver.getavg = get_measured_perf; | 665 | acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf; |
706 | 666 | ||
707 | dprintk("CPU%u - ACPI performance management activated.\n", cpu); | 667 | dprintk("CPU%u - ACPI performance management activated.\n", cpu); |
708 | for (i = 0; i < perf->state_count; i++) | 668 | for (i = 0; i < perf->state_count; i++) |
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.c b/arch/x86/kernel/cpu/cpufreq/mperf.c new file mode 100644 index 000000000000..911e193018ae --- /dev/null +++ b/arch/x86/kernel/cpu/cpufreq/mperf.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/smp.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/cpufreq.h> | ||
6 | #include <linux/slab.h> | ||
7 | |||
8 | #include "mperf.h" | ||
9 | |||
10 | static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf); | ||
11 | |||
12 | /* Called via smp_call_function_single(), on the target CPU */ | ||
13 | static void read_measured_perf_ctrs(void *_cur) | ||
14 | { | ||
15 | struct aperfmperf *am = _cur; | ||
16 | |||
17 | get_aperfmperf(am); | ||
18 | } | ||
19 | |||
20 | /* | ||
21 | * Return the measured active (C0) frequency on this CPU since last call | ||
22 | * to this function. | ||
23 | * Input: cpu number | ||
24 | * Return: Average CPU frequency in terms of max frequency (zero on error) | ||
25 | * | ||
26 | * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance | ||
27 | * over a period of time, while CPU is in C0 state. | ||
28 | * IA32_MPERF counts at the rate of max advertised frequency | ||
29 | * IA32_APERF counts at the rate of actual CPU frequency | ||
30 | * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and | ||
31 | * no meaning should be associated with absolute values of these MSRs. | ||
32 | */ | ||
33 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
34 | unsigned int cpu) | ||
35 | { | ||
36 | struct aperfmperf perf; | ||
37 | unsigned long ratio; | ||
38 | unsigned int retval; | ||
39 | |||
40 | if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1)) | ||
41 | return 0; | ||
42 | |||
43 | ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf); | ||
44 | per_cpu(acfreq_old_perf, cpu) = perf; | ||
45 | |||
46 | retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT; | ||
47 | |||
48 | return retval; | ||
49 | } | ||
50 | EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf); | ||
51 | MODULE_LICENSE("GPL"); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.h b/arch/x86/kernel/cpu/cpufreq/mperf.h new file mode 100644 index 000000000000..5dbf2950dc22 --- /dev/null +++ b/arch/x86/kernel/cpu/cpufreq/mperf.h | |||
@@ -0,0 +1,9 @@ | |||
1 | /* | ||
2 | * (c) 2010 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | */ | ||
7 | |||
8 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
9 | unsigned int cpu); | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c index b6215b9798e2..6f3dc8fbbfdc 100644 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c | |||
@@ -1,6 +1,5 @@ | |||
1 | |||
2 | /* | 1 | /* |
3 | * (c) 2003-2006 Advanced Micro Devices, Inc. | 2 | * (c) 2003-2010 Advanced Micro Devices, Inc. |
4 | * Your use of this code is subject to the terms and conditions of the | 3 | * Your use of this code is subject to the terms and conditions of the |
5 | * GNU general public license version 2. See "COPYING" or | 4 | * GNU general public license version 2. See "COPYING" or |
6 | * http://www.gnu.org/licenses/gpl.html | 5 | * http://www.gnu.org/licenses/gpl.html |
@@ -46,6 +45,7 @@ | |||
46 | #define PFX "powernow-k8: " | 45 | #define PFX "powernow-k8: " |
47 | #define VERSION "version 2.20.00" | 46 | #define VERSION "version 2.20.00" |
48 | #include "powernow-k8.h" | 47 | #include "powernow-k8.h" |
48 | #include "mperf.h" | ||
49 | 49 | ||
50 | /* serialize freq changes */ | 50 | /* serialize freq changes */ |
51 | static DEFINE_MUTEX(fidvid_mutex); | 51 | static DEFINE_MUTEX(fidvid_mutex); |
@@ -54,6 +54,12 @@ static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); | |||
54 | 54 | ||
55 | static int cpu_family = CPU_OPTERON; | 55 | static int cpu_family = CPU_OPTERON; |
56 | 56 | ||
57 | /* core performance boost */ | ||
58 | static bool cpb_capable, cpb_enabled; | ||
59 | static struct msr __percpu *msrs; | ||
60 | |||
61 | static struct cpufreq_driver cpufreq_amd64_driver; | ||
62 | |||
57 | #ifndef CONFIG_SMP | 63 | #ifndef CONFIG_SMP |
58 | static inline const struct cpumask *cpu_core_mask(int cpu) | 64 | static inline const struct cpumask *cpu_core_mask(int cpu) |
59 | { | 65 | { |
@@ -1249,6 +1255,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1249 | struct powernow_k8_data *data; | 1255 | struct powernow_k8_data *data; |
1250 | struct init_on_cpu init_on_cpu; | 1256 | struct init_on_cpu init_on_cpu; |
1251 | int rc; | 1257 | int rc; |
1258 | struct cpuinfo_x86 *c = &cpu_data(pol->cpu); | ||
1252 | 1259 | ||
1253 | if (!cpu_online(pol->cpu)) | 1260 | if (!cpu_online(pol->cpu)) |
1254 | return -ENODEV; | 1261 | return -ENODEV; |
@@ -1323,6 +1330,10 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1323 | return -EINVAL; | 1330 | return -EINVAL; |
1324 | } | 1331 | } |
1325 | 1332 | ||
1333 | /* Check for APERF/MPERF support in hardware */ | ||
1334 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
1335 | cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf; | ||
1336 | |||
1326 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | 1337 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); |
1327 | 1338 | ||
1328 | if (cpu_family == CPU_HW_PSTATE) | 1339 | if (cpu_family == CPU_HW_PSTATE) |
@@ -1394,8 +1405,77 @@ out: | |||
1394 | return khz; | 1405 | return khz; |
1395 | } | 1406 | } |
1396 | 1407 | ||
1408 | static void _cpb_toggle_msrs(bool t) | ||
1409 | { | ||
1410 | int cpu; | ||
1411 | |||
1412 | get_online_cpus(); | ||
1413 | |||
1414 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1415 | |||
1416 | for_each_cpu(cpu, cpu_online_mask) { | ||
1417 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1418 | if (t) | ||
1419 | reg->l &= ~BIT(25); | ||
1420 | else | ||
1421 | reg->l |= BIT(25); | ||
1422 | } | ||
1423 | wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1424 | |||
1425 | put_online_cpus(); | ||
1426 | } | ||
1427 | |||
1428 | /* | ||
1429 | * Switch on/off core performance boosting. | ||
1430 | * | ||
1431 | * 0=disable | ||
1432 | * 1=enable. | ||
1433 | */ | ||
1434 | static void cpb_toggle(bool t) | ||
1435 | { | ||
1436 | if (!cpb_capable) | ||
1437 | return; | ||
1438 | |||
1439 | if (t && !cpb_enabled) { | ||
1440 | cpb_enabled = true; | ||
1441 | _cpb_toggle_msrs(t); | ||
1442 | printk(KERN_INFO PFX "Core Boosting enabled.\n"); | ||
1443 | } else if (!t && cpb_enabled) { | ||
1444 | cpb_enabled = false; | ||
1445 | _cpb_toggle_msrs(t); | ||
1446 | printk(KERN_INFO PFX "Core Boosting disabled.\n"); | ||
1447 | } | ||
1448 | } | ||
1449 | |||
1450 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
1451 | size_t count) | ||
1452 | { | ||
1453 | int ret = -EINVAL; | ||
1454 | unsigned long val = 0; | ||
1455 | |||
1456 | ret = strict_strtoul(buf, 10, &val); | ||
1457 | if (!ret && (val == 0 || val == 1) && cpb_capable) | ||
1458 | cpb_toggle(val); | ||
1459 | else | ||
1460 | return -EINVAL; | ||
1461 | |||
1462 | return count; | ||
1463 | } | ||
1464 | |||
1465 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
1466 | { | ||
1467 | return sprintf(buf, "%u\n", cpb_enabled); | ||
1468 | } | ||
1469 | |||
1470 | #define define_one_rw(_name) \ | ||
1471 | static struct freq_attr _name = \ | ||
1472 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
1473 | |||
1474 | define_one_rw(cpb); | ||
1475 | |||
1397 | static struct freq_attr *powernow_k8_attr[] = { | 1476 | static struct freq_attr *powernow_k8_attr[] = { |
1398 | &cpufreq_freq_attr_scaling_available_freqs, | 1477 | &cpufreq_freq_attr_scaling_available_freqs, |
1478 | &cpb, | ||
1399 | NULL, | 1479 | NULL, |
1400 | }; | 1480 | }; |
1401 | 1481 | ||
@@ -1411,10 +1491,51 @@ static struct cpufreq_driver cpufreq_amd64_driver = { | |||
1411 | .attr = powernow_k8_attr, | 1491 | .attr = powernow_k8_attr, |
1412 | }; | 1492 | }; |
1413 | 1493 | ||
1494 | /* | ||
1495 | * Clear the boost-disable flag on the CPU_DOWN path so that this cpu | ||
1496 | * cannot block the remaining ones from boosting. On the CPU_UP path we | ||
1497 | * simply keep the boost-disable flag in sync with the current global | ||
1498 | * state. | ||
1499 | */ | ||
1500 | static int __cpuinit cpb_notify(struct notifier_block *nb, unsigned long action, | ||
1501 | void *hcpu) | ||
1502 | { | ||
1503 | unsigned cpu = (long)hcpu; | ||
1504 | u32 lo, hi; | ||
1505 | |||
1506 | switch (action) { | ||
1507 | case CPU_UP_PREPARE: | ||
1508 | case CPU_UP_PREPARE_FROZEN: | ||
1509 | |||
1510 | if (!cpb_enabled) { | ||
1511 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1512 | lo |= BIT(25); | ||
1513 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1514 | } | ||
1515 | break; | ||
1516 | |||
1517 | case CPU_DOWN_PREPARE: | ||
1518 | case CPU_DOWN_PREPARE_FROZEN: | ||
1519 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1520 | lo &= ~BIT(25); | ||
1521 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1522 | break; | ||
1523 | |||
1524 | default: | ||
1525 | break; | ||
1526 | } | ||
1527 | |||
1528 | return NOTIFY_OK; | ||
1529 | } | ||
1530 | |||
1531 | static struct notifier_block __cpuinitdata cpb_nb = { | ||
1532 | .notifier_call = cpb_notify, | ||
1533 | }; | ||
1534 | |||
1414 | /* driver entry point for init */ | 1535 | /* driver entry point for init */ |
1415 | static int __cpuinit powernowk8_init(void) | 1536 | static int __cpuinit powernowk8_init(void) |
1416 | { | 1537 | { |
1417 | unsigned int i, supported_cpus = 0; | 1538 | unsigned int i, supported_cpus = 0, cpu; |
1418 | 1539 | ||
1419 | for_each_online_cpu(i) { | 1540 | for_each_online_cpu(i) { |
1420 | int rc; | 1541 | int rc; |
@@ -1423,15 +1544,36 @@ static int __cpuinit powernowk8_init(void) | |||
1423 | supported_cpus++; | 1544 | supported_cpus++; |
1424 | } | 1545 | } |
1425 | 1546 | ||
1426 | if (supported_cpus == num_online_cpus()) { | 1547 | if (supported_cpus != num_online_cpus()) |
1427 | printk(KERN_INFO PFX "Found %d %s " | 1548 | return -ENODEV; |
1428 | "processors (%d cpu cores) (" VERSION ")\n", | 1549 | |
1429 | num_online_nodes(), | 1550 | printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", |
1430 | boot_cpu_data.x86_model_id, supported_cpus); | 1551 | num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); |
1431 | return cpufreq_register_driver(&cpufreq_amd64_driver); | 1552 | |
1553 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1554 | |||
1555 | cpb_capable = true; | ||
1556 | |||
1557 | register_cpu_notifier(&cpb_nb); | ||
1558 | |||
1559 | msrs = msrs_alloc(); | ||
1560 | if (!msrs) { | ||
1561 | printk(KERN_ERR "%s: Error allocating msrs!\n", __func__); | ||
1562 | return -ENOMEM; | ||
1563 | } | ||
1564 | |||
1565 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1566 | |||
1567 | for_each_cpu(cpu, cpu_online_mask) { | ||
1568 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1569 | cpb_enabled |= !(!!(reg->l & BIT(25))); | ||
1570 | } | ||
1571 | |||
1572 | printk(KERN_INFO PFX "Core Performance Boosting: %s.\n", | ||
1573 | (cpb_enabled ? "on" : "off")); | ||
1432 | } | 1574 | } |
1433 | 1575 | ||
1434 | return -ENODEV; | 1576 | return cpufreq_register_driver(&cpufreq_amd64_driver); |
1435 | } | 1577 | } |
1436 | 1578 | ||
1437 | /* driver entry point for term */ | 1579 | /* driver entry point for term */ |
@@ -1439,6 +1581,13 @@ static void __exit powernowk8_exit(void) | |||
1439 | { | 1581 | { |
1440 | dprintk("exit\n"); | 1582 | dprintk("exit\n"); |
1441 | 1583 | ||
1584 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1585 | msrs_free(msrs); | ||
1586 | msrs = NULL; | ||
1587 | |||
1588 | unregister_cpu_notifier(&cpb_nb); | ||
1589 | } | ||
1590 | |||
1442 | cpufreq_unregister_driver(&cpufreq_amd64_driver); | 1591 | cpufreq_unregister_driver(&cpufreq_amd64_driver); |
1443 | } | 1592 | } |
1444 | 1593 | ||
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h index 02ce824073cb..df3529b1c02d 100644 --- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h +++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h | |||
@@ -5,7 +5,6 @@ | |||
5 | * http://www.gnu.org/licenses/gpl.html | 5 | * http://www.gnu.org/licenses/gpl.html |
6 | */ | 6 | */ |
7 | 7 | ||
8 | |||
9 | enum pstate { | 8 | enum pstate { |
10 | HW_PSTATE_INVALID = 0xff, | 9 | HW_PSTATE_INVALID = 0xff, |
11 | HW_PSTATE_0 = 0, | 10 | HW_PSTATE_0 = 0, |
@@ -55,7 +54,6 @@ struct powernow_k8_data { | |||
55 | struct cpumask *available_cores; | 54 | struct cpumask *available_cores; |
56 | }; | 55 | }; |
57 | 56 | ||
58 | |||
59 | /* processor's cpuid instruction support */ | 57 | /* processor's cpuid instruction support */ |
60 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ | 58 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ |
61 | #define CPUID_XFAM 0x0ff00000 /* extended family */ | 59 | #define CPUID_XFAM 0x0ff00000 /* extended family */ |
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c index 08be922de33a..dd531cc56a8f 100644 --- a/arch/x86/kernel/cpu/hypervisor.c +++ b/arch/x86/kernel/cpu/hypervisor.c | |||
@@ -21,37 +21,55 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | ||
24 | #include <asm/processor.h> | 25 | #include <asm/processor.h> |
25 | #include <asm/vmware.h> | ||
26 | #include <asm/hypervisor.h> | 26 | #include <asm/hypervisor.h> |
27 | 27 | ||
28 | static inline void __cpuinit | 28 | /* |
29 | detect_hypervisor_vendor(struct cpuinfo_x86 *c) | 29 | * Hypervisor detect order. This is specified explicitly here because |
30 | * some hypervisors might implement compatibility modes for other | ||
31 | * hypervisors and therefore need to be detected in specific sequence. | ||
32 | */ | ||
33 | static const __initconst struct hypervisor_x86 * const hypervisors[] = | ||
30 | { | 34 | { |
31 | if (vmware_platform()) | 35 | &x86_hyper_vmware, |
32 | c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE; | 36 | &x86_hyper_ms_hyperv, |
33 | else | 37 | }; |
34 | c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE; | ||
35 | } | ||
36 | 38 | ||
37 | static inline void __cpuinit | 39 | const struct hypervisor_x86 *x86_hyper; |
38 | hypervisor_set_feature_bits(struct cpuinfo_x86 *c) | 40 | EXPORT_SYMBOL(x86_hyper); |
41 | |||
42 | static inline void __init | ||
43 | detect_hypervisor_vendor(void) | ||
39 | { | 44 | { |
40 | if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) { | 45 | const struct hypervisor_x86 *h, * const *p; |
41 | vmware_set_feature_bits(c); | 46 | |
42 | return; | 47 | for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) { |
48 | h = *p; | ||
49 | if (h->detect()) { | ||
50 | x86_hyper = h; | ||
51 | printk(KERN_INFO "Hypervisor detected: %s\n", h->name); | ||
52 | break; | ||
53 | } | ||
43 | } | 54 | } |
44 | } | 55 | } |
45 | 56 | ||
46 | void __cpuinit init_hypervisor(struct cpuinfo_x86 *c) | 57 | void __cpuinit init_hypervisor(struct cpuinfo_x86 *c) |
47 | { | 58 | { |
48 | detect_hypervisor_vendor(c); | 59 | if (x86_hyper && x86_hyper->set_cpu_features) |
49 | hypervisor_set_feature_bits(c); | 60 | x86_hyper->set_cpu_features(c); |
50 | } | 61 | } |
51 | 62 | ||
52 | void __init init_hypervisor_platform(void) | 63 | void __init init_hypervisor_platform(void) |
53 | { | 64 | { |
65 | |||
66 | detect_hypervisor_vendor(); | ||
67 | |||
68 | if (!x86_hyper) | ||
69 | return; | ||
70 | |||
54 | init_hypervisor(&boot_cpu_data); | 71 | init_hypervisor(&boot_cpu_data); |
55 | if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) | 72 | |
56 | vmware_platform_setup(); | 73 | if (x86_hyper->init_platform) |
74 | x86_hyper->init_platform(); | ||
57 | } | 75 | } |
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 1366c7cfd483..85f69cdeae10 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <asm/processor.h> | 12 | #include <asm/processor.h> |
13 | #include <asm/pgtable.h> | 13 | #include <asm/pgtable.h> |
14 | #include <asm/msr.h> | 14 | #include <asm/msr.h> |
15 | #include <asm/ds.h> | ||
16 | #include <asm/bugs.h> | 15 | #include <asm/bugs.h> |
17 | #include <asm/cpu.h> | 16 | #include <asm/cpu.h> |
18 | 17 | ||
@@ -373,12 +372,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
373 | set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); | 372 | set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); |
374 | } | 373 | } |
375 | 374 | ||
376 | if (c->cpuid_level > 6) { | ||
377 | unsigned ecx = cpuid_ecx(6); | ||
378 | if (ecx & 0x01) | ||
379 | set_cpu_cap(c, X86_FEATURE_APERFMPERF); | ||
380 | } | ||
381 | |||
382 | if (cpu_has_xmm2) | 375 | if (cpu_has_xmm2) |
383 | set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); | 376 | set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); |
384 | if (cpu_has_ds) { | 377 | if (cpu_has_ds) { |
@@ -388,7 +381,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c) | |||
388 | set_cpu_cap(c, X86_FEATURE_BTS); | 381 | set_cpu_cap(c, X86_FEATURE_BTS); |
389 | if (!(l1 & (1<<12))) | 382 | if (!(l1 & (1<<12))) |
390 | set_cpu_cap(c, X86_FEATURE_PEBS); | 383 | set_cpu_cap(c, X86_FEATURE_PEBS); |
391 | ds_init_intel(c); | ||
392 | } | 384 | } |
393 | 385 | ||
394 | if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush) | 386 | if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush) |
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index b3eeb66c0a51..33eae2062cf5 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c | |||
@@ -148,13 +148,19 @@ union _cpuid4_leaf_ecx { | |||
148 | u32 full; | 148 | u32 full; |
149 | }; | 149 | }; |
150 | 150 | ||
151 | struct amd_l3_cache { | ||
152 | struct pci_dev *dev; | ||
153 | bool can_disable; | ||
154 | unsigned indices; | ||
155 | u8 subcaches[4]; | ||
156 | }; | ||
157 | |||
151 | struct _cpuid4_info { | 158 | struct _cpuid4_info { |
152 | union _cpuid4_leaf_eax eax; | 159 | union _cpuid4_leaf_eax eax; |
153 | union _cpuid4_leaf_ebx ebx; | 160 | union _cpuid4_leaf_ebx ebx; |
154 | union _cpuid4_leaf_ecx ecx; | 161 | union _cpuid4_leaf_ecx ecx; |
155 | unsigned long size; | 162 | unsigned long size; |
156 | bool can_disable; | 163 | struct amd_l3_cache *l3; |
157 | unsigned int l3_indices; | ||
158 | DECLARE_BITMAP(shared_cpu_map, NR_CPUS); | 164 | DECLARE_BITMAP(shared_cpu_map, NR_CPUS); |
159 | }; | 165 | }; |
160 | 166 | ||
@@ -164,8 +170,7 @@ struct _cpuid4_info_regs { | |||
164 | union _cpuid4_leaf_ebx ebx; | 170 | union _cpuid4_leaf_ebx ebx; |
165 | union _cpuid4_leaf_ecx ecx; | 171 | union _cpuid4_leaf_ecx ecx; |
166 | unsigned long size; | 172 | unsigned long size; |
167 | bool can_disable; | 173 | struct amd_l3_cache *l3; |
168 | unsigned int l3_indices; | ||
169 | }; | 174 | }; |
170 | 175 | ||
171 | unsigned short num_cache_leaves; | 176 | unsigned short num_cache_leaves; |
@@ -302,87 +307,163 @@ struct _cache_attr { | |||
302 | }; | 307 | }; |
303 | 308 | ||
304 | #ifdef CONFIG_CPU_SUP_AMD | 309 | #ifdef CONFIG_CPU_SUP_AMD |
305 | static unsigned int __cpuinit amd_calc_l3_indices(void) | 310 | |
311 | /* | ||
312 | * L3 cache descriptors | ||
313 | */ | ||
314 | static struct amd_l3_cache **__cpuinitdata l3_caches; | ||
315 | |||
316 | static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3) | ||
306 | { | 317 | { |
307 | /* | ||
308 | * We're called over smp_call_function_single() and therefore | ||
309 | * are on the correct cpu. | ||
310 | */ | ||
311 | int cpu = smp_processor_id(); | ||
312 | int node = cpu_to_node(cpu); | ||
313 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
314 | unsigned int sc0, sc1, sc2, sc3; | 318 | unsigned int sc0, sc1, sc2, sc3; |
315 | u32 val = 0; | 319 | u32 val = 0; |
316 | 320 | ||
317 | pci_read_config_dword(dev, 0x1C4, &val); | 321 | pci_read_config_dword(l3->dev, 0x1C4, &val); |
318 | 322 | ||
319 | /* calculate subcache sizes */ | 323 | /* calculate subcache sizes */ |
320 | sc0 = !(val & BIT(0)); | 324 | l3->subcaches[0] = sc0 = !(val & BIT(0)); |
321 | sc1 = !(val & BIT(4)); | 325 | l3->subcaches[1] = sc1 = !(val & BIT(4)); |
322 | sc2 = !(val & BIT(8)) + !(val & BIT(9)); | 326 | l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9)); |
323 | sc3 = !(val & BIT(12)) + !(val & BIT(13)); | 327 | l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13)); |
324 | 328 | ||
325 | return (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1; | 329 | l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1; |
330 | } | ||
331 | |||
332 | static struct amd_l3_cache * __cpuinit amd_init_l3_cache(int node) | ||
333 | { | ||
334 | struct amd_l3_cache *l3; | ||
335 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
336 | |||
337 | l3 = kzalloc(sizeof(struct amd_l3_cache), GFP_ATOMIC); | ||
338 | if (!l3) { | ||
339 | printk(KERN_WARNING "Error allocating L3 struct\n"); | ||
340 | return NULL; | ||
341 | } | ||
342 | |||
343 | l3->dev = dev; | ||
344 | |||
345 | amd_calc_l3_indices(l3); | ||
346 | |||
347 | return l3; | ||
326 | } | 348 | } |
327 | 349 | ||
328 | static void __cpuinit | 350 | static void __cpuinit |
329 | amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) | 351 | amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf) |
330 | { | 352 | { |
331 | if (index < 3) | 353 | int node; |
354 | |||
355 | if (boot_cpu_data.x86 != 0x10) | ||
332 | return; | 356 | return; |
333 | 357 | ||
334 | if (boot_cpu_data.x86 == 0x11) | 358 | if (index < 3) |
335 | return; | 359 | return; |
336 | 360 | ||
337 | /* see errata #382 and #388 */ | 361 | /* see errata #382 and #388 */ |
338 | if ((boot_cpu_data.x86 == 0x10) && | 362 | if (boot_cpu_data.x86_model < 0x8) |
339 | ((boot_cpu_data.x86_model < 0x8) || | 363 | return; |
340 | (boot_cpu_data.x86_mask < 0x1))) | 364 | |
365 | if ((boot_cpu_data.x86_model == 0x8 || | ||
366 | boot_cpu_data.x86_model == 0x9) | ||
367 | && | ||
368 | boot_cpu_data.x86_mask < 0x1) | ||
369 | return; | ||
370 | |||
371 | /* not in virtualized environments */ | ||
372 | if (num_k8_northbridges == 0) | ||
341 | return; | 373 | return; |
342 | 374 | ||
343 | this_leaf->can_disable = true; | 375 | /* |
344 | this_leaf->l3_indices = amd_calc_l3_indices(); | 376 | * Strictly speaking, the amount in @size below is leaked since it is |
377 | * never freed but this is done only on shutdown so it doesn't matter. | ||
378 | */ | ||
379 | if (!l3_caches) { | ||
380 | int size = num_k8_northbridges * sizeof(struct amd_l3_cache *); | ||
381 | |||
382 | l3_caches = kzalloc(size, GFP_ATOMIC); | ||
383 | if (!l3_caches) | ||
384 | return; | ||
385 | } | ||
386 | |||
387 | node = amd_get_nb_id(smp_processor_id()); | ||
388 | |||
389 | if (!l3_caches[node]) { | ||
390 | l3_caches[node] = amd_init_l3_cache(node); | ||
391 | l3_caches[node]->can_disable = true; | ||
392 | } | ||
393 | |||
394 | WARN_ON(!l3_caches[node]); | ||
395 | |||
396 | this_leaf->l3 = l3_caches[node]; | ||
345 | } | 397 | } |
346 | 398 | ||
347 | static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, | 399 | static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf, |
348 | unsigned int index) | 400 | unsigned int slot) |
349 | { | 401 | { |
350 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | 402 | struct pci_dev *dev = this_leaf->l3->dev; |
351 | int node = amd_get_nb_id(cpu); | ||
352 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
353 | unsigned int reg = 0; | 403 | unsigned int reg = 0; |
354 | 404 | ||
355 | if (!this_leaf->can_disable) | 405 | if (!this_leaf->l3 || !this_leaf->l3->can_disable) |
356 | return -EINVAL; | 406 | return -EINVAL; |
357 | 407 | ||
358 | if (!dev) | 408 | if (!dev) |
359 | return -EINVAL; | 409 | return -EINVAL; |
360 | 410 | ||
361 | pci_read_config_dword(dev, 0x1BC + index * 4, ®); | 411 | pci_read_config_dword(dev, 0x1BC + slot * 4, ®); |
362 | return sprintf(buf, "0x%08x\n", reg); | 412 | return sprintf(buf, "0x%08x\n", reg); |
363 | } | 413 | } |
364 | 414 | ||
365 | #define SHOW_CACHE_DISABLE(index) \ | 415 | #define SHOW_CACHE_DISABLE(slot) \ |
366 | static ssize_t \ | 416 | static ssize_t \ |
367 | show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \ | 417 | show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf) \ |
368 | { \ | 418 | { \ |
369 | return show_cache_disable(this_leaf, buf, index); \ | 419 | return show_cache_disable(this_leaf, buf, slot); \ |
370 | } | 420 | } |
371 | SHOW_CACHE_DISABLE(0) | 421 | SHOW_CACHE_DISABLE(0) |
372 | SHOW_CACHE_DISABLE(1) | 422 | SHOW_CACHE_DISABLE(1) |
373 | 423 | ||
424 | static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu, | ||
425 | unsigned slot, unsigned long idx) | ||
426 | { | ||
427 | int i; | ||
428 | |||
429 | idx |= BIT(30); | ||
430 | |||
431 | /* | ||
432 | * disable index in all 4 subcaches | ||
433 | */ | ||
434 | for (i = 0; i < 4; i++) { | ||
435 | u32 reg = idx | (i << 20); | ||
436 | |||
437 | if (!l3->subcaches[i]) | ||
438 | continue; | ||
439 | |||
440 | pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg); | ||
441 | |||
442 | /* | ||
443 | * We need to WBINVD on a core on the node containing the L3 | ||
444 | * cache which indices we disable therefore a simple wbinvd() | ||
445 | * is not sufficient. | ||
446 | */ | ||
447 | wbinvd_on_cpu(cpu); | ||
448 | |||
449 | reg |= BIT(31); | ||
450 | pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | |||
374 | static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | 455 | static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, |
375 | const char *buf, size_t count, unsigned int index) | 456 | const char *buf, size_t count, |
457 | unsigned int slot) | ||
376 | { | 458 | { |
459 | struct pci_dev *dev = this_leaf->l3->dev; | ||
377 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); | 460 | int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map)); |
378 | int node = amd_get_nb_id(cpu); | ||
379 | struct pci_dev *dev = node_to_k8_nb_misc(node); | ||
380 | unsigned long val = 0; | 461 | unsigned long val = 0; |
381 | 462 | ||
382 | #define SUBCACHE_MASK (3UL << 20) | 463 | #define SUBCACHE_MASK (3UL << 20) |
383 | #define SUBCACHE_INDEX 0xfff | 464 | #define SUBCACHE_INDEX 0xfff |
384 | 465 | ||
385 | if (!this_leaf->can_disable) | 466 | if (!this_leaf->l3 || !this_leaf->l3->can_disable) |
386 | return -EINVAL; | 467 | return -EINVAL; |
387 | 468 | ||
388 | if (!capable(CAP_SYS_ADMIN)) | 469 | if (!capable(CAP_SYS_ADMIN)) |
@@ -396,26 +477,20 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, | |||
396 | 477 | ||
397 | /* do not allow writes outside of allowed bits */ | 478 | /* do not allow writes outside of allowed bits */ |
398 | if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) || | 479 | if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) || |
399 | ((val & SUBCACHE_INDEX) > this_leaf->l3_indices)) | 480 | ((val & SUBCACHE_INDEX) > this_leaf->l3->indices)) |
400 | return -EINVAL; | 481 | return -EINVAL; |
401 | 482 | ||
402 | val |= BIT(30); | 483 | amd_l3_disable_index(this_leaf->l3, cpu, slot, val); |
403 | pci_write_config_dword(dev, 0x1BC + index * 4, val); | 484 | |
404 | /* | ||
405 | * We need to WBINVD on a core on the node containing the L3 cache which | ||
406 | * indices we disable therefore a simple wbinvd() is not sufficient. | ||
407 | */ | ||
408 | wbinvd_on_cpu(cpu); | ||
409 | pci_write_config_dword(dev, 0x1BC + index * 4, val | BIT(31)); | ||
410 | return count; | 485 | return count; |
411 | } | 486 | } |
412 | 487 | ||
413 | #define STORE_CACHE_DISABLE(index) \ | 488 | #define STORE_CACHE_DISABLE(slot) \ |
414 | static ssize_t \ | 489 | static ssize_t \ |
415 | store_cache_disable_##index(struct _cpuid4_info *this_leaf, \ | 490 | store_cache_disable_##slot(struct _cpuid4_info *this_leaf, \ |
416 | const char *buf, size_t count) \ | 491 | const char *buf, size_t count) \ |
417 | { \ | 492 | { \ |
418 | return store_cache_disable(this_leaf, buf, count, index); \ | 493 | return store_cache_disable(this_leaf, buf, count, slot); \ |
419 | } | 494 | } |
420 | STORE_CACHE_DISABLE(0) | 495 | STORE_CACHE_DISABLE(0) |
421 | STORE_CACHE_DISABLE(1) | 496 | STORE_CACHE_DISABLE(1) |
@@ -443,8 +518,7 @@ __cpuinit cpuid4_cache_lookup_regs(int index, | |||
443 | 518 | ||
444 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { | 519 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { |
445 | amd_cpuid4(index, &eax, &ebx, &ecx); | 520 | amd_cpuid4(index, &eax, &ebx, &ecx); |
446 | if (boot_cpu_data.x86 >= 0x10) | 521 | amd_check_l3_disable(index, this_leaf); |
447 | amd_check_l3_disable(index, this_leaf); | ||
448 | } else { | 522 | } else { |
449 | cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); | 523 | cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); |
450 | } | 524 | } |
@@ -701,6 +775,7 @@ static void __cpuinit free_cache_attributes(unsigned int cpu) | |||
701 | for (i = 0; i < num_cache_leaves; i++) | 775 | for (i = 0; i < num_cache_leaves; i++) |
702 | cache_remove_shared_cpu_map(cpu, i); | 776 | cache_remove_shared_cpu_map(cpu, i); |
703 | 777 | ||
778 | kfree(per_cpu(ici_cpuid4_info, cpu)->l3); | ||
704 | kfree(per_cpu(ici_cpuid4_info, cpu)); | 779 | kfree(per_cpu(ici_cpuid4_info, cpu)); |
705 | per_cpu(ici_cpuid4_info, cpu) = NULL; | 780 | per_cpu(ici_cpuid4_info, cpu) = NULL; |
706 | } | 781 | } |
@@ -985,7 +1060,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev) | |||
985 | 1060 | ||
986 | this_leaf = CPUID4_INFO_IDX(cpu, i); | 1061 | this_leaf = CPUID4_INFO_IDX(cpu, i); |
987 | 1062 | ||
988 | if (this_leaf->can_disable) | 1063 | if (this_leaf->l3 && this_leaf->l3->can_disable) |
989 | ktype_cache.default_attrs = default_l3_attrs; | 1064 | ktype_cache.default_attrs = default_l3_attrs; |
990 | else | 1065 | else |
991 | ktype_cache.default_attrs = default_attrs; | 1066 | ktype_cache.default_attrs = default_attrs; |
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c index 8a6f0afa767e..7a355ddcc64b 100644 --- a/arch/x86/kernel/cpu/mcheck/mce.c +++ b/arch/x86/kernel/cpu/mcheck/mce.c | |||
@@ -539,7 +539,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b) | |||
539 | struct mce m; | 539 | struct mce m; |
540 | int i; | 540 | int i; |
541 | 541 | ||
542 | __get_cpu_var(mce_poll_count)++; | 542 | percpu_inc(mce_poll_count); |
543 | 543 | ||
544 | mce_setup(&m); | 544 | mce_setup(&m); |
545 | 545 | ||
@@ -934,7 +934,7 @@ void do_machine_check(struct pt_regs *regs, long error_code) | |||
934 | 934 | ||
935 | atomic_inc(&mce_entry); | 935 | atomic_inc(&mce_entry); |
936 | 936 | ||
937 | __get_cpu_var(mce_exception_count)++; | 937 | percpu_inc(mce_exception_count); |
938 | 938 | ||
939 | if (notify_die(DIE_NMI, "machine check", regs, error_code, | 939 | if (notify_die(DIE_NMI, "machine check", regs, error_code, |
940 | 18, SIGKILL) == NOTIFY_STOP) | 940 | 18, SIGKILL) == NOTIFY_STOP) |
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c new file mode 100644 index 000000000000..16f41bbe46b6 --- /dev/null +++ b/arch/x86/kernel/cpu/mshyperv.c | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * HyperV Detection code. | ||
3 | * | ||
4 | * Copyright (C) 2010, Novell, Inc. | ||
5 | * Author : K. Y. Srinivasan <ksrinivasan@novell.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; version 2 of the License. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/types.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <asm/processor.h> | ||
16 | #include <asm/hypervisor.h> | ||
17 | #include <asm/hyperv.h> | ||
18 | #include <asm/mshyperv.h> | ||
19 | |||
20 | struct ms_hyperv_info ms_hyperv; | ||
21 | |||
22 | static bool __init ms_hyperv_platform(void) | ||
23 | { | ||
24 | u32 eax; | ||
25 | u32 hyp_signature[3]; | ||
26 | |||
27 | if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) | ||
28 | return false; | ||
29 | |||
30 | cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS, | ||
31 | &eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]); | ||
32 | |||
33 | return eax >= HYPERV_CPUID_MIN && | ||
34 | eax <= HYPERV_CPUID_MAX && | ||
35 | !memcmp("Microsoft Hv", hyp_signature, 12); | ||
36 | } | ||
37 | |||
38 | static void __init ms_hyperv_init_platform(void) | ||
39 | { | ||
40 | /* | ||
41 | * Extract the features and hints | ||
42 | */ | ||
43 | ms_hyperv.features = cpuid_eax(HYPERV_CPUID_FEATURES); | ||
44 | ms_hyperv.hints = cpuid_eax(HYPERV_CPUID_ENLIGHTMENT_INFO); | ||
45 | |||
46 | printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n", | ||
47 | ms_hyperv.features, ms_hyperv.hints); | ||
48 | } | ||
49 | |||
50 | const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { | ||
51 | .name = "Microsoft HyperV", | ||
52 | .detect = ms_hyperv_platform, | ||
53 | .init_platform = ms_hyperv_init_platform, | ||
54 | }; | ||
55 | EXPORT_SYMBOL(x86_hyper_ms_hyperv); | ||
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c index db5bdc8addf8..fd4db0db3708 100644 --- a/arch/x86/kernel/cpu/perf_event.c +++ b/arch/x86/kernel/cpu/perf_event.c | |||
@@ -31,46 +31,51 @@ | |||
31 | #include <asm/nmi.h> | 31 | #include <asm/nmi.h> |
32 | #include <asm/compat.h> | 32 | #include <asm/compat.h> |
33 | 33 | ||
34 | static u64 perf_event_mask __read_mostly; | 34 | #if 0 |
35 | #undef wrmsrl | ||
36 | #define wrmsrl(msr, val) \ | ||
37 | do { \ | ||
38 | trace_printk("wrmsrl(%lx, %lx)\n", (unsigned long)(msr),\ | ||
39 | (unsigned long)(val)); \ | ||
40 | native_write_msr((msr), (u32)((u64)(val)), \ | ||
41 | (u32)((u64)(val) >> 32)); \ | ||
42 | } while (0) | ||
43 | #endif | ||
35 | 44 | ||
36 | /* The maximal number of PEBS events: */ | 45 | /* |
37 | #define MAX_PEBS_EVENTS 4 | 46 | * best effort, GUP based copy_from_user() that assumes IRQ or NMI context |
47 | */ | ||
48 | static unsigned long | ||
49 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | ||
50 | { | ||
51 | unsigned long offset, addr = (unsigned long)from; | ||
52 | int type = in_nmi() ? KM_NMI : KM_IRQ0; | ||
53 | unsigned long size, len = 0; | ||
54 | struct page *page; | ||
55 | void *map; | ||
56 | int ret; | ||
38 | 57 | ||
39 | /* The size of a BTS record in bytes: */ | 58 | do { |
40 | #define BTS_RECORD_SIZE 24 | 59 | ret = __get_user_pages_fast(addr, 1, 0, &page); |
60 | if (!ret) | ||
61 | break; | ||
41 | 62 | ||
42 | /* The size of a per-cpu BTS buffer in bytes: */ | 63 | offset = addr & (PAGE_SIZE - 1); |
43 | #define BTS_BUFFER_SIZE (BTS_RECORD_SIZE * 2048) | 64 | size = min(PAGE_SIZE - offset, n - len); |
44 | 65 | ||
45 | /* The BTS overflow threshold in bytes from the end of the buffer: */ | 66 | map = kmap_atomic(page, type); |
46 | #define BTS_OVFL_TH (BTS_RECORD_SIZE * 128) | 67 | memcpy(to, map+offset, size); |
68 | kunmap_atomic(map, type); | ||
69 | put_page(page); | ||
47 | 70 | ||
71 | len += size; | ||
72 | to += size; | ||
73 | addr += size; | ||
48 | 74 | ||
49 | /* | 75 | } while (len < n); |
50 | * Bits in the debugctlmsr controlling branch tracing. | ||
51 | */ | ||
52 | #define X86_DEBUGCTL_TR (1 << 6) | ||
53 | #define X86_DEBUGCTL_BTS (1 << 7) | ||
54 | #define X86_DEBUGCTL_BTINT (1 << 8) | ||
55 | #define X86_DEBUGCTL_BTS_OFF_OS (1 << 9) | ||
56 | #define X86_DEBUGCTL_BTS_OFF_USR (1 << 10) | ||
57 | 76 | ||
58 | /* | 77 | return len; |
59 | * A debug store configuration. | 78 | } |
60 | * | ||
61 | * We only support architectures that use 64bit fields. | ||
62 | */ | ||
63 | struct debug_store { | ||
64 | u64 bts_buffer_base; | ||
65 | u64 bts_index; | ||
66 | u64 bts_absolute_maximum; | ||
67 | u64 bts_interrupt_threshold; | ||
68 | u64 pebs_buffer_base; | ||
69 | u64 pebs_index; | ||
70 | u64 pebs_absolute_maximum; | ||
71 | u64 pebs_interrupt_threshold; | ||
72 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; | ||
73 | }; | ||
74 | 79 | ||
75 | struct event_constraint { | 80 | struct event_constraint { |
76 | union { | 81 | union { |
@@ -89,18 +94,41 @@ struct amd_nb { | |||
89 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; | 94 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; |
90 | }; | 95 | }; |
91 | 96 | ||
97 | #define MAX_LBR_ENTRIES 16 | ||
98 | |||
92 | struct cpu_hw_events { | 99 | struct cpu_hw_events { |
100 | /* | ||
101 | * Generic x86 PMC bits | ||
102 | */ | ||
93 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ | 103 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ |
94 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | 104 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
95 | unsigned long interrupts; | ||
96 | int enabled; | 105 | int enabled; |
97 | struct debug_store *ds; | ||
98 | 106 | ||
99 | int n_events; | 107 | int n_events; |
100 | int n_added; | 108 | int n_added; |
101 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ | 109 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ |
102 | u64 tags[X86_PMC_IDX_MAX]; | 110 | u64 tags[X86_PMC_IDX_MAX]; |
103 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ | 111 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ |
112 | |||
113 | unsigned int group_flag; | ||
114 | |||
115 | /* | ||
116 | * Intel DebugStore bits | ||
117 | */ | ||
118 | struct debug_store *ds; | ||
119 | u64 pebs_enabled; | ||
120 | |||
121 | /* | ||
122 | * Intel LBR bits | ||
123 | */ | ||
124 | int lbr_users; | ||
125 | void *lbr_context; | ||
126 | struct perf_branch_stack lbr_stack; | ||
127 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; | ||
128 | |||
129 | /* | ||
130 | * AMD specific bits | ||
131 | */ | ||
104 | struct amd_nb *amd_nb; | 132 | struct amd_nb *amd_nb; |
105 | }; | 133 | }; |
106 | 134 | ||
@@ -114,44 +142,75 @@ struct cpu_hw_events { | |||
114 | #define EVENT_CONSTRAINT(c, n, m) \ | 142 | #define EVENT_CONSTRAINT(c, n, m) \ |
115 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n)) | 143 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n)) |
116 | 144 | ||
145 | /* | ||
146 | * Constraint on the Event code. | ||
147 | */ | ||
117 | #define INTEL_EVENT_CONSTRAINT(c, n) \ | 148 | #define INTEL_EVENT_CONSTRAINT(c, n) \ |
118 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVTSEL_MASK) | 149 | EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT) |
119 | 150 | ||
151 | /* | ||
152 | * Constraint on the Event code + UMask + fixed-mask | ||
153 | * | ||
154 | * filter mask to validate fixed counter events. | ||
155 | * the following filters disqualify for fixed counters: | ||
156 | * - inv | ||
157 | * - edge | ||
158 | * - cnt-mask | ||
159 | * The other filters are supported by fixed counters. | ||
160 | * The any-thread option is supported starting with v3. | ||
161 | */ | ||
120 | #define FIXED_EVENT_CONSTRAINT(c, n) \ | 162 | #define FIXED_EVENT_CONSTRAINT(c, n) \ |
121 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), INTEL_ARCH_FIXED_MASK) | 163 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), X86_RAW_EVENT_MASK) |
164 | |||
165 | /* | ||
166 | * Constraint on the Event code + UMask | ||
167 | */ | ||
168 | #define PEBS_EVENT_CONSTRAINT(c, n) \ | ||
169 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) | ||
122 | 170 | ||
123 | #define EVENT_CONSTRAINT_END \ | 171 | #define EVENT_CONSTRAINT_END \ |
124 | EVENT_CONSTRAINT(0, 0, 0) | 172 | EVENT_CONSTRAINT(0, 0, 0) |
125 | 173 | ||
126 | #define for_each_event_constraint(e, c) \ | 174 | #define for_each_event_constraint(e, c) \ |
127 | for ((e) = (c); (e)->cmask; (e)++) | 175 | for ((e) = (c); (e)->weight; (e)++) |
176 | |||
177 | union perf_capabilities { | ||
178 | struct { | ||
179 | u64 lbr_format : 6; | ||
180 | u64 pebs_trap : 1; | ||
181 | u64 pebs_arch_reg : 1; | ||
182 | u64 pebs_format : 4; | ||
183 | u64 smm_freeze : 1; | ||
184 | }; | ||
185 | u64 capabilities; | ||
186 | }; | ||
128 | 187 | ||
129 | /* | 188 | /* |
130 | * struct x86_pmu - generic x86 pmu | 189 | * struct x86_pmu - generic x86 pmu |
131 | */ | 190 | */ |
132 | struct x86_pmu { | 191 | struct x86_pmu { |
192 | /* | ||
193 | * Generic x86 PMC bits | ||
194 | */ | ||
133 | const char *name; | 195 | const char *name; |
134 | int version; | 196 | int version; |
135 | int (*handle_irq)(struct pt_regs *); | 197 | int (*handle_irq)(struct pt_regs *); |
136 | void (*disable_all)(void); | 198 | void (*disable_all)(void); |
137 | void (*enable_all)(void); | 199 | void (*enable_all)(int added); |
138 | void (*enable)(struct perf_event *); | 200 | void (*enable)(struct perf_event *); |
139 | void (*disable)(struct perf_event *); | 201 | void (*disable)(struct perf_event *); |
202 | int (*hw_config)(struct perf_event *event); | ||
203 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); | ||
140 | unsigned eventsel; | 204 | unsigned eventsel; |
141 | unsigned perfctr; | 205 | unsigned perfctr; |
142 | u64 (*event_map)(int); | 206 | u64 (*event_map)(int); |
143 | u64 (*raw_event)(u64); | ||
144 | int max_events; | 207 | int max_events; |
145 | int num_events; | 208 | int num_counters; |
146 | int num_events_fixed; | 209 | int num_counters_fixed; |
147 | int event_bits; | 210 | int cntval_bits; |
148 | u64 event_mask; | 211 | u64 cntval_mask; |
149 | int apic; | 212 | int apic; |
150 | u64 max_period; | 213 | u64 max_period; |
151 | u64 intel_ctrl; | ||
152 | void (*enable_bts)(u64 config); | ||
153 | void (*disable_bts)(void); | ||
154 | |||
155 | struct event_constraint * | 214 | struct event_constraint * |
156 | (*get_event_constraints)(struct cpu_hw_events *cpuc, | 215 | (*get_event_constraints)(struct cpu_hw_events *cpuc, |
157 | struct perf_event *event); | 216 | struct perf_event *event); |
@@ -159,11 +218,32 @@ struct x86_pmu { | |||
159 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, | 218 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, |
160 | struct perf_event *event); | 219 | struct perf_event *event); |
161 | struct event_constraint *event_constraints; | 220 | struct event_constraint *event_constraints; |
221 | void (*quirks)(void); | ||
162 | 222 | ||
163 | int (*cpu_prepare)(int cpu); | 223 | int (*cpu_prepare)(int cpu); |
164 | void (*cpu_starting)(int cpu); | 224 | void (*cpu_starting)(int cpu); |
165 | void (*cpu_dying)(int cpu); | 225 | void (*cpu_dying)(int cpu); |
166 | void (*cpu_dead)(int cpu); | 226 | void (*cpu_dead)(int cpu); |
227 | |||
228 | /* | ||
229 | * Intel Arch Perfmon v2+ | ||
230 | */ | ||
231 | u64 intel_ctrl; | ||
232 | union perf_capabilities intel_cap; | ||
233 | |||
234 | /* | ||
235 | * Intel DebugStore bits | ||
236 | */ | ||
237 | int bts, pebs; | ||
238 | int pebs_record_size; | ||
239 | void (*drain_pebs)(struct pt_regs *regs); | ||
240 | struct event_constraint *pebs_constraints; | ||
241 | |||
242 | /* | ||
243 | * Intel LBR | ||
244 | */ | ||
245 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ | ||
246 | int lbr_nr; /* hardware stack size */ | ||
167 | }; | 247 | }; |
168 | 248 | ||
169 | static struct x86_pmu x86_pmu __read_mostly; | 249 | static struct x86_pmu x86_pmu __read_mostly; |
@@ -198,7 +278,7 @@ static u64 | |||
198 | x86_perf_event_update(struct perf_event *event) | 278 | x86_perf_event_update(struct perf_event *event) |
199 | { | 279 | { |
200 | struct hw_perf_event *hwc = &event->hw; | 280 | struct hw_perf_event *hwc = &event->hw; |
201 | int shift = 64 - x86_pmu.event_bits; | 281 | int shift = 64 - x86_pmu.cntval_bits; |
202 | u64 prev_raw_count, new_raw_count; | 282 | u64 prev_raw_count, new_raw_count; |
203 | int idx = hwc->idx; | 283 | int idx = hwc->idx; |
204 | s64 delta; | 284 | s64 delta; |
@@ -241,33 +321,32 @@ again: | |||
241 | static atomic_t active_events; | 321 | static atomic_t active_events; |
242 | static DEFINE_MUTEX(pmc_reserve_mutex); | 322 | static DEFINE_MUTEX(pmc_reserve_mutex); |
243 | 323 | ||
324 | #ifdef CONFIG_X86_LOCAL_APIC | ||
325 | |||
244 | static bool reserve_pmc_hardware(void) | 326 | static bool reserve_pmc_hardware(void) |
245 | { | 327 | { |
246 | #ifdef CONFIG_X86_LOCAL_APIC | ||
247 | int i; | 328 | int i; |
248 | 329 | ||
249 | if (nmi_watchdog == NMI_LOCAL_APIC) | 330 | if (nmi_watchdog == NMI_LOCAL_APIC) |
250 | disable_lapic_nmi_watchdog(); | 331 | disable_lapic_nmi_watchdog(); |
251 | 332 | ||
252 | for (i = 0; i < x86_pmu.num_events; i++) { | 333 | for (i = 0; i < x86_pmu.num_counters; i++) { |
253 | if (!reserve_perfctr_nmi(x86_pmu.perfctr + i)) | 334 | if (!reserve_perfctr_nmi(x86_pmu.perfctr + i)) |
254 | goto perfctr_fail; | 335 | goto perfctr_fail; |
255 | } | 336 | } |
256 | 337 | ||
257 | for (i = 0; i < x86_pmu.num_events; i++) { | 338 | for (i = 0; i < x86_pmu.num_counters; i++) { |
258 | if (!reserve_evntsel_nmi(x86_pmu.eventsel + i)) | 339 | if (!reserve_evntsel_nmi(x86_pmu.eventsel + i)) |
259 | goto eventsel_fail; | 340 | goto eventsel_fail; |
260 | } | 341 | } |
261 | #endif | ||
262 | 342 | ||
263 | return true; | 343 | return true; |
264 | 344 | ||
265 | #ifdef CONFIG_X86_LOCAL_APIC | ||
266 | eventsel_fail: | 345 | eventsel_fail: |
267 | for (i--; i >= 0; i--) | 346 | for (i--; i >= 0; i--) |
268 | release_evntsel_nmi(x86_pmu.eventsel + i); | 347 | release_evntsel_nmi(x86_pmu.eventsel + i); |
269 | 348 | ||
270 | i = x86_pmu.num_events; | 349 | i = x86_pmu.num_counters; |
271 | 350 | ||
272 | perfctr_fail: | 351 | perfctr_fail: |
273 | for (i--; i >= 0; i--) | 352 | for (i--; i >= 0; i--) |
@@ -277,128 +356,36 @@ perfctr_fail: | |||
277 | enable_lapic_nmi_watchdog(); | 356 | enable_lapic_nmi_watchdog(); |
278 | 357 | ||
279 | return false; | 358 | return false; |
280 | #endif | ||
281 | } | 359 | } |
282 | 360 | ||
283 | static void release_pmc_hardware(void) | 361 | static void release_pmc_hardware(void) |
284 | { | 362 | { |
285 | #ifdef CONFIG_X86_LOCAL_APIC | ||
286 | int i; | 363 | int i; |
287 | 364 | ||
288 | for (i = 0; i < x86_pmu.num_events; i++) { | 365 | for (i = 0; i < x86_pmu.num_counters; i++) { |
289 | release_perfctr_nmi(x86_pmu.perfctr + i); | 366 | release_perfctr_nmi(x86_pmu.perfctr + i); |
290 | release_evntsel_nmi(x86_pmu.eventsel + i); | 367 | release_evntsel_nmi(x86_pmu.eventsel + i); |
291 | } | 368 | } |
292 | 369 | ||
293 | if (nmi_watchdog == NMI_LOCAL_APIC) | 370 | if (nmi_watchdog == NMI_LOCAL_APIC) |
294 | enable_lapic_nmi_watchdog(); | 371 | enable_lapic_nmi_watchdog(); |
295 | #endif | ||
296 | } | ||
297 | |||
298 | static inline bool bts_available(void) | ||
299 | { | ||
300 | return x86_pmu.enable_bts != NULL; | ||
301 | } | 372 | } |
302 | 373 | ||
303 | static void init_debug_store_on_cpu(int cpu) | 374 | #else |
304 | { | ||
305 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
306 | |||
307 | if (!ds) | ||
308 | return; | ||
309 | |||
310 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, | ||
311 | (u32)((u64)(unsigned long)ds), | ||
312 | (u32)((u64)(unsigned long)ds >> 32)); | ||
313 | } | ||
314 | |||
315 | static void fini_debug_store_on_cpu(int cpu) | ||
316 | { | ||
317 | if (!per_cpu(cpu_hw_events, cpu).ds) | ||
318 | return; | ||
319 | |||
320 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); | ||
321 | } | ||
322 | |||
323 | static void release_bts_hardware(void) | ||
324 | { | ||
325 | int cpu; | ||
326 | |||
327 | if (!bts_available()) | ||
328 | return; | ||
329 | |||
330 | get_online_cpus(); | ||
331 | |||
332 | for_each_online_cpu(cpu) | ||
333 | fini_debug_store_on_cpu(cpu); | ||
334 | |||
335 | for_each_possible_cpu(cpu) { | ||
336 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
337 | |||
338 | if (!ds) | ||
339 | continue; | ||
340 | |||
341 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
342 | |||
343 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
344 | kfree(ds); | ||
345 | } | ||
346 | |||
347 | put_online_cpus(); | ||
348 | } | ||
349 | |||
350 | static int reserve_bts_hardware(void) | ||
351 | { | ||
352 | int cpu, err = 0; | ||
353 | |||
354 | if (!bts_available()) | ||
355 | return 0; | ||
356 | |||
357 | get_online_cpus(); | ||
358 | |||
359 | for_each_possible_cpu(cpu) { | ||
360 | struct debug_store *ds; | ||
361 | void *buffer; | ||
362 | |||
363 | err = -ENOMEM; | ||
364 | buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL); | ||
365 | if (unlikely(!buffer)) | ||
366 | break; | ||
367 | |||
368 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | ||
369 | if (unlikely(!ds)) { | ||
370 | kfree(buffer); | ||
371 | break; | ||
372 | } | ||
373 | |||
374 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
375 | ds->bts_index = ds->bts_buffer_base; | ||
376 | ds->bts_absolute_maximum = | ||
377 | ds->bts_buffer_base + BTS_BUFFER_SIZE; | ||
378 | ds->bts_interrupt_threshold = | ||
379 | ds->bts_absolute_maximum - BTS_OVFL_TH; | ||
380 | |||
381 | per_cpu(cpu_hw_events, cpu).ds = ds; | ||
382 | err = 0; | ||
383 | } | ||
384 | 375 | ||
385 | if (err) | 376 | static bool reserve_pmc_hardware(void) { return true; } |
386 | release_bts_hardware(); | 377 | static void release_pmc_hardware(void) {} |
387 | else { | ||
388 | for_each_online_cpu(cpu) | ||
389 | init_debug_store_on_cpu(cpu); | ||
390 | } | ||
391 | 378 | ||
392 | put_online_cpus(); | 379 | #endif |
393 | 380 | ||
394 | return err; | 381 | static int reserve_ds_buffers(void); |
395 | } | 382 | static void release_ds_buffers(void); |
396 | 383 | ||
397 | static void hw_perf_event_destroy(struct perf_event *event) | 384 | static void hw_perf_event_destroy(struct perf_event *event) |
398 | { | 385 | { |
399 | if (atomic_dec_and_mutex_lock(&active_events, &pmc_reserve_mutex)) { | 386 | if (atomic_dec_and_mutex_lock(&active_events, &pmc_reserve_mutex)) { |
400 | release_pmc_hardware(); | 387 | release_pmc_hardware(); |
401 | release_bts_hardware(); | 388 | release_ds_buffers(); |
402 | mutex_unlock(&pmc_reserve_mutex); | 389 | mutex_unlock(&pmc_reserve_mutex); |
403 | } | 390 | } |
404 | } | 391 | } |
@@ -441,54 +428,11 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr) | |||
441 | return 0; | 428 | return 0; |
442 | } | 429 | } |
443 | 430 | ||
444 | /* | 431 | static int x86_setup_perfctr(struct perf_event *event) |
445 | * Setup the hardware configuration for a given attr_type | ||
446 | */ | ||
447 | static int __hw_perf_event_init(struct perf_event *event) | ||
448 | { | 432 | { |
449 | struct perf_event_attr *attr = &event->attr; | 433 | struct perf_event_attr *attr = &event->attr; |
450 | struct hw_perf_event *hwc = &event->hw; | 434 | struct hw_perf_event *hwc = &event->hw; |
451 | u64 config; | 435 | u64 config; |
452 | int err; | ||
453 | |||
454 | if (!x86_pmu_initialized()) | ||
455 | return -ENODEV; | ||
456 | |||
457 | err = 0; | ||
458 | if (!atomic_inc_not_zero(&active_events)) { | ||
459 | mutex_lock(&pmc_reserve_mutex); | ||
460 | if (atomic_read(&active_events) == 0) { | ||
461 | if (!reserve_pmc_hardware()) | ||
462 | err = -EBUSY; | ||
463 | else | ||
464 | err = reserve_bts_hardware(); | ||
465 | } | ||
466 | if (!err) | ||
467 | atomic_inc(&active_events); | ||
468 | mutex_unlock(&pmc_reserve_mutex); | ||
469 | } | ||
470 | if (err) | ||
471 | return err; | ||
472 | |||
473 | event->destroy = hw_perf_event_destroy; | ||
474 | |||
475 | /* | ||
476 | * Generate PMC IRQs: | ||
477 | * (keep 'enabled' bit clear for now) | ||
478 | */ | ||
479 | hwc->config = ARCH_PERFMON_EVENTSEL_INT; | ||
480 | |||
481 | hwc->idx = -1; | ||
482 | hwc->last_cpu = -1; | ||
483 | hwc->last_tag = ~0ULL; | ||
484 | |||
485 | /* | ||
486 | * Count user and OS events unless requested not to. | ||
487 | */ | ||
488 | if (!attr->exclude_user) | ||
489 | hwc->config |= ARCH_PERFMON_EVENTSEL_USR; | ||
490 | if (!attr->exclude_kernel) | ||
491 | hwc->config |= ARCH_PERFMON_EVENTSEL_OS; | ||
492 | 436 | ||
493 | if (!hwc->sample_period) { | 437 | if (!hwc->sample_period) { |
494 | hwc->sample_period = x86_pmu.max_period; | 438 | hwc->sample_period = x86_pmu.max_period; |
@@ -505,16 +449,8 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
505 | return -EOPNOTSUPP; | 449 | return -EOPNOTSUPP; |
506 | } | 450 | } |
507 | 451 | ||
508 | /* | 452 | if (attr->type == PERF_TYPE_RAW) |
509 | * Raw hw_event type provide the config in the hw_event structure | ||
510 | */ | ||
511 | if (attr->type == PERF_TYPE_RAW) { | ||
512 | hwc->config |= x86_pmu.raw_event(attr->config); | ||
513 | if ((hwc->config & ARCH_PERFMON_EVENTSEL_ANY) && | ||
514 | perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
515 | return -EACCES; | ||
516 | return 0; | 453 | return 0; |
517 | } | ||
518 | 454 | ||
519 | if (attr->type == PERF_TYPE_HW_CACHE) | 455 | if (attr->type == PERF_TYPE_HW_CACHE) |
520 | return set_ext_hw_attr(hwc, attr); | 456 | return set_ext_hw_attr(hwc, attr); |
@@ -539,11 +475,11 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
539 | if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && | 475 | if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) && |
540 | (hwc->sample_period == 1)) { | 476 | (hwc->sample_period == 1)) { |
541 | /* BTS is not supported by this architecture. */ | 477 | /* BTS is not supported by this architecture. */ |
542 | if (!bts_available()) | 478 | if (!x86_pmu.bts) |
543 | return -EOPNOTSUPP; | 479 | return -EOPNOTSUPP; |
544 | 480 | ||
545 | /* BTS is currently only allowed for user-mode. */ | 481 | /* BTS is currently only allowed for user-mode. */ |
546 | if (hwc->config & ARCH_PERFMON_EVENTSEL_OS) | 482 | if (!attr->exclude_kernel) |
547 | return -EOPNOTSUPP; | 483 | return -EOPNOTSUPP; |
548 | } | 484 | } |
549 | 485 | ||
@@ -552,12 +488,87 @@ static int __hw_perf_event_init(struct perf_event *event) | |||
552 | return 0; | 488 | return 0; |
553 | } | 489 | } |
554 | 490 | ||
491 | static int x86_pmu_hw_config(struct perf_event *event) | ||
492 | { | ||
493 | if (event->attr.precise_ip) { | ||
494 | int precise = 0; | ||
495 | |||
496 | /* Support for constant skid */ | ||
497 | if (x86_pmu.pebs) | ||
498 | precise++; | ||
499 | |||
500 | /* Support for IP fixup */ | ||
501 | if (x86_pmu.lbr_nr) | ||
502 | precise++; | ||
503 | |||
504 | if (event->attr.precise_ip > precise) | ||
505 | return -EOPNOTSUPP; | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * Generate PMC IRQs: | ||
510 | * (keep 'enabled' bit clear for now) | ||
511 | */ | ||
512 | event->hw.config = ARCH_PERFMON_EVENTSEL_INT; | ||
513 | |||
514 | /* | ||
515 | * Count user and OS events unless requested not to | ||
516 | */ | ||
517 | if (!event->attr.exclude_user) | ||
518 | event->hw.config |= ARCH_PERFMON_EVENTSEL_USR; | ||
519 | if (!event->attr.exclude_kernel) | ||
520 | event->hw.config |= ARCH_PERFMON_EVENTSEL_OS; | ||
521 | |||
522 | if (event->attr.type == PERF_TYPE_RAW) | ||
523 | event->hw.config |= event->attr.config & X86_RAW_EVENT_MASK; | ||
524 | |||
525 | return x86_setup_perfctr(event); | ||
526 | } | ||
527 | |||
528 | /* | ||
529 | * Setup the hardware configuration for a given attr_type | ||
530 | */ | ||
531 | static int __hw_perf_event_init(struct perf_event *event) | ||
532 | { | ||
533 | int err; | ||
534 | |||
535 | if (!x86_pmu_initialized()) | ||
536 | return -ENODEV; | ||
537 | |||
538 | err = 0; | ||
539 | if (!atomic_inc_not_zero(&active_events)) { | ||
540 | mutex_lock(&pmc_reserve_mutex); | ||
541 | if (atomic_read(&active_events) == 0) { | ||
542 | if (!reserve_pmc_hardware()) | ||
543 | err = -EBUSY; | ||
544 | else { | ||
545 | err = reserve_ds_buffers(); | ||
546 | if (err) | ||
547 | release_pmc_hardware(); | ||
548 | } | ||
549 | } | ||
550 | if (!err) | ||
551 | atomic_inc(&active_events); | ||
552 | mutex_unlock(&pmc_reserve_mutex); | ||
553 | } | ||
554 | if (err) | ||
555 | return err; | ||
556 | |||
557 | event->destroy = hw_perf_event_destroy; | ||
558 | |||
559 | event->hw.idx = -1; | ||
560 | event->hw.last_cpu = -1; | ||
561 | event->hw.last_tag = ~0ULL; | ||
562 | |||
563 | return x86_pmu.hw_config(event); | ||
564 | } | ||
565 | |||
555 | static void x86_pmu_disable_all(void) | 566 | static void x86_pmu_disable_all(void) |
556 | { | 567 | { |
557 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 568 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
558 | int idx; | 569 | int idx; |
559 | 570 | ||
560 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 571 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
561 | u64 val; | 572 | u64 val; |
562 | 573 | ||
563 | if (!test_bit(idx, cpuc->active_mask)) | 574 | if (!test_bit(idx, cpuc->active_mask)) |
@@ -587,12 +598,12 @@ void hw_perf_disable(void) | |||
587 | x86_pmu.disable_all(); | 598 | x86_pmu.disable_all(); |
588 | } | 599 | } |
589 | 600 | ||
590 | static void x86_pmu_enable_all(void) | 601 | static void x86_pmu_enable_all(int added) |
591 | { | 602 | { |
592 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 603 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
593 | int idx; | 604 | int idx; |
594 | 605 | ||
595 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 606 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
596 | struct perf_event *event = cpuc->events[idx]; | 607 | struct perf_event *event = cpuc->events[idx]; |
597 | u64 val; | 608 | u64 val; |
598 | 609 | ||
@@ -667,14 +678,14 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | |||
667 | * assign events to counters starting with most | 678 | * assign events to counters starting with most |
668 | * constrained events. | 679 | * constrained events. |
669 | */ | 680 | */ |
670 | wmax = x86_pmu.num_events; | 681 | wmax = x86_pmu.num_counters; |
671 | 682 | ||
672 | /* | 683 | /* |
673 | * when fixed event counters are present, | 684 | * when fixed event counters are present, |
674 | * wmax is incremented by 1 to account | 685 | * wmax is incremented by 1 to account |
675 | * for one more choice | 686 | * for one more choice |
676 | */ | 687 | */ |
677 | if (x86_pmu.num_events_fixed) | 688 | if (x86_pmu.num_counters_fixed) |
678 | wmax++; | 689 | wmax++; |
679 | 690 | ||
680 | for (w = 1, num = n; num && w <= wmax; w++) { | 691 | for (w = 1, num = n; num && w <= wmax; w++) { |
@@ -724,7 +735,7 @@ static int collect_events(struct cpu_hw_events *cpuc, struct perf_event *leader, | |||
724 | struct perf_event *event; | 735 | struct perf_event *event; |
725 | int n, max_count; | 736 | int n, max_count; |
726 | 737 | ||
727 | max_count = x86_pmu.num_events + x86_pmu.num_events_fixed; | 738 | max_count = x86_pmu.num_counters + x86_pmu.num_counters_fixed; |
728 | 739 | ||
729 | /* current number of events already accepted */ | 740 | /* current number of events already accepted */ |
730 | n = cpuc->n_events; | 741 | n = cpuc->n_events; |
@@ -795,7 +806,7 @@ void hw_perf_enable(void) | |||
795 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 806 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
796 | struct perf_event *event; | 807 | struct perf_event *event; |
797 | struct hw_perf_event *hwc; | 808 | struct hw_perf_event *hwc; |
798 | int i; | 809 | int i, added = cpuc->n_added; |
799 | 810 | ||
800 | if (!x86_pmu_initialized()) | 811 | if (!x86_pmu_initialized()) |
801 | return; | 812 | return; |
@@ -847,19 +858,20 @@ void hw_perf_enable(void) | |||
847 | cpuc->enabled = 1; | 858 | cpuc->enabled = 1; |
848 | barrier(); | 859 | barrier(); |
849 | 860 | ||
850 | x86_pmu.enable_all(); | 861 | x86_pmu.enable_all(added); |
851 | } | 862 | } |
852 | 863 | ||
853 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc) | 864 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, |
865 | u64 enable_mask) | ||
854 | { | 866 | { |
855 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | 867 | wrmsrl(hwc->config_base + hwc->idx, hwc->config | enable_mask); |
856 | hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE); | ||
857 | } | 868 | } |
858 | 869 | ||
859 | static inline void x86_pmu_disable_event(struct perf_event *event) | 870 | static inline void x86_pmu_disable_event(struct perf_event *event) |
860 | { | 871 | { |
861 | struct hw_perf_event *hwc = &event->hw; | 872 | struct hw_perf_event *hwc = &event->hw; |
862 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, hwc->config); | 873 | |
874 | wrmsrl(hwc->config_base + hwc->idx, hwc->config); | ||
863 | } | 875 | } |
864 | 876 | ||
865 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); | 877 | static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left); |
@@ -874,7 +886,7 @@ x86_perf_event_set_period(struct perf_event *event) | |||
874 | struct hw_perf_event *hwc = &event->hw; | 886 | struct hw_perf_event *hwc = &event->hw; |
875 | s64 left = atomic64_read(&hwc->period_left); | 887 | s64 left = atomic64_read(&hwc->period_left); |
876 | s64 period = hwc->sample_period; | 888 | s64 period = hwc->sample_period; |
877 | int err, ret = 0, idx = hwc->idx; | 889 | int ret = 0, idx = hwc->idx; |
878 | 890 | ||
879 | if (idx == X86_PMC_IDX_FIXED_BTS) | 891 | if (idx == X86_PMC_IDX_FIXED_BTS) |
880 | return 0; | 892 | return 0; |
@@ -912,8 +924,8 @@ x86_perf_event_set_period(struct perf_event *event) | |||
912 | */ | 924 | */ |
913 | atomic64_set(&hwc->prev_count, (u64)-left); | 925 | atomic64_set(&hwc->prev_count, (u64)-left); |
914 | 926 | ||
915 | err = checking_wrmsrl(hwc->event_base + idx, | 927 | wrmsrl(hwc->event_base + idx, |
916 | (u64)(-left) & x86_pmu.event_mask); | 928 | (u64)(-left) & x86_pmu.cntval_mask); |
917 | 929 | ||
918 | perf_event_update_userpage(event); | 930 | perf_event_update_userpage(event); |
919 | 931 | ||
@@ -924,7 +936,8 @@ static void x86_pmu_enable_event(struct perf_event *event) | |||
924 | { | 936 | { |
925 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 937 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
926 | if (cpuc->enabled) | 938 | if (cpuc->enabled) |
927 | __x86_pmu_enable_event(&event->hw); | 939 | __x86_pmu_enable_event(&event->hw, |
940 | ARCH_PERFMON_EVENTSEL_ENABLE); | ||
928 | } | 941 | } |
929 | 942 | ||
930 | /* | 943 | /* |
@@ -950,7 +963,15 @@ static int x86_pmu_enable(struct perf_event *event) | |||
950 | if (n < 0) | 963 | if (n < 0) |
951 | return n; | 964 | return n; |
952 | 965 | ||
953 | ret = x86_schedule_events(cpuc, n, assign); | 966 | /* |
967 | * If group events scheduling transaction was started, | ||
968 | * skip the schedulability test here, it will be peformed | ||
969 | * at commit time(->commit_txn) as a whole | ||
970 | */ | ||
971 | if (cpuc->group_flag & PERF_EVENT_TXN_STARTED) | ||
972 | goto out; | ||
973 | |||
974 | ret = x86_pmu.schedule_events(cpuc, n, assign); | ||
954 | if (ret) | 975 | if (ret) |
955 | return ret; | 976 | return ret; |
956 | /* | 977 | /* |
@@ -959,6 +980,7 @@ static int x86_pmu_enable(struct perf_event *event) | |||
959 | */ | 980 | */ |
960 | memcpy(cpuc->assign, assign, n*sizeof(int)); | 981 | memcpy(cpuc->assign, assign, n*sizeof(int)); |
961 | 982 | ||
983 | out: | ||
962 | cpuc->n_events = n; | 984 | cpuc->n_events = n; |
963 | cpuc->n_added += n - n0; | 985 | cpuc->n_added += n - n0; |
964 | 986 | ||
@@ -991,11 +1013,12 @@ static void x86_pmu_unthrottle(struct perf_event *event) | |||
991 | void perf_event_print_debug(void) | 1013 | void perf_event_print_debug(void) |
992 | { | 1014 | { |
993 | u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed; | 1015 | u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed; |
1016 | u64 pebs; | ||
994 | struct cpu_hw_events *cpuc; | 1017 | struct cpu_hw_events *cpuc; |
995 | unsigned long flags; | 1018 | unsigned long flags; |
996 | int cpu, idx; | 1019 | int cpu, idx; |
997 | 1020 | ||
998 | if (!x86_pmu.num_events) | 1021 | if (!x86_pmu.num_counters) |
999 | return; | 1022 | return; |
1000 | 1023 | ||
1001 | local_irq_save(flags); | 1024 | local_irq_save(flags); |
@@ -1008,16 +1031,18 @@ void perf_event_print_debug(void) | |||
1008 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); | 1031 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); |
1009 | rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow); | 1032 | rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow); |
1010 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed); | 1033 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed); |
1034 | rdmsrl(MSR_IA32_PEBS_ENABLE, pebs); | ||
1011 | 1035 | ||
1012 | pr_info("\n"); | 1036 | pr_info("\n"); |
1013 | pr_info("CPU#%d: ctrl: %016llx\n", cpu, ctrl); | 1037 | pr_info("CPU#%d: ctrl: %016llx\n", cpu, ctrl); |
1014 | pr_info("CPU#%d: status: %016llx\n", cpu, status); | 1038 | pr_info("CPU#%d: status: %016llx\n", cpu, status); |
1015 | pr_info("CPU#%d: overflow: %016llx\n", cpu, overflow); | 1039 | pr_info("CPU#%d: overflow: %016llx\n", cpu, overflow); |
1016 | pr_info("CPU#%d: fixed: %016llx\n", cpu, fixed); | 1040 | pr_info("CPU#%d: fixed: %016llx\n", cpu, fixed); |
1041 | pr_info("CPU#%d: pebs: %016llx\n", cpu, pebs); | ||
1017 | } | 1042 | } |
1018 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); | 1043 | pr_info("CPU#%d: active: %016llx\n", cpu, *(u64 *)cpuc->active_mask); |
1019 | 1044 | ||
1020 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 1045 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1021 | rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl); | 1046 | rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl); |
1022 | rdmsrl(x86_pmu.perfctr + idx, pmc_count); | 1047 | rdmsrl(x86_pmu.perfctr + idx, pmc_count); |
1023 | 1048 | ||
@@ -1030,7 +1055,7 @@ void perf_event_print_debug(void) | |||
1030 | pr_info("CPU#%d: gen-PMC%d left: %016llx\n", | 1055 | pr_info("CPU#%d: gen-PMC%d left: %016llx\n", |
1031 | cpu, idx, prev_left); | 1056 | cpu, idx, prev_left); |
1032 | } | 1057 | } |
1033 | for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) { | 1058 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) { |
1034 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count); | 1059 | rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count); |
1035 | 1060 | ||
1036 | pr_info("CPU#%d: fixed-PMC%d count: %016llx\n", | 1061 | pr_info("CPU#%d: fixed-PMC%d count: %016llx\n", |
@@ -1095,7 +1120,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1095 | 1120 | ||
1096 | cpuc = &__get_cpu_var(cpu_hw_events); | 1121 | cpuc = &__get_cpu_var(cpu_hw_events); |
1097 | 1122 | ||
1098 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 1123 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
1099 | if (!test_bit(idx, cpuc->active_mask)) | 1124 | if (!test_bit(idx, cpuc->active_mask)) |
1100 | continue; | 1125 | continue; |
1101 | 1126 | ||
@@ -1103,7 +1128,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs) | |||
1103 | hwc = &event->hw; | 1128 | hwc = &event->hw; |
1104 | 1129 | ||
1105 | val = x86_perf_event_update(event); | 1130 | val = x86_perf_event_update(event); |
1106 | if (val & (1ULL << (x86_pmu.event_bits - 1))) | 1131 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) |
1107 | continue; | 1132 | continue; |
1108 | 1133 | ||
1109 | /* | 1134 | /* |
@@ -1146,7 +1171,6 @@ void set_perf_event_pending(void) | |||
1146 | 1171 | ||
1147 | void perf_events_lapic_init(void) | 1172 | void perf_events_lapic_init(void) |
1148 | { | 1173 | { |
1149 | #ifdef CONFIG_X86_LOCAL_APIC | ||
1150 | if (!x86_pmu.apic || !x86_pmu_initialized()) | 1174 | if (!x86_pmu.apic || !x86_pmu_initialized()) |
1151 | return; | 1175 | return; |
1152 | 1176 | ||
@@ -1154,7 +1178,6 @@ void perf_events_lapic_init(void) | |||
1154 | * Always use NMI for PMU | 1178 | * Always use NMI for PMU |
1155 | */ | 1179 | */ |
1156 | apic_write(APIC_LVTPC, APIC_DM_NMI); | 1180 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
1157 | #endif | ||
1158 | } | 1181 | } |
1159 | 1182 | ||
1160 | static int __kprobes | 1183 | static int __kprobes |
@@ -1178,9 +1201,7 @@ perf_event_nmi_handler(struct notifier_block *self, | |||
1178 | 1201 | ||
1179 | regs = args->regs; | 1202 | regs = args->regs; |
1180 | 1203 | ||
1181 | #ifdef CONFIG_X86_LOCAL_APIC | ||
1182 | apic_write(APIC_LVTPC, APIC_DM_NMI); | 1204 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
1183 | #endif | ||
1184 | /* | 1205 | /* |
1185 | * Can't rely on the handled return value to say it was our NMI, two | 1206 | * Can't rely on the handled return value to say it was our NMI, two |
1186 | * events could trigger 'simultaneously' raising two back-to-back NMIs. | 1207 | * events could trigger 'simultaneously' raising two back-to-back NMIs. |
@@ -1217,118 +1238,11 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |||
1217 | return &unconstrained; | 1238 | return &unconstrained; |
1218 | } | 1239 | } |
1219 | 1240 | ||
1220 | static int x86_event_sched_in(struct perf_event *event, | ||
1221 | struct perf_cpu_context *cpuctx) | ||
1222 | { | ||
1223 | int ret = 0; | ||
1224 | |||
1225 | event->state = PERF_EVENT_STATE_ACTIVE; | ||
1226 | event->oncpu = smp_processor_id(); | ||
1227 | event->tstamp_running += event->ctx->time - event->tstamp_stopped; | ||
1228 | |||
1229 | if (!is_x86_event(event)) | ||
1230 | ret = event->pmu->enable(event); | ||
1231 | |||
1232 | if (!ret && !is_software_event(event)) | ||
1233 | cpuctx->active_oncpu++; | ||
1234 | |||
1235 | if (!ret && event->attr.exclusive) | ||
1236 | cpuctx->exclusive = 1; | ||
1237 | |||
1238 | return ret; | ||
1239 | } | ||
1240 | |||
1241 | static void x86_event_sched_out(struct perf_event *event, | ||
1242 | struct perf_cpu_context *cpuctx) | ||
1243 | { | ||
1244 | event->state = PERF_EVENT_STATE_INACTIVE; | ||
1245 | event->oncpu = -1; | ||
1246 | |||
1247 | if (!is_x86_event(event)) | ||
1248 | event->pmu->disable(event); | ||
1249 | |||
1250 | event->tstamp_running -= event->ctx->time - event->tstamp_stopped; | ||
1251 | |||
1252 | if (!is_software_event(event)) | ||
1253 | cpuctx->active_oncpu--; | ||
1254 | |||
1255 | if (event->attr.exclusive || !cpuctx->active_oncpu) | ||
1256 | cpuctx->exclusive = 0; | ||
1257 | } | ||
1258 | |||
1259 | /* | ||
1260 | * Called to enable a whole group of events. | ||
1261 | * Returns 1 if the group was enabled, or -EAGAIN if it could not be. | ||
1262 | * Assumes the caller has disabled interrupts and has | ||
1263 | * frozen the PMU with hw_perf_save_disable. | ||
1264 | * | ||
1265 | * called with PMU disabled. If successful and return value 1, | ||
1266 | * then guaranteed to call perf_enable() and hw_perf_enable() | ||
1267 | */ | ||
1268 | int hw_perf_group_sched_in(struct perf_event *leader, | ||
1269 | struct perf_cpu_context *cpuctx, | ||
1270 | struct perf_event_context *ctx) | ||
1271 | { | ||
1272 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1273 | struct perf_event *sub; | ||
1274 | int assign[X86_PMC_IDX_MAX]; | ||
1275 | int n0, n1, ret; | ||
1276 | |||
1277 | /* n0 = total number of events */ | ||
1278 | n0 = collect_events(cpuc, leader, true); | ||
1279 | if (n0 < 0) | ||
1280 | return n0; | ||
1281 | |||
1282 | ret = x86_schedule_events(cpuc, n0, assign); | ||
1283 | if (ret) | ||
1284 | return ret; | ||
1285 | |||
1286 | ret = x86_event_sched_in(leader, cpuctx); | ||
1287 | if (ret) | ||
1288 | return ret; | ||
1289 | |||
1290 | n1 = 1; | ||
1291 | list_for_each_entry(sub, &leader->sibling_list, group_entry) { | ||
1292 | if (sub->state > PERF_EVENT_STATE_OFF) { | ||
1293 | ret = x86_event_sched_in(sub, cpuctx); | ||
1294 | if (ret) | ||
1295 | goto undo; | ||
1296 | ++n1; | ||
1297 | } | ||
1298 | } | ||
1299 | /* | ||
1300 | * copy new assignment, now we know it is possible | ||
1301 | * will be used by hw_perf_enable() | ||
1302 | */ | ||
1303 | memcpy(cpuc->assign, assign, n0*sizeof(int)); | ||
1304 | |||
1305 | cpuc->n_events = n0; | ||
1306 | cpuc->n_added += n1; | ||
1307 | ctx->nr_active += n1; | ||
1308 | |||
1309 | /* | ||
1310 | * 1 means successful and events are active | ||
1311 | * This is not quite true because we defer | ||
1312 | * actual activation until hw_perf_enable() but | ||
1313 | * this way we* ensure caller won't try to enable | ||
1314 | * individual events | ||
1315 | */ | ||
1316 | return 1; | ||
1317 | undo: | ||
1318 | x86_event_sched_out(leader, cpuctx); | ||
1319 | n0 = 1; | ||
1320 | list_for_each_entry(sub, &leader->sibling_list, group_entry) { | ||
1321 | if (sub->state == PERF_EVENT_STATE_ACTIVE) { | ||
1322 | x86_event_sched_out(sub, cpuctx); | ||
1323 | if (++n0 == n1) | ||
1324 | break; | ||
1325 | } | ||
1326 | } | ||
1327 | return ret; | ||
1328 | } | ||
1329 | |||
1330 | #include "perf_event_amd.c" | 1241 | #include "perf_event_amd.c" |
1331 | #include "perf_event_p6.c" | 1242 | #include "perf_event_p6.c" |
1243 | #include "perf_event_p4.c" | ||
1244 | #include "perf_event_intel_lbr.c" | ||
1245 | #include "perf_event_intel_ds.c" | ||
1332 | #include "perf_event_intel.c" | 1246 | #include "perf_event_intel.c" |
1333 | 1247 | ||
1334 | static int __cpuinit | 1248 | static int __cpuinit |
@@ -1402,48 +1316,50 @@ void __init init_hw_perf_events(void) | |||
1402 | 1316 | ||
1403 | pr_cont("%s PMU driver.\n", x86_pmu.name); | 1317 | pr_cont("%s PMU driver.\n", x86_pmu.name); |
1404 | 1318 | ||
1405 | if (x86_pmu.num_events > X86_PMC_MAX_GENERIC) { | 1319 | if (x86_pmu.quirks) |
1320 | x86_pmu.quirks(); | ||
1321 | |||
1322 | if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) { | ||
1406 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", | 1323 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", |
1407 | x86_pmu.num_events, X86_PMC_MAX_GENERIC); | 1324 | x86_pmu.num_counters, X86_PMC_MAX_GENERIC); |
1408 | x86_pmu.num_events = X86_PMC_MAX_GENERIC; | 1325 | x86_pmu.num_counters = X86_PMC_MAX_GENERIC; |
1409 | } | 1326 | } |
1410 | perf_event_mask = (1 << x86_pmu.num_events) - 1; | 1327 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; |
1411 | perf_max_events = x86_pmu.num_events; | 1328 | perf_max_events = x86_pmu.num_counters; |
1412 | 1329 | ||
1413 | if (x86_pmu.num_events_fixed > X86_PMC_MAX_FIXED) { | 1330 | if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) { |
1414 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", | 1331 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", |
1415 | x86_pmu.num_events_fixed, X86_PMC_MAX_FIXED); | 1332 | x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED); |
1416 | x86_pmu.num_events_fixed = X86_PMC_MAX_FIXED; | 1333 | x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED; |
1417 | } | 1334 | } |
1418 | 1335 | ||
1419 | perf_event_mask |= | 1336 | x86_pmu.intel_ctrl |= |
1420 | ((1LL << x86_pmu.num_events_fixed)-1) << X86_PMC_IDX_FIXED; | 1337 | ((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED; |
1421 | x86_pmu.intel_ctrl = perf_event_mask; | ||
1422 | 1338 | ||
1423 | perf_events_lapic_init(); | 1339 | perf_events_lapic_init(); |
1424 | register_die_notifier(&perf_event_nmi_notifier); | 1340 | register_die_notifier(&perf_event_nmi_notifier); |
1425 | 1341 | ||
1426 | unconstrained = (struct event_constraint) | 1342 | unconstrained = (struct event_constraint) |
1427 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_events) - 1, | 1343 | __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_counters) - 1, |
1428 | 0, x86_pmu.num_events); | 1344 | 0, x86_pmu.num_counters); |
1429 | 1345 | ||
1430 | if (x86_pmu.event_constraints) { | 1346 | if (x86_pmu.event_constraints) { |
1431 | for_each_event_constraint(c, x86_pmu.event_constraints) { | 1347 | for_each_event_constraint(c, x86_pmu.event_constraints) { |
1432 | if (c->cmask != INTEL_ARCH_FIXED_MASK) | 1348 | if (c->cmask != X86_RAW_EVENT_MASK) |
1433 | continue; | 1349 | continue; |
1434 | 1350 | ||
1435 | c->idxmsk64 |= (1ULL << x86_pmu.num_events) - 1; | 1351 | c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; |
1436 | c->weight += x86_pmu.num_events; | 1352 | c->weight += x86_pmu.num_counters; |
1437 | } | 1353 | } |
1438 | } | 1354 | } |
1439 | 1355 | ||
1440 | pr_info("... version: %d\n", x86_pmu.version); | 1356 | pr_info("... version: %d\n", x86_pmu.version); |
1441 | pr_info("... bit width: %d\n", x86_pmu.event_bits); | 1357 | pr_info("... bit width: %d\n", x86_pmu.cntval_bits); |
1442 | pr_info("... generic registers: %d\n", x86_pmu.num_events); | 1358 | pr_info("... generic registers: %d\n", x86_pmu.num_counters); |
1443 | pr_info("... value mask: %016Lx\n", x86_pmu.event_mask); | 1359 | pr_info("... value mask: %016Lx\n", x86_pmu.cntval_mask); |
1444 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); | 1360 | pr_info("... max period: %016Lx\n", x86_pmu.max_period); |
1445 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_events_fixed); | 1361 | pr_info("... fixed-purpose events: %d\n", x86_pmu.num_counters_fixed); |
1446 | pr_info("... event mask: %016Lx\n", perf_event_mask); | 1362 | pr_info("... event mask: %016Lx\n", x86_pmu.intel_ctrl); |
1447 | 1363 | ||
1448 | perf_cpu_notifier(x86_pmu_notifier); | 1364 | perf_cpu_notifier(x86_pmu_notifier); |
1449 | } | 1365 | } |
@@ -1453,6 +1369,59 @@ static inline void x86_pmu_read(struct perf_event *event) | |||
1453 | x86_perf_event_update(event); | 1369 | x86_perf_event_update(event); |
1454 | } | 1370 | } |
1455 | 1371 | ||
1372 | /* | ||
1373 | * Start group events scheduling transaction | ||
1374 | * Set the flag to make pmu::enable() not perform the | ||
1375 | * schedulability test, it will be performed at commit time | ||
1376 | */ | ||
1377 | static void x86_pmu_start_txn(const struct pmu *pmu) | ||
1378 | { | ||
1379 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1380 | |||
1381 | cpuc->group_flag |= PERF_EVENT_TXN_STARTED; | ||
1382 | } | ||
1383 | |||
1384 | /* | ||
1385 | * Stop group events scheduling transaction | ||
1386 | * Clear the flag and pmu::enable() will perform the | ||
1387 | * schedulability test. | ||
1388 | */ | ||
1389 | static void x86_pmu_cancel_txn(const struct pmu *pmu) | ||
1390 | { | ||
1391 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1392 | |||
1393 | cpuc->group_flag &= ~PERF_EVENT_TXN_STARTED; | ||
1394 | } | ||
1395 | |||
1396 | /* | ||
1397 | * Commit group events scheduling transaction | ||
1398 | * Perform the group schedulability test as a whole | ||
1399 | * Return 0 if success | ||
1400 | */ | ||
1401 | static int x86_pmu_commit_txn(const struct pmu *pmu) | ||
1402 | { | ||
1403 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
1404 | int assign[X86_PMC_IDX_MAX]; | ||
1405 | int n, ret; | ||
1406 | |||
1407 | n = cpuc->n_events; | ||
1408 | |||
1409 | if (!x86_pmu_initialized()) | ||
1410 | return -EAGAIN; | ||
1411 | |||
1412 | ret = x86_pmu.schedule_events(cpuc, n, assign); | ||
1413 | if (ret) | ||
1414 | return ret; | ||
1415 | |||
1416 | /* | ||
1417 | * copy new assignment, now we know it is possible | ||
1418 | * will be used by hw_perf_enable() | ||
1419 | */ | ||
1420 | memcpy(cpuc->assign, assign, n*sizeof(int)); | ||
1421 | |||
1422 | return 0; | ||
1423 | } | ||
1424 | |||
1456 | static const struct pmu pmu = { | 1425 | static const struct pmu pmu = { |
1457 | .enable = x86_pmu_enable, | 1426 | .enable = x86_pmu_enable, |
1458 | .disable = x86_pmu_disable, | 1427 | .disable = x86_pmu_disable, |
@@ -1460,9 +1429,38 @@ static const struct pmu pmu = { | |||
1460 | .stop = x86_pmu_stop, | 1429 | .stop = x86_pmu_stop, |
1461 | .read = x86_pmu_read, | 1430 | .read = x86_pmu_read, |
1462 | .unthrottle = x86_pmu_unthrottle, | 1431 | .unthrottle = x86_pmu_unthrottle, |
1432 | .start_txn = x86_pmu_start_txn, | ||
1433 | .cancel_txn = x86_pmu_cancel_txn, | ||
1434 | .commit_txn = x86_pmu_commit_txn, | ||
1463 | }; | 1435 | }; |
1464 | 1436 | ||
1465 | /* | 1437 | /* |
1438 | * validate that we can schedule this event | ||
1439 | */ | ||
1440 | static int validate_event(struct perf_event *event) | ||
1441 | { | ||
1442 | struct cpu_hw_events *fake_cpuc; | ||
1443 | struct event_constraint *c; | ||
1444 | int ret = 0; | ||
1445 | |||
1446 | fake_cpuc = kmalloc(sizeof(*fake_cpuc), GFP_KERNEL | __GFP_ZERO); | ||
1447 | if (!fake_cpuc) | ||
1448 | return -ENOMEM; | ||
1449 | |||
1450 | c = x86_pmu.get_event_constraints(fake_cpuc, event); | ||
1451 | |||
1452 | if (!c || !c->weight) | ||
1453 | ret = -ENOSPC; | ||
1454 | |||
1455 | if (x86_pmu.put_event_constraints) | ||
1456 | x86_pmu.put_event_constraints(fake_cpuc, event); | ||
1457 | |||
1458 | kfree(fake_cpuc); | ||
1459 | |||
1460 | return ret; | ||
1461 | } | ||
1462 | |||
1463 | /* | ||
1466 | * validate a single event group | 1464 | * validate a single event group |
1467 | * | 1465 | * |
1468 | * validation include: | 1466 | * validation include: |
@@ -1502,7 +1500,7 @@ static int validate_group(struct perf_event *event) | |||
1502 | 1500 | ||
1503 | fake_cpuc->n_events = n; | 1501 | fake_cpuc->n_events = n; |
1504 | 1502 | ||
1505 | ret = x86_schedule_events(fake_cpuc, n, NULL); | 1503 | ret = x86_pmu.schedule_events(fake_cpuc, n, NULL); |
1506 | 1504 | ||
1507 | out_free: | 1505 | out_free: |
1508 | kfree(fake_cpuc); | 1506 | kfree(fake_cpuc); |
@@ -1527,6 +1525,8 @@ const struct pmu *hw_perf_event_init(struct perf_event *event) | |||
1527 | 1525 | ||
1528 | if (event->group_leader != event) | 1526 | if (event->group_leader != event) |
1529 | err = validate_group(event); | 1527 | err = validate_group(event); |
1528 | else | ||
1529 | err = validate_event(event); | ||
1530 | 1530 | ||
1531 | event->pmu = tmp; | 1531 | event->pmu = tmp; |
1532 | } | 1532 | } |
@@ -1574,8 +1574,7 @@ static void backtrace_address(void *data, unsigned long addr, int reliable) | |||
1574 | { | 1574 | { |
1575 | struct perf_callchain_entry *entry = data; | 1575 | struct perf_callchain_entry *entry = data; |
1576 | 1576 | ||
1577 | if (reliable) | 1577 | callchain_store(entry, addr); |
1578 | callchain_store(entry, addr); | ||
1579 | } | 1578 | } |
1580 | 1579 | ||
1581 | static const struct stacktrace_ops backtrace_ops = { | 1580 | static const struct stacktrace_ops backtrace_ops = { |
@@ -1597,41 +1596,6 @@ perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry) | |||
1597 | dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry); | 1596 | dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry); |
1598 | } | 1597 | } |
1599 | 1598 | ||
1600 | /* | ||
1601 | * best effort, GUP based copy_from_user() that assumes IRQ or NMI context | ||
1602 | */ | ||
1603 | static unsigned long | ||
1604 | copy_from_user_nmi(void *to, const void __user *from, unsigned long n) | ||
1605 | { | ||
1606 | unsigned long offset, addr = (unsigned long)from; | ||
1607 | int type = in_nmi() ? KM_NMI : KM_IRQ0; | ||
1608 | unsigned long size, len = 0; | ||
1609 | struct page *page; | ||
1610 | void *map; | ||
1611 | int ret; | ||
1612 | |||
1613 | do { | ||
1614 | ret = __get_user_pages_fast(addr, 1, 0, &page); | ||
1615 | if (!ret) | ||
1616 | break; | ||
1617 | |||
1618 | offset = addr & (PAGE_SIZE - 1); | ||
1619 | size = min(PAGE_SIZE - offset, n - len); | ||
1620 | |||
1621 | map = kmap_atomic(page, type); | ||
1622 | memcpy(to, map+offset, size); | ||
1623 | kunmap_atomic(map, type); | ||
1624 | put_page(page); | ||
1625 | |||
1626 | len += size; | ||
1627 | to += size; | ||
1628 | addr += size; | ||
1629 | |||
1630 | } while (len < n); | ||
1631 | |||
1632 | return len; | ||
1633 | } | ||
1634 | |||
1635 | #ifdef CONFIG_COMPAT | 1599 | #ifdef CONFIG_COMPAT |
1636 | static inline int | 1600 | static inline int |
1637 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) | 1601 | perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry) |
@@ -1727,6 +1691,11 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs) | |||
1727 | { | 1691 | { |
1728 | struct perf_callchain_entry *entry; | 1692 | struct perf_callchain_entry *entry; |
1729 | 1693 | ||
1694 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { | ||
1695 | /* TODO: We don't support guest os callchain now */ | ||
1696 | return NULL; | ||
1697 | } | ||
1698 | |||
1730 | if (in_nmi()) | 1699 | if (in_nmi()) |
1731 | entry = &__get_cpu_var(pmc_nmi_entry); | 1700 | entry = &__get_cpu_var(pmc_nmi_entry); |
1732 | else | 1701 | else |
@@ -1750,3 +1719,37 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski | |||
1750 | regs->cs = __KERNEL_CS; | 1719 | regs->cs = __KERNEL_CS; |
1751 | local_save_flags(regs->flags); | 1720 | local_save_flags(regs->flags); |
1752 | } | 1721 | } |
1722 | |||
1723 | unsigned long perf_instruction_pointer(struct pt_regs *regs) | ||
1724 | { | ||
1725 | unsigned long ip; | ||
1726 | |||
1727 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) | ||
1728 | ip = perf_guest_cbs->get_guest_ip(); | ||
1729 | else | ||
1730 | ip = instruction_pointer(regs); | ||
1731 | |||
1732 | return ip; | ||
1733 | } | ||
1734 | |||
1735 | unsigned long perf_misc_flags(struct pt_regs *regs) | ||
1736 | { | ||
1737 | int misc = 0; | ||
1738 | |||
1739 | if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { | ||
1740 | if (perf_guest_cbs->is_user_mode()) | ||
1741 | misc |= PERF_RECORD_MISC_GUEST_USER; | ||
1742 | else | ||
1743 | misc |= PERF_RECORD_MISC_GUEST_KERNEL; | ||
1744 | } else { | ||
1745 | if (user_mode(regs)) | ||
1746 | misc |= PERF_RECORD_MISC_USER; | ||
1747 | else | ||
1748 | misc |= PERF_RECORD_MISC_KERNEL; | ||
1749 | } | ||
1750 | |||
1751 | if (regs->flags & PERF_EFLAGS_EXACT) | ||
1752 | misc |= PERF_RECORD_MISC_EXACT_IP; | ||
1753 | |||
1754 | return misc; | ||
1755 | } | ||
diff --git a/arch/x86/kernel/cpu/perf_event_amd.c b/arch/x86/kernel/cpu/perf_event_amd.c index db6f7d4056e1..611df11ba15e 100644 --- a/arch/x86/kernel/cpu/perf_event_amd.c +++ b/arch/x86/kernel/cpu/perf_event_amd.c | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | static DEFINE_RAW_SPINLOCK(amd_nb_lock); | 3 | static DEFINE_RAW_SPINLOCK(amd_nb_lock); |
4 | 4 | ||
5 | static __initconst u64 amd_hw_cache_event_ids | 5 | static __initconst const u64 amd_hw_cache_event_ids |
6 | [PERF_COUNT_HW_CACHE_MAX] | 6 | [PERF_COUNT_HW_CACHE_MAX] |
7 | [PERF_COUNT_HW_CACHE_OP_MAX] | 7 | [PERF_COUNT_HW_CACHE_OP_MAX] |
8 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 8 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -111,22 +111,19 @@ static u64 amd_pmu_event_map(int hw_event) | |||
111 | return amd_perfmon_event_map[hw_event]; | 111 | return amd_perfmon_event_map[hw_event]; |
112 | } | 112 | } |
113 | 113 | ||
114 | static u64 amd_pmu_raw_event(u64 hw_event) | 114 | static int amd_pmu_hw_config(struct perf_event *event) |
115 | { | 115 | { |
116 | #define K7_EVNTSEL_EVENT_MASK 0xF000000FFULL | 116 | int ret = x86_pmu_hw_config(event); |
117 | #define K7_EVNTSEL_UNIT_MASK 0x00000FF00ULL | 117 | |
118 | #define K7_EVNTSEL_EDGE_MASK 0x000040000ULL | 118 | if (ret) |
119 | #define K7_EVNTSEL_INV_MASK 0x000800000ULL | 119 | return ret; |
120 | #define K7_EVNTSEL_REG_MASK 0x0FF000000ULL | 120 | |
121 | 121 | if (event->attr.type != PERF_TYPE_RAW) | |
122 | #define K7_EVNTSEL_MASK \ | 122 | return 0; |
123 | (K7_EVNTSEL_EVENT_MASK | \ | 123 | |
124 | K7_EVNTSEL_UNIT_MASK | \ | 124 | event->hw.config |= event->attr.config & AMD64_RAW_EVENT_MASK; |
125 | K7_EVNTSEL_EDGE_MASK | \ | 125 | |
126 | K7_EVNTSEL_INV_MASK | \ | 126 | return 0; |
127 | K7_EVNTSEL_REG_MASK) | ||
128 | |||
129 | return hw_event & K7_EVNTSEL_MASK; | ||
130 | } | 127 | } |
131 | 128 | ||
132 | /* | 129 | /* |
@@ -165,7 +162,7 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc, | |||
165 | * be removed on one CPU at a time AND PMU is disabled | 162 | * be removed on one CPU at a time AND PMU is disabled |
166 | * when we come here | 163 | * when we come here |
167 | */ | 164 | */ |
168 | for (i = 0; i < x86_pmu.num_events; i++) { | 165 | for (i = 0; i < x86_pmu.num_counters; i++) { |
169 | if (nb->owners[i] == event) { | 166 | if (nb->owners[i] == event) { |
170 | cmpxchg(nb->owners+i, event, NULL); | 167 | cmpxchg(nb->owners+i, event, NULL); |
171 | break; | 168 | break; |
@@ -215,7 +212,7 @@ amd_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |||
215 | struct hw_perf_event *hwc = &event->hw; | 212 | struct hw_perf_event *hwc = &event->hw; |
216 | struct amd_nb *nb = cpuc->amd_nb; | 213 | struct amd_nb *nb = cpuc->amd_nb; |
217 | struct perf_event *old = NULL; | 214 | struct perf_event *old = NULL; |
218 | int max = x86_pmu.num_events; | 215 | int max = x86_pmu.num_counters; |
219 | int i, j, k = -1; | 216 | int i, j, k = -1; |
220 | 217 | ||
221 | /* | 218 | /* |
@@ -293,7 +290,7 @@ static struct amd_nb *amd_alloc_nb(int cpu, int nb_id) | |||
293 | /* | 290 | /* |
294 | * initialize all possible NB constraints | 291 | * initialize all possible NB constraints |
295 | */ | 292 | */ |
296 | for (i = 0; i < x86_pmu.num_events; i++) { | 293 | for (i = 0; i < x86_pmu.num_counters; i++) { |
297 | __set_bit(i, nb->event_constraints[i].idxmsk); | 294 | __set_bit(i, nb->event_constraints[i].idxmsk); |
298 | nb->event_constraints[i].weight = 1; | 295 | nb->event_constraints[i].weight = 1; |
299 | } | 296 | } |
@@ -371,21 +368,22 @@ static void amd_pmu_cpu_dead(int cpu) | |||
371 | raw_spin_unlock(&amd_nb_lock); | 368 | raw_spin_unlock(&amd_nb_lock); |
372 | } | 369 | } |
373 | 370 | ||
374 | static __initconst struct x86_pmu amd_pmu = { | 371 | static __initconst const struct x86_pmu amd_pmu = { |
375 | .name = "AMD", | 372 | .name = "AMD", |
376 | .handle_irq = x86_pmu_handle_irq, | 373 | .handle_irq = x86_pmu_handle_irq, |
377 | .disable_all = x86_pmu_disable_all, | 374 | .disable_all = x86_pmu_disable_all, |
378 | .enable_all = x86_pmu_enable_all, | 375 | .enable_all = x86_pmu_enable_all, |
379 | .enable = x86_pmu_enable_event, | 376 | .enable = x86_pmu_enable_event, |
380 | .disable = x86_pmu_disable_event, | 377 | .disable = x86_pmu_disable_event, |
378 | .hw_config = amd_pmu_hw_config, | ||
379 | .schedule_events = x86_schedule_events, | ||
381 | .eventsel = MSR_K7_EVNTSEL0, | 380 | .eventsel = MSR_K7_EVNTSEL0, |
382 | .perfctr = MSR_K7_PERFCTR0, | 381 | .perfctr = MSR_K7_PERFCTR0, |
383 | .event_map = amd_pmu_event_map, | 382 | .event_map = amd_pmu_event_map, |
384 | .raw_event = amd_pmu_raw_event, | ||
385 | .max_events = ARRAY_SIZE(amd_perfmon_event_map), | 383 | .max_events = ARRAY_SIZE(amd_perfmon_event_map), |
386 | .num_events = 4, | 384 | .num_counters = 4, |
387 | .event_bits = 48, | 385 | .cntval_bits = 48, |
388 | .event_mask = (1ULL << 48) - 1, | 386 | .cntval_mask = (1ULL << 48) - 1, |
389 | .apic = 1, | 387 | .apic = 1, |
390 | /* use highest bit to detect overflow */ | 388 | /* use highest bit to detect overflow */ |
391 | .max_period = (1ULL << 47) - 1, | 389 | .max_period = (1ULL << 47) - 1, |
diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c index 9c794ac87837..fdbc652d3feb 100644 --- a/arch/x86/kernel/cpu/perf_event_intel.c +++ b/arch/x86/kernel/cpu/perf_event_intel.c | |||
@@ -88,7 +88,7 @@ static u64 intel_pmu_event_map(int hw_event) | |||
88 | return intel_perfmon_event_map[hw_event]; | 88 | return intel_perfmon_event_map[hw_event]; |
89 | } | 89 | } |
90 | 90 | ||
91 | static __initconst u64 westmere_hw_cache_event_ids | 91 | static __initconst const u64 westmere_hw_cache_event_ids |
92 | [PERF_COUNT_HW_CACHE_MAX] | 92 | [PERF_COUNT_HW_CACHE_MAX] |
93 | [PERF_COUNT_HW_CACHE_OP_MAX] | 93 | [PERF_COUNT_HW_CACHE_OP_MAX] |
94 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 94 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -179,7 +179,7 @@ static __initconst u64 westmere_hw_cache_event_ids | |||
179 | }, | 179 | }, |
180 | }; | 180 | }; |
181 | 181 | ||
182 | static __initconst u64 nehalem_hw_cache_event_ids | 182 | static __initconst const u64 nehalem_hw_cache_event_ids |
183 | [PERF_COUNT_HW_CACHE_MAX] | 183 | [PERF_COUNT_HW_CACHE_MAX] |
184 | [PERF_COUNT_HW_CACHE_OP_MAX] | 184 | [PERF_COUNT_HW_CACHE_OP_MAX] |
185 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 185 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -270,7 +270,7 @@ static __initconst u64 nehalem_hw_cache_event_ids | |||
270 | }, | 270 | }, |
271 | }; | 271 | }; |
272 | 272 | ||
273 | static __initconst u64 core2_hw_cache_event_ids | 273 | static __initconst const u64 core2_hw_cache_event_ids |
274 | [PERF_COUNT_HW_CACHE_MAX] | 274 | [PERF_COUNT_HW_CACHE_MAX] |
275 | [PERF_COUNT_HW_CACHE_OP_MAX] | 275 | [PERF_COUNT_HW_CACHE_OP_MAX] |
276 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 276 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -361,7 +361,7 @@ static __initconst u64 core2_hw_cache_event_ids | |||
361 | }, | 361 | }, |
362 | }; | 362 | }; |
363 | 363 | ||
364 | static __initconst u64 atom_hw_cache_event_ids | 364 | static __initconst const u64 atom_hw_cache_event_ids |
365 | [PERF_COUNT_HW_CACHE_MAX] | 365 | [PERF_COUNT_HW_CACHE_MAX] |
366 | [PERF_COUNT_HW_CACHE_OP_MAX] | 366 | [PERF_COUNT_HW_CACHE_OP_MAX] |
367 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | 367 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = |
@@ -452,60 +452,6 @@ static __initconst u64 atom_hw_cache_event_ids | |||
452 | }, | 452 | }, |
453 | }; | 453 | }; |
454 | 454 | ||
455 | static u64 intel_pmu_raw_event(u64 hw_event) | ||
456 | { | ||
457 | #define CORE_EVNTSEL_EVENT_MASK 0x000000FFULL | ||
458 | #define CORE_EVNTSEL_UNIT_MASK 0x0000FF00ULL | ||
459 | #define CORE_EVNTSEL_EDGE_MASK 0x00040000ULL | ||
460 | #define CORE_EVNTSEL_INV_MASK 0x00800000ULL | ||
461 | #define CORE_EVNTSEL_REG_MASK 0xFF000000ULL | ||
462 | |||
463 | #define CORE_EVNTSEL_MASK \ | ||
464 | (INTEL_ARCH_EVTSEL_MASK | \ | ||
465 | INTEL_ARCH_UNIT_MASK | \ | ||
466 | INTEL_ARCH_EDGE_MASK | \ | ||
467 | INTEL_ARCH_INV_MASK | \ | ||
468 | INTEL_ARCH_CNT_MASK) | ||
469 | |||
470 | return hw_event & CORE_EVNTSEL_MASK; | ||
471 | } | ||
472 | |||
473 | static void intel_pmu_enable_bts(u64 config) | ||
474 | { | ||
475 | unsigned long debugctlmsr; | ||
476 | |||
477 | debugctlmsr = get_debugctlmsr(); | ||
478 | |||
479 | debugctlmsr |= X86_DEBUGCTL_TR; | ||
480 | debugctlmsr |= X86_DEBUGCTL_BTS; | ||
481 | debugctlmsr |= X86_DEBUGCTL_BTINT; | ||
482 | |||
483 | if (!(config & ARCH_PERFMON_EVENTSEL_OS)) | ||
484 | debugctlmsr |= X86_DEBUGCTL_BTS_OFF_OS; | ||
485 | |||
486 | if (!(config & ARCH_PERFMON_EVENTSEL_USR)) | ||
487 | debugctlmsr |= X86_DEBUGCTL_BTS_OFF_USR; | ||
488 | |||
489 | update_debugctlmsr(debugctlmsr); | ||
490 | } | ||
491 | |||
492 | static void intel_pmu_disable_bts(void) | ||
493 | { | ||
494 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
495 | unsigned long debugctlmsr; | ||
496 | |||
497 | if (!cpuc->ds) | ||
498 | return; | ||
499 | |||
500 | debugctlmsr = get_debugctlmsr(); | ||
501 | |||
502 | debugctlmsr &= | ||
503 | ~(X86_DEBUGCTL_TR | X86_DEBUGCTL_BTS | X86_DEBUGCTL_BTINT | | ||
504 | X86_DEBUGCTL_BTS_OFF_OS | X86_DEBUGCTL_BTS_OFF_USR); | ||
505 | |||
506 | update_debugctlmsr(debugctlmsr); | ||
507 | } | ||
508 | |||
509 | static void intel_pmu_disable_all(void) | 455 | static void intel_pmu_disable_all(void) |
510 | { | 456 | { |
511 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 457 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
@@ -514,12 +460,17 @@ static void intel_pmu_disable_all(void) | |||
514 | 460 | ||
515 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) | 461 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) |
516 | intel_pmu_disable_bts(); | 462 | intel_pmu_disable_bts(); |
463 | |||
464 | intel_pmu_pebs_disable_all(); | ||
465 | intel_pmu_lbr_disable_all(); | ||
517 | } | 466 | } |
518 | 467 | ||
519 | static void intel_pmu_enable_all(void) | 468 | static void intel_pmu_enable_all(int added) |
520 | { | 469 | { |
521 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | 470 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
522 | 471 | ||
472 | intel_pmu_pebs_enable_all(); | ||
473 | intel_pmu_lbr_enable_all(); | ||
523 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl); | 474 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl); |
524 | 475 | ||
525 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { | 476 | if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { |
@@ -533,6 +484,42 @@ static void intel_pmu_enable_all(void) | |||
533 | } | 484 | } |
534 | } | 485 | } |
535 | 486 | ||
487 | /* | ||
488 | * Workaround for: | ||
489 | * Intel Errata AAK100 (model 26) | ||
490 | * Intel Errata AAP53 (model 30) | ||
491 | * Intel Errata BD53 (model 44) | ||
492 | * | ||
493 | * These chips need to be 'reset' when adding counters by programming | ||
494 | * the magic three (non counting) events 0x4300D2, 0x4300B1 and 0x4300B5 | ||
495 | * either in sequence on the same PMC or on different PMCs. | ||
496 | */ | ||
497 | static void intel_pmu_nhm_enable_all(int added) | ||
498 | { | ||
499 | if (added) { | ||
500 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
501 | int i; | ||
502 | |||
503 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 0, 0x4300D2); | ||
504 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x4300B1); | ||
505 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x4300B5); | ||
506 | |||
507 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x3); | ||
508 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0); | ||
509 | |||
510 | for (i = 0; i < 3; i++) { | ||
511 | struct perf_event *event = cpuc->events[i]; | ||
512 | |||
513 | if (!event) | ||
514 | continue; | ||
515 | |||
516 | __x86_pmu_enable_event(&event->hw, | ||
517 | ARCH_PERFMON_EVENTSEL_ENABLE); | ||
518 | } | ||
519 | } | ||
520 | intel_pmu_enable_all(added); | ||
521 | } | ||
522 | |||
536 | static inline u64 intel_pmu_get_status(void) | 523 | static inline u64 intel_pmu_get_status(void) |
537 | { | 524 | { |
538 | u64 status; | 525 | u64 status; |
@@ -547,8 +534,7 @@ static inline void intel_pmu_ack_status(u64 ack) | |||
547 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); | 534 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); |
548 | } | 535 | } |
549 | 536 | ||
550 | static inline void | 537 | static void intel_pmu_disable_fixed(struct hw_perf_event *hwc) |
551 | intel_pmu_disable_fixed(struct hw_perf_event *hwc) | ||
552 | { | 538 | { |
553 | int idx = hwc->idx - X86_PMC_IDX_FIXED; | 539 | int idx = hwc->idx - X86_PMC_IDX_FIXED; |
554 | u64 ctrl_val, mask; | 540 | u64 ctrl_val, mask; |
@@ -557,71 +543,10 @@ intel_pmu_disable_fixed(struct hw_perf_event *hwc) | |||
557 | 543 | ||
558 | rdmsrl(hwc->config_base, ctrl_val); | 544 | rdmsrl(hwc->config_base, ctrl_val); |
559 | ctrl_val &= ~mask; | 545 | ctrl_val &= ~mask; |
560 | (void)checking_wrmsrl(hwc->config_base, ctrl_val); | 546 | wrmsrl(hwc->config_base, ctrl_val); |
561 | } | ||
562 | |||
563 | static void intel_pmu_drain_bts_buffer(void) | ||
564 | { | ||
565 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
566 | struct debug_store *ds = cpuc->ds; | ||
567 | struct bts_record { | ||
568 | u64 from; | ||
569 | u64 to; | ||
570 | u64 flags; | ||
571 | }; | ||
572 | struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS]; | ||
573 | struct bts_record *at, *top; | ||
574 | struct perf_output_handle handle; | ||
575 | struct perf_event_header header; | ||
576 | struct perf_sample_data data; | ||
577 | struct pt_regs regs; | ||
578 | |||
579 | if (!event) | ||
580 | return; | ||
581 | |||
582 | if (!ds) | ||
583 | return; | ||
584 | |||
585 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; | ||
586 | top = (struct bts_record *)(unsigned long)ds->bts_index; | ||
587 | |||
588 | if (top <= at) | ||
589 | return; | ||
590 | |||
591 | ds->bts_index = ds->bts_buffer_base; | ||
592 | |||
593 | perf_sample_data_init(&data, 0); | ||
594 | |||
595 | data.period = event->hw.last_period; | ||
596 | regs.ip = 0; | ||
597 | |||
598 | /* | ||
599 | * Prepare a generic sample, i.e. fill in the invariant fields. | ||
600 | * We will overwrite the from and to address before we output | ||
601 | * the sample. | ||
602 | */ | ||
603 | perf_prepare_sample(&header, &data, event, ®s); | ||
604 | |||
605 | if (perf_output_begin(&handle, event, | ||
606 | header.size * (top - at), 1, 1)) | ||
607 | return; | ||
608 | |||
609 | for (; at < top; at++) { | ||
610 | data.ip = at->from; | ||
611 | data.addr = at->to; | ||
612 | |||
613 | perf_output_sample(&handle, &header, &data, event); | ||
614 | } | ||
615 | |||
616 | perf_output_end(&handle); | ||
617 | |||
618 | /* There's new data available. */ | ||
619 | event->hw.interrupts++; | ||
620 | event->pending_kill = POLL_IN; | ||
621 | } | 547 | } |
622 | 548 | ||
623 | static inline void | 549 | static void intel_pmu_disable_event(struct perf_event *event) |
624 | intel_pmu_disable_event(struct perf_event *event) | ||
625 | { | 550 | { |
626 | struct hw_perf_event *hwc = &event->hw; | 551 | struct hw_perf_event *hwc = &event->hw; |
627 | 552 | ||
@@ -637,14 +562,15 @@ intel_pmu_disable_event(struct perf_event *event) | |||
637 | } | 562 | } |
638 | 563 | ||
639 | x86_pmu_disable_event(event); | 564 | x86_pmu_disable_event(event); |
565 | |||
566 | if (unlikely(event->attr.precise_ip)) | ||
567 | intel_pmu_pebs_disable(event); | ||
640 | } | 568 | } |
641 | 569 | ||
642 | static inline void | 570 | static void intel_pmu_enable_fixed(struct hw_perf_event *hwc) |
643 | intel_pmu_enable_fixed(struct hw_perf_event *hwc) | ||
644 | { | 571 | { |
645 | int idx = hwc->idx - X86_PMC_IDX_FIXED; | 572 | int idx = hwc->idx - X86_PMC_IDX_FIXED; |
646 | u64 ctrl_val, bits, mask; | 573 | u64 ctrl_val, bits, mask; |
647 | int err; | ||
648 | 574 | ||
649 | /* | 575 | /* |
650 | * Enable IRQ generation (0x8), | 576 | * Enable IRQ generation (0x8), |
@@ -669,7 +595,7 @@ intel_pmu_enable_fixed(struct hw_perf_event *hwc) | |||
669 | rdmsrl(hwc->config_base, ctrl_val); | 595 | rdmsrl(hwc->config_base, ctrl_val); |
670 | ctrl_val &= ~mask; | 596 | ctrl_val &= ~mask; |
671 | ctrl_val |= bits; | 597 | ctrl_val |= bits; |
672 | err = checking_wrmsrl(hwc->config_base, ctrl_val); | 598 | wrmsrl(hwc->config_base, ctrl_val); |
673 | } | 599 | } |
674 | 600 | ||
675 | static void intel_pmu_enable_event(struct perf_event *event) | 601 | static void intel_pmu_enable_event(struct perf_event *event) |
@@ -689,7 +615,10 @@ static void intel_pmu_enable_event(struct perf_event *event) | |||
689 | return; | 615 | return; |
690 | } | 616 | } |
691 | 617 | ||
692 | __x86_pmu_enable_event(hwc); | 618 | if (unlikely(event->attr.precise_ip)) |
619 | intel_pmu_pebs_enable(event); | ||
620 | |||
621 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); | ||
693 | } | 622 | } |
694 | 623 | ||
695 | /* | 624 | /* |
@@ -708,20 +637,20 @@ static void intel_pmu_reset(void) | |||
708 | unsigned long flags; | 637 | unsigned long flags; |
709 | int idx; | 638 | int idx; |
710 | 639 | ||
711 | if (!x86_pmu.num_events) | 640 | if (!x86_pmu.num_counters) |
712 | return; | 641 | return; |
713 | 642 | ||
714 | local_irq_save(flags); | 643 | local_irq_save(flags); |
715 | 644 | ||
716 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); | 645 | printk("clearing PMU state on CPU#%d\n", smp_processor_id()); |
717 | 646 | ||
718 | for (idx = 0; idx < x86_pmu.num_events; idx++) { | 647 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
719 | checking_wrmsrl(x86_pmu.eventsel + idx, 0ull); | 648 | checking_wrmsrl(x86_pmu.eventsel + idx, 0ull); |
720 | checking_wrmsrl(x86_pmu.perfctr + idx, 0ull); | 649 | checking_wrmsrl(x86_pmu.perfctr + idx, 0ull); |
721 | } | 650 | } |
722 | for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) { | 651 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) |
723 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); | 652 | checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); |
724 | } | 653 | |
725 | if (ds) | 654 | if (ds) |
726 | ds->bts_index = ds->bts_buffer_base; | 655 | ds->bts_index = ds->bts_buffer_base; |
727 | 656 | ||
@@ -747,7 +676,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) | |||
747 | intel_pmu_drain_bts_buffer(); | 676 | intel_pmu_drain_bts_buffer(); |
748 | status = intel_pmu_get_status(); | 677 | status = intel_pmu_get_status(); |
749 | if (!status) { | 678 | if (!status) { |
750 | intel_pmu_enable_all(); | 679 | intel_pmu_enable_all(0); |
751 | return 0; | 680 | return 0; |
752 | } | 681 | } |
753 | 682 | ||
@@ -762,6 +691,15 @@ again: | |||
762 | 691 | ||
763 | inc_irq_stat(apic_perf_irqs); | 692 | inc_irq_stat(apic_perf_irqs); |
764 | ack = status; | 693 | ack = status; |
694 | |||
695 | intel_pmu_lbr_read(); | ||
696 | |||
697 | /* | ||
698 | * PEBS overflow sets bit 62 in the global status register | ||
699 | */ | ||
700 | if (__test_and_clear_bit(62, (unsigned long *)&status)) | ||
701 | x86_pmu.drain_pebs(regs); | ||
702 | |||
765 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { | 703 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { |
766 | struct perf_event *event = cpuc->events[bit]; | 704 | struct perf_event *event = cpuc->events[bit]; |
767 | 705 | ||
@@ -787,26 +725,22 @@ again: | |||
787 | goto again; | 725 | goto again; |
788 | 726 | ||
789 | done: | 727 | done: |
790 | intel_pmu_enable_all(); | 728 | intel_pmu_enable_all(0); |
791 | return 1; | 729 | return 1; |
792 | } | 730 | } |
793 | 731 | ||
794 | static struct event_constraint bts_constraint = | ||
795 | EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0); | ||
796 | |||
797 | static struct event_constraint * | 732 | static struct event_constraint * |
798 | intel_special_constraints(struct perf_event *event) | 733 | intel_bts_constraints(struct perf_event *event) |
799 | { | 734 | { |
800 | unsigned int hw_event; | 735 | struct hw_perf_event *hwc = &event->hw; |
801 | 736 | unsigned int hw_event, bts_event; | |
802 | hw_event = event->hw.config & INTEL_ARCH_EVENT_MASK; | ||
803 | 737 | ||
804 | if (unlikely((hw_event == | 738 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; |
805 | x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) && | 739 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); |
806 | (event->hw.sample_period == 1))) { | ||
807 | 740 | ||
741 | if (unlikely(hw_event == bts_event && hwc->sample_period == 1)) | ||
808 | return &bts_constraint; | 742 | return &bts_constraint; |
809 | } | 743 | |
810 | return NULL; | 744 | return NULL; |
811 | } | 745 | } |
812 | 746 | ||
@@ -815,24 +749,53 @@ intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event | |||
815 | { | 749 | { |
816 | struct event_constraint *c; | 750 | struct event_constraint *c; |
817 | 751 | ||
818 | c = intel_special_constraints(event); | 752 | c = intel_bts_constraints(event); |
753 | if (c) | ||
754 | return c; | ||
755 | |||
756 | c = intel_pebs_constraints(event); | ||
819 | if (c) | 757 | if (c) |
820 | return c; | 758 | return c; |
821 | 759 | ||
822 | return x86_get_event_constraints(cpuc, event); | 760 | return x86_get_event_constraints(cpuc, event); |
823 | } | 761 | } |
824 | 762 | ||
825 | static __initconst struct x86_pmu core_pmu = { | 763 | static int intel_pmu_hw_config(struct perf_event *event) |
764 | { | ||
765 | int ret = x86_pmu_hw_config(event); | ||
766 | |||
767 | if (ret) | ||
768 | return ret; | ||
769 | |||
770 | if (event->attr.type != PERF_TYPE_RAW) | ||
771 | return 0; | ||
772 | |||
773 | if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY)) | ||
774 | return 0; | ||
775 | |||
776 | if (x86_pmu.version < 3) | ||
777 | return -EINVAL; | ||
778 | |||
779 | if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | ||
780 | return -EACCES; | ||
781 | |||
782 | event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY; | ||
783 | |||
784 | return 0; | ||
785 | } | ||
786 | |||
787 | static __initconst const struct x86_pmu core_pmu = { | ||
826 | .name = "core", | 788 | .name = "core", |
827 | .handle_irq = x86_pmu_handle_irq, | 789 | .handle_irq = x86_pmu_handle_irq, |
828 | .disable_all = x86_pmu_disable_all, | 790 | .disable_all = x86_pmu_disable_all, |
829 | .enable_all = x86_pmu_enable_all, | 791 | .enable_all = x86_pmu_enable_all, |
830 | .enable = x86_pmu_enable_event, | 792 | .enable = x86_pmu_enable_event, |
831 | .disable = x86_pmu_disable_event, | 793 | .disable = x86_pmu_disable_event, |
794 | .hw_config = x86_pmu_hw_config, | ||
795 | .schedule_events = x86_schedule_events, | ||
832 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, | 796 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
833 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | 797 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, |
834 | .event_map = intel_pmu_event_map, | 798 | .event_map = intel_pmu_event_map, |
835 | .raw_event = intel_pmu_raw_event, | ||
836 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), | 799 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
837 | .apic = 1, | 800 | .apic = 1, |
838 | /* | 801 | /* |
@@ -845,17 +808,32 @@ static __initconst struct x86_pmu core_pmu = { | |||
845 | .event_constraints = intel_core_event_constraints, | 808 | .event_constraints = intel_core_event_constraints, |
846 | }; | 809 | }; |
847 | 810 | ||
848 | static __initconst struct x86_pmu intel_pmu = { | 811 | static void intel_pmu_cpu_starting(int cpu) |
812 | { | ||
813 | init_debug_store_on_cpu(cpu); | ||
814 | /* | ||
815 | * Deal with CPUs that don't clear their LBRs on power-up. | ||
816 | */ | ||
817 | intel_pmu_lbr_reset(); | ||
818 | } | ||
819 | |||
820 | static void intel_pmu_cpu_dying(int cpu) | ||
821 | { | ||
822 | fini_debug_store_on_cpu(cpu); | ||
823 | } | ||
824 | |||
825 | static __initconst const struct x86_pmu intel_pmu = { | ||
849 | .name = "Intel", | 826 | .name = "Intel", |
850 | .handle_irq = intel_pmu_handle_irq, | 827 | .handle_irq = intel_pmu_handle_irq, |
851 | .disable_all = intel_pmu_disable_all, | 828 | .disable_all = intel_pmu_disable_all, |
852 | .enable_all = intel_pmu_enable_all, | 829 | .enable_all = intel_pmu_enable_all, |
853 | .enable = intel_pmu_enable_event, | 830 | .enable = intel_pmu_enable_event, |
854 | .disable = intel_pmu_disable_event, | 831 | .disable = intel_pmu_disable_event, |
832 | .hw_config = intel_pmu_hw_config, | ||
833 | .schedule_events = x86_schedule_events, | ||
855 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, | 834 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
856 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | 835 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, |
857 | .event_map = intel_pmu_event_map, | 836 | .event_map = intel_pmu_event_map, |
858 | .raw_event = intel_pmu_raw_event, | ||
859 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), | 837 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
860 | .apic = 1, | 838 | .apic = 1, |
861 | /* | 839 | /* |
@@ -864,14 +842,38 @@ static __initconst struct x86_pmu intel_pmu = { | |||
864 | * the generic event period: | 842 | * the generic event period: |
865 | */ | 843 | */ |
866 | .max_period = (1ULL << 31) - 1, | 844 | .max_period = (1ULL << 31) - 1, |
867 | .enable_bts = intel_pmu_enable_bts, | ||
868 | .disable_bts = intel_pmu_disable_bts, | ||
869 | .get_event_constraints = intel_get_event_constraints, | 845 | .get_event_constraints = intel_get_event_constraints, |
870 | 846 | ||
871 | .cpu_starting = init_debug_store_on_cpu, | 847 | .cpu_starting = intel_pmu_cpu_starting, |
872 | .cpu_dying = fini_debug_store_on_cpu, | 848 | .cpu_dying = intel_pmu_cpu_dying, |
873 | }; | 849 | }; |
874 | 850 | ||
851 | static void intel_clovertown_quirks(void) | ||
852 | { | ||
853 | /* | ||
854 | * PEBS is unreliable due to: | ||
855 | * | ||
856 | * AJ67 - PEBS may experience CPL leaks | ||
857 | * AJ68 - PEBS PMI may be delayed by one event | ||
858 | * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12] | ||
859 | * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS | ||
860 | * | ||
861 | * AJ67 could be worked around by restricting the OS/USR flags. | ||
862 | * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI. | ||
863 | * | ||
864 | * AJ106 could possibly be worked around by not allowing LBR | ||
865 | * usage from PEBS, including the fixup. | ||
866 | * AJ68 could possibly be worked around by always programming | ||
867 | * a pebs_event_reset[0] value and coping with the lost events. | ||
868 | * | ||
869 | * But taken together it might just make sense to not enable PEBS on | ||
870 | * these chips. | ||
871 | */ | ||
872 | printk(KERN_WARNING "PEBS disabled due to CPU errata.\n"); | ||
873 | x86_pmu.pebs = 0; | ||
874 | x86_pmu.pebs_constraints = NULL; | ||
875 | } | ||
876 | |||
875 | static __init int intel_pmu_init(void) | 877 | static __init int intel_pmu_init(void) |
876 | { | 878 | { |
877 | union cpuid10_edx edx; | 879 | union cpuid10_edx edx; |
@@ -881,12 +883,13 @@ static __init int intel_pmu_init(void) | |||
881 | int version; | 883 | int version; |
882 | 884 | ||
883 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { | 885 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { |
884 | /* check for P6 processor family */ | 886 | switch (boot_cpu_data.x86) { |
885 | if (boot_cpu_data.x86 == 6) { | 887 | case 0x6: |
886 | return p6_pmu_init(); | 888 | return p6_pmu_init(); |
887 | } else { | 889 | case 0xf: |
890 | return p4_pmu_init(); | ||
891 | } | ||
888 | return -ENODEV; | 892 | return -ENODEV; |
889 | } | ||
890 | } | 893 | } |
891 | 894 | ||
892 | /* | 895 | /* |
@@ -904,16 +907,28 @@ static __init int intel_pmu_init(void) | |||
904 | x86_pmu = intel_pmu; | 907 | x86_pmu = intel_pmu; |
905 | 908 | ||
906 | x86_pmu.version = version; | 909 | x86_pmu.version = version; |
907 | x86_pmu.num_events = eax.split.num_events; | 910 | x86_pmu.num_counters = eax.split.num_counters; |
908 | x86_pmu.event_bits = eax.split.bit_width; | 911 | x86_pmu.cntval_bits = eax.split.bit_width; |
909 | x86_pmu.event_mask = (1ULL << eax.split.bit_width) - 1; | 912 | x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1; |
910 | 913 | ||
911 | /* | 914 | /* |
912 | * Quirk: v2 perfmon does not report fixed-purpose events, so | 915 | * Quirk: v2 perfmon does not report fixed-purpose events, so |
913 | * assume at least 3 events: | 916 | * assume at least 3 events: |
914 | */ | 917 | */ |
915 | if (version > 1) | 918 | if (version > 1) |
916 | x86_pmu.num_events_fixed = max((int)edx.split.num_events_fixed, 3); | 919 | x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); |
920 | |||
921 | /* | ||
922 | * v2 and above have a perf capabilities MSR | ||
923 | */ | ||
924 | if (version > 1) { | ||
925 | u64 capabilities; | ||
926 | |||
927 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities); | ||
928 | x86_pmu.intel_cap.capabilities = capabilities; | ||
929 | } | ||
930 | |||
931 | intel_ds_init(); | ||
917 | 932 | ||
918 | /* | 933 | /* |
919 | * Install the hw-cache-events table: | 934 | * Install the hw-cache-events table: |
@@ -924,12 +939,15 @@ static __init int intel_pmu_init(void) | |||
924 | break; | 939 | break; |
925 | 940 | ||
926 | case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */ | 941 | case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */ |
942 | x86_pmu.quirks = intel_clovertown_quirks; | ||
927 | case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */ | 943 | case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */ |
928 | case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */ | 944 | case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */ |
929 | case 29: /* six-core 45 nm xeon "Dunnington" */ | 945 | case 29: /* six-core 45 nm xeon "Dunnington" */ |
930 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, | 946 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, |
931 | sizeof(hw_cache_event_ids)); | 947 | sizeof(hw_cache_event_ids)); |
932 | 948 | ||
949 | intel_pmu_lbr_init_core(); | ||
950 | |||
933 | x86_pmu.event_constraints = intel_core2_event_constraints; | 951 | x86_pmu.event_constraints = intel_core2_event_constraints; |
934 | pr_cont("Core2 events, "); | 952 | pr_cont("Core2 events, "); |
935 | break; | 953 | break; |
@@ -940,13 +958,19 @@ static __init int intel_pmu_init(void) | |||
940 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, | 958 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, |
941 | sizeof(hw_cache_event_ids)); | 959 | sizeof(hw_cache_event_ids)); |
942 | 960 | ||
961 | intel_pmu_lbr_init_nhm(); | ||
962 | |||
943 | x86_pmu.event_constraints = intel_nehalem_event_constraints; | 963 | x86_pmu.event_constraints = intel_nehalem_event_constraints; |
944 | pr_cont("Nehalem/Corei7 events, "); | 964 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
965 | pr_cont("Nehalem events, "); | ||
945 | break; | 966 | break; |
967 | |||
946 | case 28: /* Atom */ | 968 | case 28: /* Atom */ |
947 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, | 969 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, |
948 | sizeof(hw_cache_event_ids)); | 970 | sizeof(hw_cache_event_ids)); |
949 | 971 | ||
972 | intel_pmu_lbr_init_atom(); | ||
973 | |||
950 | x86_pmu.event_constraints = intel_gen_event_constraints; | 974 | x86_pmu.event_constraints = intel_gen_event_constraints; |
951 | pr_cont("Atom events, "); | 975 | pr_cont("Atom events, "); |
952 | break; | 976 | break; |
@@ -956,7 +980,10 @@ static __init int intel_pmu_init(void) | |||
956 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, | 980 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, |
957 | sizeof(hw_cache_event_ids)); | 981 | sizeof(hw_cache_event_ids)); |
958 | 982 | ||
983 | intel_pmu_lbr_init_nhm(); | ||
984 | |||
959 | x86_pmu.event_constraints = intel_westmere_event_constraints; | 985 | x86_pmu.event_constraints = intel_westmere_event_constraints; |
986 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; | ||
960 | pr_cont("Westmere events, "); | 987 | pr_cont("Westmere events, "); |
961 | break; | 988 | break; |
962 | 989 | ||
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c new file mode 100644 index 000000000000..18018d1311cd --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c | |||
@@ -0,0 +1,641 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_INTEL | ||
2 | |||
3 | /* The maximal number of PEBS events: */ | ||
4 | #define MAX_PEBS_EVENTS 4 | ||
5 | |||
6 | /* The size of a BTS record in bytes: */ | ||
7 | #define BTS_RECORD_SIZE 24 | ||
8 | |||
9 | #define BTS_BUFFER_SIZE (PAGE_SIZE << 4) | ||
10 | #define PEBS_BUFFER_SIZE PAGE_SIZE | ||
11 | |||
12 | /* | ||
13 | * pebs_record_32 for p4 and core not supported | ||
14 | |||
15 | struct pebs_record_32 { | ||
16 | u32 flags, ip; | ||
17 | u32 ax, bc, cx, dx; | ||
18 | u32 si, di, bp, sp; | ||
19 | }; | ||
20 | |||
21 | */ | ||
22 | |||
23 | struct pebs_record_core { | ||
24 | u64 flags, ip; | ||
25 | u64 ax, bx, cx, dx; | ||
26 | u64 si, di, bp, sp; | ||
27 | u64 r8, r9, r10, r11; | ||
28 | u64 r12, r13, r14, r15; | ||
29 | }; | ||
30 | |||
31 | struct pebs_record_nhm { | ||
32 | u64 flags, ip; | ||
33 | u64 ax, bx, cx, dx; | ||
34 | u64 si, di, bp, sp; | ||
35 | u64 r8, r9, r10, r11; | ||
36 | u64 r12, r13, r14, r15; | ||
37 | u64 status, dla, dse, lat; | ||
38 | }; | ||
39 | |||
40 | /* | ||
41 | * A debug store configuration. | ||
42 | * | ||
43 | * We only support architectures that use 64bit fields. | ||
44 | */ | ||
45 | struct debug_store { | ||
46 | u64 bts_buffer_base; | ||
47 | u64 bts_index; | ||
48 | u64 bts_absolute_maximum; | ||
49 | u64 bts_interrupt_threshold; | ||
50 | u64 pebs_buffer_base; | ||
51 | u64 pebs_index; | ||
52 | u64 pebs_absolute_maximum; | ||
53 | u64 pebs_interrupt_threshold; | ||
54 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; | ||
55 | }; | ||
56 | |||
57 | static void init_debug_store_on_cpu(int cpu) | ||
58 | { | ||
59 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
60 | |||
61 | if (!ds) | ||
62 | return; | ||
63 | |||
64 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, | ||
65 | (u32)((u64)(unsigned long)ds), | ||
66 | (u32)((u64)(unsigned long)ds >> 32)); | ||
67 | } | ||
68 | |||
69 | static void fini_debug_store_on_cpu(int cpu) | ||
70 | { | ||
71 | if (!per_cpu(cpu_hw_events, cpu).ds) | ||
72 | return; | ||
73 | |||
74 | wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0); | ||
75 | } | ||
76 | |||
77 | static void release_ds_buffers(void) | ||
78 | { | ||
79 | int cpu; | ||
80 | |||
81 | if (!x86_pmu.bts && !x86_pmu.pebs) | ||
82 | return; | ||
83 | |||
84 | get_online_cpus(); | ||
85 | |||
86 | for_each_online_cpu(cpu) | ||
87 | fini_debug_store_on_cpu(cpu); | ||
88 | |||
89 | for_each_possible_cpu(cpu) { | ||
90 | struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds; | ||
91 | |||
92 | if (!ds) | ||
93 | continue; | ||
94 | |||
95 | per_cpu(cpu_hw_events, cpu).ds = NULL; | ||
96 | |||
97 | kfree((void *)(unsigned long)ds->pebs_buffer_base); | ||
98 | kfree((void *)(unsigned long)ds->bts_buffer_base); | ||
99 | kfree(ds); | ||
100 | } | ||
101 | |||
102 | put_online_cpus(); | ||
103 | } | ||
104 | |||
105 | static int reserve_ds_buffers(void) | ||
106 | { | ||
107 | int cpu, err = 0; | ||
108 | |||
109 | if (!x86_pmu.bts && !x86_pmu.pebs) | ||
110 | return 0; | ||
111 | |||
112 | get_online_cpus(); | ||
113 | |||
114 | for_each_possible_cpu(cpu) { | ||
115 | struct debug_store *ds; | ||
116 | void *buffer; | ||
117 | int max, thresh; | ||
118 | |||
119 | err = -ENOMEM; | ||
120 | ds = kzalloc(sizeof(*ds), GFP_KERNEL); | ||
121 | if (unlikely(!ds)) | ||
122 | break; | ||
123 | per_cpu(cpu_hw_events, cpu).ds = ds; | ||
124 | |||
125 | if (x86_pmu.bts) { | ||
126 | buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL); | ||
127 | if (unlikely(!buffer)) | ||
128 | break; | ||
129 | |||
130 | max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE; | ||
131 | thresh = max / 16; | ||
132 | |||
133 | ds->bts_buffer_base = (u64)(unsigned long)buffer; | ||
134 | ds->bts_index = ds->bts_buffer_base; | ||
135 | ds->bts_absolute_maximum = ds->bts_buffer_base + | ||
136 | max * BTS_RECORD_SIZE; | ||
137 | ds->bts_interrupt_threshold = ds->bts_absolute_maximum - | ||
138 | thresh * BTS_RECORD_SIZE; | ||
139 | } | ||
140 | |||
141 | if (x86_pmu.pebs) { | ||
142 | buffer = kzalloc(PEBS_BUFFER_SIZE, GFP_KERNEL); | ||
143 | if (unlikely(!buffer)) | ||
144 | break; | ||
145 | |||
146 | max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size; | ||
147 | |||
148 | ds->pebs_buffer_base = (u64)(unsigned long)buffer; | ||
149 | ds->pebs_index = ds->pebs_buffer_base; | ||
150 | ds->pebs_absolute_maximum = ds->pebs_buffer_base + | ||
151 | max * x86_pmu.pebs_record_size; | ||
152 | /* | ||
153 | * Always use single record PEBS | ||
154 | */ | ||
155 | ds->pebs_interrupt_threshold = ds->pebs_buffer_base + | ||
156 | x86_pmu.pebs_record_size; | ||
157 | } | ||
158 | |||
159 | err = 0; | ||
160 | } | ||
161 | |||
162 | if (err) | ||
163 | release_ds_buffers(); | ||
164 | else { | ||
165 | for_each_online_cpu(cpu) | ||
166 | init_debug_store_on_cpu(cpu); | ||
167 | } | ||
168 | |||
169 | put_online_cpus(); | ||
170 | |||
171 | return err; | ||
172 | } | ||
173 | |||
174 | /* | ||
175 | * BTS | ||
176 | */ | ||
177 | |||
178 | static struct event_constraint bts_constraint = | ||
179 | EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0); | ||
180 | |||
181 | static void intel_pmu_enable_bts(u64 config) | ||
182 | { | ||
183 | unsigned long debugctlmsr; | ||
184 | |||
185 | debugctlmsr = get_debugctlmsr(); | ||
186 | |||
187 | debugctlmsr |= DEBUGCTLMSR_TR; | ||
188 | debugctlmsr |= DEBUGCTLMSR_BTS; | ||
189 | debugctlmsr |= DEBUGCTLMSR_BTINT; | ||
190 | |||
191 | if (!(config & ARCH_PERFMON_EVENTSEL_OS)) | ||
192 | debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS; | ||
193 | |||
194 | if (!(config & ARCH_PERFMON_EVENTSEL_USR)) | ||
195 | debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR; | ||
196 | |||
197 | update_debugctlmsr(debugctlmsr); | ||
198 | } | ||
199 | |||
200 | static void intel_pmu_disable_bts(void) | ||
201 | { | ||
202 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
203 | unsigned long debugctlmsr; | ||
204 | |||
205 | if (!cpuc->ds) | ||
206 | return; | ||
207 | |||
208 | debugctlmsr = get_debugctlmsr(); | ||
209 | |||
210 | debugctlmsr &= | ||
211 | ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT | | ||
212 | DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR); | ||
213 | |||
214 | update_debugctlmsr(debugctlmsr); | ||
215 | } | ||
216 | |||
217 | static void intel_pmu_drain_bts_buffer(void) | ||
218 | { | ||
219 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
220 | struct debug_store *ds = cpuc->ds; | ||
221 | struct bts_record { | ||
222 | u64 from; | ||
223 | u64 to; | ||
224 | u64 flags; | ||
225 | }; | ||
226 | struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS]; | ||
227 | struct bts_record *at, *top; | ||
228 | struct perf_output_handle handle; | ||
229 | struct perf_event_header header; | ||
230 | struct perf_sample_data data; | ||
231 | struct pt_regs regs; | ||
232 | |||
233 | if (!event) | ||
234 | return; | ||
235 | |||
236 | if (!ds) | ||
237 | return; | ||
238 | |||
239 | at = (struct bts_record *)(unsigned long)ds->bts_buffer_base; | ||
240 | top = (struct bts_record *)(unsigned long)ds->bts_index; | ||
241 | |||
242 | if (top <= at) | ||
243 | return; | ||
244 | |||
245 | ds->bts_index = ds->bts_buffer_base; | ||
246 | |||
247 | perf_sample_data_init(&data, 0); | ||
248 | data.period = event->hw.last_period; | ||
249 | regs.ip = 0; | ||
250 | |||
251 | /* | ||
252 | * Prepare a generic sample, i.e. fill in the invariant fields. | ||
253 | * We will overwrite the from and to address before we output | ||
254 | * the sample. | ||
255 | */ | ||
256 | perf_prepare_sample(&header, &data, event, ®s); | ||
257 | |||
258 | if (perf_output_begin(&handle, event, header.size * (top - at), 1, 1)) | ||
259 | return; | ||
260 | |||
261 | for (; at < top; at++) { | ||
262 | data.ip = at->from; | ||
263 | data.addr = at->to; | ||
264 | |||
265 | perf_output_sample(&handle, &header, &data, event); | ||
266 | } | ||
267 | |||
268 | perf_output_end(&handle); | ||
269 | |||
270 | /* There's new data available. */ | ||
271 | event->hw.interrupts++; | ||
272 | event->pending_kill = POLL_IN; | ||
273 | } | ||
274 | |||
275 | /* | ||
276 | * PEBS | ||
277 | */ | ||
278 | |||
279 | static struct event_constraint intel_core_pebs_events[] = { | ||
280 | PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */ | ||
281 | PEBS_EVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */ | ||
282 | PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */ | ||
283 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */ | ||
284 | PEBS_EVENT_CONSTRAINT(0x01cb, 0x1), /* MEM_LOAD_RETIRED.L1D_MISS */ | ||
285 | PEBS_EVENT_CONSTRAINT(0x02cb, 0x1), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | ||
286 | PEBS_EVENT_CONSTRAINT(0x04cb, 0x1), /* MEM_LOAD_RETIRED.L2_MISS */ | ||
287 | PEBS_EVENT_CONSTRAINT(0x08cb, 0x1), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | ||
288 | PEBS_EVENT_CONSTRAINT(0x10cb, 0x1), /* MEM_LOAD_RETIRED.DTLB_MISS */ | ||
289 | EVENT_CONSTRAINT_END | ||
290 | }; | ||
291 | |||
292 | static struct event_constraint intel_nehalem_pebs_events[] = { | ||
293 | PEBS_EVENT_CONSTRAINT(0x00c0, 0xf), /* INSTR_RETIRED.ANY */ | ||
294 | PEBS_EVENT_CONSTRAINT(0xfec1, 0xf), /* X87_OPS_RETIRED.ANY */ | ||
295 | PEBS_EVENT_CONSTRAINT(0x00c5, 0xf), /* BR_INST_RETIRED.MISPRED */ | ||
296 | PEBS_EVENT_CONSTRAINT(0x1fc7, 0xf), /* SIMD_INST_RETURED.ANY */ | ||
297 | PEBS_EVENT_CONSTRAINT(0x01cb, 0xf), /* MEM_LOAD_RETIRED.L1D_MISS */ | ||
298 | PEBS_EVENT_CONSTRAINT(0x02cb, 0xf), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */ | ||
299 | PEBS_EVENT_CONSTRAINT(0x04cb, 0xf), /* MEM_LOAD_RETIRED.L2_MISS */ | ||
300 | PEBS_EVENT_CONSTRAINT(0x08cb, 0xf), /* MEM_LOAD_RETIRED.L2_LINE_MISS */ | ||
301 | PEBS_EVENT_CONSTRAINT(0x10cb, 0xf), /* MEM_LOAD_RETIRED.DTLB_MISS */ | ||
302 | EVENT_CONSTRAINT_END | ||
303 | }; | ||
304 | |||
305 | static struct event_constraint * | ||
306 | intel_pebs_constraints(struct perf_event *event) | ||
307 | { | ||
308 | struct event_constraint *c; | ||
309 | |||
310 | if (!event->attr.precise_ip) | ||
311 | return NULL; | ||
312 | |||
313 | if (x86_pmu.pebs_constraints) { | ||
314 | for_each_event_constraint(c, x86_pmu.pebs_constraints) { | ||
315 | if ((event->hw.config & c->cmask) == c->code) | ||
316 | return c; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return &emptyconstraint; | ||
321 | } | ||
322 | |||
323 | static void intel_pmu_pebs_enable(struct perf_event *event) | ||
324 | { | ||
325 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
326 | struct hw_perf_event *hwc = &event->hw; | ||
327 | |||
328 | hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT; | ||
329 | |||
330 | cpuc->pebs_enabled |= 1ULL << hwc->idx; | ||
331 | WARN_ON_ONCE(cpuc->enabled); | ||
332 | |||
333 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1) | ||
334 | intel_pmu_lbr_enable(event); | ||
335 | } | ||
336 | |||
337 | static void intel_pmu_pebs_disable(struct perf_event *event) | ||
338 | { | ||
339 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
340 | struct hw_perf_event *hwc = &event->hw; | ||
341 | |||
342 | cpuc->pebs_enabled &= ~(1ULL << hwc->idx); | ||
343 | if (cpuc->enabled) | ||
344 | wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled); | ||
345 | |||
346 | hwc->config |= ARCH_PERFMON_EVENTSEL_INT; | ||
347 | |||
348 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1) | ||
349 | intel_pmu_lbr_disable(event); | ||
350 | } | ||
351 | |||
352 | static void intel_pmu_pebs_enable_all(void) | ||
353 | { | ||
354 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
355 | |||
356 | if (cpuc->pebs_enabled) | ||
357 | wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled); | ||
358 | } | ||
359 | |||
360 | static void intel_pmu_pebs_disable_all(void) | ||
361 | { | ||
362 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
363 | |||
364 | if (cpuc->pebs_enabled) | ||
365 | wrmsrl(MSR_IA32_PEBS_ENABLE, 0); | ||
366 | } | ||
367 | |||
368 | #include <asm/insn.h> | ||
369 | |||
370 | static inline bool kernel_ip(unsigned long ip) | ||
371 | { | ||
372 | #ifdef CONFIG_X86_32 | ||
373 | return ip > PAGE_OFFSET; | ||
374 | #else | ||
375 | return (long)ip < 0; | ||
376 | #endif | ||
377 | } | ||
378 | |||
379 | static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs) | ||
380 | { | ||
381 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
382 | unsigned long from = cpuc->lbr_entries[0].from; | ||
383 | unsigned long old_to, to = cpuc->lbr_entries[0].to; | ||
384 | unsigned long ip = regs->ip; | ||
385 | |||
386 | /* | ||
387 | * We don't need to fixup if the PEBS assist is fault like | ||
388 | */ | ||
389 | if (!x86_pmu.intel_cap.pebs_trap) | ||
390 | return 1; | ||
391 | |||
392 | /* | ||
393 | * No LBR entry, no basic block, no rewinding | ||
394 | */ | ||
395 | if (!cpuc->lbr_stack.nr || !from || !to) | ||
396 | return 0; | ||
397 | |||
398 | /* | ||
399 | * Basic blocks should never cross user/kernel boundaries | ||
400 | */ | ||
401 | if (kernel_ip(ip) != kernel_ip(to)) | ||
402 | return 0; | ||
403 | |||
404 | /* | ||
405 | * unsigned math, either ip is before the start (impossible) or | ||
406 | * the basic block is larger than 1 page (sanity) | ||
407 | */ | ||
408 | if ((ip - to) > PAGE_SIZE) | ||
409 | return 0; | ||
410 | |||
411 | /* | ||
412 | * We sampled a branch insn, rewind using the LBR stack | ||
413 | */ | ||
414 | if (ip == to) { | ||
415 | regs->ip = from; | ||
416 | return 1; | ||
417 | } | ||
418 | |||
419 | do { | ||
420 | struct insn insn; | ||
421 | u8 buf[MAX_INSN_SIZE]; | ||
422 | void *kaddr; | ||
423 | |||
424 | old_to = to; | ||
425 | if (!kernel_ip(ip)) { | ||
426 | int bytes, size = MAX_INSN_SIZE; | ||
427 | |||
428 | bytes = copy_from_user_nmi(buf, (void __user *)to, size); | ||
429 | if (bytes != size) | ||
430 | return 0; | ||
431 | |||
432 | kaddr = buf; | ||
433 | } else | ||
434 | kaddr = (void *)to; | ||
435 | |||
436 | kernel_insn_init(&insn, kaddr); | ||
437 | insn_get_length(&insn); | ||
438 | to += insn.length; | ||
439 | } while (to < ip); | ||
440 | |||
441 | if (to == ip) { | ||
442 | regs->ip = old_to; | ||
443 | return 1; | ||
444 | } | ||
445 | |||
446 | /* | ||
447 | * Even though we decoded the basic block, the instruction stream | ||
448 | * never matched the given IP, either the TO or the IP got corrupted. | ||
449 | */ | ||
450 | return 0; | ||
451 | } | ||
452 | |||
453 | static int intel_pmu_save_and_restart(struct perf_event *event); | ||
454 | |||
455 | static void __intel_pmu_pebs_event(struct perf_event *event, | ||
456 | struct pt_regs *iregs, void *__pebs) | ||
457 | { | ||
458 | /* | ||
459 | * We cast to pebs_record_core since that is a subset of | ||
460 | * both formats and we don't use the other fields in this | ||
461 | * routine. | ||
462 | */ | ||
463 | struct pebs_record_core *pebs = __pebs; | ||
464 | struct perf_sample_data data; | ||
465 | struct pt_regs regs; | ||
466 | |||
467 | if (!intel_pmu_save_and_restart(event)) | ||
468 | return; | ||
469 | |||
470 | perf_sample_data_init(&data, 0); | ||
471 | data.period = event->hw.last_period; | ||
472 | |||
473 | /* | ||
474 | * We use the interrupt regs as a base because the PEBS record | ||
475 | * does not contain a full regs set, specifically it seems to | ||
476 | * lack segment descriptors, which get used by things like | ||
477 | * user_mode(). | ||
478 | * | ||
479 | * In the simple case fix up only the IP and BP,SP regs, for | ||
480 | * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly. | ||
481 | * A possible PERF_SAMPLE_REGS will have to transfer all regs. | ||
482 | */ | ||
483 | regs = *iregs; | ||
484 | regs.ip = pebs->ip; | ||
485 | regs.bp = pebs->bp; | ||
486 | regs.sp = pebs->sp; | ||
487 | |||
488 | if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(®s)) | ||
489 | regs.flags |= PERF_EFLAGS_EXACT; | ||
490 | else | ||
491 | regs.flags &= ~PERF_EFLAGS_EXACT; | ||
492 | |||
493 | if (perf_event_overflow(event, 1, &data, ®s)) | ||
494 | x86_pmu_stop(event); | ||
495 | } | ||
496 | |||
497 | static void intel_pmu_drain_pebs_core(struct pt_regs *iregs) | ||
498 | { | ||
499 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
500 | struct debug_store *ds = cpuc->ds; | ||
501 | struct perf_event *event = cpuc->events[0]; /* PMC0 only */ | ||
502 | struct pebs_record_core *at, *top; | ||
503 | int n; | ||
504 | |||
505 | if (!ds || !x86_pmu.pebs) | ||
506 | return; | ||
507 | |||
508 | at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base; | ||
509 | top = (struct pebs_record_core *)(unsigned long)ds->pebs_index; | ||
510 | |||
511 | /* | ||
512 | * Whatever else happens, drain the thing | ||
513 | */ | ||
514 | ds->pebs_index = ds->pebs_buffer_base; | ||
515 | |||
516 | if (!test_bit(0, cpuc->active_mask)) | ||
517 | return; | ||
518 | |||
519 | WARN_ON_ONCE(!event); | ||
520 | |||
521 | if (!event->attr.precise_ip) | ||
522 | return; | ||
523 | |||
524 | n = top - at; | ||
525 | if (n <= 0) | ||
526 | return; | ||
527 | |||
528 | /* | ||
529 | * Should not happen, we program the threshold at 1 and do not | ||
530 | * set a reset value. | ||
531 | */ | ||
532 | WARN_ON_ONCE(n > 1); | ||
533 | at += n - 1; | ||
534 | |||
535 | __intel_pmu_pebs_event(event, iregs, at); | ||
536 | } | ||
537 | |||
538 | static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs) | ||
539 | { | ||
540 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
541 | struct debug_store *ds = cpuc->ds; | ||
542 | struct pebs_record_nhm *at, *top; | ||
543 | struct perf_event *event = NULL; | ||
544 | u64 status = 0; | ||
545 | int bit, n; | ||
546 | |||
547 | if (!ds || !x86_pmu.pebs) | ||
548 | return; | ||
549 | |||
550 | at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base; | ||
551 | top = (struct pebs_record_nhm *)(unsigned long)ds->pebs_index; | ||
552 | |||
553 | ds->pebs_index = ds->pebs_buffer_base; | ||
554 | |||
555 | n = top - at; | ||
556 | if (n <= 0) | ||
557 | return; | ||
558 | |||
559 | /* | ||
560 | * Should not happen, we program the threshold at 1 and do not | ||
561 | * set a reset value. | ||
562 | */ | ||
563 | WARN_ON_ONCE(n > MAX_PEBS_EVENTS); | ||
564 | |||
565 | for ( ; at < top; at++) { | ||
566 | for_each_set_bit(bit, (unsigned long *)&at->status, MAX_PEBS_EVENTS) { | ||
567 | event = cpuc->events[bit]; | ||
568 | if (!test_bit(bit, cpuc->active_mask)) | ||
569 | continue; | ||
570 | |||
571 | WARN_ON_ONCE(!event); | ||
572 | |||
573 | if (!event->attr.precise_ip) | ||
574 | continue; | ||
575 | |||
576 | if (__test_and_set_bit(bit, (unsigned long *)&status)) | ||
577 | continue; | ||
578 | |||
579 | break; | ||
580 | } | ||
581 | |||
582 | if (!event || bit >= MAX_PEBS_EVENTS) | ||
583 | continue; | ||
584 | |||
585 | __intel_pmu_pebs_event(event, iregs, at); | ||
586 | } | ||
587 | } | ||
588 | |||
589 | /* | ||
590 | * BTS, PEBS probe and setup | ||
591 | */ | ||
592 | |||
593 | static void intel_ds_init(void) | ||
594 | { | ||
595 | /* | ||
596 | * No support for 32bit formats | ||
597 | */ | ||
598 | if (!boot_cpu_has(X86_FEATURE_DTES64)) | ||
599 | return; | ||
600 | |||
601 | x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS); | ||
602 | x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS); | ||
603 | if (x86_pmu.pebs) { | ||
604 | char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-'; | ||
605 | int format = x86_pmu.intel_cap.pebs_format; | ||
606 | |||
607 | switch (format) { | ||
608 | case 0: | ||
609 | printk(KERN_CONT "PEBS fmt0%c, ", pebs_type); | ||
610 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_core); | ||
611 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_core; | ||
612 | x86_pmu.pebs_constraints = intel_core_pebs_events; | ||
613 | break; | ||
614 | |||
615 | case 1: | ||
616 | printk(KERN_CONT "PEBS fmt1%c, ", pebs_type); | ||
617 | x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm); | ||
618 | x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm; | ||
619 | x86_pmu.pebs_constraints = intel_nehalem_pebs_events; | ||
620 | break; | ||
621 | |||
622 | default: | ||
623 | printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type); | ||
624 | x86_pmu.pebs = 0; | ||
625 | break; | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | |||
630 | #else /* CONFIG_CPU_SUP_INTEL */ | ||
631 | |||
632 | static int reserve_ds_buffers(void) | ||
633 | { | ||
634 | return 0; | ||
635 | } | ||
636 | |||
637 | static void release_ds_buffers(void) | ||
638 | { | ||
639 | } | ||
640 | |||
641 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c new file mode 100644 index 000000000000..d202c1bece1a --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c | |||
@@ -0,0 +1,218 @@ | |||
1 | #ifdef CONFIG_CPU_SUP_INTEL | ||
2 | |||
3 | enum { | ||
4 | LBR_FORMAT_32 = 0x00, | ||
5 | LBR_FORMAT_LIP = 0x01, | ||
6 | LBR_FORMAT_EIP = 0x02, | ||
7 | LBR_FORMAT_EIP_FLAGS = 0x03, | ||
8 | }; | ||
9 | |||
10 | /* | ||
11 | * We only support LBR implementations that have FREEZE_LBRS_ON_PMI | ||
12 | * otherwise it becomes near impossible to get a reliable stack. | ||
13 | */ | ||
14 | |||
15 | static void __intel_pmu_lbr_enable(void) | ||
16 | { | ||
17 | u64 debugctl; | ||
18 | |||
19 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
20 | debugctl |= (DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); | ||
21 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
22 | } | ||
23 | |||
24 | static void __intel_pmu_lbr_disable(void) | ||
25 | { | ||
26 | u64 debugctl; | ||
27 | |||
28 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
29 | debugctl &= ~(DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI); | ||
30 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl); | ||
31 | } | ||
32 | |||
33 | static void intel_pmu_lbr_reset_32(void) | ||
34 | { | ||
35 | int i; | ||
36 | |||
37 | for (i = 0; i < x86_pmu.lbr_nr; i++) | ||
38 | wrmsrl(x86_pmu.lbr_from + i, 0); | ||
39 | } | ||
40 | |||
41 | static void intel_pmu_lbr_reset_64(void) | ||
42 | { | ||
43 | int i; | ||
44 | |||
45 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
46 | wrmsrl(x86_pmu.lbr_from + i, 0); | ||
47 | wrmsrl(x86_pmu.lbr_to + i, 0); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static void intel_pmu_lbr_reset(void) | ||
52 | { | ||
53 | if (!x86_pmu.lbr_nr) | ||
54 | return; | ||
55 | |||
56 | if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) | ||
57 | intel_pmu_lbr_reset_32(); | ||
58 | else | ||
59 | intel_pmu_lbr_reset_64(); | ||
60 | } | ||
61 | |||
62 | static void intel_pmu_lbr_enable(struct perf_event *event) | ||
63 | { | ||
64 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
65 | |||
66 | if (!x86_pmu.lbr_nr) | ||
67 | return; | ||
68 | |||
69 | WARN_ON_ONCE(cpuc->enabled); | ||
70 | |||
71 | /* | ||
72 | * Reset the LBR stack if we changed task context to | ||
73 | * avoid data leaks. | ||
74 | */ | ||
75 | |||
76 | if (event->ctx->task && cpuc->lbr_context != event->ctx) { | ||
77 | intel_pmu_lbr_reset(); | ||
78 | cpuc->lbr_context = event->ctx; | ||
79 | } | ||
80 | |||
81 | cpuc->lbr_users++; | ||
82 | } | ||
83 | |||
84 | static void intel_pmu_lbr_disable(struct perf_event *event) | ||
85 | { | ||
86 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
87 | |||
88 | if (!x86_pmu.lbr_nr) | ||
89 | return; | ||
90 | |||
91 | cpuc->lbr_users--; | ||
92 | WARN_ON_ONCE(cpuc->lbr_users < 0); | ||
93 | |||
94 | if (cpuc->enabled && !cpuc->lbr_users) | ||
95 | __intel_pmu_lbr_disable(); | ||
96 | } | ||
97 | |||
98 | static void intel_pmu_lbr_enable_all(void) | ||
99 | { | ||
100 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
101 | |||
102 | if (cpuc->lbr_users) | ||
103 | __intel_pmu_lbr_enable(); | ||
104 | } | ||
105 | |||
106 | static void intel_pmu_lbr_disable_all(void) | ||
107 | { | ||
108 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
109 | |||
110 | if (cpuc->lbr_users) | ||
111 | __intel_pmu_lbr_disable(); | ||
112 | } | ||
113 | |||
114 | static inline u64 intel_pmu_lbr_tos(void) | ||
115 | { | ||
116 | u64 tos; | ||
117 | |||
118 | rdmsrl(x86_pmu.lbr_tos, tos); | ||
119 | |||
120 | return tos; | ||
121 | } | ||
122 | |||
123 | static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc) | ||
124 | { | ||
125 | unsigned long mask = x86_pmu.lbr_nr - 1; | ||
126 | u64 tos = intel_pmu_lbr_tos(); | ||
127 | int i; | ||
128 | |||
129 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
130 | unsigned long lbr_idx = (tos - i) & mask; | ||
131 | union { | ||
132 | struct { | ||
133 | u32 from; | ||
134 | u32 to; | ||
135 | }; | ||
136 | u64 lbr; | ||
137 | } msr_lastbranch; | ||
138 | |||
139 | rdmsrl(x86_pmu.lbr_from + lbr_idx, msr_lastbranch.lbr); | ||
140 | |||
141 | cpuc->lbr_entries[i].from = msr_lastbranch.from; | ||
142 | cpuc->lbr_entries[i].to = msr_lastbranch.to; | ||
143 | cpuc->lbr_entries[i].flags = 0; | ||
144 | } | ||
145 | cpuc->lbr_stack.nr = i; | ||
146 | } | ||
147 | |||
148 | #define LBR_FROM_FLAG_MISPRED (1ULL << 63) | ||
149 | |||
150 | /* | ||
151 | * Due to lack of segmentation in Linux the effective address (offset) | ||
152 | * is the same as the linear address, allowing us to merge the LIP and EIP | ||
153 | * LBR formats. | ||
154 | */ | ||
155 | static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc) | ||
156 | { | ||
157 | unsigned long mask = x86_pmu.lbr_nr - 1; | ||
158 | int lbr_format = x86_pmu.intel_cap.lbr_format; | ||
159 | u64 tos = intel_pmu_lbr_tos(); | ||
160 | int i; | ||
161 | |||
162 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | ||
163 | unsigned long lbr_idx = (tos - i) & mask; | ||
164 | u64 from, to, flags = 0; | ||
165 | |||
166 | rdmsrl(x86_pmu.lbr_from + lbr_idx, from); | ||
167 | rdmsrl(x86_pmu.lbr_to + lbr_idx, to); | ||
168 | |||
169 | if (lbr_format == LBR_FORMAT_EIP_FLAGS) { | ||
170 | flags = !!(from & LBR_FROM_FLAG_MISPRED); | ||
171 | from = (u64)((((s64)from) << 1) >> 1); | ||
172 | } | ||
173 | |||
174 | cpuc->lbr_entries[i].from = from; | ||
175 | cpuc->lbr_entries[i].to = to; | ||
176 | cpuc->lbr_entries[i].flags = flags; | ||
177 | } | ||
178 | cpuc->lbr_stack.nr = i; | ||
179 | } | ||
180 | |||
181 | static void intel_pmu_lbr_read(void) | ||
182 | { | ||
183 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
184 | |||
185 | if (!cpuc->lbr_users) | ||
186 | return; | ||
187 | |||
188 | if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) | ||
189 | intel_pmu_lbr_read_32(cpuc); | ||
190 | else | ||
191 | intel_pmu_lbr_read_64(cpuc); | ||
192 | } | ||
193 | |||
194 | static void intel_pmu_lbr_init_core(void) | ||
195 | { | ||
196 | x86_pmu.lbr_nr = 4; | ||
197 | x86_pmu.lbr_tos = 0x01c9; | ||
198 | x86_pmu.lbr_from = 0x40; | ||
199 | x86_pmu.lbr_to = 0x60; | ||
200 | } | ||
201 | |||
202 | static void intel_pmu_lbr_init_nhm(void) | ||
203 | { | ||
204 | x86_pmu.lbr_nr = 16; | ||
205 | x86_pmu.lbr_tos = 0x01c9; | ||
206 | x86_pmu.lbr_from = 0x680; | ||
207 | x86_pmu.lbr_to = 0x6c0; | ||
208 | } | ||
209 | |||
210 | static void intel_pmu_lbr_init_atom(void) | ||
211 | { | ||
212 | x86_pmu.lbr_nr = 8; | ||
213 | x86_pmu.lbr_tos = 0x01c9; | ||
214 | x86_pmu.lbr_from = 0x40; | ||
215 | x86_pmu.lbr_to = 0x60; | ||
216 | } | ||
217 | |||
218 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c new file mode 100644 index 000000000000..424fc8de68e4 --- /dev/null +++ b/arch/x86/kernel/cpu/perf_event_p4.c | |||
@@ -0,0 +1,857 @@ | |||
1 | /* | ||
2 | * Netburst Perfomance Events (P4, old Xeon) | ||
3 | * | ||
4 | * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org> | ||
5 | * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com> | ||
6 | * | ||
7 | * For licencing details see kernel-base/COPYING | ||
8 | */ | ||
9 | |||
10 | #ifdef CONFIG_CPU_SUP_INTEL | ||
11 | |||
12 | #include <asm/perf_event_p4.h> | ||
13 | |||
14 | #define P4_CNTR_LIMIT 3 | ||
15 | /* | ||
16 | * array indices: 0,1 - HT threads, used with HT enabled cpu | ||
17 | */ | ||
18 | struct p4_event_bind { | ||
19 | unsigned int opcode; /* Event code and ESCR selector */ | ||
20 | unsigned int escr_msr[2]; /* ESCR MSR for this event */ | ||
21 | char cntr[2][P4_CNTR_LIMIT]; /* counter index (offset), -1 on abscence */ | ||
22 | }; | ||
23 | |||
24 | struct p4_cache_event_bind { | ||
25 | unsigned int metric_pebs; | ||
26 | unsigned int metric_vert; | ||
27 | }; | ||
28 | |||
29 | #define P4_GEN_CACHE_EVENT_BIND(name) \ | ||
30 | [P4_CACHE__##name] = { \ | ||
31 | .metric_pebs = P4_PEBS__##name, \ | ||
32 | .metric_vert = P4_VERT__##name, \ | ||
33 | } | ||
34 | |||
35 | static struct p4_cache_event_bind p4_cache_event_bind_map[] = { | ||
36 | P4_GEN_CACHE_EVENT_BIND(1stl_cache_load_miss_retired), | ||
37 | P4_GEN_CACHE_EVENT_BIND(2ndl_cache_load_miss_retired), | ||
38 | P4_GEN_CACHE_EVENT_BIND(dtlb_load_miss_retired), | ||
39 | P4_GEN_CACHE_EVENT_BIND(dtlb_store_miss_retired), | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * Note that we don't use CCCR1 here, there is an | ||
44 | * exception for P4_BSQ_ALLOCATION but we just have | ||
45 | * no workaround | ||
46 | * | ||
47 | * consider this binding as resources which particular | ||
48 | * event may borrow, it doesn't contain EventMask, | ||
49 | * Tags and friends -- they are left to a caller | ||
50 | */ | ||
51 | static struct p4_event_bind p4_event_bind_map[] = { | ||
52 | [P4_EVENT_TC_DELIVER_MODE] = { | ||
53 | .opcode = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE), | ||
54 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | ||
55 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
56 | }, | ||
57 | [P4_EVENT_BPU_FETCH_REQUEST] = { | ||
58 | .opcode = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST), | ||
59 | .escr_msr = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 }, | ||
60 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
61 | }, | ||
62 | [P4_EVENT_ITLB_REFERENCE] = { | ||
63 | .opcode = P4_OPCODE(P4_EVENT_ITLB_REFERENCE), | ||
64 | .escr_msr = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 }, | ||
65 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
66 | }, | ||
67 | [P4_EVENT_MEMORY_CANCEL] = { | ||
68 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_CANCEL), | ||
69 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | ||
70 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
71 | }, | ||
72 | [P4_EVENT_MEMORY_COMPLETE] = { | ||
73 | .opcode = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE), | ||
74 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | ||
75 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
76 | }, | ||
77 | [P4_EVENT_LOAD_PORT_REPLAY] = { | ||
78 | .opcode = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY), | ||
79 | .escr_msr = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 }, | ||
80 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
81 | }, | ||
82 | [P4_EVENT_STORE_PORT_REPLAY] = { | ||
83 | .opcode = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY), | ||
84 | .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 }, | ||
85 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
86 | }, | ||
87 | [P4_EVENT_MOB_LOAD_REPLAY] = { | ||
88 | .opcode = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY), | ||
89 | .escr_msr = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 }, | ||
90 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
91 | }, | ||
92 | [P4_EVENT_PAGE_WALK_TYPE] = { | ||
93 | .opcode = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE), | ||
94 | .escr_msr = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 }, | ||
95 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
96 | }, | ||
97 | [P4_EVENT_BSQ_CACHE_REFERENCE] = { | ||
98 | .opcode = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE), | ||
99 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 }, | ||
100 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
101 | }, | ||
102 | [P4_EVENT_IOQ_ALLOCATION] = { | ||
103 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION), | ||
104 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
105 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
106 | }, | ||
107 | [P4_EVENT_IOQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | ||
108 | .opcode = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES), | ||
109 | .escr_msr = { MSR_P4_FSB_ESCR1, MSR_P4_FSB_ESCR1 }, | ||
110 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | ||
111 | }, | ||
112 | [P4_EVENT_FSB_DATA_ACTIVITY] = { | ||
113 | .opcode = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY), | ||
114 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
115 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
116 | }, | ||
117 | [P4_EVENT_BSQ_ALLOCATION] = { /* shared ESCR, broken CCCR1 */ | ||
118 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION), | ||
119 | .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 }, | ||
120 | .cntr = { {0, -1, -1}, {1, -1, -1} }, | ||
121 | }, | ||
122 | [P4_EVENT_BSQ_ACTIVE_ENTRIES] = { /* shared ESCR */ | ||
123 | .opcode = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES), | ||
124 | .escr_msr = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 }, | ||
125 | .cntr = { {2, -1, -1}, {3, -1, -1} }, | ||
126 | }, | ||
127 | [P4_EVENT_SSE_INPUT_ASSIST] = { | ||
128 | .opcode = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST), | ||
129 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
130 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
131 | }, | ||
132 | [P4_EVENT_PACKED_SP_UOP] = { | ||
133 | .opcode = P4_OPCODE(P4_EVENT_PACKED_SP_UOP), | ||
134 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
135 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
136 | }, | ||
137 | [P4_EVENT_PACKED_DP_UOP] = { | ||
138 | .opcode = P4_OPCODE(P4_EVENT_PACKED_DP_UOP), | ||
139 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
140 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
141 | }, | ||
142 | [P4_EVENT_SCALAR_SP_UOP] = { | ||
143 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP), | ||
144 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
145 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
146 | }, | ||
147 | [P4_EVENT_SCALAR_DP_UOP] = { | ||
148 | .opcode = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP), | ||
149 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
150 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
151 | }, | ||
152 | [P4_EVENT_64BIT_MMX_UOP] = { | ||
153 | .opcode = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP), | ||
154 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
155 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
156 | }, | ||
157 | [P4_EVENT_128BIT_MMX_UOP] = { | ||
158 | .opcode = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP), | ||
159 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
160 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
161 | }, | ||
162 | [P4_EVENT_X87_FP_UOP] = { | ||
163 | .opcode = P4_OPCODE(P4_EVENT_X87_FP_UOP), | ||
164 | .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 }, | ||
165 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
166 | }, | ||
167 | [P4_EVENT_TC_MISC] = { | ||
168 | .opcode = P4_OPCODE(P4_EVENT_TC_MISC), | ||
169 | .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 }, | ||
170 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
171 | }, | ||
172 | [P4_EVENT_GLOBAL_POWER_EVENTS] = { | ||
173 | .opcode = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS), | ||
174 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
175 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
176 | }, | ||
177 | [P4_EVENT_TC_MS_XFER] = { | ||
178 | .opcode = P4_OPCODE(P4_EVENT_TC_MS_XFER), | ||
179 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | ||
180 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
181 | }, | ||
182 | [P4_EVENT_UOP_QUEUE_WRITES] = { | ||
183 | .opcode = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES), | ||
184 | .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 }, | ||
185 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
186 | }, | ||
187 | [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = { | ||
188 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE), | ||
189 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 }, | ||
190 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
191 | }, | ||
192 | [P4_EVENT_RETIRED_BRANCH_TYPE] = { | ||
193 | .opcode = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE), | ||
194 | .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 }, | ||
195 | .cntr = { {4, 5, -1}, {6, 7, -1} }, | ||
196 | }, | ||
197 | [P4_EVENT_RESOURCE_STALL] = { | ||
198 | .opcode = P4_OPCODE(P4_EVENT_RESOURCE_STALL), | ||
199 | .escr_msr = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 }, | ||
200 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
201 | }, | ||
202 | [P4_EVENT_WC_BUFFER] = { | ||
203 | .opcode = P4_OPCODE(P4_EVENT_WC_BUFFER), | ||
204 | .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 }, | ||
205 | .cntr = { {8, 9, -1}, {10, 11, -1} }, | ||
206 | }, | ||
207 | [P4_EVENT_B2B_CYCLES] = { | ||
208 | .opcode = P4_OPCODE(P4_EVENT_B2B_CYCLES), | ||
209 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
210 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
211 | }, | ||
212 | [P4_EVENT_BNR] = { | ||
213 | .opcode = P4_OPCODE(P4_EVENT_BNR), | ||
214 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
215 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
216 | }, | ||
217 | [P4_EVENT_SNOOP] = { | ||
218 | .opcode = P4_OPCODE(P4_EVENT_SNOOP), | ||
219 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
220 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
221 | }, | ||
222 | [P4_EVENT_RESPONSE] = { | ||
223 | .opcode = P4_OPCODE(P4_EVENT_RESPONSE), | ||
224 | .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 }, | ||
225 | .cntr = { {0, -1, -1}, {2, -1, -1} }, | ||
226 | }, | ||
227 | [P4_EVENT_FRONT_END_EVENT] = { | ||
228 | .opcode = P4_OPCODE(P4_EVENT_FRONT_END_EVENT), | ||
229 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
230 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
231 | }, | ||
232 | [P4_EVENT_EXECUTION_EVENT] = { | ||
233 | .opcode = P4_OPCODE(P4_EVENT_EXECUTION_EVENT), | ||
234 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
235 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
236 | }, | ||
237 | [P4_EVENT_REPLAY_EVENT] = { | ||
238 | .opcode = P4_OPCODE(P4_EVENT_REPLAY_EVENT), | ||
239 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
240 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
241 | }, | ||
242 | [P4_EVENT_INSTR_RETIRED] = { | ||
243 | .opcode = P4_OPCODE(P4_EVENT_INSTR_RETIRED), | ||
244 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
245 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
246 | }, | ||
247 | [P4_EVENT_UOPS_RETIRED] = { | ||
248 | .opcode = P4_OPCODE(P4_EVENT_UOPS_RETIRED), | ||
249 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
250 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
251 | }, | ||
252 | [P4_EVENT_UOP_TYPE] = { | ||
253 | .opcode = P4_OPCODE(P4_EVENT_UOP_TYPE), | ||
254 | .escr_msr = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 }, | ||
255 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
256 | }, | ||
257 | [P4_EVENT_BRANCH_RETIRED] = { | ||
258 | .opcode = P4_OPCODE(P4_EVENT_BRANCH_RETIRED), | ||
259 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
260 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
261 | }, | ||
262 | [P4_EVENT_MISPRED_BRANCH_RETIRED] = { | ||
263 | .opcode = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED), | ||
264 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
265 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
266 | }, | ||
267 | [P4_EVENT_X87_ASSIST] = { | ||
268 | .opcode = P4_OPCODE(P4_EVENT_X87_ASSIST), | ||
269 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
270 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
271 | }, | ||
272 | [P4_EVENT_MACHINE_CLEAR] = { | ||
273 | .opcode = P4_OPCODE(P4_EVENT_MACHINE_CLEAR), | ||
274 | .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 }, | ||
275 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
276 | }, | ||
277 | [P4_EVENT_INSTR_COMPLETED] = { | ||
278 | .opcode = P4_OPCODE(P4_EVENT_INSTR_COMPLETED), | ||
279 | .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 }, | ||
280 | .cntr = { {12, 13, 16}, {14, 15, 17} }, | ||
281 | }, | ||
282 | }; | ||
283 | |||
284 | #define P4_GEN_CACHE_EVENT(event, bit, cache_event) \ | ||
285 | p4_config_pack_escr(P4_ESCR_EVENT(event) | \ | ||
286 | P4_ESCR_EMASK_BIT(event, bit)) | \ | ||
287 | p4_config_pack_cccr(cache_event | \ | ||
288 | P4_CCCR_ESEL(P4_OPCODE_ESEL(P4_OPCODE(event)))) | ||
289 | |||
290 | static __initconst const u64 p4_hw_cache_event_ids | ||
291 | [PERF_COUNT_HW_CACHE_MAX] | ||
292 | [PERF_COUNT_HW_CACHE_OP_MAX] | ||
293 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | ||
294 | { | ||
295 | [ C(L1D ) ] = { | ||
296 | [ C(OP_READ) ] = { | ||
297 | [ C(RESULT_ACCESS) ] = 0x0, | ||
298 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
299 | P4_CACHE__1stl_cache_load_miss_retired), | ||
300 | }, | ||
301 | }, | ||
302 | [ C(LL ) ] = { | ||
303 | [ C(OP_READ) ] = { | ||
304 | [ C(RESULT_ACCESS) ] = 0x0, | ||
305 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
306 | P4_CACHE__2ndl_cache_load_miss_retired), | ||
307 | }, | ||
308 | }, | ||
309 | [ C(DTLB) ] = { | ||
310 | [ C(OP_READ) ] = { | ||
311 | [ C(RESULT_ACCESS) ] = 0x0, | ||
312 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
313 | P4_CACHE__dtlb_load_miss_retired), | ||
314 | }, | ||
315 | [ C(OP_WRITE) ] = { | ||
316 | [ C(RESULT_ACCESS) ] = 0x0, | ||
317 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS, | ||
318 | P4_CACHE__dtlb_store_miss_retired), | ||
319 | }, | ||
320 | }, | ||
321 | [ C(ITLB) ] = { | ||
322 | [ C(OP_READ) ] = { | ||
323 | [ C(RESULT_ACCESS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, HIT, | ||
324 | P4_CACHE__itlb_reference_hit), | ||
325 | [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, MISS, | ||
326 | P4_CACHE__itlb_reference_miss), | ||
327 | }, | ||
328 | [ C(OP_WRITE) ] = { | ||
329 | [ C(RESULT_ACCESS) ] = -1, | ||
330 | [ C(RESULT_MISS) ] = -1, | ||
331 | }, | ||
332 | [ C(OP_PREFETCH) ] = { | ||
333 | [ C(RESULT_ACCESS) ] = -1, | ||
334 | [ C(RESULT_MISS) ] = -1, | ||
335 | }, | ||
336 | }, | ||
337 | }; | ||
338 | |||
339 | static u64 p4_general_events[PERF_COUNT_HW_MAX] = { | ||
340 | /* non-halted CPU clocks */ | ||
341 | [PERF_COUNT_HW_CPU_CYCLES] = | ||
342 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) | | ||
343 | P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)), | ||
344 | |||
345 | /* | ||
346 | * retired instructions | ||
347 | * in a sake of simplicity we don't use the FSB tagging | ||
348 | */ | ||
349 | [PERF_COUNT_HW_INSTRUCTIONS] = | ||
350 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_INSTR_RETIRED) | | ||
351 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG) | | ||
352 | P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG)), | ||
353 | |||
354 | /* cache hits */ | ||
355 | [PERF_COUNT_HW_CACHE_REFERENCES] = | ||
356 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) | | ||
357 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS) | | ||
358 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE) | | ||
359 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM) | | ||
360 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS) | | ||
361 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE) | | ||
362 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM)), | ||
363 | |||
364 | /* cache misses */ | ||
365 | [PERF_COUNT_HW_CACHE_MISSES] = | ||
366 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) | | ||
367 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS) | | ||
368 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS) | | ||
369 | P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS)), | ||
370 | |||
371 | /* branch instructions retired */ | ||
372 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = | ||
373 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_RETIRED_BRANCH_TYPE) | | ||
374 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL) | | ||
375 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL) | | ||
376 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN) | | ||
377 | P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT)), | ||
378 | |||
379 | /* mispredicted branches retired */ | ||
380 | [PERF_COUNT_HW_BRANCH_MISSES] = | ||
381 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_MISPRED_BRANCH_RETIRED) | | ||
382 | P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS)), | ||
383 | |||
384 | /* bus ready clocks (cpu is driving #DRDY_DRV\#DRDY_OWN): */ | ||
385 | [PERF_COUNT_HW_BUS_CYCLES] = | ||
386 | p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_FSB_DATA_ACTIVITY) | | ||
387 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV) | | ||
388 | P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN)) | | ||
389 | p4_config_pack_cccr(P4_CCCR_EDGE | P4_CCCR_COMPARE), | ||
390 | }; | ||
391 | |||
392 | static struct p4_event_bind *p4_config_get_bind(u64 config) | ||
393 | { | ||
394 | unsigned int evnt = p4_config_unpack_event(config); | ||
395 | struct p4_event_bind *bind = NULL; | ||
396 | |||
397 | if (evnt < ARRAY_SIZE(p4_event_bind_map)) | ||
398 | bind = &p4_event_bind_map[evnt]; | ||
399 | |||
400 | return bind; | ||
401 | } | ||
402 | |||
403 | static u64 p4_pmu_event_map(int hw_event) | ||
404 | { | ||
405 | struct p4_event_bind *bind; | ||
406 | unsigned int esel; | ||
407 | u64 config; | ||
408 | |||
409 | config = p4_general_events[hw_event]; | ||
410 | bind = p4_config_get_bind(config); | ||
411 | esel = P4_OPCODE_ESEL(bind->opcode); | ||
412 | config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel)); | ||
413 | |||
414 | return config; | ||
415 | } | ||
416 | |||
417 | static int p4_hw_config(struct perf_event *event) | ||
418 | { | ||
419 | int cpu = get_cpu(); | ||
420 | int rc = 0; | ||
421 | unsigned int evnt; | ||
422 | u32 escr, cccr; | ||
423 | |||
424 | /* | ||
425 | * the reason we use cpu that early is that: if we get scheduled | ||
426 | * first time on the same cpu -- we will not need swap thread | ||
427 | * specific flags in config (and will save some cpu cycles) | ||
428 | */ | ||
429 | |||
430 | cccr = p4_default_cccr_conf(cpu); | ||
431 | escr = p4_default_escr_conf(cpu, event->attr.exclude_kernel, | ||
432 | event->attr.exclude_user); | ||
433 | event->hw.config = p4_config_pack_escr(escr) | | ||
434 | p4_config_pack_cccr(cccr); | ||
435 | |||
436 | if (p4_ht_active() && p4_ht_thread(cpu)) | ||
437 | event->hw.config = p4_set_ht_bit(event->hw.config); | ||
438 | |||
439 | if (event->attr.type == PERF_TYPE_RAW) { | ||
440 | |||
441 | /* user data may have out-of-bound event index */ | ||
442 | evnt = p4_config_unpack_event(event->attr.config); | ||
443 | if (evnt >= ARRAY_SIZE(p4_event_bind_map)) { | ||
444 | rc = -EINVAL; | ||
445 | goto out; | ||
446 | } | ||
447 | |||
448 | /* | ||
449 | * We don't control raw events so it's up to the caller | ||
450 | * to pass sane values (and we don't count the thread number | ||
451 | * on HT machine but allow HT-compatible specifics to be | ||
452 | * passed on) | ||
453 | * | ||
454 | * XXX: HT wide things should check perf_paranoid_cpu() && | ||
455 | * CAP_SYS_ADMIN | ||
456 | */ | ||
457 | event->hw.config |= event->attr.config & | ||
458 | (p4_config_pack_escr(P4_ESCR_MASK_HT) | | ||
459 | p4_config_pack_cccr(P4_CCCR_MASK_HT)); | ||
460 | } | ||
461 | |||
462 | rc = x86_setup_perfctr(event); | ||
463 | out: | ||
464 | put_cpu(); | ||
465 | return rc; | ||
466 | } | ||
467 | |||
468 | static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc) | ||
469 | { | ||
470 | unsigned long dummy; | ||
471 | |||
472 | rdmsrl(hwc->config_base + hwc->idx, dummy); | ||
473 | if (dummy & P4_CCCR_OVF) { | ||
474 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
475 | ((u64)dummy) & ~P4_CCCR_OVF); | ||
476 | } | ||
477 | } | ||
478 | |||
479 | static inline void p4_pmu_disable_event(struct perf_event *event) | ||
480 | { | ||
481 | struct hw_perf_event *hwc = &event->hw; | ||
482 | |||
483 | /* | ||
484 | * If event gets disabled while counter is in overflowed | ||
485 | * state we need to clear P4_CCCR_OVF, otherwise interrupt get | ||
486 | * asserted again and again | ||
487 | */ | ||
488 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
489 | (u64)(p4_config_unpack_cccr(hwc->config)) & | ||
490 | ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED); | ||
491 | } | ||
492 | |||
493 | static void p4_pmu_disable_all(void) | ||
494 | { | ||
495 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
496 | int idx; | ||
497 | |||
498 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
499 | struct perf_event *event = cpuc->events[idx]; | ||
500 | if (!test_bit(idx, cpuc->active_mask)) | ||
501 | continue; | ||
502 | p4_pmu_disable_event(event); | ||
503 | } | ||
504 | } | ||
505 | |||
506 | static void p4_pmu_enable_event(struct perf_event *event) | ||
507 | { | ||
508 | struct hw_perf_event *hwc = &event->hw; | ||
509 | int thread = p4_ht_config_thread(hwc->config); | ||
510 | u64 escr_conf = p4_config_unpack_escr(p4_clear_ht_bit(hwc->config)); | ||
511 | unsigned int idx = p4_config_unpack_event(hwc->config); | ||
512 | unsigned int idx_cache = p4_config_unpack_cache_event(hwc->config); | ||
513 | struct p4_event_bind *bind; | ||
514 | struct p4_cache_event_bind *bind_cache; | ||
515 | u64 escr_addr, cccr; | ||
516 | |||
517 | bind = &p4_event_bind_map[idx]; | ||
518 | escr_addr = (u64)bind->escr_msr[thread]; | ||
519 | |||
520 | /* | ||
521 | * - we dont support cascaded counters yet | ||
522 | * - and counter 1 is broken (erratum) | ||
523 | */ | ||
524 | WARN_ON_ONCE(p4_is_event_cascaded(hwc->config)); | ||
525 | WARN_ON_ONCE(hwc->idx == 1); | ||
526 | |||
527 | /* we need a real Event value */ | ||
528 | escr_conf &= ~P4_ESCR_EVENT_MASK; | ||
529 | escr_conf |= P4_ESCR_EVENT(P4_OPCODE_EVNT(bind->opcode)); | ||
530 | |||
531 | cccr = p4_config_unpack_cccr(hwc->config); | ||
532 | |||
533 | /* | ||
534 | * it could be Cache event so that we need to | ||
535 | * set metrics into additional MSRs | ||
536 | */ | ||
537 | BUILD_BUG_ON(P4_CACHE__MAX > P4_CCCR_CACHE_OPS_MASK); | ||
538 | if (idx_cache > P4_CACHE__NONE && | ||
539 | idx_cache < ARRAY_SIZE(p4_cache_event_bind_map)) { | ||
540 | bind_cache = &p4_cache_event_bind_map[idx_cache]; | ||
541 | (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)bind_cache->metric_pebs); | ||
542 | (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)bind_cache->metric_vert); | ||
543 | } | ||
544 | |||
545 | (void)checking_wrmsrl(escr_addr, escr_conf); | ||
546 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, | ||
547 | (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE); | ||
548 | } | ||
549 | |||
550 | static void p4_pmu_enable_all(int added) | ||
551 | { | ||
552 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | ||
553 | int idx; | ||
554 | |||
555 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
556 | struct perf_event *event = cpuc->events[idx]; | ||
557 | if (!test_bit(idx, cpuc->active_mask)) | ||
558 | continue; | ||
559 | p4_pmu_enable_event(event); | ||
560 | } | ||
561 | } | ||
562 | |||
563 | static int p4_pmu_handle_irq(struct pt_regs *regs) | ||
564 | { | ||
565 | struct perf_sample_data data; | ||
566 | struct cpu_hw_events *cpuc; | ||
567 | struct perf_event *event; | ||
568 | struct hw_perf_event *hwc; | ||
569 | int idx, handled = 0; | ||
570 | u64 val; | ||
571 | |||
572 | data.addr = 0; | ||
573 | data.raw = NULL; | ||
574 | |||
575 | cpuc = &__get_cpu_var(cpu_hw_events); | ||
576 | |||
577 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | ||
578 | |||
579 | if (!test_bit(idx, cpuc->active_mask)) | ||
580 | continue; | ||
581 | |||
582 | event = cpuc->events[idx]; | ||
583 | hwc = &event->hw; | ||
584 | |||
585 | WARN_ON_ONCE(hwc->idx != idx); | ||
586 | |||
587 | /* | ||
588 | * FIXME: Redundant call, actually not needed | ||
589 | * but just to check if we're screwed | ||
590 | */ | ||
591 | p4_pmu_clear_cccr_ovf(hwc); | ||
592 | |||
593 | val = x86_perf_event_update(event); | ||
594 | if (val & (1ULL << (x86_pmu.cntval_bits - 1))) | ||
595 | continue; | ||
596 | |||
597 | /* | ||
598 | * event overflow | ||
599 | */ | ||
600 | handled = 1; | ||
601 | data.period = event->hw.last_period; | ||
602 | |||
603 | if (!x86_perf_event_set_period(event)) | ||
604 | continue; | ||
605 | if (perf_event_overflow(event, 1, &data, regs)) | ||
606 | p4_pmu_disable_event(event); | ||
607 | } | ||
608 | |||
609 | if (handled) { | ||
610 | /* p4 quirk: unmask it again */ | ||
611 | apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED); | ||
612 | inc_irq_stat(apic_perf_irqs); | ||
613 | } | ||
614 | |||
615 | return handled; | ||
616 | } | ||
617 | |||
618 | /* | ||
619 | * swap thread specific fields according to a thread | ||
620 | * we are going to run on | ||
621 | */ | ||
622 | static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu) | ||
623 | { | ||
624 | u32 escr, cccr; | ||
625 | |||
626 | /* | ||
627 | * we either lucky and continue on same cpu or no HT support | ||
628 | */ | ||
629 | if (!p4_should_swap_ts(hwc->config, cpu)) | ||
630 | return; | ||
631 | |||
632 | /* | ||
633 | * the event is migrated from an another logical | ||
634 | * cpu, so we need to swap thread specific flags | ||
635 | */ | ||
636 | |||
637 | escr = p4_config_unpack_escr(hwc->config); | ||
638 | cccr = p4_config_unpack_cccr(hwc->config); | ||
639 | |||
640 | if (p4_ht_thread(cpu)) { | ||
641 | cccr &= ~P4_CCCR_OVF_PMI_T0; | ||
642 | cccr |= P4_CCCR_OVF_PMI_T1; | ||
643 | if (escr & P4_ESCR_T0_OS) { | ||
644 | escr &= ~P4_ESCR_T0_OS; | ||
645 | escr |= P4_ESCR_T1_OS; | ||
646 | } | ||
647 | if (escr & P4_ESCR_T0_USR) { | ||
648 | escr &= ~P4_ESCR_T0_USR; | ||
649 | escr |= P4_ESCR_T1_USR; | ||
650 | } | ||
651 | hwc->config = p4_config_pack_escr(escr); | ||
652 | hwc->config |= p4_config_pack_cccr(cccr); | ||
653 | hwc->config |= P4_CONFIG_HT; | ||
654 | } else { | ||
655 | cccr &= ~P4_CCCR_OVF_PMI_T1; | ||
656 | cccr |= P4_CCCR_OVF_PMI_T0; | ||
657 | if (escr & P4_ESCR_T1_OS) { | ||
658 | escr &= ~P4_ESCR_T1_OS; | ||
659 | escr |= P4_ESCR_T0_OS; | ||
660 | } | ||
661 | if (escr & P4_ESCR_T1_USR) { | ||
662 | escr &= ~P4_ESCR_T1_USR; | ||
663 | escr |= P4_ESCR_T0_USR; | ||
664 | } | ||
665 | hwc->config = p4_config_pack_escr(escr); | ||
666 | hwc->config |= p4_config_pack_cccr(cccr); | ||
667 | hwc->config &= ~P4_CONFIG_HT; | ||
668 | } | ||
669 | } | ||
670 | |||
671 | /* | ||
672 | * ESCR address hashing is tricky, ESCRs are not sequential | ||
673 | * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and | ||
674 | * the metric between any ESCRs is laid in range [0xa0,0xe1] | ||
675 | * | ||
676 | * so we make ~70% filled hashtable | ||
677 | */ | ||
678 | |||
679 | #define P4_ESCR_MSR_BASE 0x000003a0 | ||
680 | #define P4_ESCR_MSR_MAX 0x000003e1 | ||
681 | #define P4_ESCR_MSR_TABLE_SIZE (P4_ESCR_MSR_MAX - P4_ESCR_MSR_BASE + 1) | ||
682 | #define P4_ESCR_MSR_IDX(msr) (msr - P4_ESCR_MSR_BASE) | ||
683 | #define P4_ESCR_MSR_TABLE_ENTRY(msr) [P4_ESCR_MSR_IDX(msr)] = msr | ||
684 | |||
685 | static const unsigned int p4_escr_table[P4_ESCR_MSR_TABLE_SIZE] = { | ||
686 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR0), | ||
687 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR1), | ||
688 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR0), | ||
689 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR1), | ||
690 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR0), | ||
691 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR1), | ||
692 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR0), | ||
693 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR1), | ||
694 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR2), | ||
695 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR3), | ||
696 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR4), | ||
697 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR5), | ||
698 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR0), | ||
699 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR1), | ||
700 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR0), | ||
701 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR1), | ||
702 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR0), | ||
703 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR1), | ||
704 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR0), | ||
705 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR1), | ||
706 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR0), | ||
707 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR1), | ||
708 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR0), | ||
709 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR1), | ||
710 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR0), | ||
711 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR1), | ||
712 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR0), | ||
713 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR1), | ||
714 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR0), | ||
715 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR1), | ||
716 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR0), | ||
717 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR1), | ||
718 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR0), | ||
719 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR1), | ||
720 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR0), | ||
721 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR1), | ||
722 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR0), | ||
723 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR1), | ||
724 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR0), | ||
725 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR1), | ||
726 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR0), | ||
727 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR1), | ||
728 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR0), | ||
729 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR1), | ||
730 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR0), | ||
731 | P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR1), | ||
732 | }; | ||
733 | |||
734 | static int p4_get_escr_idx(unsigned int addr) | ||
735 | { | ||
736 | unsigned int idx = P4_ESCR_MSR_IDX(addr); | ||
737 | |||
738 | if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE || | ||
739 | !p4_escr_table[idx])) { | ||
740 | WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr); | ||
741 | return -1; | ||
742 | } | ||
743 | |||
744 | return idx; | ||
745 | } | ||
746 | |||
747 | static int p4_next_cntr(int thread, unsigned long *used_mask, | ||
748 | struct p4_event_bind *bind) | ||
749 | { | ||
750 | int i, j; | ||
751 | |||
752 | for (i = 0; i < P4_CNTR_LIMIT; i++) { | ||
753 | j = bind->cntr[thread][i]; | ||
754 | if (j != -1 && !test_bit(j, used_mask)) | ||
755 | return j; | ||
756 | } | ||
757 | |||
758 | return -1; | ||
759 | } | ||
760 | |||
761 | static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign) | ||
762 | { | ||
763 | unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | ||
764 | unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)]; | ||
765 | int cpu = raw_smp_processor_id(); | ||
766 | struct hw_perf_event *hwc; | ||
767 | struct p4_event_bind *bind; | ||
768 | unsigned int i, thread, num; | ||
769 | int cntr_idx, escr_idx; | ||
770 | |||
771 | bitmap_zero(used_mask, X86_PMC_IDX_MAX); | ||
772 | bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE); | ||
773 | |||
774 | for (i = 0, num = n; i < n; i++, num--) { | ||
775 | |||
776 | hwc = &cpuc->event_list[i]->hw; | ||
777 | thread = p4_ht_thread(cpu); | ||
778 | bind = p4_config_get_bind(hwc->config); | ||
779 | escr_idx = p4_get_escr_idx(bind->escr_msr[thread]); | ||
780 | if (unlikely(escr_idx == -1)) | ||
781 | goto done; | ||
782 | |||
783 | if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) { | ||
784 | cntr_idx = hwc->idx; | ||
785 | if (assign) | ||
786 | assign[i] = hwc->idx; | ||
787 | goto reserve; | ||
788 | } | ||
789 | |||
790 | cntr_idx = p4_next_cntr(thread, used_mask, bind); | ||
791 | if (cntr_idx == -1 || test_bit(escr_idx, escr_mask)) | ||
792 | goto done; | ||
793 | |||
794 | p4_pmu_swap_config_ts(hwc, cpu); | ||
795 | if (assign) | ||
796 | assign[i] = cntr_idx; | ||
797 | reserve: | ||
798 | set_bit(cntr_idx, used_mask); | ||
799 | set_bit(escr_idx, escr_mask); | ||
800 | } | ||
801 | |||
802 | done: | ||
803 | return num ? -ENOSPC : 0; | ||
804 | } | ||
805 | |||
806 | static __initconst const struct x86_pmu p4_pmu = { | ||
807 | .name = "Netburst P4/Xeon", | ||
808 | .handle_irq = p4_pmu_handle_irq, | ||
809 | .disable_all = p4_pmu_disable_all, | ||
810 | .enable_all = p4_pmu_enable_all, | ||
811 | .enable = p4_pmu_enable_event, | ||
812 | .disable = p4_pmu_disable_event, | ||
813 | .eventsel = MSR_P4_BPU_CCCR0, | ||
814 | .perfctr = MSR_P4_BPU_PERFCTR0, | ||
815 | .event_map = p4_pmu_event_map, | ||
816 | .max_events = ARRAY_SIZE(p4_general_events), | ||
817 | .get_event_constraints = x86_get_event_constraints, | ||
818 | /* | ||
819 | * IF HT disabled we may need to use all | ||
820 | * ARCH_P4_MAX_CCCR counters simulaneously | ||
821 | * though leave it restricted at moment assuming | ||
822 | * HT is on | ||
823 | */ | ||
824 | .num_counters = ARCH_P4_MAX_CCCR, | ||
825 | .apic = 1, | ||
826 | .cntval_bits = 40, | ||
827 | .cntval_mask = (1ULL << 40) - 1, | ||
828 | .max_period = (1ULL << 39) - 1, | ||
829 | .hw_config = p4_hw_config, | ||
830 | .schedule_events = p4_pmu_schedule_events, | ||
831 | }; | ||
832 | |||
833 | static __init int p4_pmu_init(void) | ||
834 | { | ||
835 | unsigned int low, high; | ||
836 | |||
837 | /* If we get stripped -- indexig fails */ | ||
838 | BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC); | ||
839 | |||
840 | rdmsr(MSR_IA32_MISC_ENABLE, low, high); | ||
841 | if (!(low & (1 << 7))) { | ||
842 | pr_cont("unsupported Netburst CPU model %d ", | ||
843 | boot_cpu_data.x86_model); | ||
844 | return -ENODEV; | ||
845 | } | ||
846 | |||
847 | memcpy(hw_cache_event_ids, p4_hw_cache_event_ids, | ||
848 | sizeof(hw_cache_event_ids)); | ||
849 | |||
850 | pr_cont("Netburst events, "); | ||
851 | |||
852 | x86_pmu = p4_pmu; | ||
853 | |||
854 | return 0; | ||
855 | } | ||
856 | |||
857 | #endif /* CONFIG_CPU_SUP_INTEL */ | ||
diff --git a/arch/x86/kernel/cpu/perf_event_p6.c b/arch/x86/kernel/cpu/perf_event_p6.c index a330485d14da..34ba07be2cda 100644 --- a/arch/x86/kernel/cpu/perf_event_p6.c +++ b/arch/x86/kernel/cpu/perf_event_p6.c | |||
@@ -27,24 +27,6 @@ static u64 p6_pmu_event_map(int hw_event) | |||
27 | */ | 27 | */ |
28 | #define P6_NOP_EVENT 0x0000002EULL | 28 | #define P6_NOP_EVENT 0x0000002EULL |
29 | 29 | ||
30 | static u64 p6_pmu_raw_event(u64 hw_event) | ||
31 | { | ||
32 | #define P6_EVNTSEL_EVENT_MASK 0x000000FFULL | ||
33 | #define P6_EVNTSEL_UNIT_MASK 0x0000FF00ULL | ||
34 | #define P6_EVNTSEL_EDGE_MASK 0x00040000ULL | ||
35 | #define P6_EVNTSEL_INV_MASK 0x00800000ULL | ||
36 | #define P6_EVNTSEL_REG_MASK 0xFF000000ULL | ||
37 | |||
38 | #define P6_EVNTSEL_MASK \ | ||
39 | (P6_EVNTSEL_EVENT_MASK | \ | ||
40 | P6_EVNTSEL_UNIT_MASK | \ | ||
41 | P6_EVNTSEL_EDGE_MASK | \ | ||
42 | P6_EVNTSEL_INV_MASK | \ | ||
43 | P6_EVNTSEL_REG_MASK) | ||
44 | |||
45 | return hw_event & P6_EVNTSEL_MASK; | ||
46 | } | ||
47 | |||
48 | static struct event_constraint p6_event_constraints[] = | 30 | static struct event_constraint p6_event_constraints[] = |
49 | { | 31 | { |
50 | INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FLOPS */ | 32 | INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FLOPS */ |
@@ -66,7 +48,7 @@ static void p6_pmu_disable_all(void) | |||
66 | wrmsrl(MSR_P6_EVNTSEL0, val); | 48 | wrmsrl(MSR_P6_EVNTSEL0, val); |
67 | } | 49 | } |
68 | 50 | ||
69 | static void p6_pmu_enable_all(void) | 51 | static void p6_pmu_enable_all(int added) |
70 | { | 52 | { |
71 | unsigned long val; | 53 | unsigned long val; |
72 | 54 | ||
@@ -102,22 +84,23 @@ static void p6_pmu_enable_event(struct perf_event *event) | |||
102 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); | 84 | (void)checking_wrmsrl(hwc->config_base + hwc->idx, val); |
103 | } | 85 | } |
104 | 86 | ||
105 | static __initconst struct x86_pmu p6_pmu = { | 87 | static __initconst const struct x86_pmu p6_pmu = { |
106 | .name = "p6", | 88 | .name = "p6", |
107 | .handle_irq = x86_pmu_handle_irq, | 89 | .handle_irq = x86_pmu_handle_irq, |
108 | .disable_all = p6_pmu_disable_all, | 90 | .disable_all = p6_pmu_disable_all, |
109 | .enable_all = p6_pmu_enable_all, | 91 | .enable_all = p6_pmu_enable_all, |
110 | .enable = p6_pmu_enable_event, | 92 | .enable = p6_pmu_enable_event, |
111 | .disable = p6_pmu_disable_event, | 93 | .disable = p6_pmu_disable_event, |
94 | .hw_config = x86_pmu_hw_config, | ||
95 | .schedule_events = x86_schedule_events, | ||
112 | .eventsel = MSR_P6_EVNTSEL0, | 96 | .eventsel = MSR_P6_EVNTSEL0, |
113 | .perfctr = MSR_P6_PERFCTR0, | 97 | .perfctr = MSR_P6_PERFCTR0, |
114 | .event_map = p6_pmu_event_map, | 98 | .event_map = p6_pmu_event_map, |
115 | .raw_event = p6_pmu_raw_event, | ||
116 | .max_events = ARRAY_SIZE(p6_perfmon_event_map), | 99 | .max_events = ARRAY_SIZE(p6_perfmon_event_map), |
117 | .apic = 1, | 100 | .apic = 1, |
118 | .max_period = (1ULL << 31) - 1, | 101 | .max_period = (1ULL << 31) - 1, |
119 | .version = 0, | 102 | .version = 0, |
120 | .num_events = 2, | 103 | .num_counters = 2, |
121 | /* | 104 | /* |
122 | * Events have 40 bits implemented. However they are designed such | 105 | * Events have 40 bits implemented. However they are designed such |
123 | * that bits [32-39] are sign extensions of bit 31. As such the | 106 | * that bits [32-39] are sign extensions of bit 31. As such the |
@@ -125,8 +108,8 @@ static __initconst struct x86_pmu p6_pmu = { | |||
125 | * | 108 | * |
126 | * See IA-32 Intel Architecture Software developer manual Vol 3B | 109 | * See IA-32 Intel Architecture Software developer manual Vol 3B |
127 | */ | 110 | */ |
128 | .event_bits = 32, | 111 | .cntval_bits = 32, |
129 | .event_mask = (1ULL << 32) - 1, | 112 | .cntval_mask = (1ULL << 32) - 1, |
130 | .get_event_constraints = x86_get_event_constraints, | 113 | .get_event_constraints = x86_get_event_constraints, |
131 | .event_constraints = p6_event_constraints, | 114 | .event_constraints = p6_event_constraints, |
132 | }; | 115 | }; |
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index dfdb4dba2320..b9d1ff588445 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c | |||
@@ -24,8 +24,8 @@ | |||
24 | #include <linux/dmi.h> | 24 | #include <linux/dmi.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <asm/div64.h> | 26 | #include <asm/div64.h> |
27 | #include <asm/vmware.h> | ||
28 | #include <asm/x86_init.h> | 27 | #include <asm/x86_init.h> |
28 | #include <asm/hypervisor.h> | ||
29 | 29 | ||
30 | #define CPUID_VMWARE_INFO_LEAF 0x40000000 | 30 | #define CPUID_VMWARE_INFO_LEAF 0x40000000 |
31 | #define VMWARE_HYPERVISOR_MAGIC 0x564D5868 | 31 | #define VMWARE_HYPERVISOR_MAGIC 0x564D5868 |
@@ -65,7 +65,7 @@ static unsigned long vmware_get_tsc_khz(void) | |||
65 | return tsc_hz; | 65 | return tsc_hz; |
66 | } | 66 | } |
67 | 67 | ||
68 | void __init vmware_platform_setup(void) | 68 | static void __init vmware_platform_setup(void) |
69 | { | 69 | { |
70 | uint32_t eax, ebx, ecx, edx; | 70 | uint32_t eax, ebx, ecx, edx; |
71 | 71 | ||
@@ -83,26 +83,22 @@ void __init vmware_platform_setup(void) | |||
83 | * serial key should be enough, as this will always have a VMware | 83 | * serial key should be enough, as this will always have a VMware |
84 | * specific string when running under VMware hypervisor. | 84 | * specific string when running under VMware hypervisor. |
85 | */ | 85 | */ |
86 | int vmware_platform(void) | 86 | static bool __init vmware_platform(void) |
87 | { | 87 | { |
88 | if (cpu_has_hypervisor) { | 88 | if (cpu_has_hypervisor) { |
89 | unsigned int eax, ebx, ecx, edx; | 89 | unsigned int eax; |
90 | char hyper_vendor_id[13]; | 90 | unsigned int hyper_vendor_id[3]; |
91 | 91 | ||
92 | cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &ebx, &ecx, &edx); | 92 | cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &hyper_vendor_id[0], |
93 | memcpy(hyper_vendor_id + 0, &ebx, 4); | 93 | &hyper_vendor_id[1], &hyper_vendor_id[2]); |
94 | memcpy(hyper_vendor_id + 4, &ecx, 4); | 94 | if (!memcmp(hyper_vendor_id, "VMwareVMware", 12)) |
95 | memcpy(hyper_vendor_id + 8, &edx, 4); | 95 | return true; |
96 | hyper_vendor_id[12] = '\0'; | ||
97 | if (!strcmp(hyper_vendor_id, "VMwareVMware")) | ||
98 | return 1; | ||
99 | } else if (dmi_available && dmi_name_in_serial("VMware") && | 96 | } else if (dmi_available && dmi_name_in_serial("VMware") && |
100 | __vmware_platform()) | 97 | __vmware_platform()) |
101 | return 1; | 98 | return true; |
102 | 99 | ||
103 | return 0; | 100 | return false; |
104 | } | 101 | } |
105 | EXPORT_SYMBOL(vmware_platform); | ||
106 | 102 | ||
107 | /* | 103 | /* |
108 | * VMware hypervisor takes care of exporting a reliable TSC to the guest. | 104 | * VMware hypervisor takes care of exporting a reliable TSC to the guest. |
@@ -116,8 +112,16 @@ EXPORT_SYMBOL(vmware_platform); | |||
116 | * so that the kernel could just trust the hypervisor with providing a | 112 | * so that the kernel could just trust the hypervisor with providing a |
117 | * reliable virtual TSC that is suitable for timekeeping. | 113 | * reliable virtual TSC that is suitable for timekeeping. |
118 | */ | 114 | */ |
119 | void __cpuinit vmware_set_feature_bits(struct cpuinfo_x86 *c) | 115 | static void __cpuinit vmware_set_cpu_features(struct cpuinfo_x86 *c) |
120 | { | 116 | { |
121 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); | 117 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); |
122 | set_cpu_cap(c, X86_FEATURE_TSC_RELIABLE); | 118 | set_cpu_cap(c, X86_FEATURE_TSC_RELIABLE); |
123 | } | 119 | } |
120 | |||
121 | const __refconst struct hypervisor_x86 x86_hyper_vmware = { | ||
122 | .name = "VMware", | ||
123 | .detect = vmware_platform, | ||
124 | .set_cpu_features = vmware_set_cpu_features, | ||
125 | .init_platform = vmware_platform_setup, | ||
126 | }; | ||
127 | EXPORT_SYMBOL(x86_hyper_vmware); | ||
diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c deleted file mode 100644 index 1c47390dd0e5..000000000000 --- a/arch/x86/kernel/ds.c +++ /dev/null | |||
@@ -1,1437 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support | ||
3 | * | ||
4 | * This provides a low-level interface to the hardware's Debug Store | ||
5 | * feature that is used for branch trace store (BTS) and | ||
6 | * precise-event based sampling (PEBS). | ||
7 | * | ||
8 | * It manages: | ||
9 | * - DS and BTS hardware configuration | ||
10 | * - buffer overflow handling (to be done) | ||
11 | * - buffer access | ||
12 | * | ||
13 | * It does not do: | ||
14 | * - security checking (is the caller allowed to trace the task) | ||
15 | * - buffer allocation (memory accounting) | ||
16 | * | ||
17 | * | ||
18 | * Copyright (C) 2007-2009 Intel Corporation. | ||
19 | * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009 | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/errno.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/trace_clock.h> | ||
29 | |||
30 | #include <asm/ds.h> | ||
31 | |||
32 | #include "ds_selftest.h" | ||
33 | |||
34 | /* | ||
35 | * The configuration for a particular DS hardware implementation: | ||
36 | */ | ||
37 | struct ds_configuration { | ||
38 | /* The name of the configuration: */ | ||
39 | const char *name; | ||
40 | |||
41 | /* The size of pointer-typed fields in DS, BTS, and PEBS: */ | ||
42 | unsigned char sizeof_ptr_field; | ||
43 | |||
44 | /* The size of a BTS/PEBS record in bytes: */ | ||
45 | unsigned char sizeof_rec[2]; | ||
46 | |||
47 | /* The number of pebs counter reset values in the DS structure. */ | ||
48 | unsigned char nr_counter_reset; | ||
49 | |||
50 | /* Control bit-masks indexed by enum ds_feature: */ | ||
51 | unsigned long ctl[dsf_ctl_max]; | ||
52 | }; | ||
53 | static struct ds_configuration ds_cfg __read_mostly; | ||
54 | |||
55 | |||
56 | /* Maximal size of a DS configuration: */ | ||
57 | #define MAX_SIZEOF_DS 0x80 | ||
58 | |||
59 | /* Maximal size of a BTS record: */ | ||
60 | #define MAX_SIZEOF_BTS (3 * 8) | ||
61 | |||
62 | /* BTS and PEBS buffer alignment: */ | ||
63 | #define DS_ALIGNMENT (1 << 3) | ||
64 | |||
65 | /* Number of buffer pointers in DS: */ | ||
66 | #define NUM_DS_PTR_FIELDS 8 | ||
67 | |||
68 | /* Size of a pebs reset value in DS: */ | ||
69 | #define PEBS_RESET_FIELD_SIZE 8 | ||
70 | |||
71 | /* Mask of control bits in the DS MSR register: */ | ||
72 | #define BTS_CONTROL \ | ||
73 | ( ds_cfg.ctl[dsf_bts] | \ | ||
74 | ds_cfg.ctl[dsf_bts_kernel] | \ | ||
75 | ds_cfg.ctl[dsf_bts_user] | \ | ||
76 | ds_cfg.ctl[dsf_bts_overflow] ) | ||
77 | |||
78 | /* | ||
79 | * A BTS or PEBS tracer. | ||
80 | * | ||
81 | * This holds the configuration of the tracer and serves as a handle | ||
82 | * to identify tracers. | ||
83 | */ | ||
84 | struct ds_tracer { | ||
85 | /* The DS context (partially) owned by this tracer. */ | ||
86 | struct ds_context *context; | ||
87 | /* The buffer provided on ds_request() and its size in bytes. */ | ||
88 | void *buffer; | ||
89 | size_t size; | ||
90 | }; | ||
91 | |||
92 | struct bts_tracer { | ||
93 | /* The common DS part: */ | ||
94 | struct ds_tracer ds; | ||
95 | |||
96 | /* The trace including the DS configuration: */ | ||
97 | struct bts_trace trace; | ||
98 | |||
99 | /* Buffer overflow notification function: */ | ||
100 | bts_ovfl_callback_t ovfl; | ||
101 | |||
102 | /* Active flags affecting trace collection. */ | ||
103 | unsigned int flags; | ||
104 | }; | ||
105 | |||
106 | struct pebs_tracer { | ||
107 | /* The common DS part: */ | ||
108 | struct ds_tracer ds; | ||
109 | |||
110 | /* The trace including the DS configuration: */ | ||
111 | struct pebs_trace trace; | ||
112 | |||
113 | /* Buffer overflow notification function: */ | ||
114 | pebs_ovfl_callback_t ovfl; | ||
115 | }; | ||
116 | |||
117 | /* | ||
118 | * Debug Store (DS) save area configuration (see Intel64 and IA32 | ||
119 | * Architectures Software Developer's Manual, section 18.5) | ||
120 | * | ||
121 | * The DS configuration consists of the following fields; different | ||
122 | * architetures vary in the size of those fields. | ||
123 | * | ||
124 | * - double-word aligned base linear address of the BTS buffer | ||
125 | * - write pointer into the BTS buffer | ||
126 | * - end linear address of the BTS buffer (one byte beyond the end of | ||
127 | * the buffer) | ||
128 | * - interrupt pointer into BTS buffer | ||
129 | * (interrupt occurs when write pointer passes interrupt pointer) | ||
130 | * - double-word aligned base linear address of the PEBS buffer | ||
131 | * - write pointer into the PEBS buffer | ||
132 | * - end linear address of the PEBS buffer (one byte beyond the end of | ||
133 | * the buffer) | ||
134 | * - interrupt pointer into PEBS buffer | ||
135 | * (interrupt occurs when write pointer passes interrupt pointer) | ||
136 | * - value to which counter is reset following counter overflow | ||
137 | * | ||
138 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
139 | * architectures use 32bit pointers in 32bit mode. | ||
140 | * | ||
141 | * | ||
142 | * We compute the base address for the first 8 fields based on: | ||
143 | * - the field size stored in the DS configuration | ||
144 | * - the relative field position | ||
145 | * - an offset giving the start of the respective region | ||
146 | * | ||
147 | * This offset is further used to index various arrays holding | ||
148 | * information for BTS and PEBS at the respective index. | ||
149 | * | ||
150 | * On later 32bit processors, we only access the lower 32bit of the | ||
151 | * 64bit pointer fields. The upper halves will be zeroed out. | ||
152 | */ | ||
153 | |||
154 | enum ds_field { | ||
155 | ds_buffer_base = 0, | ||
156 | ds_index, | ||
157 | ds_absolute_maximum, | ||
158 | ds_interrupt_threshold, | ||
159 | }; | ||
160 | |||
161 | enum ds_qualifier { | ||
162 | ds_bts = 0, | ||
163 | ds_pebs | ||
164 | }; | ||
165 | |||
166 | static inline unsigned long | ||
167 | ds_get(const unsigned char *base, enum ds_qualifier qual, enum ds_field field) | ||
168 | { | ||
169 | base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual))); | ||
170 | return *(unsigned long *)base; | ||
171 | } | ||
172 | |||
173 | static inline void | ||
174 | ds_set(unsigned char *base, enum ds_qualifier qual, enum ds_field field, | ||
175 | unsigned long value) | ||
176 | { | ||
177 | base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual))); | ||
178 | (*(unsigned long *)base) = value; | ||
179 | } | ||
180 | |||
181 | |||
182 | /* | ||
183 | * Locking is done only for allocating BTS or PEBS resources. | ||
184 | */ | ||
185 | static DEFINE_SPINLOCK(ds_lock); | ||
186 | |||
187 | /* | ||
188 | * We either support (system-wide) per-cpu or per-thread allocation. | ||
189 | * We distinguish the two based on the task_struct pointer, where a | ||
190 | * NULL pointer indicates per-cpu allocation for the current cpu. | ||
191 | * | ||
192 | * Allocations are use-counted. As soon as resources are allocated, | ||
193 | * further allocations must be of the same type (per-cpu or | ||
194 | * per-thread). We model this by counting allocations (i.e. the number | ||
195 | * of tracers of a certain type) for one type negatively: | ||
196 | * =0 no tracers | ||
197 | * >0 number of per-thread tracers | ||
198 | * <0 number of per-cpu tracers | ||
199 | * | ||
200 | * Tracers essentially gives the number of ds contexts for a certain | ||
201 | * type of allocation. | ||
202 | */ | ||
203 | static atomic_t tracers = ATOMIC_INIT(0); | ||
204 | |||
205 | static inline int get_tracer(struct task_struct *task) | ||
206 | { | ||
207 | int error; | ||
208 | |||
209 | spin_lock_irq(&ds_lock); | ||
210 | |||
211 | if (task) { | ||
212 | error = -EPERM; | ||
213 | if (atomic_read(&tracers) < 0) | ||
214 | goto out; | ||
215 | atomic_inc(&tracers); | ||
216 | } else { | ||
217 | error = -EPERM; | ||
218 | if (atomic_read(&tracers) > 0) | ||
219 | goto out; | ||
220 | atomic_dec(&tracers); | ||
221 | } | ||
222 | |||
223 | error = 0; | ||
224 | out: | ||
225 | spin_unlock_irq(&ds_lock); | ||
226 | return error; | ||
227 | } | ||
228 | |||
229 | static inline void put_tracer(struct task_struct *task) | ||
230 | { | ||
231 | if (task) | ||
232 | atomic_dec(&tracers); | ||
233 | else | ||
234 | atomic_inc(&tracers); | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * The DS context is either attached to a thread or to a cpu: | ||
239 | * - in the former case, the thread_struct contains a pointer to the | ||
240 | * attached context. | ||
241 | * - in the latter case, we use a static array of per-cpu context | ||
242 | * pointers. | ||
243 | * | ||
244 | * Contexts are use-counted. They are allocated on first access and | ||
245 | * deallocated when the last user puts the context. | ||
246 | */ | ||
247 | struct ds_context { | ||
248 | /* The DS configuration; goes into MSR_IA32_DS_AREA: */ | ||
249 | unsigned char ds[MAX_SIZEOF_DS]; | ||
250 | |||
251 | /* The owner of the BTS and PEBS configuration, respectively: */ | ||
252 | struct bts_tracer *bts_master; | ||
253 | struct pebs_tracer *pebs_master; | ||
254 | |||
255 | /* Use count: */ | ||
256 | unsigned long count; | ||
257 | |||
258 | /* Pointer to the context pointer field: */ | ||
259 | struct ds_context **this; | ||
260 | |||
261 | /* The traced task; NULL for cpu tracing: */ | ||
262 | struct task_struct *task; | ||
263 | |||
264 | /* The traced cpu; only valid if task is NULL: */ | ||
265 | int cpu; | ||
266 | }; | ||
267 | |||
268 | static DEFINE_PER_CPU(struct ds_context *, cpu_ds_context); | ||
269 | |||
270 | |||
271 | static struct ds_context *ds_get_context(struct task_struct *task, int cpu) | ||
272 | { | ||
273 | struct ds_context **p_context = | ||
274 | (task ? &task->thread.ds_ctx : &per_cpu(cpu_ds_context, cpu)); | ||
275 | struct ds_context *context = NULL; | ||
276 | struct ds_context *new_context = NULL; | ||
277 | |||
278 | /* Chances are small that we already have a context. */ | ||
279 | new_context = kzalloc(sizeof(*new_context), GFP_KERNEL); | ||
280 | if (!new_context) | ||
281 | return NULL; | ||
282 | |||
283 | spin_lock_irq(&ds_lock); | ||
284 | |||
285 | context = *p_context; | ||
286 | if (likely(!context)) { | ||
287 | context = new_context; | ||
288 | |||
289 | context->this = p_context; | ||
290 | context->task = task; | ||
291 | context->cpu = cpu; | ||
292 | context->count = 0; | ||
293 | |||
294 | *p_context = context; | ||
295 | } | ||
296 | |||
297 | context->count++; | ||
298 | |||
299 | spin_unlock_irq(&ds_lock); | ||
300 | |||
301 | if (context != new_context) | ||
302 | kfree(new_context); | ||
303 | |||
304 | return context; | ||
305 | } | ||
306 | |||
307 | static void ds_put_context(struct ds_context *context) | ||
308 | { | ||
309 | struct task_struct *task; | ||
310 | unsigned long irq; | ||
311 | |||
312 | if (!context) | ||
313 | return; | ||
314 | |||
315 | spin_lock_irqsave(&ds_lock, irq); | ||
316 | |||
317 | if (--context->count) { | ||
318 | spin_unlock_irqrestore(&ds_lock, irq); | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | *(context->this) = NULL; | ||
323 | |||
324 | task = context->task; | ||
325 | |||
326 | if (task) | ||
327 | clear_tsk_thread_flag(task, TIF_DS_AREA_MSR); | ||
328 | |||
329 | /* | ||
330 | * We leave the (now dangling) pointer to the DS configuration in | ||
331 | * the DS_AREA msr. This is as good or as bad as replacing it with | ||
332 | * NULL - the hardware would crash if we enabled tracing. | ||
333 | * | ||
334 | * This saves us some problems with having to write an msr on a | ||
335 | * different cpu while preventing others from doing the same for the | ||
336 | * next context for that same cpu. | ||
337 | */ | ||
338 | |||
339 | spin_unlock_irqrestore(&ds_lock, irq); | ||
340 | |||
341 | /* The context might still be in use for context switching. */ | ||
342 | if (task && (task != current)) | ||
343 | wait_task_context_switch(task); | ||
344 | |||
345 | kfree(context); | ||
346 | } | ||
347 | |||
348 | static void ds_install_ds_area(struct ds_context *context) | ||
349 | { | ||
350 | unsigned long ds; | ||
351 | |||
352 | ds = (unsigned long)context->ds; | ||
353 | |||
354 | /* | ||
355 | * There is a race between the bts master and the pebs master. | ||
356 | * | ||
357 | * The thread/cpu access is synchronized via get/put_cpu() for | ||
358 | * task tracing and via wrmsr_on_cpu for cpu tracing. | ||
359 | * | ||
360 | * If bts and pebs are collected for the same task or same cpu, | ||
361 | * the same confiuration is written twice. | ||
362 | */ | ||
363 | if (context->task) { | ||
364 | get_cpu(); | ||
365 | if (context->task == current) | ||
366 | wrmsrl(MSR_IA32_DS_AREA, ds); | ||
367 | set_tsk_thread_flag(context->task, TIF_DS_AREA_MSR); | ||
368 | put_cpu(); | ||
369 | } else | ||
370 | wrmsr_on_cpu(context->cpu, MSR_IA32_DS_AREA, | ||
371 | (u32)((u64)ds), (u32)((u64)ds >> 32)); | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | * Call the tracer's callback on a buffer overflow. | ||
376 | * | ||
377 | * context: the ds context | ||
378 | * qual: the buffer type | ||
379 | */ | ||
380 | static void ds_overflow(struct ds_context *context, enum ds_qualifier qual) | ||
381 | { | ||
382 | switch (qual) { | ||
383 | case ds_bts: | ||
384 | if (context->bts_master && | ||
385 | context->bts_master->ovfl) | ||
386 | context->bts_master->ovfl(context->bts_master); | ||
387 | break; | ||
388 | case ds_pebs: | ||
389 | if (context->pebs_master && | ||
390 | context->pebs_master->ovfl) | ||
391 | context->pebs_master->ovfl(context->pebs_master); | ||
392 | break; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | |||
397 | /* | ||
398 | * Write raw data into the BTS or PEBS buffer. | ||
399 | * | ||
400 | * The remainder of any partially written record is zeroed out. | ||
401 | * | ||
402 | * context: the DS context | ||
403 | * qual: the buffer type | ||
404 | * record: the data to write | ||
405 | * size: the size of the data | ||
406 | */ | ||
407 | static int ds_write(struct ds_context *context, enum ds_qualifier qual, | ||
408 | const void *record, size_t size) | ||
409 | { | ||
410 | int bytes_written = 0; | ||
411 | |||
412 | if (!record) | ||
413 | return -EINVAL; | ||
414 | |||
415 | while (size) { | ||
416 | unsigned long base, index, end, write_end, int_th; | ||
417 | unsigned long write_size, adj_write_size; | ||
418 | |||
419 | /* | ||
420 | * Write as much as possible without producing an | ||
421 | * overflow interrupt. | ||
422 | * | ||
423 | * Interrupt_threshold must either be | ||
424 | * - bigger than absolute_maximum or | ||
425 | * - point to a record between buffer_base and absolute_maximum | ||
426 | * | ||
427 | * Index points to a valid record. | ||
428 | */ | ||
429 | base = ds_get(context->ds, qual, ds_buffer_base); | ||
430 | index = ds_get(context->ds, qual, ds_index); | ||
431 | end = ds_get(context->ds, qual, ds_absolute_maximum); | ||
432 | int_th = ds_get(context->ds, qual, ds_interrupt_threshold); | ||
433 | |||
434 | write_end = min(end, int_th); | ||
435 | |||
436 | /* | ||
437 | * If we are already beyond the interrupt threshold, | ||
438 | * we fill the entire buffer. | ||
439 | */ | ||
440 | if (write_end <= index) | ||
441 | write_end = end; | ||
442 | |||
443 | if (write_end <= index) | ||
444 | break; | ||
445 | |||
446 | write_size = min((unsigned long) size, write_end - index); | ||
447 | memcpy((void *)index, record, write_size); | ||
448 | |||
449 | record = (const char *)record + write_size; | ||
450 | size -= write_size; | ||
451 | bytes_written += write_size; | ||
452 | |||
453 | adj_write_size = write_size / ds_cfg.sizeof_rec[qual]; | ||
454 | adj_write_size *= ds_cfg.sizeof_rec[qual]; | ||
455 | |||
456 | /* Zero out trailing bytes. */ | ||
457 | memset((char *)index + write_size, 0, | ||
458 | adj_write_size - write_size); | ||
459 | index += adj_write_size; | ||
460 | |||
461 | if (index >= end) | ||
462 | index = base; | ||
463 | ds_set(context->ds, qual, ds_index, index); | ||
464 | |||
465 | if (index >= int_th) | ||
466 | ds_overflow(context, qual); | ||
467 | } | ||
468 | |||
469 | return bytes_written; | ||
470 | } | ||
471 | |||
472 | |||
473 | /* | ||
474 | * Branch Trace Store (BTS) uses the following format. Different | ||
475 | * architectures vary in the size of those fields. | ||
476 | * - source linear address | ||
477 | * - destination linear address | ||
478 | * - flags | ||
479 | * | ||
480 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
481 | * architectures use 32bit pointers in 32bit mode. | ||
482 | * | ||
483 | * We compute the base address for the fields based on: | ||
484 | * - the field size stored in the DS configuration | ||
485 | * - the relative field position | ||
486 | * | ||
487 | * In order to store additional information in the BTS buffer, we use | ||
488 | * a special source address to indicate that the record requires | ||
489 | * special interpretation. | ||
490 | * | ||
491 | * Netburst indicated via a bit in the flags field whether the branch | ||
492 | * was predicted; this is ignored. | ||
493 | * | ||
494 | * We use two levels of abstraction: | ||
495 | * - the raw data level defined here | ||
496 | * - an arch-independent level defined in ds.h | ||
497 | */ | ||
498 | |||
499 | enum bts_field { | ||
500 | bts_from, | ||
501 | bts_to, | ||
502 | bts_flags, | ||
503 | |||
504 | bts_qual = bts_from, | ||
505 | bts_clock = bts_to, | ||
506 | bts_pid = bts_flags, | ||
507 | |||
508 | bts_qual_mask = (bts_qual_max - 1), | ||
509 | bts_escape = ((unsigned long)-1 & ~bts_qual_mask) | ||
510 | }; | ||
511 | |||
512 | static inline unsigned long bts_get(const char *base, unsigned long field) | ||
513 | { | ||
514 | base += (ds_cfg.sizeof_ptr_field * field); | ||
515 | return *(unsigned long *)base; | ||
516 | } | ||
517 | |||
518 | static inline void bts_set(char *base, unsigned long field, unsigned long val) | ||
519 | { | ||
520 | base += (ds_cfg.sizeof_ptr_field * field); | ||
521 | (*(unsigned long *)base) = val; | ||
522 | } | ||
523 | |||
524 | |||
525 | /* | ||
526 | * The raw BTS data is architecture dependent. | ||
527 | * | ||
528 | * For higher-level users, we give an arch-independent view. | ||
529 | * - ds.h defines struct bts_struct | ||
530 | * - bts_read translates one raw bts record into a bts_struct | ||
531 | * - bts_write translates one bts_struct into the raw format and | ||
532 | * writes it into the top of the parameter tracer's buffer. | ||
533 | * | ||
534 | * return: bytes read/written on success; -Eerrno, otherwise | ||
535 | */ | ||
536 | static int | ||
537 | bts_read(struct bts_tracer *tracer, const void *at, struct bts_struct *out) | ||
538 | { | ||
539 | if (!tracer) | ||
540 | return -EINVAL; | ||
541 | |||
542 | if (at < tracer->trace.ds.begin) | ||
543 | return -EINVAL; | ||
544 | |||
545 | if (tracer->trace.ds.end < (at + tracer->trace.ds.size)) | ||
546 | return -EINVAL; | ||
547 | |||
548 | memset(out, 0, sizeof(*out)); | ||
549 | if ((bts_get(at, bts_qual) & ~bts_qual_mask) == bts_escape) { | ||
550 | out->qualifier = (bts_get(at, bts_qual) & bts_qual_mask); | ||
551 | out->variant.event.clock = bts_get(at, bts_clock); | ||
552 | out->variant.event.pid = bts_get(at, bts_pid); | ||
553 | } else { | ||
554 | out->qualifier = bts_branch; | ||
555 | out->variant.lbr.from = bts_get(at, bts_from); | ||
556 | out->variant.lbr.to = bts_get(at, bts_to); | ||
557 | |||
558 | if (!out->variant.lbr.from && !out->variant.lbr.to) | ||
559 | out->qualifier = bts_invalid; | ||
560 | } | ||
561 | |||
562 | return ds_cfg.sizeof_rec[ds_bts]; | ||
563 | } | ||
564 | |||
565 | static int bts_write(struct bts_tracer *tracer, const struct bts_struct *in) | ||
566 | { | ||
567 | unsigned char raw[MAX_SIZEOF_BTS]; | ||
568 | |||
569 | if (!tracer) | ||
570 | return -EINVAL; | ||
571 | |||
572 | if (MAX_SIZEOF_BTS < ds_cfg.sizeof_rec[ds_bts]) | ||
573 | return -EOVERFLOW; | ||
574 | |||
575 | switch (in->qualifier) { | ||
576 | case bts_invalid: | ||
577 | bts_set(raw, bts_from, 0); | ||
578 | bts_set(raw, bts_to, 0); | ||
579 | bts_set(raw, bts_flags, 0); | ||
580 | break; | ||
581 | case bts_branch: | ||
582 | bts_set(raw, bts_from, in->variant.lbr.from); | ||
583 | bts_set(raw, bts_to, in->variant.lbr.to); | ||
584 | bts_set(raw, bts_flags, 0); | ||
585 | break; | ||
586 | case bts_task_arrives: | ||
587 | case bts_task_departs: | ||
588 | bts_set(raw, bts_qual, (bts_escape | in->qualifier)); | ||
589 | bts_set(raw, bts_clock, in->variant.event.clock); | ||
590 | bts_set(raw, bts_pid, in->variant.event.pid); | ||
591 | break; | ||
592 | default: | ||
593 | return -EINVAL; | ||
594 | } | ||
595 | |||
596 | return ds_write(tracer->ds.context, ds_bts, raw, | ||
597 | ds_cfg.sizeof_rec[ds_bts]); | ||
598 | } | ||
599 | |||
600 | |||
601 | static void ds_write_config(struct ds_context *context, | ||
602 | struct ds_trace *cfg, enum ds_qualifier qual) | ||
603 | { | ||
604 | unsigned char *ds = context->ds; | ||
605 | |||
606 | ds_set(ds, qual, ds_buffer_base, (unsigned long)cfg->begin); | ||
607 | ds_set(ds, qual, ds_index, (unsigned long)cfg->top); | ||
608 | ds_set(ds, qual, ds_absolute_maximum, (unsigned long)cfg->end); | ||
609 | ds_set(ds, qual, ds_interrupt_threshold, (unsigned long)cfg->ith); | ||
610 | } | ||
611 | |||
612 | static void ds_read_config(struct ds_context *context, | ||
613 | struct ds_trace *cfg, enum ds_qualifier qual) | ||
614 | { | ||
615 | unsigned char *ds = context->ds; | ||
616 | |||
617 | cfg->begin = (void *)ds_get(ds, qual, ds_buffer_base); | ||
618 | cfg->top = (void *)ds_get(ds, qual, ds_index); | ||
619 | cfg->end = (void *)ds_get(ds, qual, ds_absolute_maximum); | ||
620 | cfg->ith = (void *)ds_get(ds, qual, ds_interrupt_threshold); | ||
621 | } | ||
622 | |||
623 | static void ds_init_ds_trace(struct ds_trace *trace, enum ds_qualifier qual, | ||
624 | void *base, size_t size, size_t ith, | ||
625 | unsigned int flags) { | ||
626 | unsigned long buffer, adj; | ||
627 | |||
628 | /* | ||
629 | * Adjust the buffer address and size to meet alignment | ||
630 | * constraints: | ||
631 | * - buffer is double-word aligned | ||
632 | * - size is multiple of record size | ||
633 | * | ||
634 | * We checked the size at the very beginning; we have enough | ||
635 | * space to do the adjustment. | ||
636 | */ | ||
637 | buffer = (unsigned long)base; | ||
638 | |||
639 | adj = ALIGN(buffer, DS_ALIGNMENT) - buffer; | ||
640 | buffer += adj; | ||
641 | size -= adj; | ||
642 | |||
643 | trace->n = size / ds_cfg.sizeof_rec[qual]; | ||
644 | trace->size = ds_cfg.sizeof_rec[qual]; | ||
645 | |||
646 | size = (trace->n * trace->size); | ||
647 | |||
648 | trace->begin = (void *)buffer; | ||
649 | trace->top = trace->begin; | ||
650 | trace->end = (void *)(buffer + size); | ||
651 | /* | ||
652 | * The value for 'no threshold' is -1, which will set the | ||
653 | * threshold outside of the buffer, just like we want it. | ||
654 | */ | ||
655 | ith *= ds_cfg.sizeof_rec[qual]; | ||
656 | trace->ith = (void *)(buffer + size - ith); | ||
657 | |||
658 | trace->flags = flags; | ||
659 | } | ||
660 | |||
661 | |||
662 | static int ds_request(struct ds_tracer *tracer, struct ds_trace *trace, | ||
663 | enum ds_qualifier qual, struct task_struct *task, | ||
664 | int cpu, void *base, size_t size, size_t th) | ||
665 | { | ||
666 | struct ds_context *context; | ||
667 | int error; | ||
668 | size_t req_size; | ||
669 | |||
670 | error = -EOPNOTSUPP; | ||
671 | if (!ds_cfg.sizeof_rec[qual]) | ||
672 | goto out; | ||
673 | |||
674 | error = -EINVAL; | ||
675 | if (!base) | ||
676 | goto out; | ||
677 | |||
678 | req_size = ds_cfg.sizeof_rec[qual]; | ||
679 | /* We might need space for alignment adjustments. */ | ||
680 | if (!IS_ALIGNED((unsigned long)base, DS_ALIGNMENT)) | ||
681 | req_size += DS_ALIGNMENT; | ||
682 | |||
683 | error = -EINVAL; | ||
684 | if (size < req_size) | ||
685 | goto out; | ||
686 | |||
687 | if (th != (size_t)-1) { | ||
688 | th *= ds_cfg.sizeof_rec[qual]; | ||
689 | |||
690 | error = -EINVAL; | ||
691 | if (size <= th) | ||
692 | goto out; | ||
693 | } | ||
694 | |||
695 | tracer->buffer = base; | ||
696 | tracer->size = size; | ||
697 | |||
698 | error = -ENOMEM; | ||
699 | context = ds_get_context(task, cpu); | ||
700 | if (!context) | ||
701 | goto out; | ||
702 | tracer->context = context; | ||
703 | |||
704 | /* | ||
705 | * Defer any tracer-specific initialization work for the context until | ||
706 | * context ownership has been clarified. | ||
707 | */ | ||
708 | |||
709 | error = 0; | ||
710 | out: | ||
711 | return error; | ||
712 | } | ||
713 | |||
714 | static struct bts_tracer *ds_request_bts(struct task_struct *task, int cpu, | ||
715 | void *base, size_t size, | ||
716 | bts_ovfl_callback_t ovfl, size_t th, | ||
717 | unsigned int flags) | ||
718 | { | ||
719 | struct bts_tracer *tracer; | ||
720 | int error; | ||
721 | |||
722 | /* Buffer overflow notification is not yet implemented. */ | ||
723 | error = -EOPNOTSUPP; | ||
724 | if (ovfl) | ||
725 | goto out; | ||
726 | |||
727 | error = get_tracer(task); | ||
728 | if (error < 0) | ||
729 | goto out; | ||
730 | |||
731 | error = -ENOMEM; | ||
732 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); | ||
733 | if (!tracer) | ||
734 | goto out_put_tracer; | ||
735 | tracer->ovfl = ovfl; | ||
736 | |||
737 | /* Do some more error checking and acquire a tracing context. */ | ||
738 | error = ds_request(&tracer->ds, &tracer->trace.ds, | ||
739 | ds_bts, task, cpu, base, size, th); | ||
740 | if (error < 0) | ||
741 | goto out_tracer; | ||
742 | |||
743 | /* Claim the bts part of the tracing context we acquired above. */ | ||
744 | spin_lock_irq(&ds_lock); | ||
745 | |||
746 | error = -EPERM; | ||
747 | if (tracer->ds.context->bts_master) | ||
748 | goto out_unlock; | ||
749 | tracer->ds.context->bts_master = tracer; | ||
750 | |||
751 | spin_unlock_irq(&ds_lock); | ||
752 | |||
753 | /* | ||
754 | * Now that we own the bts part of the context, let's complete the | ||
755 | * initialization for that part. | ||
756 | */ | ||
757 | ds_init_ds_trace(&tracer->trace.ds, ds_bts, base, size, th, flags); | ||
758 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_bts); | ||
759 | ds_install_ds_area(tracer->ds.context); | ||
760 | |||
761 | tracer->trace.read = bts_read; | ||
762 | tracer->trace.write = bts_write; | ||
763 | |||
764 | /* Start tracing. */ | ||
765 | ds_resume_bts(tracer); | ||
766 | |||
767 | return tracer; | ||
768 | |||
769 | out_unlock: | ||
770 | spin_unlock_irq(&ds_lock); | ||
771 | ds_put_context(tracer->ds.context); | ||
772 | out_tracer: | ||
773 | kfree(tracer); | ||
774 | out_put_tracer: | ||
775 | put_tracer(task); | ||
776 | out: | ||
777 | return ERR_PTR(error); | ||
778 | } | ||
779 | |||
780 | struct bts_tracer *ds_request_bts_task(struct task_struct *task, | ||
781 | void *base, size_t size, | ||
782 | bts_ovfl_callback_t ovfl, | ||
783 | size_t th, unsigned int flags) | ||
784 | { | ||
785 | return ds_request_bts(task, 0, base, size, ovfl, th, flags); | ||
786 | } | ||
787 | |||
788 | struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size, | ||
789 | bts_ovfl_callback_t ovfl, | ||
790 | size_t th, unsigned int flags) | ||
791 | { | ||
792 | return ds_request_bts(NULL, cpu, base, size, ovfl, th, flags); | ||
793 | } | ||
794 | |||
795 | static struct pebs_tracer *ds_request_pebs(struct task_struct *task, int cpu, | ||
796 | void *base, size_t size, | ||
797 | pebs_ovfl_callback_t ovfl, size_t th, | ||
798 | unsigned int flags) | ||
799 | { | ||
800 | struct pebs_tracer *tracer; | ||
801 | int error; | ||
802 | |||
803 | /* Buffer overflow notification is not yet implemented. */ | ||
804 | error = -EOPNOTSUPP; | ||
805 | if (ovfl) | ||
806 | goto out; | ||
807 | |||
808 | error = get_tracer(task); | ||
809 | if (error < 0) | ||
810 | goto out; | ||
811 | |||
812 | error = -ENOMEM; | ||
813 | tracer = kzalloc(sizeof(*tracer), GFP_KERNEL); | ||
814 | if (!tracer) | ||
815 | goto out_put_tracer; | ||
816 | tracer->ovfl = ovfl; | ||
817 | |||
818 | /* Do some more error checking and acquire a tracing context. */ | ||
819 | error = ds_request(&tracer->ds, &tracer->trace.ds, | ||
820 | ds_pebs, task, cpu, base, size, th); | ||
821 | if (error < 0) | ||
822 | goto out_tracer; | ||
823 | |||
824 | /* Claim the pebs part of the tracing context we acquired above. */ | ||
825 | spin_lock_irq(&ds_lock); | ||
826 | |||
827 | error = -EPERM; | ||
828 | if (tracer->ds.context->pebs_master) | ||
829 | goto out_unlock; | ||
830 | tracer->ds.context->pebs_master = tracer; | ||
831 | |||
832 | spin_unlock_irq(&ds_lock); | ||
833 | |||
834 | /* | ||
835 | * Now that we own the pebs part of the context, let's complete the | ||
836 | * initialization for that part. | ||
837 | */ | ||
838 | ds_init_ds_trace(&tracer->trace.ds, ds_pebs, base, size, th, flags); | ||
839 | ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_pebs); | ||
840 | ds_install_ds_area(tracer->ds.context); | ||
841 | |||
842 | /* Start tracing. */ | ||
843 | ds_resume_pebs(tracer); | ||
844 | |||
845 | return tracer; | ||
846 | |||
847 | out_unlock: | ||
848 | spin_unlock_irq(&ds_lock); | ||
849 | ds_put_context(tracer->ds.context); | ||
850 | out_tracer: | ||
851 | kfree(tracer); | ||
852 | out_put_tracer: | ||
853 | put_tracer(task); | ||
854 | out: | ||
855 | return ERR_PTR(error); | ||
856 | } | ||
857 | |||
858 | struct pebs_tracer *ds_request_pebs_task(struct task_struct *task, | ||
859 | void *base, size_t size, | ||
860 | pebs_ovfl_callback_t ovfl, | ||
861 | size_t th, unsigned int flags) | ||
862 | { | ||
863 | return ds_request_pebs(task, 0, base, size, ovfl, th, flags); | ||
864 | } | ||
865 | |||
866 | struct pebs_tracer *ds_request_pebs_cpu(int cpu, void *base, size_t size, | ||
867 | pebs_ovfl_callback_t ovfl, | ||
868 | size_t th, unsigned int flags) | ||
869 | { | ||
870 | return ds_request_pebs(NULL, cpu, base, size, ovfl, th, flags); | ||
871 | } | ||
872 | |||
873 | static void ds_free_bts(struct bts_tracer *tracer) | ||
874 | { | ||
875 | struct task_struct *task; | ||
876 | |||
877 | task = tracer->ds.context->task; | ||
878 | |||
879 | WARN_ON_ONCE(tracer->ds.context->bts_master != tracer); | ||
880 | tracer->ds.context->bts_master = NULL; | ||
881 | |||
882 | /* Make sure tracing stopped and the tracer is not in use. */ | ||
883 | if (task && (task != current)) | ||
884 | wait_task_context_switch(task); | ||
885 | |||
886 | ds_put_context(tracer->ds.context); | ||
887 | put_tracer(task); | ||
888 | |||
889 | kfree(tracer); | ||
890 | } | ||
891 | |||
892 | void ds_release_bts(struct bts_tracer *tracer) | ||
893 | { | ||
894 | might_sleep(); | ||
895 | |||
896 | if (!tracer) | ||
897 | return; | ||
898 | |||
899 | ds_suspend_bts(tracer); | ||
900 | ds_free_bts(tracer); | ||
901 | } | ||
902 | |||
903 | int ds_release_bts_noirq(struct bts_tracer *tracer) | ||
904 | { | ||
905 | struct task_struct *task; | ||
906 | unsigned long irq; | ||
907 | int error; | ||
908 | |||
909 | if (!tracer) | ||
910 | return 0; | ||
911 | |||
912 | task = tracer->ds.context->task; | ||
913 | |||
914 | local_irq_save(irq); | ||
915 | |||
916 | error = -EPERM; | ||
917 | if (!task && | ||
918 | (tracer->ds.context->cpu != smp_processor_id())) | ||
919 | goto out; | ||
920 | |||
921 | error = -EPERM; | ||
922 | if (task && (task != current)) | ||
923 | goto out; | ||
924 | |||
925 | ds_suspend_bts_noirq(tracer); | ||
926 | ds_free_bts(tracer); | ||
927 | |||
928 | error = 0; | ||
929 | out: | ||
930 | local_irq_restore(irq); | ||
931 | return error; | ||
932 | } | ||
933 | |||
934 | static void update_task_debugctlmsr(struct task_struct *task, | ||
935 | unsigned long debugctlmsr) | ||
936 | { | ||
937 | task->thread.debugctlmsr = debugctlmsr; | ||
938 | |||
939 | get_cpu(); | ||
940 | if (task == current) | ||
941 | update_debugctlmsr(debugctlmsr); | ||
942 | put_cpu(); | ||
943 | } | ||
944 | |||
945 | void ds_suspend_bts(struct bts_tracer *tracer) | ||
946 | { | ||
947 | struct task_struct *task; | ||
948 | unsigned long debugctlmsr; | ||
949 | int cpu; | ||
950 | |||
951 | if (!tracer) | ||
952 | return; | ||
953 | |||
954 | tracer->flags = 0; | ||
955 | |||
956 | task = tracer->ds.context->task; | ||
957 | cpu = tracer->ds.context->cpu; | ||
958 | |||
959 | WARN_ON(!task && irqs_disabled()); | ||
960 | |||
961 | debugctlmsr = (task ? | ||
962 | task->thread.debugctlmsr : | ||
963 | get_debugctlmsr_on_cpu(cpu)); | ||
964 | debugctlmsr &= ~BTS_CONTROL; | ||
965 | |||
966 | if (task) | ||
967 | update_task_debugctlmsr(task, debugctlmsr); | ||
968 | else | ||
969 | update_debugctlmsr_on_cpu(cpu, debugctlmsr); | ||
970 | } | ||
971 | |||
972 | int ds_suspend_bts_noirq(struct bts_tracer *tracer) | ||
973 | { | ||
974 | struct task_struct *task; | ||
975 | unsigned long debugctlmsr, irq; | ||
976 | int cpu, error = 0; | ||
977 | |||
978 | if (!tracer) | ||
979 | return 0; | ||
980 | |||
981 | tracer->flags = 0; | ||
982 | |||
983 | task = tracer->ds.context->task; | ||
984 | cpu = tracer->ds.context->cpu; | ||
985 | |||
986 | local_irq_save(irq); | ||
987 | |||
988 | error = -EPERM; | ||
989 | if (!task && (cpu != smp_processor_id())) | ||
990 | goto out; | ||
991 | |||
992 | debugctlmsr = (task ? | ||
993 | task->thread.debugctlmsr : | ||
994 | get_debugctlmsr()); | ||
995 | debugctlmsr &= ~BTS_CONTROL; | ||
996 | |||
997 | if (task) | ||
998 | update_task_debugctlmsr(task, debugctlmsr); | ||
999 | else | ||
1000 | update_debugctlmsr(debugctlmsr); | ||
1001 | |||
1002 | error = 0; | ||
1003 | out: | ||
1004 | local_irq_restore(irq); | ||
1005 | return error; | ||
1006 | } | ||
1007 | |||
1008 | static unsigned long ds_bts_control(struct bts_tracer *tracer) | ||
1009 | { | ||
1010 | unsigned long control; | ||
1011 | |||
1012 | control = ds_cfg.ctl[dsf_bts]; | ||
1013 | if (!(tracer->trace.ds.flags & BTS_KERNEL)) | ||
1014 | control |= ds_cfg.ctl[dsf_bts_kernel]; | ||
1015 | if (!(tracer->trace.ds.flags & BTS_USER)) | ||
1016 | control |= ds_cfg.ctl[dsf_bts_user]; | ||
1017 | |||
1018 | return control; | ||
1019 | } | ||
1020 | |||
1021 | void ds_resume_bts(struct bts_tracer *tracer) | ||
1022 | { | ||
1023 | struct task_struct *task; | ||
1024 | unsigned long debugctlmsr; | ||
1025 | int cpu; | ||
1026 | |||
1027 | if (!tracer) | ||
1028 | return; | ||
1029 | |||
1030 | tracer->flags = tracer->trace.ds.flags; | ||
1031 | |||
1032 | task = tracer->ds.context->task; | ||
1033 | cpu = tracer->ds.context->cpu; | ||
1034 | |||
1035 | WARN_ON(!task && irqs_disabled()); | ||
1036 | |||
1037 | debugctlmsr = (task ? | ||
1038 | task->thread.debugctlmsr : | ||
1039 | get_debugctlmsr_on_cpu(cpu)); | ||
1040 | debugctlmsr |= ds_bts_control(tracer); | ||
1041 | |||
1042 | if (task) | ||
1043 | update_task_debugctlmsr(task, debugctlmsr); | ||
1044 | else | ||
1045 | update_debugctlmsr_on_cpu(cpu, debugctlmsr); | ||
1046 | } | ||
1047 | |||
1048 | int ds_resume_bts_noirq(struct bts_tracer *tracer) | ||
1049 | { | ||
1050 | struct task_struct *task; | ||
1051 | unsigned long debugctlmsr, irq; | ||
1052 | int cpu, error = 0; | ||
1053 | |||
1054 | if (!tracer) | ||
1055 | return 0; | ||
1056 | |||
1057 | tracer->flags = tracer->trace.ds.flags; | ||
1058 | |||
1059 | task = tracer->ds.context->task; | ||
1060 | cpu = tracer->ds.context->cpu; | ||
1061 | |||
1062 | local_irq_save(irq); | ||
1063 | |||
1064 | error = -EPERM; | ||
1065 | if (!task && (cpu != smp_processor_id())) | ||
1066 | goto out; | ||
1067 | |||
1068 | debugctlmsr = (task ? | ||
1069 | task->thread.debugctlmsr : | ||
1070 | get_debugctlmsr()); | ||
1071 | debugctlmsr |= ds_bts_control(tracer); | ||
1072 | |||
1073 | if (task) | ||
1074 | update_task_debugctlmsr(task, debugctlmsr); | ||
1075 | else | ||
1076 | update_debugctlmsr(debugctlmsr); | ||
1077 | |||
1078 | error = 0; | ||
1079 | out: | ||
1080 | local_irq_restore(irq); | ||
1081 | return error; | ||
1082 | } | ||
1083 | |||
1084 | static void ds_free_pebs(struct pebs_tracer *tracer) | ||
1085 | { | ||
1086 | struct task_struct *task; | ||
1087 | |||
1088 | task = tracer->ds.context->task; | ||
1089 | |||
1090 | WARN_ON_ONCE(tracer->ds.context->pebs_master != tracer); | ||
1091 | tracer->ds.context->pebs_master = NULL; | ||
1092 | |||
1093 | ds_put_context(tracer->ds.context); | ||
1094 | put_tracer(task); | ||
1095 | |||
1096 | kfree(tracer); | ||
1097 | } | ||
1098 | |||
1099 | void ds_release_pebs(struct pebs_tracer *tracer) | ||
1100 | { | ||
1101 | might_sleep(); | ||
1102 | |||
1103 | if (!tracer) | ||
1104 | return; | ||
1105 | |||
1106 | ds_suspend_pebs(tracer); | ||
1107 | ds_free_pebs(tracer); | ||
1108 | } | ||
1109 | |||
1110 | int ds_release_pebs_noirq(struct pebs_tracer *tracer) | ||
1111 | { | ||
1112 | struct task_struct *task; | ||
1113 | unsigned long irq; | ||
1114 | int error; | ||
1115 | |||
1116 | if (!tracer) | ||
1117 | return 0; | ||
1118 | |||
1119 | task = tracer->ds.context->task; | ||
1120 | |||
1121 | local_irq_save(irq); | ||
1122 | |||
1123 | error = -EPERM; | ||
1124 | if (!task && | ||
1125 | (tracer->ds.context->cpu != smp_processor_id())) | ||
1126 | goto out; | ||
1127 | |||
1128 | error = -EPERM; | ||
1129 | if (task && (task != current)) | ||
1130 | goto out; | ||
1131 | |||
1132 | ds_suspend_pebs_noirq(tracer); | ||
1133 | ds_free_pebs(tracer); | ||
1134 | |||
1135 | error = 0; | ||
1136 | out: | ||
1137 | local_irq_restore(irq); | ||
1138 | return error; | ||
1139 | } | ||
1140 | |||
1141 | void ds_suspend_pebs(struct pebs_tracer *tracer) | ||
1142 | { | ||
1143 | |||
1144 | } | ||
1145 | |||
1146 | int ds_suspend_pebs_noirq(struct pebs_tracer *tracer) | ||
1147 | { | ||
1148 | return 0; | ||
1149 | } | ||
1150 | |||
1151 | void ds_resume_pebs(struct pebs_tracer *tracer) | ||
1152 | { | ||
1153 | |||
1154 | } | ||
1155 | |||
1156 | int ds_resume_pebs_noirq(struct pebs_tracer *tracer) | ||
1157 | { | ||
1158 | return 0; | ||
1159 | } | ||
1160 | |||
1161 | const struct bts_trace *ds_read_bts(struct bts_tracer *tracer) | ||
1162 | { | ||
1163 | if (!tracer) | ||
1164 | return NULL; | ||
1165 | |||
1166 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_bts); | ||
1167 | return &tracer->trace; | ||
1168 | } | ||
1169 | |||
1170 | const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer) | ||
1171 | { | ||
1172 | if (!tracer) | ||
1173 | return NULL; | ||
1174 | |||
1175 | ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_pebs); | ||
1176 | |||
1177 | tracer->trace.counters = ds_cfg.nr_counter_reset; | ||
1178 | memcpy(tracer->trace.counter_reset, | ||
1179 | tracer->ds.context->ds + | ||
1180 | (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field), | ||
1181 | ds_cfg.nr_counter_reset * PEBS_RESET_FIELD_SIZE); | ||
1182 | |||
1183 | return &tracer->trace; | ||
1184 | } | ||
1185 | |||
1186 | int ds_reset_bts(struct bts_tracer *tracer) | ||
1187 | { | ||
1188 | if (!tracer) | ||
1189 | return -EINVAL; | ||
1190 | |||
1191 | tracer->trace.ds.top = tracer->trace.ds.begin; | ||
1192 | |||
1193 | ds_set(tracer->ds.context->ds, ds_bts, ds_index, | ||
1194 | (unsigned long)tracer->trace.ds.top); | ||
1195 | |||
1196 | return 0; | ||
1197 | } | ||
1198 | |||
1199 | int ds_reset_pebs(struct pebs_tracer *tracer) | ||
1200 | { | ||
1201 | if (!tracer) | ||
1202 | return -EINVAL; | ||
1203 | |||
1204 | tracer->trace.ds.top = tracer->trace.ds.begin; | ||
1205 | |||
1206 | ds_set(tracer->ds.context->ds, ds_pebs, ds_index, | ||
1207 | (unsigned long)tracer->trace.ds.top); | ||
1208 | |||
1209 | return 0; | ||
1210 | } | ||
1211 | |||
1212 | int ds_set_pebs_reset(struct pebs_tracer *tracer, | ||
1213 | unsigned int counter, u64 value) | ||
1214 | { | ||
1215 | if (!tracer) | ||
1216 | return -EINVAL; | ||
1217 | |||
1218 | if (ds_cfg.nr_counter_reset < counter) | ||
1219 | return -EINVAL; | ||
1220 | |||
1221 | *(u64 *)(tracer->ds.context->ds + | ||
1222 | (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field) + | ||
1223 | (counter * PEBS_RESET_FIELD_SIZE)) = value; | ||
1224 | |||
1225 | return 0; | ||
1226 | } | ||
1227 | |||
1228 | static const struct ds_configuration ds_cfg_netburst = { | ||
1229 | .name = "Netburst", | ||
1230 | .ctl[dsf_bts] = (1 << 2) | (1 << 3), | ||
1231 | .ctl[dsf_bts_kernel] = (1 << 5), | ||
1232 | .ctl[dsf_bts_user] = (1 << 6), | ||
1233 | .nr_counter_reset = 1, | ||
1234 | }; | ||
1235 | static const struct ds_configuration ds_cfg_pentium_m = { | ||
1236 | .name = "Pentium M", | ||
1237 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1238 | .nr_counter_reset = 1, | ||
1239 | }; | ||
1240 | static const struct ds_configuration ds_cfg_core2_atom = { | ||
1241 | .name = "Core 2/Atom", | ||
1242 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1243 | .ctl[dsf_bts_kernel] = (1 << 9), | ||
1244 | .ctl[dsf_bts_user] = (1 << 10), | ||
1245 | .nr_counter_reset = 1, | ||
1246 | }; | ||
1247 | static const struct ds_configuration ds_cfg_core_i7 = { | ||
1248 | .name = "Core i7", | ||
1249 | .ctl[dsf_bts] = (1 << 6) | (1 << 7), | ||
1250 | .ctl[dsf_bts_kernel] = (1 << 9), | ||
1251 | .ctl[dsf_bts_user] = (1 << 10), | ||
1252 | .nr_counter_reset = 4, | ||
1253 | }; | ||
1254 | |||
1255 | static void | ||
1256 | ds_configure(const struct ds_configuration *cfg, | ||
1257 | struct cpuinfo_x86 *cpu) | ||
1258 | { | ||
1259 | unsigned long nr_pebs_fields = 0; | ||
1260 | |||
1261 | printk(KERN_INFO "[ds] using %s configuration\n", cfg->name); | ||
1262 | |||
1263 | #ifdef __i386__ | ||
1264 | nr_pebs_fields = 10; | ||
1265 | #else | ||
1266 | nr_pebs_fields = 18; | ||
1267 | #endif | ||
1268 | |||
1269 | /* | ||
1270 | * Starting with version 2, architectural performance | ||
1271 | * monitoring supports a format specifier. | ||
1272 | */ | ||
1273 | if ((cpuid_eax(0xa) & 0xff) > 1) { | ||
1274 | unsigned long perf_capabilities, format; | ||
1275 | |||
1276 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_capabilities); | ||
1277 | |||
1278 | format = (perf_capabilities >> 8) & 0xf; | ||
1279 | |||
1280 | switch (format) { | ||
1281 | case 0: | ||
1282 | nr_pebs_fields = 18; | ||
1283 | break; | ||
1284 | case 1: | ||
1285 | nr_pebs_fields = 22; | ||
1286 | break; | ||
1287 | default: | ||
1288 | printk(KERN_INFO | ||
1289 | "[ds] unknown PEBS format: %lu\n", format); | ||
1290 | nr_pebs_fields = 0; | ||
1291 | break; | ||
1292 | } | ||
1293 | } | ||
1294 | |||
1295 | memset(&ds_cfg, 0, sizeof(ds_cfg)); | ||
1296 | ds_cfg = *cfg; | ||
1297 | |||
1298 | ds_cfg.sizeof_ptr_field = | ||
1299 | (cpu_has(cpu, X86_FEATURE_DTES64) ? 8 : 4); | ||
1300 | |||
1301 | ds_cfg.sizeof_rec[ds_bts] = ds_cfg.sizeof_ptr_field * 3; | ||
1302 | ds_cfg.sizeof_rec[ds_pebs] = ds_cfg.sizeof_ptr_field * nr_pebs_fields; | ||
1303 | |||
1304 | if (!cpu_has(cpu, X86_FEATURE_BTS)) { | ||
1305 | ds_cfg.sizeof_rec[ds_bts] = 0; | ||
1306 | printk(KERN_INFO "[ds] bts not available\n"); | ||
1307 | } | ||
1308 | if (!cpu_has(cpu, X86_FEATURE_PEBS)) { | ||
1309 | ds_cfg.sizeof_rec[ds_pebs] = 0; | ||
1310 | printk(KERN_INFO "[ds] pebs not available\n"); | ||
1311 | } | ||
1312 | |||
1313 | printk(KERN_INFO "[ds] sizes: address: %u bit, ", | ||
1314 | 8 * ds_cfg.sizeof_ptr_field); | ||
1315 | printk("bts/pebs record: %u/%u bytes\n", | ||
1316 | ds_cfg.sizeof_rec[ds_bts], ds_cfg.sizeof_rec[ds_pebs]); | ||
1317 | |||
1318 | WARN_ON_ONCE(MAX_PEBS_COUNTERS < ds_cfg.nr_counter_reset); | ||
1319 | } | ||
1320 | |||
1321 | void __cpuinit ds_init_intel(struct cpuinfo_x86 *c) | ||
1322 | { | ||
1323 | /* Only configure the first cpu. Others are identical. */ | ||
1324 | if (ds_cfg.name) | ||
1325 | return; | ||
1326 | |||
1327 | switch (c->x86) { | ||
1328 | case 0x6: | ||
1329 | switch (c->x86_model) { | ||
1330 | case 0x9: | ||
1331 | case 0xd: /* Pentium M */ | ||
1332 | ds_configure(&ds_cfg_pentium_m, c); | ||
1333 | break; | ||
1334 | case 0xf: | ||
1335 | case 0x17: /* Core2 */ | ||
1336 | case 0x1c: /* Atom */ | ||
1337 | ds_configure(&ds_cfg_core2_atom, c); | ||
1338 | break; | ||
1339 | case 0x1a: /* Core i7 */ | ||
1340 | ds_configure(&ds_cfg_core_i7, c); | ||
1341 | break; | ||
1342 | default: | ||
1343 | /* Sorry, don't know about them. */ | ||
1344 | break; | ||
1345 | } | ||
1346 | break; | ||
1347 | case 0xf: | ||
1348 | switch (c->x86_model) { | ||
1349 | case 0x0: | ||
1350 | case 0x1: | ||
1351 | case 0x2: /* Netburst */ | ||
1352 | ds_configure(&ds_cfg_netburst, c); | ||
1353 | break; | ||
1354 | default: | ||
1355 | /* Sorry, don't know about them. */ | ||
1356 | break; | ||
1357 | } | ||
1358 | break; | ||
1359 | default: | ||
1360 | /* Sorry, don't know about them. */ | ||
1361 | break; | ||
1362 | } | ||
1363 | } | ||
1364 | |||
1365 | static inline void ds_take_timestamp(struct ds_context *context, | ||
1366 | enum bts_qualifier qualifier, | ||
1367 | struct task_struct *task) | ||
1368 | { | ||
1369 | struct bts_tracer *tracer = context->bts_master; | ||
1370 | struct bts_struct ts; | ||
1371 | |||
1372 | /* Prevent compilers from reading the tracer pointer twice. */ | ||
1373 | barrier(); | ||
1374 | |||
1375 | if (!tracer || !(tracer->flags & BTS_TIMESTAMPS)) | ||
1376 | return; | ||
1377 | |||
1378 | memset(&ts, 0, sizeof(ts)); | ||
1379 | ts.qualifier = qualifier; | ||
1380 | ts.variant.event.clock = trace_clock_global(); | ||
1381 | ts.variant.event.pid = task->pid; | ||
1382 | |||
1383 | bts_write(tracer, &ts); | ||
1384 | } | ||
1385 | |||
1386 | /* | ||
1387 | * Change the DS configuration from tracing prev to tracing next. | ||
1388 | */ | ||
1389 | void ds_switch_to(struct task_struct *prev, struct task_struct *next) | ||
1390 | { | ||
1391 | struct ds_context *prev_ctx = prev->thread.ds_ctx; | ||
1392 | struct ds_context *next_ctx = next->thread.ds_ctx; | ||
1393 | unsigned long debugctlmsr = next->thread.debugctlmsr; | ||
1394 | |||
1395 | /* Make sure all data is read before we start. */ | ||
1396 | barrier(); | ||
1397 | |||
1398 | if (prev_ctx) { | ||
1399 | update_debugctlmsr(0); | ||
1400 | |||
1401 | ds_take_timestamp(prev_ctx, bts_task_departs, prev); | ||
1402 | } | ||
1403 | |||
1404 | if (next_ctx) { | ||
1405 | ds_take_timestamp(next_ctx, bts_task_arrives, next); | ||
1406 | |||
1407 | wrmsrl(MSR_IA32_DS_AREA, (unsigned long)next_ctx->ds); | ||
1408 | } | ||
1409 | |||
1410 | update_debugctlmsr(debugctlmsr); | ||
1411 | } | ||
1412 | |||
1413 | static __init int ds_selftest(void) | ||
1414 | { | ||
1415 | if (ds_cfg.sizeof_rec[ds_bts]) { | ||
1416 | int error; | ||
1417 | |||
1418 | error = ds_selftest_bts(); | ||
1419 | if (error) { | ||
1420 | WARN(1, "[ds] selftest failed. disabling bts.\n"); | ||
1421 | ds_cfg.sizeof_rec[ds_bts] = 0; | ||
1422 | } | ||
1423 | } | ||
1424 | |||
1425 | if (ds_cfg.sizeof_rec[ds_pebs]) { | ||
1426 | int error; | ||
1427 | |||
1428 | error = ds_selftest_pebs(); | ||
1429 | if (error) { | ||
1430 | WARN(1, "[ds] selftest failed. disabling pebs.\n"); | ||
1431 | ds_cfg.sizeof_rec[ds_pebs] = 0; | ||
1432 | } | ||
1433 | } | ||
1434 | |||
1435 | return 0; | ||
1436 | } | ||
1437 | device_initcall(ds_selftest); | ||
diff --git a/arch/x86/kernel/ds_selftest.c b/arch/x86/kernel/ds_selftest.c deleted file mode 100644 index 6bc7c199ab99..000000000000 --- a/arch/x86/kernel/ds_selftest.c +++ /dev/null | |||
@@ -1,408 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support - selftest | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2009 Intel Corporation. | ||
6 | * Markus Metzger <markus.t.metzger@intel.com>, 2009 | ||
7 | */ | ||
8 | |||
9 | #include "ds_selftest.h" | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/smp.h> | ||
14 | #include <linux/cpu.h> | ||
15 | |||
16 | #include <asm/ds.h> | ||
17 | |||
18 | |||
19 | #define BUFFER_SIZE 521 /* Intentionally chose an odd size. */ | ||
20 | #define SMALL_BUFFER_SIZE 24 /* A single bts entry. */ | ||
21 | |||
22 | struct ds_selftest_bts_conf { | ||
23 | struct bts_tracer *tracer; | ||
24 | int error; | ||
25 | int (*suspend)(struct bts_tracer *); | ||
26 | int (*resume)(struct bts_tracer *); | ||
27 | }; | ||
28 | |||
29 | static int ds_selftest_bts_consistency(const struct bts_trace *trace) | ||
30 | { | ||
31 | int error = 0; | ||
32 | |||
33 | if (!trace) { | ||
34 | printk(KERN_CONT "failed to access trace..."); | ||
35 | /* Bail out. Other tests are pointless. */ | ||
36 | return -1; | ||
37 | } | ||
38 | |||
39 | if (!trace->read) { | ||
40 | printk(KERN_CONT "bts read not available..."); | ||
41 | error = -1; | ||
42 | } | ||
43 | |||
44 | /* Do some sanity checks on the trace configuration. */ | ||
45 | if (!trace->ds.n) { | ||
46 | printk(KERN_CONT "empty bts buffer..."); | ||
47 | error = -1; | ||
48 | } | ||
49 | if (!trace->ds.size) { | ||
50 | printk(KERN_CONT "bad bts trace setup..."); | ||
51 | error = -1; | ||
52 | } | ||
53 | if (trace->ds.end != | ||
54 | (char *)trace->ds.begin + (trace->ds.n * trace->ds.size)) { | ||
55 | printk(KERN_CONT "bad bts buffer setup..."); | ||
56 | error = -1; | ||
57 | } | ||
58 | /* | ||
59 | * We allow top in [begin; end], since its not clear when the | ||
60 | * overflow adjustment happens: after the increment or before the | ||
61 | * write. | ||
62 | */ | ||
63 | if ((trace->ds.top < trace->ds.begin) || | ||
64 | (trace->ds.end < trace->ds.top)) { | ||
65 | printk(KERN_CONT "bts top out of bounds..."); | ||
66 | error = -1; | ||
67 | } | ||
68 | |||
69 | return error; | ||
70 | } | ||
71 | |||
72 | static int ds_selftest_bts_read(struct bts_tracer *tracer, | ||
73 | const struct bts_trace *trace, | ||
74 | const void *from, const void *to) | ||
75 | { | ||
76 | const unsigned char *at; | ||
77 | |||
78 | /* | ||
79 | * Check a few things which do not belong to this test. | ||
80 | * They should be covered by other tests. | ||
81 | */ | ||
82 | if (!trace) | ||
83 | return -1; | ||
84 | |||
85 | if (!trace->read) | ||
86 | return -1; | ||
87 | |||
88 | if (to < from) | ||
89 | return -1; | ||
90 | |||
91 | if (from < trace->ds.begin) | ||
92 | return -1; | ||
93 | |||
94 | if (trace->ds.end < to) | ||
95 | return -1; | ||
96 | |||
97 | if (!trace->ds.size) | ||
98 | return -1; | ||
99 | |||
100 | /* Now to the test itself. */ | ||
101 | for (at = from; (void *)at < to; at += trace->ds.size) { | ||
102 | struct bts_struct bts; | ||
103 | unsigned long index; | ||
104 | int error; | ||
105 | |||
106 | if (((void *)at - trace->ds.begin) % trace->ds.size) { | ||
107 | printk(KERN_CONT | ||
108 | "read from non-integer index..."); | ||
109 | return -1; | ||
110 | } | ||
111 | index = ((void *)at - trace->ds.begin) / trace->ds.size; | ||
112 | |||
113 | memset(&bts, 0, sizeof(bts)); | ||
114 | error = trace->read(tracer, at, &bts); | ||
115 | if (error < 0) { | ||
116 | printk(KERN_CONT | ||
117 | "error reading bts trace at [%lu] (0x%p)...", | ||
118 | index, at); | ||
119 | return error; | ||
120 | } | ||
121 | |||
122 | switch (bts.qualifier) { | ||
123 | case BTS_BRANCH: | ||
124 | break; | ||
125 | default: | ||
126 | printk(KERN_CONT | ||
127 | "unexpected bts entry %llu at [%lu] (0x%p)...", | ||
128 | bts.qualifier, index, at); | ||
129 | return -1; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static void ds_selftest_bts_cpu(void *arg) | ||
137 | { | ||
138 | struct ds_selftest_bts_conf *conf = arg; | ||
139 | const struct bts_trace *trace; | ||
140 | void *top; | ||
141 | |||
142 | if (IS_ERR(conf->tracer)) { | ||
143 | conf->error = PTR_ERR(conf->tracer); | ||
144 | conf->tracer = NULL; | ||
145 | |||
146 | printk(KERN_CONT | ||
147 | "initialization failed (err: %d)...", conf->error); | ||
148 | return; | ||
149 | } | ||
150 | |||
151 | /* We should meanwhile have enough trace. */ | ||
152 | conf->error = conf->suspend(conf->tracer); | ||
153 | if (conf->error < 0) | ||
154 | return; | ||
155 | |||
156 | /* Let's see if we can access the trace. */ | ||
157 | trace = ds_read_bts(conf->tracer); | ||
158 | |||
159 | conf->error = ds_selftest_bts_consistency(trace); | ||
160 | if (conf->error < 0) | ||
161 | return; | ||
162 | |||
163 | /* If everything went well, we should have a few trace entries. */ | ||
164 | if (trace->ds.top == trace->ds.begin) { | ||
165 | /* | ||
166 | * It is possible but highly unlikely that we got a | ||
167 | * buffer overflow and end up at exactly the same | ||
168 | * position we started from. | ||
169 | * Let's issue a warning, but continue. | ||
170 | */ | ||
171 | printk(KERN_CONT "no trace/overflow..."); | ||
172 | } | ||
173 | |||
174 | /* Let's try to read the trace we collected. */ | ||
175 | conf->error = | ||
176 | ds_selftest_bts_read(conf->tracer, trace, | ||
177 | trace->ds.begin, trace->ds.top); | ||
178 | if (conf->error < 0) | ||
179 | return; | ||
180 | |||
181 | /* | ||
182 | * Let's read the trace again. | ||
183 | * Since we suspended tracing, we should get the same result. | ||
184 | */ | ||
185 | top = trace->ds.top; | ||
186 | |||
187 | trace = ds_read_bts(conf->tracer); | ||
188 | conf->error = ds_selftest_bts_consistency(trace); | ||
189 | if (conf->error < 0) | ||
190 | return; | ||
191 | |||
192 | if (top != trace->ds.top) { | ||
193 | printk(KERN_CONT "suspend not working..."); | ||
194 | conf->error = -1; | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | /* Let's collect some more trace - see if resume is working. */ | ||
199 | conf->error = conf->resume(conf->tracer); | ||
200 | if (conf->error < 0) | ||
201 | return; | ||
202 | |||
203 | conf->error = conf->suspend(conf->tracer); | ||
204 | if (conf->error < 0) | ||
205 | return; | ||
206 | |||
207 | trace = ds_read_bts(conf->tracer); | ||
208 | |||
209 | conf->error = ds_selftest_bts_consistency(trace); | ||
210 | if (conf->error < 0) | ||
211 | return; | ||
212 | |||
213 | if (trace->ds.top == top) { | ||
214 | /* | ||
215 | * It is possible but highly unlikely that we got a | ||
216 | * buffer overflow and end up at exactly the same | ||
217 | * position we started from. | ||
218 | * Let's issue a warning and check the full trace. | ||
219 | */ | ||
220 | printk(KERN_CONT | ||
221 | "no resume progress/overflow..."); | ||
222 | |||
223 | conf->error = | ||
224 | ds_selftest_bts_read(conf->tracer, trace, | ||
225 | trace->ds.begin, trace->ds.end); | ||
226 | } else if (trace->ds.top < top) { | ||
227 | /* | ||
228 | * We had a buffer overflow - the entire buffer should | ||
229 | * contain trace records. | ||
230 | */ | ||
231 | conf->error = | ||
232 | ds_selftest_bts_read(conf->tracer, trace, | ||
233 | trace->ds.begin, trace->ds.end); | ||
234 | } else { | ||
235 | /* | ||
236 | * It is quite likely that the buffer did not overflow. | ||
237 | * Let's just check the delta trace. | ||
238 | */ | ||
239 | conf->error = | ||
240 | ds_selftest_bts_read(conf->tracer, trace, top, | ||
241 | trace->ds.top); | ||
242 | } | ||
243 | if (conf->error < 0) | ||
244 | return; | ||
245 | |||
246 | conf->error = 0; | ||
247 | } | ||
248 | |||
249 | static int ds_suspend_bts_wrap(struct bts_tracer *tracer) | ||
250 | { | ||
251 | ds_suspend_bts(tracer); | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static int ds_resume_bts_wrap(struct bts_tracer *tracer) | ||
256 | { | ||
257 | ds_resume_bts(tracer); | ||
258 | return 0; | ||
259 | } | ||
260 | |||
261 | static void ds_release_bts_noirq_wrap(void *tracer) | ||
262 | { | ||
263 | (void)ds_release_bts_noirq(tracer); | ||
264 | } | ||
265 | |||
266 | static int ds_selftest_bts_bad_release_noirq(int cpu, | ||
267 | struct bts_tracer *tracer) | ||
268 | { | ||
269 | int error = -EPERM; | ||
270 | |||
271 | /* Try to release the tracer on the wrong cpu. */ | ||
272 | get_cpu(); | ||
273 | if (cpu != smp_processor_id()) { | ||
274 | error = ds_release_bts_noirq(tracer); | ||
275 | if (error != -EPERM) | ||
276 | printk(KERN_CONT "release on wrong cpu..."); | ||
277 | } | ||
278 | put_cpu(); | ||
279 | |||
280 | return error ? 0 : -1; | ||
281 | } | ||
282 | |||
283 | static int ds_selftest_bts_bad_request_cpu(int cpu, void *buffer) | ||
284 | { | ||
285 | struct bts_tracer *tracer; | ||
286 | int error; | ||
287 | |||
288 | /* Try to request cpu tracing while task tracing is active. */ | ||
289 | tracer = ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, NULL, | ||
290 | (size_t)-1, BTS_KERNEL); | ||
291 | error = PTR_ERR(tracer); | ||
292 | if (!IS_ERR(tracer)) { | ||
293 | ds_release_bts(tracer); | ||
294 | error = 0; | ||
295 | } | ||
296 | |||
297 | if (error != -EPERM) | ||
298 | printk(KERN_CONT "cpu/task tracing overlap..."); | ||
299 | |||
300 | return error ? 0 : -1; | ||
301 | } | ||
302 | |||
303 | static int ds_selftest_bts_bad_request_task(void *buffer) | ||
304 | { | ||
305 | struct bts_tracer *tracer; | ||
306 | int error; | ||
307 | |||
308 | /* Try to request cpu tracing while task tracing is active. */ | ||
309 | tracer = ds_request_bts_task(current, buffer, BUFFER_SIZE, NULL, | ||
310 | (size_t)-1, BTS_KERNEL); | ||
311 | error = PTR_ERR(tracer); | ||
312 | if (!IS_ERR(tracer)) { | ||
313 | error = 0; | ||
314 | ds_release_bts(tracer); | ||
315 | } | ||
316 | |||
317 | if (error != -EPERM) | ||
318 | printk(KERN_CONT "task/cpu tracing overlap..."); | ||
319 | |||
320 | return error ? 0 : -1; | ||
321 | } | ||
322 | |||
323 | int ds_selftest_bts(void) | ||
324 | { | ||
325 | struct ds_selftest_bts_conf conf; | ||
326 | unsigned char buffer[BUFFER_SIZE], *small_buffer; | ||
327 | unsigned long irq; | ||
328 | int cpu; | ||
329 | |||
330 | printk(KERN_INFO "[ds] bts selftest..."); | ||
331 | conf.error = 0; | ||
332 | |||
333 | small_buffer = (unsigned char *)ALIGN((unsigned long)buffer, 8) + 8; | ||
334 | |||
335 | get_online_cpus(); | ||
336 | for_each_online_cpu(cpu) { | ||
337 | conf.suspend = ds_suspend_bts_wrap; | ||
338 | conf.resume = ds_resume_bts_wrap; | ||
339 | conf.tracer = | ||
340 | ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, | ||
341 | NULL, (size_t)-1, BTS_KERNEL); | ||
342 | ds_selftest_bts_cpu(&conf); | ||
343 | if (conf.error >= 0) | ||
344 | conf.error = ds_selftest_bts_bad_request_task(buffer); | ||
345 | ds_release_bts(conf.tracer); | ||
346 | if (conf.error < 0) | ||
347 | goto out; | ||
348 | |||
349 | conf.suspend = ds_suspend_bts_noirq; | ||
350 | conf.resume = ds_resume_bts_noirq; | ||
351 | conf.tracer = | ||
352 | ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, | ||
353 | NULL, (size_t)-1, BTS_KERNEL); | ||
354 | smp_call_function_single(cpu, ds_selftest_bts_cpu, &conf, 1); | ||
355 | if (conf.error >= 0) { | ||
356 | conf.error = | ||
357 | ds_selftest_bts_bad_release_noirq(cpu, | ||
358 | conf.tracer); | ||
359 | /* We must not release the tracer twice. */ | ||
360 | if (conf.error < 0) | ||
361 | conf.tracer = NULL; | ||
362 | } | ||
363 | if (conf.error >= 0) | ||
364 | conf.error = ds_selftest_bts_bad_request_task(buffer); | ||
365 | smp_call_function_single(cpu, ds_release_bts_noirq_wrap, | ||
366 | conf.tracer, 1); | ||
367 | if (conf.error < 0) | ||
368 | goto out; | ||
369 | } | ||
370 | |||
371 | conf.suspend = ds_suspend_bts_wrap; | ||
372 | conf.resume = ds_resume_bts_wrap; | ||
373 | conf.tracer = | ||
374 | ds_request_bts_task(current, buffer, BUFFER_SIZE, | ||
375 | NULL, (size_t)-1, BTS_KERNEL); | ||
376 | ds_selftest_bts_cpu(&conf); | ||
377 | if (conf.error >= 0) | ||
378 | conf.error = ds_selftest_bts_bad_request_cpu(0, buffer); | ||
379 | ds_release_bts(conf.tracer); | ||
380 | if (conf.error < 0) | ||
381 | goto out; | ||
382 | |||
383 | conf.suspend = ds_suspend_bts_noirq; | ||
384 | conf.resume = ds_resume_bts_noirq; | ||
385 | conf.tracer = | ||
386 | ds_request_bts_task(current, small_buffer, SMALL_BUFFER_SIZE, | ||
387 | NULL, (size_t)-1, BTS_KERNEL); | ||
388 | local_irq_save(irq); | ||
389 | ds_selftest_bts_cpu(&conf); | ||
390 | if (conf.error >= 0) | ||
391 | conf.error = ds_selftest_bts_bad_request_cpu(0, buffer); | ||
392 | ds_release_bts_noirq(conf.tracer); | ||
393 | local_irq_restore(irq); | ||
394 | if (conf.error < 0) | ||
395 | goto out; | ||
396 | |||
397 | conf.error = 0; | ||
398 | out: | ||
399 | put_online_cpus(); | ||
400 | printk(KERN_CONT "%s.\n", (conf.error ? "failed" : "passed")); | ||
401 | |||
402 | return conf.error; | ||
403 | } | ||
404 | |||
405 | int ds_selftest_pebs(void) | ||
406 | { | ||
407 | return 0; | ||
408 | } | ||
diff --git a/arch/x86/kernel/ds_selftest.h b/arch/x86/kernel/ds_selftest.h deleted file mode 100644 index 2ba8745c6663..000000000000 --- a/arch/x86/kernel/ds_selftest.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /* | ||
2 | * Debug Store support - selftest | ||
3 | * | ||
4 | * | ||
5 | * Copyright (C) 2009 Intel Corporation. | ||
6 | * Markus Metzger <markus.t.metzger@intel.com>, 2009 | ||
7 | */ | ||
8 | |||
9 | #ifdef CONFIG_X86_DS_SELFTEST | ||
10 | extern int ds_selftest_bts(void); | ||
11 | extern int ds_selftest_pebs(void); | ||
12 | #else | ||
13 | static inline int ds_selftest_bts(void) { return 0; } | ||
14 | static inline int ds_selftest_pebs(void) { return 0; } | ||
15 | #endif | ||
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 6d817554780a..c89a386930b7 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c | |||
@@ -224,11 +224,6 @@ unsigned __kprobes long oops_begin(void) | |||
224 | int cpu; | 224 | int cpu; |
225 | unsigned long flags; | 225 | unsigned long flags; |
226 | 226 | ||
227 | /* notify the hw-branch tracer so it may disable tracing and | ||
228 | add the last trace to the trace buffer - | ||
229 | the earlier this happens, the more useful the trace. */ | ||
230 | trace_hw_branch_oops(); | ||
231 | |||
232 | oops_enter(); | 227 | oops_enter(); |
233 | 228 | ||
234 | /* racy, but better than risking deadlock. */ | 229 | /* racy, but better than risking deadlock. */ |
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S index 44a8e0dc6737..cd49141cf153 100644 --- a/arch/x86/kernel/entry_32.S +++ b/arch/x86/kernel/entry_32.S | |||
@@ -53,6 +53,7 @@ | |||
53 | #include <asm/processor-flags.h> | 53 | #include <asm/processor-flags.h> |
54 | #include <asm/ftrace.h> | 54 | #include <asm/ftrace.h> |
55 | #include <asm/irq_vectors.h> | 55 | #include <asm/irq_vectors.h> |
56 | #include <asm/cpufeature.h> | ||
56 | 57 | ||
57 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ | 58 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
58 | #include <linux/elf-em.h> | 59 | #include <linux/elf-em.h> |
@@ -905,7 +906,25 @@ ENTRY(simd_coprocessor_error) | |||
905 | RING0_INT_FRAME | 906 | RING0_INT_FRAME |
906 | pushl $0 | 907 | pushl $0 |
907 | CFI_ADJUST_CFA_OFFSET 4 | 908 | CFI_ADJUST_CFA_OFFSET 4 |
909 | #ifdef CONFIG_X86_INVD_BUG | ||
910 | /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ | ||
911 | 661: pushl $do_general_protection | ||
912 | 662: | ||
913 | .section .altinstructions,"a" | ||
914 | .balign 4 | ||
915 | .long 661b | ||
916 | .long 663f | ||
917 | .byte X86_FEATURE_XMM | ||
918 | .byte 662b-661b | ||
919 | .byte 664f-663f | ||
920 | .previous | ||
921 | .section .altinstr_replacement,"ax" | ||
922 | 663: pushl $do_simd_coprocessor_error | ||
923 | 664: | ||
924 | .previous | ||
925 | #else | ||
908 | pushl $do_simd_coprocessor_error | 926 | pushl $do_simd_coprocessor_error |
927 | #endif | ||
909 | CFI_ADJUST_CFA_OFFSET 4 | 928 | CFI_ADJUST_CFA_OFFSET 4 |
910 | jmp error_code | 929 | jmp error_code |
911 | CFI_ENDPROC | 930 | CFI_ENDPROC |
diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index d6cc065f519f..a8f1b803d2fd 100644 --- a/arch/x86/kernel/hw_breakpoint.c +++ b/arch/x86/kernel/hw_breakpoint.c | |||
@@ -189,25 +189,16 @@ static int get_hbp_len(u8 hbp_len) | |||
189 | } | 189 | } |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * Check for virtual address in user space. | ||
193 | */ | ||
194 | int arch_check_va_in_userspace(unsigned long va, u8 hbp_len) | ||
195 | { | ||
196 | unsigned int len; | ||
197 | |||
198 | len = get_hbp_len(hbp_len); | ||
199 | |||
200 | return (va <= TASK_SIZE - len); | ||
201 | } | ||
202 | |||
203 | /* | ||
204 | * Check for virtual address in kernel space. | 192 | * Check for virtual address in kernel space. |
205 | */ | 193 | */ |
206 | static int arch_check_va_in_kernelspace(unsigned long va, u8 hbp_len) | 194 | int arch_check_bp_in_kernelspace(struct perf_event *bp) |
207 | { | 195 | { |
208 | unsigned int len; | 196 | unsigned int len; |
197 | unsigned long va; | ||
198 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | ||
209 | 199 | ||
210 | len = get_hbp_len(hbp_len); | 200 | va = info->address; |
201 | len = get_hbp_len(info->len); | ||
211 | 202 | ||
212 | return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE); | 203 | return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE); |
213 | } | 204 | } |
@@ -300,8 +291,7 @@ static int arch_build_bp_info(struct perf_event *bp) | |||
300 | /* | 291 | /* |
301 | * Validate the arch-specific HW Breakpoint register settings | 292 | * Validate the arch-specific HW Breakpoint register settings |
302 | */ | 293 | */ |
303 | int arch_validate_hwbkpt_settings(struct perf_event *bp, | 294 | int arch_validate_hwbkpt_settings(struct perf_event *bp) |
304 | struct task_struct *tsk) | ||
305 | { | 295 | { |
306 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); | 296 | struct arch_hw_breakpoint *info = counter_arch_bp(bp); |
307 | unsigned int align; | 297 | unsigned int align; |
@@ -314,16 +304,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp, | |||
314 | 304 | ||
315 | ret = -EINVAL; | 305 | ret = -EINVAL; |
316 | 306 | ||
317 | if (info->type == X86_BREAKPOINT_EXECUTE) | ||
318 | /* | ||
319 | * Ptrace-refactoring code | ||
320 | * For now, we'll allow instruction breakpoint only for user-space | ||
321 | * addresses | ||
322 | */ | ||
323 | if ((!arch_check_va_in_userspace(info->address, info->len)) && | ||
324 | info->len != X86_BREAKPOINT_EXECUTE) | ||
325 | return ret; | ||
326 | |||
327 | switch (info->len) { | 307 | switch (info->len) { |
328 | case X86_BREAKPOINT_LEN_1: | 308 | case X86_BREAKPOINT_LEN_1: |
329 | align = 0; | 309 | align = 0; |
@@ -350,15 +330,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp, | |||
350 | if (info->address & align) | 330 | if (info->address & align) |
351 | return -EINVAL; | 331 | return -EINVAL; |
352 | 332 | ||
353 | /* Check that the virtual address is in the proper range */ | ||
354 | if (tsk) { | ||
355 | if (!arch_check_va_in_userspace(info->address, info->len)) | ||
356 | return -EFAULT; | ||
357 | } else { | ||
358 | if (!arch_check_va_in_kernelspace(info->address, info->len)) | ||
359 | return -EFAULT; | ||
360 | } | ||
361 | |||
362 | return 0; | 333 | return 0; |
363 | } | 334 | } |
364 | 335 | ||
diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c index 54c31c285488..86cef6b32253 100644 --- a/arch/x86/kernel/i387.c +++ b/arch/x86/kernel/i387.c | |||
@@ -102,65 +102,62 @@ void __cpuinit fpu_init(void) | |||
102 | 102 | ||
103 | mxcsr_feature_mask_init(); | 103 | mxcsr_feature_mask_init(); |
104 | /* clean state in init */ | 104 | /* clean state in init */ |
105 | if (cpu_has_xsave) | 105 | current_thread_info()->status = 0; |
106 | current_thread_info()->status = TS_XSAVE; | ||
107 | else | ||
108 | current_thread_info()->status = 0; | ||
109 | clear_used_math(); | 106 | clear_used_math(); |
110 | } | 107 | } |
111 | #endif /* CONFIG_X86_64 */ | 108 | #endif /* CONFIG_X86_64 */ |
112 | 109 | ||
113 | /* | 110 | static void fpu_finit(struct fpu *fpu) |
114 | * The _current_ task is using the FPU for the first time | ||
115 | * so initialize it and set the mxcsr to its default | ||
116 | * value at reset if we support XMM instructions and then | ||
117 | * remeber the current task has used the FPU. | ||
118 | */ | ||
119 | int init_fpu(struct task_struct *tsk) | ||
120 | { | 111 | { |
121 | if (tsk_used_math(tsk)) { | ||
122 | if (HAVE_HWFP && tsk == current) | ||
123 | unlazy_fpu(tsk); | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | /* | ||
128 | * Memory allocation at the first usage of the FPU and other state. | ||
129 | */ | ||
130 | if (!tsk->thread.xstate) { | ||
131 | tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep, | ||
132 | GFP_KERNEL); | ||
133 | if (!tsk->thread.xstate) | ||
134 | return -ENOMEM; | ||
135 | } | ||
136 | |||
137 | #ifdef CONFIG_X86_32 | 112 | #ifdef CONFIG_X86_32 |
138 | if (!HAVE_HWFP) { | 113 | if (!HAVE_HWFP) { |
139 | memset(tsk->thread.xstate, 0, xstate_size); | 114 | finit_soft_fpu(&fpu->state->soft); |
140 | finit_task(tsk); | 115 | return; |
141 | set_stopped_child_used_math(tsk); | ||
142 | return 0; | ||
143 | } | 116 | } |
144 | #endif | 117 | #endif |
145 | 118 | ||
146 | if (cpu_has_fxsr) { | 119 | if (cpu_has_fxsr) { |
147 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; | 120 | struct i387_fxsave_struct *fx = &fpu->state->fxsave; |
148 | 121 | ||
149 | memset(fx, 0, xstate_size); | 122 | memset(fx, 0, xstate_size); |
150 | fx->cwd = 0x37f; | 123 | fx->cwd = 0x37f; |
151 | if (cpu_has_xmm) | 124 | if (cpu_has_xmm) |
152 | fx->mxcsr = MXCSR_DEFAULT; | 125 | fx->mxcsr = MXCSR_DEFAULT; |
153 | } else { | 126 | } else { |
154 | struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave; | 127 | struct i387_fsave_struct *fp = &fpu->state->fsave; |
155 | memset(fp, 0, xstate_size); | 128 | memset(fp, 0, xstate_size); |
156 | fp->cwd = 0xffff037fu; | 129 | fp->cwd = 0xffff037fu; |
157 | fp->swd = 0xffff0000u; | 130 | fp->swd = 0xffff0000u; |
158 | fp->twd = 0xffffffffu; | 131 | fp->twd = 0xffffffffu; |
159 | fp->fos = 0xffff0000u; | 132 | fp->fos = 0xffff0000u; |
160 | } | 133 | } |
134 | } | ||
135 | |||
136 | /* | ||
137 | * The _current_ task is using the FPU for the first time | ||
138 | * so initialize it and set the mxcsr to its default | ||
139 | * value at reset if we support XMM instructions and then | ||
140 | * remeber the current task has used the FPU. | ||
141 | */ | ||
142 | int init_fpu(struct task_struct *tsk) | ||
143 | { | ||
144 | int ret; | ||
145 | |||
146 | if (tsk_used_math(tsk)) { | ||
147 | if (HAVE_HWFP && tsk == current) | ||
148 | unlazy_fpu(tsk); | ||
149 | return 0; | ||
150 | } | ||
151 | |||
161 | /* | 152 | /* |
162 | * Only the device not available exception or ptrace can call init_fpu. | 153 | * Memory allocation at the first usage of the FPU and other state. |
163 | */ | 154 | */ |
155 | ret = fpu_alloc(&tsk->thread.fpu); | ||
156 | if (ret) | ||
157 | return ret; | ||
158 | |||
159 | fpu_finit(&tsk->thread.fpu); | ||
160 | |||
164 | set_stopped_child_used_math(tsk); | 161 | set_stopped_child_used_math(tsk); |
165 | return 0; | 162 | return 0; |
166 | } | 163 | } |
@@ -194,7 +191,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset, | |||
194 | return ret; | 191 | return ret; |
195 | 192 | ||
196 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | 193 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
197 | &target->thread.xstate->fxsave, 0, -1); | 194 | &target->thread.fpu.state->fxsave, 0, -1); |
198 | } | 195 | } |
199 | 196 | ||
200 | int xfpregs_set(struct task_struct *target, const struct user_regset *regset, | 197 | int xfpregs_set(struct task_struct *target, const struct user_regset *regset, |
@@ -211,19 +208,19 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
211 | return ret; | 208 | return ret; |
212 | 209 | ||
213 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | 210 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
214 | &target->thread.xstate->fxsave, 0, -1); | 211 | &target->thread.fpu.state->fxsave, 0, -1); |
215 | 212 | ||
216 | /* | 213 | /* |
217 | * mxcsr reserved bits must be masked to zero for security reasons. | 214 | * mxcsr reserved bits must be masked to zero for security reasons. |
218 | */ | 215 | */ |
219 | target->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask; | 216 | target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; |
220 | 217 | ||
221 | /* | 218 | /* |
222 | * update the header bits in the xsave header, indicating the | 219 | * update the header bits in the xsave header, indicating the |
223 | * presence of FP and SSE state. | 220 | * presence of FP and SSE state. |
224 | */ | 221 | */ |
225 | if (cpu_has_xsave) | 222 | if (cpu_has_xsave) |
226 | target->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE; | 223 | target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE; |
227 | 224 | ||
228 | return ret; | 225 | return ret; |
229 | } | 226 | } |
@@ -246,14 +243,14 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset, | |||
246 | * memory layout in the thread struct, so that we can copy the entire | 243 | * memory layout in the thread struct, so that we can copy the entire |
247 | * xstateregs to the user using one user_regset_copyout(). | 244 | * xstateregs to the user using one user_regset_copyout(). |
248 | */ | 245 | */ |
249 | memcpy(&target->thread.xstate->fxsave.sw_reserved, | 246 | memcpy(&target->thread.fpu.state->fxsave.sw_reserved, |
250 | xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes)); | 247 | xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes)); |
251 | 248 | ||
252 | /* | 249 | /* |
253 | * Copy the xstate memory layout. | 250 | * Copy the xstate memory layout. |
254 | */ | 251 | */ |
255 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, | 252 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
256 | &target->thread.xstate->xsave, 0, -1); | 253 | &target->thread.fpu.state->xsave, 0, -1); |
257 | return ret; | 254 | return ret; |
258 | } | 255 | } |
259 | 256 | ||
@@ -272,14 +269,14 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset, | |||
272 | return ret; | 269 | return ret; |
273 | 270 | ||
274 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, | 271 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
275 | &target->thread.xstate->xsave, 0, -1); | 272 | &target->thread.fpu.state->xsave, 0, -1); |
276 | 273 | ||
277 | /* | 274 | /* |
278 | * mxcsr reserved bits must be masked to zero for security reasons. | 275 | * mxcsr reserved bits must be masked to zero for security reasons. |
279 | */ | 276 | */ |
280 | target->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask; | 277 | target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; |
281 | 278 | ||
282 | xsave_hdr = &target->thread.xstate->xsave.xsave_hdr; | 279 | xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr; |
283 | 280 | ||
284 | xsave_hdr->xstate_bv &= pcntxt_mask; | 281 | xsave_hdr->xstate_bv &= pcntxt_mask; |
285 | /* | 282 | /* |
@@ -365,7 +362,7 @@ static inline u32 twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) | |||
365 | static void | 362 | static void |
366 | convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk) | 363 | convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk) |
367 | { | 364 | { |
368 | struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave; | 365 | struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave; |
369 | struct _fpreg *to = (struct _fpreg *) &env->st_space[0]; | 366 | struct _fpreg *to = (struct _fpreg *) &env->st_space[0]; |
370 | struct _fpxreg *from = (struct _fpxreg *) &fxsave->st_space[0]; | 367 | struct _fpxreg *from = (struct _fpxreg *) &fxsave->st_space[0]; |
371 | int i; | 368 | int i; |
@@ -405,7 +402,7 @@ static void convert_to_fxsr(struct task_struct *tsk, | |||
405 | const struct user_i387_ia32_struct *env) | 402 | const struct user_i387_ia32_struct *env) |
406 | 403 | ||
407 | { | 404 | { |
408 | struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave; | 405 | struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave; |
409 | struct _fpreg *from = (struct _fpreg *) &env->st_space[0]; | 406 | struct _fpreg *from = (struct _fpreg *) &env->st_space[0]; |
410 | struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0]; | 407 | struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0]; |
411 | int i; | 408 | int i; |
@@ -445,7 +442,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset, | |||
445 | 442 | ||
446 | if (!cpu_has_fxsr) { | 443 | if (!cpu_has_fxsr) { |
447 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, | 444 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
448 | &target->thread.xstate->fsave, 0, | 445 | &target->thread.fpu.state->fsave, 0, |
449 | -1); | 446 | -1); |
450 | } | 447 | } |
451 | 448 | ||
@@ -475,7 +472,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
475 | 472 | ||
476 | if (!cpu_has_fxsr) { | 473 | if (!cpu_has_fxsr) { |
477 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, | 474 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
478 | &target->thread.xstate->fsave, 0, -1); | 475 | &target->thread.fpu.state->fsave, 0, -1); |
479 | } | 476 | } |
480 | 477 | ||
481 | if (pos > 0 || count < sizeof(env)) | 478 | if (pos > 0 || count < sizeof(env)) |
@@ -490,7 +487,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
490 | * presence of FP. | 487 | * presence of FP. |
491 | */ | 488 | */ |
492 | if (cpu_has_xsave) | 489 | if (cpu_has_xsave) |
493 | target->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FP; | 490 | target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FP; |
494 | return ret; | 491 | return ret; |
495 | } | 492 | } |
496 | 493 | ||
@@ -501,7 +498,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, | |||
501 | static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf) | 498 | static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf) |
502 | { | 499 | { |
503 | struct task_struct *tsk = current; | 500 | struct task_struct *tsk = current; |
504 | struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave; | 501 | struct i387_fsave_struct *fp = &tsk->thread.fpu.state->fsave; |
505 | 502 | ||
506 | fp->status = fp->swd; | 503 | fp->status = fp->swd; |
507 | if (__copy_to_user(buf, fp, sizeof(struct i387_fsave_struct))) | 504 | if (__copy_to_user(buf, fp, sizeof(struct i387_fsave_struct))) |
@@ -512,7 +509,7 @@ static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf) | |||
512 | static int save_i387_fxsave(struct _fpstate_ia32 __user *buf) | 509 | static int save_i387_fxsave(struct _fpstate_ia32 __user *buf) |
513 | { | 510 | { |
514 | struct task_struct *tsk = current; | 511 | struct task_struct *tsk = current; |
515 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; | 512 | struct i387_fxsave_struct *fx = &tsk->thread.fpu.state->fxsave; |
516 | struct user_i387_ia32_struct env; | 513 | struct user_i387_ia32_struct env; |
517 | int err = 0; | 514 | int err = 0; |
518 | 515 | ||
@@ -547,7 +544,7 @@ static int save_i387_xsave(void __user *buf) | |||
547 | * header as well as change any contents in the memory layout. | 544 | * header as well as change any contents in the memory layout. |
548 | * xrestore as part of sigreturn will capture all the changes. | 545 | * xrestore as part of sigreturn will capture all the changes. |
549 | */ | 546 | */ |
550 | tsk->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE; | 547 | tsk->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE; |
551 | 548 | ||
552 | if (save_i387_fxsave(fx) < 0) | 549 | if (save_i387_fxsave(fx) < 0) |
553 | return -1; | 550 | return -1; |
@@ -599,7 +596,7 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf) | |||
599 | { | 596 | { |
600 | struct task_struct *tsk = current; | 597 | struct task_struct *tsk = current; |
601 | 598 | ||
602 | return __copy_from_user(&tsk->thread.xstate->fsave, buf, | 599 | return __copy_from_user(&tsk->thread.fpu.state->fsave, buf, |
603 | sizeof(struct i387_fsave_struct)); | 600 | sizeof(struct i387_fsave_struct)); |
604 | } | 601 | } |
605 | 602 | ||
@@ -610,10 +607,10 @@ static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf, | |||
610 | struct user_i387_ia32_struct env; | 607 | struct user_i387_ia32_struct env; |
611 | int err; | 608 | int err; |
612 | 609 | ||
613 | err = __copy_from_user(&tsk->thread.xstate->fxsave, &buf->_fxsr_env[0], | 610 | err = __copy_from_user(&tsk->thread.fpu.state->fxsave, &buf->_fxsr_env[0], |
614 | size); | 611 | size); |
615 | /* mxcsr reserved bits must be masked to zero for security reasons */ | 612 | /* mxcsr reserved bits must be masked to zero for security reasons */ |
616 | tsk->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask; | 613 | tsk->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask; |
617 | if (err || __copy_from_user(&env, buf, sizeof(env))) | 614 | if (err || __copy_from_user(&env, buf, sizeof(env))) |
618 | return 1; | 615 | return 1; |
619 | convert_to_fxsr(tsk, &env); | 616 | convert_to_fxsr(tsk, &env); |
@@ -629,7 +626,7 @@ static int restore_i387_xsave(void __user *buf) | |||
629 | struct i387_fxsave_struct __user *fx = | 626 | struct i387_fxsave_struct __user *fx = |
630 | (struct i387_fxsave_struct __user *) &fx_user->_fxsr_env[0]; | 627 | (struct i387_fxsave_struct __user *) &fx_user->_fxsr_env[0]; |
631 | struct xsave_hdr_struct *xsave_hdr = | 628 | struct xsave_hdr_struct *xsave_hdr = |
632 | ¤t->thread.xstate->xsave.xsave_hdr; | 629 | ¤t->thread.fpu.state->xsave.xsave_hdr; |
633 | u64 mask; | 630 | u64 mask; |
634 | int err; | 631 | int err; |
635 | 632 | ||
diff --git a/arch/x86/kernel/i8253.c b/arch/x86/kernel/i8253.c index 23c167925a5c..2dfd31597443 100644 --- a/arch/x86/kernel/i8253.c +++ b/arch/x86/kernel/i8253.c | |||
@@ -16,7 +16,7 @@ | |||
16 | #include <asm/hpet.h> | 16 | #include <asm/hpet.h> |
17 | #include <asm/smp.h> | 17 | #include <asm/smp.h> |
18 | 18 | ||
19 | DEFINE_SPINLOCK(i8253_lock); | 19 | DEFINE_RAW_SPINLOCK(i8253_lock); |
20 | EXPORT_SYMBOL(i8253_lock); | 20 | EXPORT_SYMBOL(i8253_lock); |
21 | 21 | ||
22 | /* | 22 | /* |
@@ -33,7 +33,7 @@ struct clock_event_device *global_clock_event; | |||
33 | static void init_pit_timer(enum clock_event_mode mode, | 33 | static void init_pit_timer(enum clock_event_mode mode, |
34 | struct clock_event_device *evt) | 34 | struct clock_event_device *evt) |
35 | { | 35 | { |
36 | spin_lock(&i8253_lock); | 36 | raw_spin_lock(&i8253_lock); |
37 | 37 | ||
38 | switch (mode) { | 38 | switch (mode) { |
39 | case CLOCK_EVT_MODE_PERIODIC: | 39 | case CLOCK_EVT_MODE_PERIODIC: |
@@ -62,7 +62,7 @@ static void init_pit_timer(enum clock_event_mode mode, | |||
62 | /* Nothing to do here */ | 62 | /* Nothing to do here */ |
63 | break; | 63 | break; |
64 | } | 64 | } |
65 | spin_unlock(&i8253_lock); | 65 | raw_spin_unlock(&i8253_lock); |
66 | } | 66 | } |
67 | 67 | ||
68 | /* | 68 | /* |
@@ -72,10 +72,10 @@ static void init_pit_timer(enum clock_event_mode mode, | |||
72 | */ | 72 | */ |
73 | static int pit_next_event(unsigned long delta, struct clock_event_device *evt) | 73 | static int pit_next_event(unsigned long delta, struct clock_event_device *evt) |
74 | { | 74 | { |
75 | spin_lock(&i8253_lock); | 75 | raw_spin_lock(&i8253_lock); |
76 | outb_pit(delta & 0xff , PIT_CH0); /* LSB */ | 76 | outb_pit(delta & 0xff , PIT_CH0); /* LSB */ |
77 | outb_pit(delta >> 8 , PIT_CH0); /* MSB */ | 77 | outb_pit(delta >> 8 , PIT_CH0); /* MSB */ |
78 | spin_unlock(&i8253_lock); | 78 | raw_spin_unlock(&i8253_lock); |
79 | 79 | ||
80 | return 0; | 80 | return 0; |
81 | } | 81 | } |
@@ -130,7 +130,7 @@ static cycle_t pit_read(struct clocksource *cs) | |||
130 | int count; | 130 | int count; |
131 | u32 jifs; | 131 | u32 jifs; |
132 | 132 | ||
133 | spin_lock_irqsave(&i8253_lock, flags); | 133 | raw_spin_lock_irqsave(&i8253_lock, flags); |
134 | /* | 134 | /* |
135 | * Although our caller may have the read side of xtime_lock, | 135 | * Although our caller may have the read side of xtime_lock, |
136 | * this is now a seqlock, and we are cheating in this routine | 136 | * this is now a seqlock, and we are cheating in this routine |
@@ -176,7 +176,7 @@ static cycle_t pit_read(struct clocksource *cs) | |||
176 | old_count = count; | 176 | old_count = count; |
177 | old_jifs = jifs; | 177 | old_jifs = jifs; |
178 | 178 | ||
179 | spin_unlock_irqrestore(&i8253_lock, flags); | 179 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
180 | 180 | ||
181 | count = (LATCH - 1) - count; | 181 | count = (LATCH - 1) - count; |
182 | 182 | ||
diff --git a/arch/x86/kernel/irqinit.c b/arch/x86/kernel/irqinit.c index 0ed2d300cd46..990ae7cfc578 100644 --- a/arch/x86/kernel/irqinit.c +++ b/arch/x86/kernel/irqinit.c | |||
@@ -60,7 +60,7 @@ static irqreturn_t math_error_irq(int cpl, void *dev_id) | |||
60 | outb(0, 0xF0); | 60 | outb(0, 0xF0); |
61 | if (ignore_fpu_irq || !boot_cpu_data.hard_math) | 61 | if (ignore_fpu_irq || !boot_cpu_data.hard_math) |
62 | return IRQ_NONE; | 62 | return IRQ_NONE; |
63 | math_error((void __user *)get_irq_regs()->ip); | 63 | math_error(get_irq_regs(), 0, 16); |
64 | return IRQ_HANDLED; | 64 | return IRQ_HANDLED; |
65 | } | 65 | } |
66 | 66 | ||
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index 1658efdfb4e5..345a4b1fe144 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
@@ -422,14 +422,22 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs, | |||
422 | 422 | ||
423 | static void __kprobes clear_btf(void) | 423 | static void __kprobes clear_btf(void) |
424 | { | 424 | { |
425 | if (test_thread_flag(TIF_DEBUGCTLMSR)) | 425 | if (test_thread_flag(TIF_BLOCKSTEP)) { |
426 | update_debugctlmsr(0); | 426 | unsigned long debugctl = get_debugctlmsr(); |
427 | |||
428 | debugctl &= ~DEBUGCTLMSR_BTF; | ||
429 | update_debugctlmsr(debugctl); | ||
430 | } | ||
427 | } | 431 | } |
428 | 432 | ||
429 | static void __kprobes restore_btf(void) | 433 | static void __kprobes restore_btf(void) |
430 | { | 434 | { |
431 | if (test_thread_flag(TIF_DEBUGCTLMSR)) | 435 | if (test_thread_flag(TIF_BLOCKSTEP)) { |
432 | update_debugctlmsr(current->thread.debugctlmsr); | 436 | unsigned long debugctl = get_debugctlmsr(); |
437 | |||
438 | debugctl |= DEBUGCTLMSR_BTF; | ||
439 | update_debugctlmsr(debugctl); | ||
440 | } | ||
433 | } | 441 | } |
434 | 442 | ||
435 | void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, | 443 | void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, |
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c index cceb5bc3c3c2..2cd8c544e41a 100644 --- a/arch/x86/kernel/microcode_core.c +++ b/arch/x86/kernel/microcode_core.c | |||
@@ -201,9 +201,9 @@ static int do_microcode_update(const void __user *buf, size_t size) | |||
201 | return error; | 201 | return error; |
202 | } | 202 | } |
203 | 203 | ||
204 | static int microcode_open(struct inode *unused1, struct file *unused2) | 204 | static int microcode_open(struct inode *inode, struct file *file) |
205 | { | 205 | { |
206 | return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; | 206 | return capable(CAP_SYS_RAWIO) ? nonseekable_open(inode, file) : -EPERM; |
207 | } | 207 | } |
208 | 208 | ||
209 | static ssize_t microcode_write(struct file *file, const char __user *buf, | 209 | static ssize_t microcode_write(struct file *file, const char __user *buf, |
diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c index 85a343e28937..356170262a93 100644 --- a/arch/x86/kernel/microcode_intel.c +++ b/arch/x86/kernel/microcode_intel.c | |||
@@ -343,10 +343,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, | |||
343 | int (*get_ucode_data)(void *, const void *, size_t)) | 343 | int (*get_ucode_data)(void *, const void *, size_t)) |
344 | { | 344 | { |
345 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 345 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
346 | u8 *ucode_ptr = data, *new_mc = NULL, *mc; | 346 | u8 *ucode_ptr = data, *new_mc = NULL, *mc = NULL; |
347 | int new_rev = uci->cpu_sig.rev; | 347 | int new_rev = uci->cpu_sig.rev; |
348 | unsigned int leftover = size; | 348 | unsigned int leftover = size; |
349 | enum ucode_state state = UCODE_OK; | 349 | enum ucode_state state = UCODE_OK; |
350 | unsigned int curr_mc_size = 0; | ||
350 | 351 | ||
351 | while (leftover) { | 352 | while (leftover) { |
352 | struct microcode_header_intel mc_header; | 353 | struct microcode_header_intel mc_header; |
@@ -361,9 +362,15 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, | |||
361 | break; | 362 | break; |
362 | } | 363 | } |
363 | 364 | ||
364 | mc = vmalloc(mc_size); | 365 | /* For performance reasons, reuse mc area when possible */ |
365 | if (!mc) | 366 | if (!mc || mc_size > curr_mc_size) { |
366 | break; | 367 | if (mc) |
368 | vfree(mc); | ||
369 | mc = vmalloc(mc_size); | ||
370 | if (!mc) | ||
371 | break; | ||
372 | curr_mc_size = mc_size; | ||
373 | } | ||
367 | 374 | ||
368 | if (get_ucode_data(mc, ucode_ptr, mc_size) || | 375 | if (get_ucode_data(mc, ucode_ptr, mc_size) || |
369 | microcode_sanity_check(mc) < 0) { | 376 | microcode_sanity_check(mc) < 0) { |
@@ -376,13 +383,16 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, | |||
376 | vfree(new_mc); | 383 | vfree(new_mc); |
377 | new_rev = mc_header.rev; | 384 | new_rev = mc_header.rev; |
378 | new_mc = mc; | 385 | new_mc = mc; |
379 | } else | 386 | mc = NULL; /* trigger new vmalloc */ |
380 | vfree(mc); | 387 | } |
381 | 388 | ||
382 | ucode_ptr += mc_size; | 389 | ucode_ptr += mc_size; |
383 | leftover -= mc_size; | 390 | leftover -= mc_size; |
384 | } | 391 | } |
385 | 392 | ||
393 | if (mc) | ||
394 | vfree(mc); | ||
395 | |||
386 | if (leftover) { | 396 | if (leftover) { |
387 | if (new_mc) | 397 | if (new_mc) |
388 | vfree(new_mc); | 398 | vfree(new_mc); |
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c index e81030f71a8f..5ae5d2426edf 100644 --- a/arch/x86/kernel/mpparse.c +++ b/arch/x86/kernel/mpparse.c | |||
@@ -115,21 +115,6 @@ static void __init MP_bus_info(struct mpc_bus *m) | |||
115 | printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str); | 115 | printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str); |
116 | } | 116 | } |
117 | 117 | ||
118 | static int bad_ioapic(unsigned long address) | ||
119 | { | ||
120 | if (nr_ioapics >= MAX_IO_APICS) { | ||
121 | printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded " | ||
122 | "(found %d)\n", MAX_IO_APICS, nr_ioapics); | ||
123 | panic("Recompile kernel with bigger MAX_IO_APICS!\n"); | ||
124 | } | ||
125 | if (!address) { | ||
126 | printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address" | ||
127 | " found in table, skipping!\n"); | ||
128 | return 1; | ||
129 | } | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | static void __init MP_ioapic_info(struct mpc_ioapic *m) | 118 | static void __init MP_ioapic_info(struct mpc_ioapic *m) |
134 | { | 119 | { |
135 | if (!(m->flags & MPC_APIC_USABLE)) | 120 | if (!(m->flags & MPC_APIC_USABLE)) |
@@ -138,15 +123,7 @@ static void __init MP_ioapic_info(struct mpc_ioapic *m) | |||
138 | printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n", | 123 | printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n", |
139 | m->apicid, m->apicver, m->apicaddr); | 124 | m->apicid, m->apicver, m->apicaddr); |
140 | 125 | ||
141 | if (bad_ioapic(m->apicaddr)) | 126 | mp_register_ioapic(m->apicid, m->apicaddr, gsi_end + 1); |
142 | return; | ||
143 | |||
144 | mp_ioapics[nr_ioapics].apicaddr = m->apicaddr; | ||
145 | mp_ioapics[nr_ioapics].apicid = m->apicid; | ||
146 | mp_ioapics[nr_ioapics].type = m->type; | ||
147 | mp_ioapics[nr_ioapics].apicver = m->apicver; | ||
148 | mp_ioapics[nr_ioapics].flags = m->flags; | ||
149 | nr_ioapics++; | ||
150 | } | 127 | } |
151 | 128 | ||
152 | static void print_MP_intsrc_info(struct mpc_intsrc *m) | 129 | static void print_MP_intsrc_info(struct mpc_intsrc *m) |
diff --git a/arch/x86/kernel/mrst.c b/arch/x86/kernel/mrst.c index 0aad8670858e..e796448f0eb5 100644 --- a/arch/x86/kernel/mrst.c +++ b/arch/x86/kernel/mrst.c | |||
@@ -237,4 +237,9 @@ void __init x86_mrst_early_setup(void) | |||
237 | x86_init.pci.fixup_irqs = x86_init_noop; | 237 | x86_init.pci.fixup_irqs = x86_init_noop; |
238 | 238 | ||
239 | legacy_pic = &null_legacy_pic; | 239 | legacy_pic = &null_legacy_pic; |
240 | |||
241 | /* Avoid searching for BIOS MP tables */ | ||
242 | x86_init.mpparse.find_smp_config = x86_init_noop; | ||
243 | x86_init.mpparse.get_smp_config = x86_init_uint_noop; | ||
244 | |||
240 | } | 245 | } |
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 28ad9f4d8b94..e7e35219b32f 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <asm/idle.h> | 20 | #include <asm/idle.h> |
21 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
22 | #include <asm/i387.h> | 22 | #include <asm/i387.h> |
23 | #include <asm/ds.h> | ||
24 | #include <asm/debugreg.h> | 23 | #include <asm/debugreg.h> |
25 | 24 | ||
26 | unsigned long idle_halt; | 25 | unsigned long idle_halt; |
@@ -32,26 +31,22 @@ struct kmem_cache *task_xstate_cachep; | |||
32 | 31 | ||
33 | int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) | 32 | int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) |
34 | { | 33 | { |
34 | int ret; | ||
35 | |||
35 | *dst = *src; | 36 | *dst = *src; |
36 | if (src->thread.xstate) { | 37 | if (fpu_allocated(&src->thread.fpu)) { |
37 | dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep, | 38 | memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu)); |
38 | GFP_KERNEL); | 39 | ret = fpu_alloc(&dst->thread.fpu); |
39 | if (!dst->thread.xstate) | 40 | if (ret) |
40 | return -ENOMEM; | 41 | return ret; |
41 | WARN_ON((unsigned long)dst->thread.xstate & 15); | 42 | fpu_copy(&dst->thread.fpu, &src->thread.fpu); |
42 | memcpy(dst->thread.xstate, src->thread.xstate, xstate_size); | ||
43 | } | 43 | } |
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | void free_thread_xstate(struct task_struct *tsk) | 47 | void free_thread_xstate(struct task_struct *tsk) |
48 | { | 48 | { |
49 | if (tsk->thread.xstate) { | 49 | fpu_free(&tsk->thread.fpu); |
50 | kmem_cache_free(task_xstate_cachep, tsk->thread.xstate); | ||
51 | tsk->thread.xstate = NULL; | ||
52 | } | ||
53 | |||
54 | WARN(tsk->thread.ds_ctx, "leaking DS context\n"); | ||
55 | } | 50 | } |
56 | 51 | ||
57 | void free_thread_info(struct thread_info *ti) | 52 | void free_thread_info(struct thread_info *ti) |
@@ -198,11 +193,16 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p, | |||
198 | prev = &prev_p->thread; | 193 | prev = &prev_p->thread; |
199 | next = &next_p->thread; | 194 | next = &next_p->thread; |
200 | 195 | ||
201 | if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) || | 196 | if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^ |
202 | test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR)) | 197 | test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) { |
203 | ds_switch_to(prev_p, next_p); | 198 | unsigned long debugctl = get_debugctlmsr(); |
204 | else if (next->debugctlmsr != prev->debugctlmsr) | 199 | |
205 | update_debugctlmsr(next->debugctlmsr); | 200 | debugctl &= ~DEBUGCTLMSR_BTF; |
201 | if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) | ||
202 | debugctl |= DEBUGCTLMSR_BTF; | ||
203 | |||
204 | update_debugctlmsr(debugctl); | ||
205 | } | ||
206 | 206 | ||
207 | if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ | 207 | if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^ |
208 | test_tsk_thread_flag(next_p, TIF_NOTSC)) { | 208 | test_tsk_thread_flag(next_p, TIF_NOTSC)) { |
@@ -546,11 +546,13 @@ static int __cpuinit check_c1e_idle(const struct cpuinfo_x86 *c) | |||
546 | * check OSVW bit for CPUs that are not affected | 546 | * check OSVW bit for CPUs that are not affected |
547 | * by erratum #400 | 547 | * by erratum #400 |
548 | */ | 548 | */ |
549 | rdmsrl(MSR_AMD64_OSVW_ID_LENGTH, val); | 549 | if (cpu_has(c, X86_FEATURE_OSVW)) { |
550 | if (val >= 2) { | 550 | rdmsrl(MSR_AMD64_OSVW_ID_LENGTH, val); |
551 | rdmsrl(MSR_AMD64_OSVW_STATUS, val); | 551 | if (val >= 2) { |
552 | if (!(val & BIT(1))) | 552 | rdmsrl(MSR_AMD64_OSVW_STATUS, val); |
553 | goto no_c1e_idle; | 553 | if (!(val & BIT(1))) |
554 | goto no_c1e_idle; | ||
555 | } | ||
554 | } | 556 | } |
555 | return 1; | 557 | return 1; |
556 | } | 558 | } |
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index f6c62667e30c..8d128783af47 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c | |||
@@ -55,7 +55,6 @@ | |||
55 | #include <asm/cpu.h> | 55 | #include <asm/cpu.h> |
56 | #include <asm/idle.h> | 56 | #include <asm/idle.h> |
57 | #include <asm/syscalls.h> | 57 | #include <asm/syscalls.h> |
58 | #include <asm/ds.h> | ||
59 | #include <asm/debugreg.h> | 58 | #include <asm/debugreg.h> |
60 | 59 | ||
61 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); | 60 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); |
@@ -238,13 +237,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
238 | kfree(p->thread.io_bitmap_ptr); | 237 | kfree(p->thread.io_bitmap_ptr); |
239 | p->thread.io_bitmap_max = 0; | 238 | p->thread.io_bitmap_max = 0; |
240 | } | 239 | } |
241 | |||
242 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); | ||
243 | p->thread.ds_ctx = NULL; | ||
244 | |||
245 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
246 | p->thread.debugctlmsr = 0; | ||
247 | |||
248 | return err; | 240 | return err; |
249 | } | 241 | } |
250 | 242 | ||
@@ -317,7 +309,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | |||
317 | 309 | ||
318 | /* we're going to use this soon, after a few expensive things */ | 310 | /* we're going to use this soon, after a few expensive things */ |
319 | if (preload_fpu) | 311 | if (preload_fpu) |
320 | prefetch(next->xstate); | 312 | prefetch(next->fpu.state); |
321 | 313 | ||
322 | /* | 314 | /* |
323 | * Reload esp0. | 315 | * Reload esp0. |
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 17cb3295cbf7..3c2422a99f1f 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c | |||
@@ -49,7 +49,6 @@ | |||
49 | #include <asm/ia32.h> | 49 | #include <asm/ia32.h> |
50 | #include <asm/idle.h> | 50 | #include <asm/idle.h> |
51 | #include <asm/syscalls.h> | 51 | #include <asm/syscalls.h> |
52 | #include <asm/ds.h> | ||
53 | #include <asm/debugreg.h> | 52 | #include <asm/debugreg.h> |
54 | 53 | ||
55 | asmlinkage extern void ret_from_fork(void); | 54 | asmlinkage extern void ret_from_fork(void); |
@@ -313,13 +312,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, | |||
313 | if (err) | 312 | if (err) |
314 | goto out; | 313 | goto out; |
315 | } | 314 | } |
316 | |||
317 | clear_tsk_thread_flag(p, TIF_DS_AREA_MSR); | ||
318 | p->thread.ds_ctx = NULL; | ||
319 | |||
320 | clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR); | ||
321 | p->thread.debugctlmsr = 0; | ||
322 | |||
323 | err = 0; | 315 | err = 0; |
324 | out: | 316 | out: |
325 | if (err && p->thread.io_bitmap_ptr) { | 317 | if (err && p->thread.io_bitmap_ptr) { |
@@ -396,7 +388,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) | |||
396 | 388 | ||
397 | /* we're going to use this soon, after a few expensive things */ | 389 | /* we're going to use this soon, after a few expensive things */ |
398 | if (preload_fpu) | 390 | if (preload_fpu) |
399 | prefetch(next->xstate); | 391 | prefetch(next->fpu.state); |
400 | 392 | ||
401 | /* | 393 | /* |
402 | * Reload esp0, LDT and the page table pointer: | 394 | * Reload esp0, LDT and the page table pointer: |
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 2e9b55027b7e..70c4872cd8aa 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -2,9 +2,6 @@ | |||
2 | /* | 2 | /* |
3 | * Pentium III FXSR, SSE support | 3 | * Pentium III FXSR, SSE support |
4 | * Gareth Hughes <gareth@valinux.com>, May 2000 | 4 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
5 | * | ||
6 | * BTS tracing | ||
7 | * Markus Metzger <markus.t.metzger@intel.com>, Dec 2007 | ||
8 | */ | 5 | */ |
9 | 6 | ||
10 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
@@ -22,7 +19,6 @@ | |||
22 | #include <linux/audit.h> | 19 | #include <linux/audit.h> |
23 | #include <linux/seccomp.h> | 20 | #include <linux/seccomp.h> |
24 | #include <linux/signal.h> | 21 | #include <linux/signal.h> |
25 | #include <linux/workqueue.h> | ||
26 | #include <linux/perf_event.h> | 22 | #include <linux/perf_event.h> |
27 | #include <linux/hw_breakpoint.h> | 23 | #include <linux/hw_breakpoint.h> |
28 | 24 | ||
@@ -36,7 +32,6 @@ | |||
36 | #include <asm/desc.h> | 32 | #include <asm/desc.h> |
37 | #include <asm/prctl.h> | 33 | #include <asm/prctl.h> |
38 | #include <asm/proto.h> | 34 | #include <asm/proto.h> |
39 | #include <asm/ds.h> | ||
40 | #include <asm/hw_breakpoint.h> | 35 | #include <asm/hw_breakpoint.h> |
41 | 36 | ||
42 | #include "tls.h" | 37 | #include "tls.h" |
@@ -693,7 +688,7 @@ static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr, | |||
693 | struct perf_event_attr attr; | 688 | struct perf_event_attr attr; |
694 | 689 | ||
695 | if (!t->ptrace_bps[nr]) { | 690 | if (!t->ptrace_bps[nr]) { |
696 | hw_breakpoint_init(&attr); | 691 | ptrace_breakpoint_init(&attr); |
697 | /* | 692 | /* |
698 | * Put stub len and type to register (reserve) an inactive but | 693 | * Put stub len and type to register (reserve) an inactive but |
699 | * correct bp | 694 | * correct bp |
@@ -789,342 +784,6 @@ static int ioperm_get(struct task_struct *target, | |||
789 | 0, IO_BITMAP_BYTES); | 784 | 0, IO_BITMAP_BYTES); |
790 | } | 785 | } |
791 | 786 | ||
792 | #ifdef CONFIG_X86_PTRACE_BTS | ||
793 | /* | ||
794 | * A branch trace store context. | ||
795 | * | ||
796 | * Contexts may only be installed by ptrace_bts_config() and only for | ||
797 | * ptraced tasks. | ||
798 | * | ||
799 | * Contexts are destroyed when the tracee is detached from the tracer. | ||
800 | * The actual destruction work requires interrupts enabled, so the | ||
801 | * work is deferred and will be scheduled during __ptrace_unlink(). | ||
802 | * | ||
803 | * Contexts hold an additional task_struct reference on the traced | ||
804 | * task, as well as a reference on the tracer's mm. | ||
805 | * | ||
806 | * Ptrace already holds a task_struct for the duration of ptrace operations, | ||
807 | * but since destruction is deferred, it may be executed after both | ||
808 | * tracer and tracee exited. | ||
809 | */ | ||
810 | struct bts_context { | ||
811 | /* The branch trace handle. */ | ||
812 | struct bts_tracer *tracer; | ||
813 | |||
814 | /* The buffer used to store the branch trace and its size. */ | ||
815 | void *buffer; | ||
816 | unsigned int size; | ||
817 | |||
818 | /* The mm that paid for the above buffer. */ | ||
819 | struct mm_struct *mm; | ||
820 | |||
821 | /* The task this context belongs to. */ | ||
822 | struct task_struct *task; | ||
823 | |||
824 | /* The signal to send on a bts buffer overflow. */ | ||
825 | unsigned int bts_ovfl_signal; | ||
826 | |||
827 | /* The work struct to destroy a context. */ | ||
828 | struct work_struct work; | ||
829 | }; | ||
830 | |||
831 | static int alloc_bts_buffer(struct bts_context *context, unsigned int size) | ||
832 | { | ||
833 | void *buffer = NULL; | ||
834 | int err = -ENOMEM; | ||
835 | |||
836 | err = account_locked_memory(current->mm, current->signal->rlim, size); | ||
837 | if (err < 0) | ||
838 | return err; | ||
839 | |||
840 | buffer = kzalloc(size, GFP_KERNEL); | ||
841 | if (!buffer) | ||
842 | goto out_refund; | ||
843 | |||
844 | context->buffer = buffer; | ||
845 | context->size = size; | ||
846 | context->mm = get_task_mm(current); | ||
847 | |||
848 | return 0; | ||
849 | |||
850 | out_refund: | ||
851 | refund_locked_memory(current->mm, size); | ||
852 | return err; | ||
853 | } | ||
854 | |||
855 | static inline void free_bts_buffer(struct bts_context *context) | ||
856 | { | ||
857 | if (!context->buffer) | ||
858 | return; | ||
859 | |||
860 | kfree(context->buffer); | ||
861 | context->buffer = NULL; | ||
862 | |||
863 | refund_locked_memory(context->mm, context->size); | ||
864 | context->size = 0; | ||
865 | |||
866 | mmput(context->mm); | ||
867 | context->mm = NULL; | ||
868 | } | ||
869 | |||
870 | static void free_bts_context_work(struct work_struct *w) | ||
871 | { | ||
872 | struct bts_context *context; | ||
873 | |||
874 | context = container_of(w, struct bts_context, work); | ||
875 | |||
876 | ds_release_bts(context->tracer); | ||
877 | put_task_struct(context->task); | ||
878 | free_bts_buffer(context); | ||
879 | kfree(context); | ||
880 | } | ||
881 | |||
882 | static inline void free_bts_context(struct bts_context *context) | ||
883 | { | ||
884 | INIT_WORK(&context->work, free_bts_context_work); | ||
885 | schedule_work(&context->work); | ||
886 | } | ||
887 | |||
888 | static inline struct bts_context *alloc_bts_context(struct task_struct *task) | ||
889 | { | ||
890 | struct bts_context *context = kzalloc(sizeof(*context), GFP_KERNEL); | ||
891 | if (context) { | ||
892 | context->task = task; | ||
893 | task->bts = context; | ||
894 | |||
895 | get_task_struct(task); | ||
896 | } | ||
897 | |||
898 | return context; | ||
899 | } | ||
900 | |||
901 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, | ||
902 | struct bts_struct __user *out) | ||
903 | { | ||
904 | struct bts_context *context; | ||
905 | const struct bts_trace *trace; | ||
906 | struct bts_struct bts; | ||
907 | const unsigned char *at; | ||
908 | int error; | ||
909 | |||
910 | context = child->bts; | ||
911 | if (!context) | ||
912 | return -ESRCH; | ||
913 | |||
914 | trace = ds_read_bts(context->tracer); | ||
915 | if (!trace) | ||
916 | return -ESRCH; | ||
917 | |||
918 | at = trace->ds.top - ((index + 1) * trace->ds.size); | ||
919 | if ((void *)at < trace->ds.begin) | ||
920 | at += (trace->ds.n * trace->ds.size); | ||
921 | |||
922 | if (!trace->read) | ||
923 | return -EOPNOTSUPP; | ||
924 | |||
925 | error = trace->read(context->tracer, at, &bts); | ||
926 | if (error < 0) | ||
927 | return error; | ||
928 | |||
929 | if (copy_to_user(out, &bts, sizeof(bts))) | ||
930 | return -EFAULT; | ||
931 | |||
932 | return sizeof(bts); | ||
933 | } | ||
934 | |||
935 | static int ptrace_bts_drain(struct task_struct *child, | ||
936 | long size, | ||
937 | struct bts_struct __user *out) | ||
938 | { | ||
939 | struct bts_context *context; | ||
940 | const struct bts_trace *trace; | ||
941 | const unsigned char *at; | ||
942 | int error, drained = 0; | ||
943 | |||
944 | context = child->bts; | ||
945 | if (!context) | ||
946 | return -ESRCH; | ||
947 | |||
948 | trace = ds_read_bts(context->tracer); | ||
949 | if (!trace) | ||
950 | return -ESRCH; | ||
951 | |||
952 | if (!trace->read) | ||
953 | return -EOPNOTSUPP; | ||
954 | |||
955 | if (size < (trace->ds.top - trace->ds.begin)) | ||
956 | return -EIO; | ||
957 | |||
958 | for (at = trace->ds.begin; (void *)at < trace->ds.top; | ||
959 | out++, drained++, at += trace->ds.size) { | ||
960 | struct bts_struct bts; | ||
961 | |||
962 | error = trace->read(context->tracer, at, &bts); | ||
963 | if (error < 0) | ||
964 | return error; | ||
965 | |||
966 | if (copy_to_user(out, &bts, sizeof(bts))) | ||
967 | return -EFAULT; | ||
968 | } | ||
969 | |||
970 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); | ||
971 | |||
972 | error = ds_reset_bts(context->tracer); | ||
973 | if (error < 0) | ||
974 | return error; | ||
975 | |||
976 | return drained; | ||
977 | } | ||
978 | |||
979 | static int ptrace_bts_config(struct task_struct *child, | ||
980 | long cfg_size, | ||
981 | const struct ptrace_bts_config __user *ucfg) | ||
982 | { | ||
983 | struct bts_context *context; | ||
984 | struct ptrace_bts_config cfg; | ||
985 | unsigned int flags = 0; | ||
986 | |||
987 | if (cfg_size < sizeof(cfg)) | ||
988 | return -EIO; | ||
989 | |||
990 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) | ||
991 | return -EFAULT; | ||
992 | |||
993 | context = child->bts; | ||
994 | if (!context) | ||
995 | context = alloc_bts_context(child); | ||
996 | if (!context) | ||
997 | return -ENOMEM; | ||
998 | |||
999 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { | ||
1000 | if (!cfg.signal) | ||
1001 | return -EINVAL; | ||
1002 | |||
1003 | return -EOPNOTSUPP; | ||
1004 | context->bts_ovfl_signal = cfg.signal; | ||
1005 | } | ||
1006 | |||
1007 | ds_release_bts(context->tracer); | ||
1008 | context->tracer = NULL; | ||
1009 | |||
1010 | if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) { | ||
1011 | int err; | ||
1012 | |||
1013 | free_bts_buffer(context); | ||
1014 | if (!cfg.size) | ||
1015 | return 0; | ||
1016 | |||
1017 | err = alloc_bts_buffer(context, cfg.size); | ||
1018 | if (err < 0) | ||
1019 | return err; | ||
1020 | } | ||
1021 | |||
1022 | if (cfg.flags & PTRACE_BTS_O_TRACE) | ||
1023 | flags |= BTS_USER; | ||
1024 | |||
1025 | if (cfg.flags & PTRACE_BTS_O_SCHED) | ||
1026 | flags |= BTS_TIMESTAMPS; | ||
1027 | |||
1028 | context->tracer = | ||
1029 | ds_request_bts_task(child, context->buffer, context->size, | ||
1030 | NULL, (size_t)-1, flags); | ||
1031 | if (unlikely(IS_ERR(context->tracer))) { | ||
1032 | int error = PTR_ERR(context->tracer); | ||
1033 | |||
1034 | free_bts_buffer(context); | ||
1035 | context->tracer = NULL; | ||
1036 | return error; | ||
1037 | } | ||
1038 | |||
1039 | return sizeof(cfg); | ||
1040 | } | ||
1041 | |||
1042 | static int ptrace_bts_status(struct task_struct *child, | ||
1043 | long cfg_size, | ||
1044 | struct ptrace_bts_config __user *ucfg) | ||
1045 | { | ||
1046 | struct bts_context *context; | ||
1047 | const struct bts_trace *trace; | ||
1048 | struct ptrace_bts_config cfg; | ||
1049 | |||
1050 | context = child->bts; | ||
1051 | if (!context) | ||
1052 | return -ESRCH; | ||
1053 | |||
1054 | if (cfg_size < sizeof(cfg)) | ||
1055 | return -EIO; | ||
1056 | |||
1057 | trace = ds_read_bts(context->tracer); | ||
1058 | if (!trace) | ||
1059 | return -ESRCH; | ||
1060 | |||
1061 | memset(&cfg, 0, sizeof(cfg)); | ||
1062 | cfg.size = trace->ds.end - trace->ds.begin; | ||
1063 | cfg.signal = context->bts_ovfl_signal; | ||
1064 | cfg.bts_size = sizeof(struct bts_struct); | ||
1065 | |||
1066 | if (cfg.signal) | ||
1067 | cfg.flags |= PTRACE_BTS_O_SIGNAL; | ||
1068 | |||
1069 | if (trace->ds.flags & BTS_USER) | ||
1070 | cfg.flags |= PTRACE_BTS_O_TRACE; | ||
1071 | |||
1072 | if (trace->ds.flags & BTS_TIMESTAMPS) | ||
1073 | cfg.flags |= PTRACE_BTS_O_SCHED; | ||
1074 | |||
1075 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) | ||
1076 | return -EFAULT; | ||
1077 | |||
1078 | return sizeof(cfg); | ||
1079 | } | ||
1080 | |||
1081 | static int ptrace_bts_clear(struct task_struct *child) | ||
1082 | { | ||
1083 | struct bts_context *context; | ||
1084 | const struct bts_trace *trace; | ||
1085 | |||
1086 | context = child->bts; | ||
1087 | if (!context) | ||
1088 | return -ESRCH; | ||
1089 | |||
1090 | trace = ds_read_bts(context->tracer); | ||
1091 | if (!trace) | ||
1092 | return -ESRCH; | ||
1093 | |||
1094 | memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size); | ||
1095 | |||
1096 | return ds_reset_bts(context->tracer); | ||
1097 | } | ||
1098 | |||
1099 | static int ptrace_bts_size(struct task_struct *child) | ||
1100 | { | ||
1101 | struct bts_context *context; | ||
1102 | const struct bts_trace *trace; | ||
1103 | |||
1104 | context = child->bts; | ||
1105 | if (!context) | ||
1106 | return -ESRCH; | ||
1107 | |||
1108 | trace = ds_read_bts(context->tracer); | ||
1109 | if (!trace) | ||
1110 | return -ESRCH; | ||
1111 | |||
1112 | return (trace->ds.top - trace->ds.begin) / trace->ds.size; | ||
1113 | } | ||
1114 | |||
1115 | /* | ||
1116 | * Called from __ptrace_unlink() after the child has been moved back | ||
1117 | * to its original parent. | ||
1118 | */ | ||
1119 | void ptrace_bts_untrace(struct task_struct *child) | ||
1120 | { | ||
1121 | if (unlikely(child->bts)) { | ||
1122 | free_bts_context(child->bts); | ||
1123 | child->bts = NULL; | ||
1124 | } | ||
1125 | } | ||
1126 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1127 | |||
1128 | /* | 787 | /* |
1129 | * Called by kernel/ptrace.c when detaching.. | 788 | * Called by kernel/ptrace.c when detaching.. |
1130 | * | 789 | * |
@@ -1252,39 +911,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
1252 | break; | 911 | break; |
1253 | #endif | 912 | #endif |
1254 | 913 | ||
1255 | /* | ||
1256 | * These bits need more cooking - not enabled yet: | ||
1257 | */ | ||
1258 | #ifdef CONFIG_X86_PTRACE_BTS | ||
1259 | case PTRACE_BTS_CONFIG: | ||
1260 | ret = ptrace_bts_config | ||
1261 | (child, data, (struct ptrace_bts_config __user *)addr); | ||
1262 | break; | ||
1263 | |||
1264 | case PTRACE_BTS_STATUS: | ||
1265 | ret = ptrace_bts_status | ||
1266 | (child, data, (struct ptrace_bts_config __user *)addr); | ||
1267 | break; | ||
1268 | |||
1269 | case PTRACE_BTS_SIZE: | ||
1270 | ret = ptrace_bts_size(child); | ||
1271 | break; | ||
1272 | |||
1273 | case PTRACE_BTS_GET: | ||
1274 | ret = ptrace_bts_read_record | ||
1275 | (child, data, (struct bts_struct __user *) addr); | ||
1276 | break; | ||
1277 | |||
1278 | case PTRACE_BTS_CLEAR: | ||
1279 | ret = ptrace_bts_clear(child); | ||
1280 | break; | ||
1281 | |||
1282 | case PTRACE_BTS_DRAIN: | ||
1283 | ret = ptrace_bts_drain | ||
1284 | (child, data, (struct bts_struct __user *) addr); | ||
1285 | break; | ||
1286 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1287 | |||
1288 | default: | 914 | default: |
1289 | ret = ptrace_request(child, request, addr, data); | 915 | ret = ptrace_request(child, request, addr, data); |
1290 | break; | 916 | break; |
@@ -1544,14 +1170,6 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
1544 | 1170 | ||
1545 | case PTRACE_GET_THREAD_AREA: | 1171 | case PTRACE_GET_THREAD_AREA: |
1546 | case PTRACE_SET_THREAD_AREA: | 1172 | case PTRACE_SET_THREAD_AREA: |
1547 | #ifdef CONFIG_X86_PTRACE_BTS | ||
1548 | case PTRACE_BTS_CONFIG: | ||
1549 | case PTRACE_BTS_STATUS: | ||
1550 | case PTRACE_BTS_SIZE: | ||
1551 | case PTRACE_BTS_GET: | ||
1552 | case PTRACE_BTS_CLEAR: | ||
1553 | case PTRACE_BTS_DRAIN: | ||
1554 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
1555 | return arch_ptrace(child, request, addr, data); | 1173 | return arch_ptrace(child, request, addr, data); |
1556 | 1174 | ||
1557 | default: | 1175 | default: |
diff --git a/arch/x86/kernel/sfi.c b/arch/x86/kernel/sfi.c index 34e099382651..7ded57896c0a 100644 --- a/arch/x86/kernel/sfi.c +++ b/arch/x86/kernel/sfi.c | |||
@@ -81,7 +81,6 @@ static int __init sfi_parse_cpus(struct sfi_table_header *table) | |||
81 | #endif /* CONFIG_X86_LOCAL_APIC */ | 81 | #endif /* CONFIG_X86_LOCAL_APIC */ |
82 | 82 | ||
83 | #ifdef CONFIG_X86_IO_APIC | 83 | #ifdef CONFIG_X86_IO_APIC |
84 | static u32 gsi_base; | ||
85 | 84 | ||
86 | static int __init sfi_parse_ioapic(struct sfi_table_header *table) | 85 | static int __init sfi_parse_ioapic(struct sfi_table_header *table) |
87 | { | 86 | { |
@@ -94,8 +93,7 @@ static int __init sfi_parse_ioapic(struct sfi_table_header *table) | |||
94 | pentry = (struct sfi_apic_table_entry *)sb->pentry; | 93 | pentry = (struct sfi_apic_table_entry *)sb->pentry; |
95 | 94 | ||
96 | for (i = 0; i < num; i++) { | 95 | for (i = 0; i < num; i++) { |
97 | mp_register_ioapic(i, pentry->phys_addr, gsi_base); | 96 | mp_register_ioapic(i, pentry->phys_addr, gsi_end + 1); |
98 | gsi_base += io_apic_get_redir_entries(i); | ||
99 | pentry++; | 97 | pentry++; |
100 | } | 98 | } |
101 | 99 | ||
diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c index 3149032ff107..58de45ee08b6 100644 --- a/arch/x86/kernel/step.c +++ b/arch/x86/kernel/step.c | |||
@@ -158,22 +158,6 @@ static int enable_single_step(struct task_struct *child) | |||
158 | } | 158 | } |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * Install this value in MSR_IA32_DEBUGCTLMSR whenever child is running. | ||
162 | */ | ||
163 | static void write_debugctlmsr(struct task_struct *child, unsigned long val) | ||
164 | { | ||
165 | if (child->thread.debugctlmsr == val) | ||
166 | return; | ||
167 | |||
168 | child->thread.debugctlmsr = val; | ||
169 | |||
170 | if (child != current) | ||
171 | return; | ||
172 | |||
173 | update_debugctlmsr(val); | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * Enable single or block step. | 161 | * Enable single or block step. |
178 | */ | 162 | */ |
179 | static void enable_step(struct task_struct *child, bool block) | 163 | static void enable_step(struct task_struct *child, bool block) |
@@ -186,15 +170,17 @@ static void enable_step(struct task_struct *child, bool block) | |||
186 | * that uses user-mode single stepping itself. | 170 | * that uses user-mode single stepping itself. |
187 | */ | 171 | */ |
188 | if (enable_single_step(child) && block) { | 172 | if (enable_single_step(child) && block) { |
189 | set_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 173 | unsigned long debugctl = get_debugctlmsr(); |
190 | write_debugctlmsr(child, | 174 | |
191 | child->thread.debugctlmsr | DEBUGCTLMSR_BTF); | 175 | debugctl |= DEBUGCTLMSR_BTF; |
192 | } else { | 176 | update_debugctlmsr(debugctl); |
193 | write_debugctlmsr(child, | 177 | set_tsk_thread_flag(child, TIF_BLOCKSTEP); |
194 | child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF); | 178 | } else if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) { |
195 | 179 | unsigned long debugctl = get_debugctlmsr(); | |
196 | if (!child->thread.debugctlmsr) | 180 | |
197 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 181 | debugctl &= ~DEBUGCTLMSR_BTF; |
182 | update_debugctlmsr(debugctl); | ||
183 | clear_tsk_thread_flag(child, TIF_BLOCKSTEP); | ||
198 | } | 184 | } |
199 | } | 185 | } |
200 | 186 | ||
@@ -213,11 +199,13 @@ void user_disable_single_step(struct task_struct *child) | |||
213 | /* | 199 | /* |
214 | * Make sure block stepping (BTF) is disabled. | 200 | * Make sure block stepping (BTF) is disabled. |
215 | */ | 201 | */ |
216 | write_debugctlmsr(child, | 202 | if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) { |
217 | child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF); | 203 | unsigned long debugctl = get_debugctlmsr(); |
218 | 204 | ||
219 | if (!child->thread.debugctlmsr) | 205 | debugctl &= ~DEBUGCTLMSR_BTF; |
220 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 206 | update_debugctlmsr(debugctl); |
207 | clear_tsk_thread_flag(child, TIF_BLOCKSTEP); | ||
208 | } | ||
221 | 209 | ||
222 | /* Always clear TIF_SINGLESTEP... */ | 210 | /* Always clear TIF_SINGLESTEP... */ |
223 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); | 211 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); |
diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 86c9f91b48ae..cc2c60474fd0 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c | |||
@@ -175,6 +175,9 @@ static void add_mac_region(phys_addr_t start, unsigned long size) | |||
175 | struct tboot_mac_region *mr; | 175 | struct tboot_mac_region *mr; |
176 | phys_addr_t end = start + size; | 176 | phys_addr_t end = start + size; |
177 | 177 | ||
178 | if (tboot->num_mac_regions >= MAX_TB_MAC_REGIONS) | ||
179 | panic("tboot: Too many MAC regions\n"); | ||
180 | |||
178 | if (start && size) { | 181 | if (start && size) { |
179 | mr = &tboot->mac_regions[tboot->num_mac_regions++]; | 182 | mr = &tboot->mac_regions[tboot->num_mac_regions++]; |
180 | mr->start = round_down(start, PAGE_SIZE); | 183 | mr->start = round_down(start, PAGE_SIZE); |
@@ -184,18 +187,17 @@ static void add_mac_region(phys_addr_t start, unsigned long size) | |||
184 | 187 | ||
185 | static int tboot_setup_sleep(void) | 188 | static int tboot_setup_sleep(void) |
186 | { | 189 | { |
190 | int i; | ||
191 | |||
187 | tboot->num_mac_regions = 0; | 192 | tboot->num_mac_regions = 0; |
188 | 193 | ||
189 | /* S3 resume code */ | 194 | for (i = 0; i < e820.nr_map; i++) { |
190 | add_mac_region(acpi_wakeup_address, WAKEUP_SIZE); | 195 | if ((e820.map[i].type != E820_RAM) |
196 | && (e820.map[i].type != E820_RESERVED_KERN)) | ||
197 | continue; | ||
191 | 198 | ||
192 | #ifdef CONFIG_X86_TRAMPOLINE | 199 | add_mac_region(e820.map[i].addr, e820.map[i].size); |
193 | /* AP trampoline code */ | 200 | } |
194 | add_mac_region(virt_to_phys(trampoline_base), TRAMPOLINE_SIZE); | ||
195 | #endif | ||
196 | |||
197 | /* kernel code + data + bss */ | ||
198 | add_mac_region(virt_to_phys(_text), _end - _text); | ||
199 | 201 | ||
200 | tboot->acpi_sinfo.kernel_s3_resume_vector = acpi_wakeup_address; | 202 | tboot->acpi_sinfo.kernel_s3_resume_vector = acpi_wakeup_address; |
201 | 203 | ||
diff --git a/arch/x86/kernel/tlb_uv.c b/arch/x86/kernel/tlb_uv.c index 17b03dd3a6b5..7fea555929e2 100644 --- a/arch/x86/kernel/tlb_uv.c +++ b/arch/x86/kernel/tlb_uv.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * SGI UltraViolet TLB flush routines. | 2 | * SGI UltraViolet TLB flush routines. |
3 | * | 3 | * |
4 | * (c) 2008 Cliff Wickman <cpw@sgi.com>, SGI. | 4 | * (c) 2008-2010 Cliff Wickman <cpw@sgi.com>, SGI. |
5 | * | 5 | * |
6 | * This code is released under the GNU General Public License version 2 or | 6 | * This code is released under the GNU General Public License version 2 or |
7 | * later. | 7 | * later. |
@@ -20,42 +20,67 @@ | |||
20 | #include <asm/idle.h> | 20 | #include <asm/idle.h> |
21 | #include <asm/tsc.h> | 21 | #include <asm/tsc.h> |
22 | #include <asm/irq_vectors.h> | 22 | #include <asm/irq_vectors.h> |
23 | #include <asm/timer.h> | ||
23 | 24 | ||
24 | static struct bau_control **uv_bau_table_bases __read_mostly; | 25 | struct msg_desc { |
25 | static int uv_bau_retry_limit __read_mostly; | 26 | struct bau_payload_queue_entry *msg; |
27 | int msg_slot; | ||
28 | int sw_ack_slot; | ||
29 | struct bau_payload_queue_entry *va_queue_first; | ||
30 | struct bau_payload_queue_entry *va_queue_last; | ||
31 | }; | ||
26 | 32 | ||
27 | /* base pnode in this partition */ | 33 | #define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL |
28 | static int uv_partition_base_pnode __read_mostly; | 34 | |
35 | static int uv_bau_max_concurrent __read_mostly; | ||
36 | |||
37 | static int nobau; | ||
38 | static int __init setup_nobau(char *arg) | ||
39 | { | ||
40 | nobau = 1; | ||
41 | return 0; | ||
42 | } | ||
43 | early_param("nobau", setup_nobau); | ||
29 | 44 | ||
30 | static unsigned long uv_mmask __read_mostly; | 45 | /* base pnode in this partition */ |
46 | static int uv_partition_base_pnode __read_mostly; | ||
47 | /* position of pnode (which is nasid>>1): */ | ||
48 | static int uv_nshift __read_mostly; | ||
49 | static unsigned long uv_mmask __read_mostly; | ||
31 | 50 | ||
32 | static DEFINE_PER_CPU(struct ptc_stats, ptcstats); | 51 | static DEFINE_PER_CPU(struct ptc_stats, ptcstats); |
33 | static DEFINE_PER_CPU(struct bau_control, bau_control); | 52 | static DEFINE_PER_CPU(struct bau_control, bau_control); |
53 | static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask); | ||
54 | |||
55 | struct reset_args { | ||
56 | int sender; | ||
57 | }; | ||
34 | 58 | ||
35 | /* | 59 | /* |
36 | * Determine the first node on a blade. | 60 | * Determine the first node on a uvhub. 'Nodes' are used for kernel |
61 | * memory allocation. | ||
37 | */ | 62 | */ |
38 | static int __init blade_to_first_node(int blade) | 63 | static int __init uvhub_to_first_node(int uvhub) |
39 | { | 64 | { |
40 | int node, b; | 65 | int node, b; |
41 | 66 | ||
42 | for_each_online_node(node) { | 67 | for_each_online_node(node) { |
43 | b = uv_node_to_blade_id(node); | 68 | b = uv_node_to_blade_id(node); |
44 | if (blade == b) | 69 | if (uvhub == b) |
45 | return node; | 70 | return node; |
46 | } | 71 | } |
47 | return -1; /* shouldn't happen */ | 72 | return -1; |
48 | } | 73 | } |
49 | 74 | ||
50 | /* | 75 | /* |
51 | * Determine the apicid of the first cpu on a blade. | 76 | * Determine the apicid of the first cpu on a uvhub. |
52 | */ | 77 | */ |
53 | static int __init blade_to_first_apicid(int blade) | 78 | static int __init uvhub_to_first_apicid(int uvhub) |
54 | { | 79 | { |
55 | int cpu; | 80 | int cpu; |
56 | 81 | ||
57 | for_each_present_cpu(cpu) | 82 | for_each_present_cpu(cpu) |
58 | if (blade == uv_cpu_to_blade_id(cpu)) | 83 | if (uvhub == uv_cpu_to_blade_id(cpu)) |
59 | return per_cpu(x86_cpu_to_apicid, cpu); | 84 | return per_cpu(x86_cpu_to_apicid, cpu); |
60 | return -1; | 85 | return -1; |
61 | } | 86 | } |
@@ -68,195 +93,459 @@ static int __init blade_to_first_apicid(int blade) | |||
68 | * clear of the Timeout bit (as well) will free the resource. No reply will | 93 | * clear of the Timeout bit (as well) will free the resource. No reply will |
69 | * be sent (the hardware will only do one reply per message). | 94 | * be sent (the hardware will only do one reply per message). |
70 | */ | 95 | */ |
71 | static void uv_reply_to_message(int resource, | 96 | static inline void uv_reply_to_message(struct msg_desc *mdp, |
72 | struct bau_payload_queue_entry *msg, | 97 | struct bau_control *bcp) |
73 | struct bau_msg_status *msp) | ||
74 | { | 98 | { |
75 | unsigned long dw; | 99 | unsigned long dw; |
100 | struct bau_payload_queue_entry *msg; | ||
76 | 101 | ||
77 | dw = (1 << (resource + UV_SW_ACK_NPENDING)) | (1 << resource); | 102 | msg = mdp->msg; |
103 | if (!msg->canceled) { | ||
104 | dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) | | ||
105 | msg->sw_ack_vector; | ||
106 | uv_write_local_mmr( | ||
107 | UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw); | ||
108 | } | ||
78 | msg->replied_to = 1; | 109 | msg->replied_to = 1; |
79 | msg->sw_ack_vector = 0; | 110 | msg->sw_ack_vector = 0; |
80 | if (msp) | ||
81 | msp->seen_by.bits = 0; | ||
82 | uv_write_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw); | ||
83 | } | 111 | } |
84 | 112 | ||
85 | /* | 113 | /* |
86 | * Do all the things a cpu should do for a TLB shootdown message. | 114 | * Process the receipt of a RETRY message |
87 | * Other cpu's may come here at the same time for this message. | ||
88 | */ | 115 | */ |
89 | static void uv_bau_process_message(struct bau_payload_queue_entry *msg, | 116 | static inline void uv_bau_process_retry_msg(struct msg_desc *mdp, |
90 | int msg_slot, int sw_ack_slot) | 117 | struct bau_control *bcp) |
91 | { | 118 | { |
92 | unsigned long this_cpu_mask; | 119 | int i; |
93 | struct bau_msg_status *msp; | 120 | int cancel_count = 0; |
94 | int cpu; | 121 | int slot2; |
122 | unsigned long msg_res; | ||
123 | unsigned long mmr = 0; | ||
124 | struct bau_payload_queue_entry *msg; | ||
125 | struct bau_payload_queue_entry *msg2; | ||
126 | struct ptc_stats *stat; | ||
95 | 127 | ||
96 | msp = __get_cpu_var(bau_control).msg_statuses + msg_slot; | 128 | msg = mdp->msg; |
97 | cpu = uv_blade_processor_id(); | 129 | stat = &per_cpu(ptcstats, bcp->cpu); |
98 | msg->number_of_cpus = | 130 | stat->d_retries++; |
99 | uv_blade_nr_online_cpus(uv_node_to_blade_id(numa_node_id())); | 131 | /* |
100 | this_cpu_mask = 1UL << cpu; | 132 | * cancel any message from msg+1 to the retry itself |
101 | if (msp->seen_by.bits & this_cpu_mask) | 133 | */ |
102 | return; | 134 | for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) { |
103 | atomic_or_long(&msp->seen_by.bits, this_cpu_mask); | 135 | if (msg2 > mdp->va_queue_last) |
136 | msg2 = mdp->va_queue_first; | ||
137 | if (msg2 == msg) | ||
138 | break; | ||
139 | |||
140 | /* same conditions for cancellation as uv_do_reset */ | ||
141 | if ((msg2->replied_to == 0) && (msg2->canceled == 0) && | ||
142 | (msg2->sw_ack_vector) && ((msg2->sw_ack_vector & | ||
143 | msg->sw_ack_vector) == 0) && | ||
144 | (msg2->sending_cpu == msg->sending_cpu) && | ||
145 | (msg2->msg_type != MSG_NOOP)) { | ||
146 | slot2 = msg2 - mdp->va_queue_first; | ||
147 | mmr = uv_read_local_mmr | ||
148 | (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE); | ||
149 | msg_res = ((msg2->sw_ack_vector << 8) | | ||
150 | msg2->sw_ack_vector); | ||
151 | /* | ||
152 | * This is a message retry; clear the resources held | ||
153 | * by the previous message only if they timed out. | ||
154 | * If it has not timed out we have an unexpected | ||
155 | * situation to report. | ||
156 | */ | ||
157 | if (mmr & (msg_res << 8)) { | ||
158 | /* | ||
159 | * is the resource timed out? | ||
160 | * make everyone ignore the cancelled message. | ||
161 | */ | ||
162 | msg2->canceled = 1; | ||
163 | stat->d_canceled++; | ||
164 | cancel_count++; | ||
165 | uv_write_local_mmr( | ||
166 | UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, | ||
167 | (msg_res << 8) | msg_res); | ||
168 | } else | ||
169 | printk(KERN_INFO "note bau retry: no effect\n"); | ||
170 | } | ||
171 | } | ||
172 | if (!cancel_count) | ||
173 | stat->d_nocanceled++; | ||
174 | } | ||
104 | 175 | ||
105 | if (msg->replied_to == 1) | 176 | /* |
106 | return; | 177 | * Do all the things a cpu should do for a TLB shootdown message. |
178 | * Other cpu's may come here at the same time for this message. | ||
179 | */ | ||
180 | static void uv_bau_process_message(struct msg_desc *mdp, | ||
181 | struct bau_control *bcp) | ||
182 | { | ||
183 | int msg_ack_count; | ||
184 | short socket_ack_count = 0; | ||
185 | struct ptc_stats *stat; | ||
186 | struct bau_payload_queue_entry *msg; | ||
187 | struct bau_control *smaster = bcp->socket_master; | ||
107 | 188 | ||
189 | /* | ||
190 | * This must be a normal message, or retry of a normal message | ||
191 | */ | ||
192 | msg = mdp->msg; | ||
193 | stat = &per_cpu(ptcstats, bcp->cpu); | ||
108 | if (msg->address == TLB_FLUSH_ALL) { | 194 | if (msg->address == TLB_FLUSH_ALL) { |
109 | local_flush_tlb(); | 195 | local_flush_tlb(); |
110 | __get_cpu_var(ptcstats).alltlb++; | 196 | stat->d_alltlb++; |
111 | } else { | 197 | } else { |
112 | __flush_tlb_one(msg->address); | 198 | __flush_tlb_one(msg->address); |
113 | __get_cpu_var(ptcstats).onetlb++; | 199 | stat->d_onetlb++; |
114 | } | 200 | } |
201 | stat->d_requestee++; | ||
202 | |||
203 | /* | ||
204 | * One cpu on each uvhub has the additional job on a RETRY | ||
205 | * of releasing the resource held by the message that is | ||
206 | * being retried. That message is identified by sending | ||
207 | * cpu number. | ||
208 | */ | ||
209 | if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master) | ||
210 | uv_bau_process_retry_msg(mdp, bcp); | ||
115 | 211 | ||
116 | __get_cpu_var(ptcstats).requestee++; | 212 | /* |
213 | * This is a sw_ack message, so we have to reply to it. | ||
214 | * Count each responding cpu on the socket. This avoids | ||
215 | * pinging the count's cache line back and forth between | ||
216 | * the sockets. | ||
217 | */ | ||
218 | socket_ack_count = atomic_add_short_return(1, (struct atomic_short *) | ||
219 | &smaster->socket_acknowledge_count[mdp->msg_slot]); | ||
220 | if (socket_ack_count == bcp->cpus_in_socket) { | ||
221 | /* | ||
222 | * Both sockets dump their completed count total into | ||
223 | * the message's count. | ||
224 | */ | ||
225 | smaster->socket_acknowledge_count[mdp->msg_slot] = 0; | ||
226 | msg_ack_count = atomic_add_short_return(socket_ack_count, | ||
227 | (struct atomic_short *)&msg->acknowledge_count); | ||
228 | |||
229 | if (msg_ack_count == bcp->cpus_in_uvhub) { | ||
230 | /* | ||
231 | * All cpus in uvhub saw it; reply | ||
232 | */ | ||
233 | uv_reply_to_message(mdp, bcp); | ||
234 | } | ||
235 | } | ||
117 | 236 | ||
118 | atomic_inc_short(&msg->acknowledge_count); | 237 | return; |
119 | if (msg->number_of_cpus == msg->acknowledge_count) | ||
120 | uv_reply_to_message(sw_ack_slot, msg, msp); | ||
121 | } | 238 | } |
122 | 239 | ||
123 | /* | 240 | /* |
124 | * Examine the payload queue on one distribution node to see | 241 | * Determine the first cpu on a uvhub. |
125 | * which messages have not been seen, and which cpu(s) have not seen them. | 242 | */ |
243 | static int uvhub_to_first_cpu(int uvhub) | ||
244 | { | ||
245 | int cpu; | ||
246 | for_each_present_cpu(cpu) | ||
247 | if (uvhub == uv_cpu_to_blade_id(cpu)) | ||
248 | return cpu; | ||
249 | return -1; | ||
250 | } | ||
251 | |||
252 | /* | ||
253 | * Last resort when we get a large number of destination timeouts is | ||
254 | * to clear resources held by a given cpu. | ||
255 | * Do this with IPI so that all messages in the BAU message queue | ||
256 | * can be identified by their nonzero sw_ack_vector field. | ||
126 | * | 257 | * |
127 | * Returns the number of cpu's that have not responded. | 258 | * This is entered for a single cpu on the uvhub. |
259 | * The sender want's this uvhub to free a specific message's | ||
260 | * sw_ack resources. | ||
128 | */ | 261 | */ |
129 | static int uv_examine_destination(struct bau_control *bau_tablesp, int sender) | 262 | static void |
263 | uv_do_reset(void *ptr) | ||
130 | { | 264 | { |
131 | struct bau_payload_queue_entry *msg; | ||
132 | struct bau_msg_status *msp; | ||
133 | int count = 0; | ||
134 | int i; | 265 | int i; |
135 | int j; | 266 | int slot; |
267 | int count = 0; | ||
268 | unsigned long mmr; | ||
269 | unsigned long msg_res; | ||
270 | struct bau_control *bcp; | ||
271 | struct reset_args *rap; | ||
272 | struct bau_payload_queue_entry *msg; | ||
273 | struct ptc_stats *stat; | ||
136 | 274 | ||
137 | for (msg = bau_tablesp->va_queue_first, i = 0; i < DEST_Q_SIZE; | 275 | bcp = &per_cpu(bau_control, smp_processor_id()); |
138 | msg++, i++) { | 276 | rap = (struct reset_args *)ptr; |
139 | if ((msg->sending_cpu == sender) && (!msg->replied_to)) { | 277 | stat = &per_cpu(ptcstats, bcp->cpu); |
140 | msp = bau_tablesp->msg_statuses + i; | 278 | stat->d_resets++; |
141 | printk(KERN_DEBUG | 279 | |
142 | "blade %d: address:%#lx %d of %d, not cpu(s): ", | 280 | /* |
143 | i, msg->address, msg->acknowledge_count, | 281 | * We're looking for the given sender, and |
144 | msg->number_of_cpus); | 282 | * will free its sw_ack resource. |
145 | for (j = 0; j < msg->number_of_cpus; j++) { | 283 | * If all cpu's finally responded after the timeout, its |
146 | if (!((1L << j) & msp->seen_by.bits)) { | 284 | * message 'replied_to' was set. |
147 | count++; | 285 | */ |
148 | printk("%d ", j); | 286 | for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) { |
149 | } | 287 | /* uv_do_reset: same conditions for cancellation as |
288 | uv_bau_process_retry_msg() */ | ||
289 | if ((msg->replied_to == 0) && | ||
290 | (msg->canceled == 0) && | ||
291 | (msg->sending_cpu == rap->sender) && | ||
292 | (msg->sw_ack_vector) && | ||
293 | (msg->msg_type != MSG_NOOP)) { | ||
294 | /* | ||
295 | * make everyone else ignore this message | ||
296 | */ | ||
297 | msg->canceled = 1; | ||
298 | slot = msg - bcp->va_queue_first; | ||
299 | count++; | ||
300 | /* | ||
301 | * only reset the resource if it is still pending | ||
302 | */ | ||
303 | mmr = uv_read_local_mmr | ||
304 | (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE); | ||
305 | msg_res = ((msg->sw_ack_vector << 8) | | ||
306 | msg->sw_ack_vector); | ||
307 | if (mmr & msg_res) { | ||
308 | stat->d_rcanceled++; | ||
309 | uv_write_local_mmr( | ||
310 | UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, | ||
311 | msg_res); | ||
150 | } | 312 | } |
151 | printk("\n"); | ||
152 | } | 313 | } |
153 | } | 314 | } |
154 | return count; | 315 | return; |
155 | } | 316 | } |
156 | 317 | ||
157 | /* | 318 | /* |
158 | * Examine the payload queue on all the distribution nodes to see | 319 | * Use IPI to get all target uvhubs to release resources held by |
159 | * which messages have not been seen, and which cpu(s) have not seen them. | 320 | * a given sending cpu number. |
160 | * | ||
161 | * Returns the number of cpu's that have not responded. | ||
162 | */ | 321 | */ |
163 | static int uv_examine_destinations(struct bau_target_nodemask *distribution) | 322 | static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution, |
323 | int sender) | ||
164 | { | 324 | { |
165 | int sender; | 325 | int uvhub; |
166 | int i; | 326 | int cpu; |
167 | int count = 0; | 327 | cpumask_t mask; |
328 | struct reset_args reset_args; | ||
329 | |||
330 | reset_args.sender = sender; | ||
168 | 331 | ||
169 | sender = smp_processor_id(); | 332 | cpus_clear(mask); |
170 | for (i = 0; i < sizeof(struct bau_target_nodemask) * BITSPERBYTE; i++) { | 333 | /* find a single cpu for each uvhub in this distribution mask */ |
171 | if (!bau_node_isset(i, distribution)) | 334 | for (uvhub = 0; |
335 | uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE; | ||
336 | uvhub++) { | ||
337 | if (!bau_uvhub_isset(uvhub, distribution)) | ||
172 | continue; | 338 | continue; |
173 | count += uv_examine_destination(uv_bau_table_bases[i], sender); | 339 | /* find a cpu for this uvhub */ |
340 | cpu = uvhub_to_first_cpu(uvhub); | ||
341 | cpu_set(cpu, mask); | ||
174 | } | 342 | } |
175 | return count; | 343 | /* IPI all cpus; Preemption is already disabled */ |
344 | smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1); | ||
345 | return; | ||
346 | } | ||
347 | |||
348 | static inline unsigned long | ||
349 | cycles_2_us(unsigned long long cyc) | ||
350 | { | ||
351 | unsigned long long ns; | ||
352 | unsigned long us; | ||
353 | ns = (cyc * per_cpu(cyc2ns, smp_processor_id())) | ||
354 | >> CYC2NS_SCALE_FACTOR; | ||
355 | us = ns / 1000; | ||
356 | return us; | ||
176 | } | 357 | } |
177 | 358 | ||
178 | /* | 359 | /* |
179 | * wait for completion of a broadcast message | 360 | * wait for all cpus on this hub to finish their sends and go quiet |
180 | * | 361 | * leaves uvhub_quiesce set so that no new broadcasts are started by |
181 | * return COMPLETE, RETRY or GIVEUP | 362 | * bau_flush_send_and_wait() |
363 | */ | ||
364 | static inline void | ||
365 | quiesce_local_uvhub(struct bau_control *hmaster) | ||
366 | { | ||
367 | atomic_add_short_return(1, (struct atomic_short *) | ||
368 | &hmaster->uvhub_quiesce); | ||
369 | } | ||
370 | |||
371 | /* | ||
372 | * mark this quiet-requestor as done | ||
373 | */ | ||
374 | static inline void | ||
375 | end_uvhub_quiesce(struct bau_control *hmaster) | ||
376 | { | ||
377 | atomic_add_short_return(-1, (struct atomic_short *) | ||
378 | &hmaster->uvhub_quiesce); | ||
379 | } | ||
380 | |||
381 | /* | ||
382 | * Wait for completion of a broadcast software ack message | ||
383 | * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP | ||
182 | */ | 384 | */ |
183 | static int uv_wait_completion(struct bau_desc *bau_desc, | 385 | static int uv_wait_completion(struct bau_desc *bau_desc, |
184 | unsigned long mmr_offset, int right_shift) | 386 | unsigned long mmr_offset, int right_shift, int this_cpu, |
387 | struct bau_control *bcp, struct bau_control *smaster, long try) | ||
185 | { | 388 | { |
186 | int exams = 0; | 389 | int relaxes = 0; |
187 | long destination_timeouts = 0; | ||
188 | long source_timeouts = 0; | ||
189 | unsigned long descriptor_status; | 390 | unsigned long descriptor_status; |
391 | unsigned long mmr; | ||
392 | unsigned long mask; | ||
393 | cycles_t ttime; | ||
394 | cycles_t timeout_time; | ||
395 | struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu); | ||
396 | struct bau_control *hmaster; | ||
397 | |||
398 | hmaster = bcp->uvhub_master; | ||
399 | timeout_time = get_cycles() + bcp->timeout_interval; | ||
190 | 400 | ||
401 | /* spin on the status MMR, waiting for it to go idle */ | ||
191 | while ((descriptor_status = (((unsigned long) | 402 | while ((descriptor_status = (((unsigned long) |
192 | uv_read_local_mmr(mmr_offset) >> | 403 | uv_read_local_mmr(mmr_offset) >> |
193 | right_shift) & UV_ACT_STATUS_MASK)) != | 404 | right_shift) & UV_ACT_STATUS_MASK)) != |
194 | DESC_STATUS_IDLE) { | 405 | DESC_STATUS_IDLE) { |
195 | if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) { | ||
196 | source_timeouts++; | ||
197 | if (source_timeouts > SOURCE_TIMEOUT_LIMIT) | ||
198 | source_timeouts = 0; | ||
199 | __get_cpu_var(ptcstats).s_retry++; | ||
200 | return FLUSH_RETRY; | ||
201 | } | ||
202 | /* | 406 | /* |
203 | * spin here looking for progress at the destinations | 407 | * Our software ack messages may be blocked because there are |
408 | * no swack resources available. As long as none of them | ||
409 | * has timed out hardware will NACK our message and its | ||
410 | * state will stay IDLE. | ||
204 | */ | 411 | */ |
205 | if (descriptor_status == DESC_STATUS_DESTINATION_TIMEOUT) { | 412 | if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) { |
206 | destination_timeouts++; | 413 | stat->s_stimeout++; |
207 | if (destination_timeouts > DESTINATION_TIMEOUT_LIMIT) { | 414 | return FLUSH_GIVEUP; |
208 | /* | 415 | } else if (descriptor_status == |
209 | * returns number of cpus not responding | 416 | DESC_STATUS_DESTINATION_TIMEOUT) { |
210 | */ | 417 | stat->s_dtimeout++; |
211 | if (uv_examine_destinations | 418 | ttime = get_cycles(); |
212 | (&bau_desc->distribution) == 0) { | 419 | |
213 | __get_cpu_var(ptcstats).d_retry++; | 420 | /* |
214 | return FLUSH_RETRY; | 421 | * Our retries may be blocked by all destination |
215 | } | 422 | * swack resources being consumed, and a timeout |
216 | exams++; | 423 | * pending. In that case hardware returns the |
217 | if (exams >= uv_bau_retry_limit) { | 424 | * ERROR that looks like a destination timeout. |
218 | printk(KERN_DEBUG | 425 | */ |
219 | "uv_flush_tlb_others"); | 426 | if (cycles_2_us(ttime - bcp->send_message) < BIOS_TO) { |
220 | printk("giving up on cpu %d\n", | 427 | bcp->conseccompletes = 0; |
221 | smp_processor_id()); | 428 | return FLUSH_RETRY_PLUGGED; |
429 | } | ||
430 | |||
431 | bcp->conseccompletes = 0; | ||
432 | return FLUSH_RETRY_TIMEOUT; | ||
433 | } else { | ||
434 | /* | ||
435 | * descriptor_status is still BUSY | ||
436 | */ | ||
437 | cpu_relax(); | ||
438 | relaxes++; | ||
439 | if (relaxes >= 10000) { | ||
440 | relaxes = 0; | ||
441 | if (get_cycles() > timeout_time) { | ||
442 | quiesce_local_uvhub(hmaster); | ||
443 | |||
444 | /* single-thread the register change */ | ||
445 | spin_lock(&hmaster->masks_lock); | ||
446 | mmr = uv_read_local_mmr(mmr_offset); | ||
447 | mask = 0UL; | ||
448 | mask |= (3UL < right_shift); | ||
449 | mask = ~mask; | ||
450 | mmr &= mask; | ||
451 | uv_write_local_mmr(mmr_offset, mmr); | ||
452 | spin_unlock(&hmaster->masks_lock); | ||
453 | end_uvhub_quiesce(hmaster); | ||
454 | stat->s_busy++; | ||
222 | return FLUSH_GIVEUP; | 455 | return FLUSH_GIVEUP; |
223 | } | 456 | } |
224 | /* | ||
225 | * delays can hang the simulator | ||
226 | udelay(1000); | ||
227 | */ | ||
228 | destination_timeouts = 0; | ||
229 | } | 457 | } |
230 | } | 458 | } |
231 | cpu_relax(); | ||
232 | } | 459 | } |
460 | bcp->conseccompletes++; | ||
233 | return FLUSH_COMPLETE; | 461 | return FLUSH_COMPLETE; |
234 | } | 462 | } |
235 | 463 | ||
464 | static inline cycles_t | ||
465 | sec_2_cycles(unsigned long sec) | ||
466 | { | ||
467 | unsigned long ns; | ||
468 | cycles_t cyc; | ||
469 | |||
470 | ns = sec * 1000000000; | ||
471 | cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id())); | ||
472 | return cyc; | ||
473 | } | ||
474 | |||
475 | /* | ||
476 | * conditionally add 1 to *v, unless *v is >= u | ||
477 | * return 0 if we cannot add 1 to *v because it is >= u | ||
478 | * return 1 if we can add 1 to *v because it is < u | ||
479 | * the add is atomic | ||
480 | * | ||
481 | * This is close to atomic_add_unless(), but this allows the 'u' value | ||
482 | * to be lowered below the current 'v'. atomic_add_unless can only stop | ||
483 | * on equal. | ||
484 | */ | ||
485 | static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u) | ||
486 | { | ||
487 | spin_lock(lock); | ||
488 | if (atomic_read(v) >= u) { | ||
489 | spin_unlock(lock); | ||
490 | return 0; | ||
491 | } | ||
492 | atomic_inc(v); | ||
493 | spin_unlock(lock); | ||
494 | return 1; | ||
495 | } | ||
496 | |||
236 | /** | 497 | /** |
237 | * uv_flush_send_and_wait | 498 | * uv_flush_send_and_wait |
238 | * | 499 | * |
239 | * Send a broadcast and wait for a broadcast message to complete. | 500 | * Send a broadcast and wait for it to complete. |
240 | * | 501 | * |
241 | * The flush_mask contains the cpus the broadcast was sent to. | 502 | * The flush_mask contains the cpus the broadcast is to be sent to, plus |
503 | * cpus that are on the local uvhub. | ||
242 | * | 504 | * |
243 | * Returns NULL if all remote flushing was done. The mask is zeroed. | 505 | * Returns NULL if all flushing represented in the mask was done. The mask |
506 | * is zeroed. | ||
244 | * Returns @flush_mask if some remote flushing remains to be done. The | 507 | * Returns @flush_mask if some remote flushing remains to be done. The |
245 | * mask will have some bits still set. | 508 | * mask will have some bits still set, representing any cpus on the local |
509 | * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed. | ||
246 | */ | 510 | */ |
247 | const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode, | 511 | const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc, |
248 | struct bau_desc *bau_desc, | 512 | struct cpumask *flush_mask, |
249 | struct cpumask *flush_mask) | 513 | struct bau_control *bcp) |
250 | { | 514 | { |
251 | int completion_status = 0; | ||
252 | int right_shift; | 515 | int right_shift; |
253 | int tries = 0; | 516 | int uvhub; |
254 | int pnode; | ||
255 | int bit; | 517 | int bit; |
518 | int completion_status = 0; | ||
519 | int seq_number = 0; | ||
520 | long try = 0; | ||
521 | int cpu = bcp->uvhub_cpu; | ||
522 | int this_cpu = bcp->cpu; | ||
523 | int this_uvhub = bcp->uvhub; | ||
256 | unsigned long mmr_offset; | 524 | unsigned long mmr_offset; |
257 | unsigned long index; | 525 | unsigned long index; |
258 | cycles_t time1; | 526 | cycles_t time1; |
259 | cycles_t time2; | 527 | cycles_t time2; |
528 | struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu); | ||
529 | struct bau_control *smaster = bcp->socket_master; | ||
530 | struct bau_control *hmaster = bcp->uvhub_master; | ||
531 | |||
532 | /* | ||
533 | * Spin here while there are hmaster->max_concurrent or more active | ||
534 | * descriptors. This is the per-uvhub 'throttle'. | ||
535 | */ | ||
536 | if (!atomic_inc_unless_ge(&hmaster->uvhub_lock, | ||
537 | &hmaster->active_descriptor_count, | ||
538 | hmaster->max_concurrent)) { | ||
539 | stat->s_throttles++; | ||
540 | do { | ||
541 | cpu_relax(); | ||
542 | } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock, | ||
543 | &hmaster->active_descriptor_count, | ||
544 | hmaster->max_concurrent)); | ||
545 | } | ||
546 | |||
547 | while (hmaster->uvhub_quiesce) | ||
548 | cpu_relax(); | ||
260 | 549 | ||
261 | if (cpu < UV_CPUS_PER_ACT_STATUS) { | 550 | if (cpu < UV_CPUS_PER_ACT_STATUS) { |
262 | mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0; | 551 | mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0; |
@@ -268,24 +557,108 @@ const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode, | |||
268 | } | 557 | } |
269 | time1 = get_cycles(); | 558 | time1 = get_cycles(); |
270 | do { | 559 | do { |
271 | tries++; | 560 | /* |
561 | * Every message from any given cpu gets a unique message | ||
562 | * sequence number. But retries use that same number. | ||
563 | * Our message may have timed out at the destination because | ||
564 | * all sw-ack resources are in use and there is a timeout | ||
565 | * pending there. In that case, our last send never got | ||
566 | * placed into the queue and we need to persist until it | ||
567 | * does. | ||
568 | * | ||
569 | * Make any retry a type MSG_RETRY so that the destination will | ||
570 | * free any resource held by a previous message from this cpu. | ||
571 | */ | ||
572 | if (try == 0) { | ||
573 | /* use message type set by the caller the first time */ | ||
574 | seq_number = bcp->message_number++; | ||
575 | } else { | ||
576 | /* use RETRY type on all the rest; same sequence */ | ||
577 | bau_desc->header.msg_type = MSG_RETRY; | ||
578 | stat->s_retry_messages++; | ||
579 | } | ||
580 | bau_desc->header.sequence = seq_number; | ||
272 | index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) | | 581 | index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) | |
273 | cpu; | 582 | bcp->uvhub_cpu; |
583 | bcp->send_message = get_cycles(); | ||
584 | |||
274 | uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index); | 585 | uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index); |
586 | |||
587 | try++; | ||
275 | completion_status = uv_wait_completion(bau_desc, mmr_offset, | 588 | completion_status = uv_wait_completion(bau_desc, mmr_offset, |
276 | right_shift); | 589 | right_shift, this_cpu, bcp, smaster, try); |
277 | } while (completion_status == FLUSH_RETRY); | 590 | |
591 | if (completion_status == FLUSH_RETRY_PLUGGED) { | ||
592 | /* | ||
593 | * Our retries may be blocked by all destination swack | ||
594 | * resources being consumed, and a timeout pending. In | ||
595 | * that case hardware immediately returns the ERROR | ||
596 | * that looks like a destination timeout. | ||
597 | */ | ||
598 | udelay(TIMEOUT_DELAY); | ||
599 | bcp->plugged_tries++; | ||
600 | if (bcp->plugged_tries >= PLUGSB4RESET) { | ||
601 | bcp->plugged_tries = 0; | ||
602 | quiesce_local_uvhub(hmaster); | ||
603 | spin_lock(&hmaster->queue_lock); | ||
604 | uv_reset_with_ipi(&bau_desc->distribution, | ||
605 | this_cpu); | ||
606 | spin_unlock(&hmaster->queue_lock); | ||
607 | end_uvhub_quiesce(hmaster); | ||
608 | bcp->ipi_attempts++; | ||
609 | stat->s_resets_plug++; | ||
610 | } | ||
611 | } else if (completion_status == FLUSH_RETRY_TIMEOUT) { | ||
612 | hmaster->max_concurrent = 1; | ||
613 | bcp->timeout_tries++; | ||
614 | udelay(TIMEOUT_DELAY); | ||
615 | if (bcp->timeout_tries >= TIMEOUTSB4RESET) { | ||
616 | bcp->timeout_tries = 0; | ||
617 | quiesce_local_uvhub(hmaster); | ||
618 | spin_lock(&hmaster->queue_lock); | ||
619 | uv_reset_with_ipi(&bau_desc->distribution, | ||
620 | this_cpu); | ||
621 | spin_unlock(&hmaster->queue_lock); | ||
622 | end_uvhub_quiesce(hmaster); | ||
623 | bcp->ipi_attempts++; | ||
624 | stat->s_resets_timeout++; | ||
625 | } | ||
626 | } | ||
627 | if (bcp->ipi_attempts >= 3) { | ||
628 | bcp->ipi_attempts = 0; | ||
629 | completion_status = FLUSH_GIVEUP; | ||
630 | break; | ||
631 | } | ||
632 | cpu_relax(); | ||
633 | } while ((completion_status == FLUSH_RETRY_PLUGGED) || | ||
634 | (completion_status == FLUSH_RETRY_TIMEOUT)); | ||
278 | time2 = get_cycles(); | 635 | time2 = get_cycles(); |
279 | __get_cpu_var(ptcstats).sflush += (time2 - time1); | ||
280 | if (tries > 1) | ||
281 | __get_cpu_var(ptcstats).retriesok++; | ||
282 | 636 | ||
283 | if (completion_status == FLUSH_GIVEUP) { | 637 | if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5) |
638 | && (hmaster->max_concurrent < hmaster->max_concurrent_constant)) | ||
639 | hmaster->max_concurrent++; | ||
640 | |||
641 | /* | ||
642 | * hold any cpu not timing out here; no other cpu currently held by | ||
643 | * the 'throttle' should enter the activation code | ||
644 | */ | ||
645 | while (hmaster->uvhub_quiesce) | ||
646 | cpu_relax(); | ||
647 | atomic_dec(&hmaster->active_descriptor_count); | ||
648 | |||
649 | /* guard against cycles wrap */ | ||
650 | if (time2 > time1) | ||
651 | stat->s_time += (time2 - time1); | ||
652 | else | ||
653 | stat->s_requestor--; /* don't count this one */ | ||
654 | if (completion_status == FLUSH_COMPLETE && try > 1) | ||
655 | stat->s_retriesok++; | ||
656 | else if (completion_status == FLUSH_GIVEUP) { | ||
284 | /* | 657 | /* |
285 | * Cause the caller to do an IPI-style TLB shootdown on | 658 | * Cause the caller to do an IPI-style TLB shootdown on |
286 | * the cpu's, all of which are still in the mask. | 659 | * the target cpu's, all of which are still in the mask. |
287 | */ | 660 | */ |
288 | __get_cpu_var(ptcstats).ptc_i++; | 661 | stat->s_giveup++; |
289 | return flush_mask; | 662 | return flush_mask; |
290 | } | 663 | } |
291 | 664 | ||
@@ -294,18 +667,17 @@ const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode, | |||
294 | * use the IPI method of shootdown on them. | 667 | * use the IPI method of shootdown on them. |
295 | */ | 668 | */ |
296 | for_each_cpu(bit, flush_mask) { | 669 | for_each_cpu(bit, flush_mask) { |
297 | pnode = uv_cpu_to_pnode(bit); | 670 | uvhub = uv_cpu_to_blade_id(bit); |
298 | if (pnode == this_pnode) | 671 | if (uvhub == this_uvhub) |
299 | continue; | 672 | continue; |
300 | cpumask_clear_cpu(bit, flush_mask); | 673 | cpumask_clear_cpu(bit, flush_mask); |
301 | } | 674 | } |
302 | if (!cpumask_empty(flush_mask)) | 675 | if (!cpumask_empty(flush_mask)) |
303 | return flush_mask; | 676 | return flush_mask; |
677 | |||
304 | return NULL; | 678 | return NULL; |
305 | } | 679 | } |
306 | 680 | ||
307 | static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask); | ||
308 | |||
309 | /** | 681 | /** |
310 | * uv_flush_tlb_others - globally purge translation cache of a virtual | 682 | * uv_flush_tlb_others - globally purge translation cache of a virtual |
311 | * address or all TLB's | 683 | * address or all TLB's |
@@ -322,8 +694,8 @@ static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask); | |||
322 | * The caller has derived the cpumask from the mm_struct. This function | 694 | * The caller has derived the cpumask from the mm_struct. This function |
323 | * is called only if there are bits set in the mask. (e.g. flush_tlb_page()) | 695 | * is called only if there are bits set in the mask. (e.g. flush_tlb_page()) |
324 | * | 696 | * |
325 | * The cpumask is converted into a nodemask of the nodes containing | 697 | * The cpumask is converted into a uvhubmask of the uvhubs containing |
326 | * the cpus. | 698 | * those cpus. |
327 | * | 699 | * |
328 | * Note that this function should be called with preemption disabled. | 700 | * Note that this function should be called with preemption disabled. |
329 | * | 701 | * |
@@ -335,52 +707,82 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask, | |||
335 | struct mm_struct *mm, | 707 | struct mm_struct *mm, |
336 | unsigned long va, unsigned int cpu) | 708 | unsigned long va, unsigned int cpu) |
337 | { | 709 | { |
338 | struct cpumask *flush_mask = __get_cpu_var(uv_flush_tlb_mask); | 710 | int remotes; |
339 | int i; | 711 | int tcpu; |
340 | int bit; | 712 | int uvhub; |
341 | int pnode; | ||
342 | int uv_cpu; | ||
343 | int this_pnode; | ||
344 | int locals = 0; | 713 | int locals = 0; |
345 | struct bau_desc *bau_desc; | 714 | struct bau_desc *bau_desc; |
715 | struct cpumask *flush_mask; | ||
716 | struct ptc_stats *stat; | ||
717 | struct bau_control *bcp; | ||
346 | 718 | ||
347 | cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu)); | 719 | if (nobau) |
720 | return cpumask; | ||
348 | 721 | ||
349 | uv_cpu = uv_blade_processor_id(); | 722 | bcp = &per_cpu(bau_control, cpu); |
350 | this_pnode = uv_hub_info->pnode; | 723 | /* |
351 | bau_desc = __get_cpu_var(bau_control).descriptor_base; | 724 | * Each sending cpu has a per-cpu mask which it fills from the caller's |
352 | bau_desc += UV_ITEMS_PER_DESCRIPTOR * uv_cpu; | 725 | * cpu mask. Only remote cpus are converted to uvhubs and copied. |
726 | */ | ||
727 | flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu); | ||
728 | /* | ||
729 | * copy cpumask to flush_mask, removing current cpu | ||
730 | * (current cpu should already have been flushed by the caller and | ||
731 | * should never be returned if we return flush_mask) | ||
732 | */ | ||
733 | cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu)); | ||
734 | if (cpu_isset(cpu, *cpumask)) | ||
735 | locals++; /* current cpu was targeted */ | ||
353 | 736 | ||
354 | bau_nodes_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE); | 737 | bau_desc = bcp->descriptor_base; |
738 | bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu; | ||
355 | 739 | ||
356 | i = 0; | 740 | bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE); |
357 | for_each_cpu(bit, flush_mask) { | 741 | remotes = 0; |
358 | pnode = uv_cpu_to_pnode(bit); | 742 | for_each_cpu(tcpu, flush_mask) { |
359 | BUG_ON(pnode > (UV_DISTRIBUTION_SIZE - 1)); | 743 | uvhub = uv_cpu_to_blade_id(tcpu); |
360 | if (pnode == this_pnode) { | 744 | if (uvhub == bcp->uvhub) { |
361 | locals++; | 745 | locals++; |
362 | continue; | 746 | continue; |
363 | } | 747 | } |
364 | bau_node_set(pnode - uv_partition_base_pnode, | 748 | bau_uvhub_set(uvhub, &bau_desc->distribution); |
365 | &bau_desc->distribution); | 749 | remotes++; |
366 | i++; | ||
367 | } | 750 | } |
368 | if (i == 0) { | 751 | if (remotes == 0) { |
369 | /* | 752 | /* |
370 | * no off_node flushing; return status for local node | 753 | * No off_hub flushing; return status for local hub. |
754 | * Return the caller's mask if all were local (the current | ||
755 | * cpu may be in that mask). | ||
371 | */ | 756 | */ |
372 | if (locals) | 757 | if (locals) |
373 | return flush_mask; | 758 | return cpumask; |
374 | else | 759 | else |
375 | return NULL; | 760 | return NULL; |
376 | } | 761 | } |
377 | __get_cpu_var(ptcstats).requestor++; | 762 | stat = &per_cpu(ptcstats, cpu); |
378 | __get_cpu_var(ptcstats).ntargeted += i; | 763 | stat->s_requestor++; |
764 | stat->s_ntargcpu += remotes; | ||
765 | remotes = bau_uvhub_weight(&bau_desc->distribution); | ||
766 | stat->s_ntarguvhub += remotes; | ||
767 | if (remotes >= 16) | ||
768 | stat->s_ntarguvhub16++; | ||
769 | else if (remotes >= 8) | ||
770 | stat->s_ntarguvhub8++; | ||
771 | else if (remotes >= 4) | ||
772 | stat->s_ntarguvhub4++; | ||
773 | else if (remotes >= 2) | ||
774 | stat->s_ntarguvhub2++; | ||
775 | else | ||
776 | stat->s_ntarguvhub1++; | ||
379 | 777 | ||
380 | bau_desc->payload.address = va; | 778 | bau_desc->payload.address = va; |
381 | bau_desc->payload.sending_cpu = cpu; | 779 | bau_desc->payload.sending_cpu = cpu; |
382 | 780 | ||
383 | return uv_flush_send_and_wait(uv_cpu, this_pnode, bau_desc, flush_mask); | 781 | /* |
782 | * uv_flush_send_and_wait returns null if all cpu's were messaged, or | ||
783 | * the adjusted flush_mask if any cpu's were not messaged. | ||
784 | */ | ||
785 | return uv_flush_send_and_wait(bau_desc, flush_mask, bcp); | ||
384 | } | 786 | } |
385 | 787 | ||
386 | /* | 788 | /* |
@@ -389,87 +791,70 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask, | |||
389 | * | 791 | * |
390 | * We received a broadcast assist message. | 792 | * We received a broadcast assist message. |
391 | * | 793 | * |
392 | * Interrupts may have been disabled; this interrupt could represent | 794 | * Interrupts are disabled; this interrupt could represent |
393 | * the receipt of several messages. | 795 | * the receipt of several messages. |
394 | * | 796 | * |
395 | * All cores/threads on this node get this interrupt. | 797 | * All cores/threads on this hub get this interrupt. |
396 | * The last one to see it does the s/w ack. | 798 | * The last one to see it does the software ack. |
397 | * (the resource will not be freed until noninterruptable cpus see this | 799 | * (the resource will not be freed until noninterruptable cpus see this |
398 | * interrupt; hardware will timeout the s/w ack and reply ERROR) | 800 | * interrupt; hardware may timeout the s/w ack and reply ERROR) |
399 | */ | 801 | */ |
400 | void uv_bau_message_interrupt(struct pt_regs *regs) | 802 | void uv_bau_message_interrupt(struct pt_regs *regs) |
401 | { | 803 | { |
402 | struct bau_payload_queue_entry *va_queue_first; | ||
403 | struct bau_payload_queue_entry *va_queue_last; | ||
404 | struct bau_payload_queue_entry *msg; | ||
405 | struct pt_regs *old_regs = set_irq_regs(regs); | ||
406 | cycles_t time1; | ||
407 | cycles_t time2; | ||
408 | int msg_slot; | ||
409 | int sw_ack_slot; | ||
410 | int fw; | ||
411 | int count = 0; | 804 | int count = 0; |
412 | unsigned long local_pnode; | 805 | cycles_t time_start; |
413 | 806 | struct bau_payload_queue_entry *msg; | |
414 | ack_APIC_irq(); | 807 | struct bau_control *bcp; |
415 | exit_idle(); | 808 | struct ptc_stats *stat; |
416 | irq_enter(); | 809 | struct msg_desc msgdesc; |
417 | 810 | ||
418 | time1 = get_cycles(); | 811 | time_start = get_cycles(); |
419 | 812 | bcp = &per_cpu(bau_control, smp_processor_id()); | |
420 | local_pnode = uv_blade_to_pnode(uv_numa_blade_id()); | 813 | stat = &per_cpu(ptcstats, smp_processor_id()); |
421 | 814 | msgdesc.va_queue_first = bcp->va_queue_first; | |
422 | va_queue_first = __get_cpu_var(bau_control).va_queue_first; | 815 | msgdesc.va_queue_last = bcp->va_queue_last; |
423 | va_queue_last = __get_cpu_var(bau_control).va_queue_last; | 816 | msg = bcp->bau_msg_head; |
424 | |||
425 | msg = __get_cpu_var(bau_control).bau_msg_head; | ||
426 | while (msg->sw_ack_vector) { | 817 | while (msg->sw_ack_vector) { |
427 | count++; | 818 | count++; |
428 | fw = msg->sw_ack_vector; | 819 | msgdesc.msg_slot = msg - msgdesc.va_queue_first; |
429 | msg_slot = msg - va_queue_first; | 820 | msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1; |
430 | sw_ack_slot = ffs(fw) - 1; | 821 | msgdesc.msg = msg; |
431 | 822 | uv_bau_process_message(&msgdesc, bcp); | |
432 | uv_bau_process_message(msg, msg_slot, sw_ack_slot); | ||
433 | |||
434 | msg++; | 823 | msg++; |
435 | if (msg > va_queue_last) | 824 | if (msg > msgdesc.va_queue_last) |
436 | msg = va_queue_first; | 825 | msg = msgdesc.va_queue_first; |
437 | __get_cpu_var(bau_control).bau_msg_head = msg; | 826 | bcp->bau_msg_head = msg; |
438 | } | 827 | } |
828 | stat->d_time += (get_cycles() - time_start); | ||
439 | if (!count) | 829 | if (!count) |
440 | __get_cpu_var(ptcstats).nomsg++; | 830 | stat->d_nomsg++; |
441 | else if (count > 1) | 831 | else if (count > 1) |
442 | __get_cpu_var(ptcstats).multmsg++; | 832 | stat->d_multmsg++; |
443 | 833 | ack_APIC_irq(); | |
444 | time2 = get_cycles(); | ||
445 | __get_cpu_var(ptcstats).dflush += (time2 - time1); | ||
446 | |||
447 | irq_exit(); | ||
448 | set_irq_regs(old_regs); | ||
449 | } | 834 | } |
450 | 835 | ||
451 | /* | 836 | /* |
452 | * uv_enable_timeouts | 837 | * uv_enable_timeouts |
453 | * | 838 | * |
454 | * Each target blade (i.e. blades that have cpu's) needs to have | 839 | * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have |
455 | * shootdown message timeouts enabled. The timeout does not cause | 840 | * shootdown message timeouts enabled. The timeout does not cause |
456 | * an interrupt, but causes an error message to be returned to | 841 | * an interrupt, but causes an error message to be returned to |
457 | * the sender. | 842 | * the sender. |
458 | */ | 843 | */ |
459 | static void uv_enable_timeouts(void) | 844 | static void uv_enable_timeouts(void) |
460 | { | 845 | { |
461 | int blade; | 846 | int uvhub; |
462 | int nblades; | 847 | int nuvhubs; |
463 | int pnode; | 848 | int pnode; |
464 | unsigned long mmr_image; | 849 | unsigned long mmr_image; |
465 | 850 | ||
466 | nblades = uv_num_possible_blades(); | 851 | nuvhubs = uv_num_possible_blades(); |
467 | 852 | ||
468 | for (blade = 0; blade < nblades; blade++) { | 853 | for (uvhub = 0; uvhub < nuvhubs; uvhub++) { |
469 | if (!uv_blade_nr_possible_cpus(blade)) | 854 | if (!uv_blade_nr_possible_cpus(uvhub)) |
470 | continue; | 855 | continue; |
471 | 856 | ||
472 | pnode = uv_blade_to_pnode(blade); | 857 | pnode = uv_blade_to_pnode(uvhub); |
473 | mmr_image = | 858 | mmr_image = |
474 | uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL); | 859 | uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL); |
475 | /* | 860 | /* |
@@ -479,16 +864,16 @@ static void uv_enable_timeouts(void) | |||
479 | * To program the period, the SOFT_ACK_MODE must be off. | 864 | * To program the period, the SOFT_ACK_MODE must be off. |
480 | */ | 865 | */ |
481 | mmr_image &= ~((unsigned long)1 << | 866 | mmr_image &= ~((unsigned long)1 << |
482 | UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT); | 867 | UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT); |
483 | uv_write_global_mmr64 | 868 | uv_write_global_mmr64 |
484 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); | 869 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); |
485 | /* | 870 | /* |
486 | * Set the 4-bit period. | 871 | * Set the 4-bit period. |
487 | */ | 872 | */ |
488 | mmr_image &= ~((unsigned long)0xf << | 873 | mmr_image &= ~((unsigned long)0xf << |
489 | UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT); | 874 | UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT); |
490 | mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD << | 875 | mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD << |
491 | UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT); | 876 | UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT); |
492 | uv_write_global_mmr64 | 877 | uv_write_global_mmr64 |
493 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); | 878 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); |
494 | /* | 879 | /* |
@@ -497,7 +882,7 @@ static void uv_enable_timeouts(void) | |||
497 | * indicated in bits 2:0 (7 causes all of them to timeout). | 882 | * indicated in bits 2:0 (7 causes all of them to timeout). |
498 | */ | 883 | */ |
499 | mmr_image |= ((unsigned long)1 << | 884 | mmr_image |= ((unsigned long)1 << |
500 | UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT); | 885 | UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT); |
501 | uv_write_global_mmr64 | 886 | uv_write_global_mmr64 |
502 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); | 887 | (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image); |
503 | } | 888 | } |
@@ -522,9 +907,20 @@ static void uv_ptc_seq_stop(struct seq_file *file, void *data) | |||
522 | { | 907 | { |
523 | } | 908 | } |
524 | 909 | ||
910 | static inline unsigned long long | ||
911 | millisec_2_cycles(unsigned long millisec) | ||
912 | { | ||
913 | unsigned long ns; | ||
914 | unsigned long long cyc; | ||
915 | |||
916 | ns = millisec * 1000; | ||
917 | cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id())); | ||
918 | return cyc; | ||
919 | } | ||
920 | |||
525 | /* | 921 | /* |
526 | * Display the statistics thru /proc | 922 | * Display the statistics thru /proc. |
527 | * data points to the cpu number | 923 | * 'data' points to the cpu number |
528 | */ | 924 | */ |
529 | static int uv_ptc_seq_show(struct seq_file *file, void *data) | 925 | static int uv_ptc_seq_show(struct seq_file *file, void *data) |
530 | { | 926 | { |
@@ -535,78 +931,155 @@ static int uv_ptc_seq_show(struct seq_file *file, void *data) | |||
535 | 931 | ||
536 | if (!cpu) { | 932 | if (!cpu) { |
537 | seq_printf(file, | 933 | seq_printf(file, |
538 | "# cpu requestor requestee one all sretry dretry ptc_i "); | 934 | "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 "); |
539 | seq_printf(file, | 935 | seq_printf(file, |
540 | "sw_ack sflush dflush sok dnomsg dmult starget\n"); | 936 | "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto "); |
937 | seq_printf(file, | ||
938 | "retries rok resetp resett giveup sto bz throt "); | ||
939 | seq_printf(file, | ||
940 | "sw_ack recv rtime all "); | ||
941 | seq_printf(file, | ||
942 | "one mult none retry canc nocan reset rcan\n"); | ||
541 | } | 943 | } |
542 | if (cpu < num_possible_cpus() && cpu_online(cpu)) { | 944 | if (cpu < num_possible_cpus() && cpu_online(cpu)) { |
543 | stat = &per_cpu(ptcstats, cpu); | 945 | stat = &per_cpu(ptcstats, cpu); |
544 | seq_printf(file, "cpu %d %ld %ld %ld %ld %ld %ld %ld ", | 946 | /* source side statistics */ |
545 | cpu, stat->requestor, | 947 | seq_printf(file, |
546 | stat->requestee, stat->onetlb, stat->alltlb, | 948 | "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ", |
547 | stat->s_retry, stat->d_retry, stat->ptc_i); | 949 | cpu, stat->s_requestor, cycles_2_us(stat->s_time), |
548 | seq_printf(file, "%lx %ld %ld %ld %ld %ld %ld\n", | 950 | stat->s_ntarguvhub, stat->s_ntarguvhub16, |
951 | stat->s_ntarguvhub8, stat->s_ntarguvhub4, | ||
952 | stat->s_ntarguvhub2, stat->s_ntarguvhub1, | ||
953 | stat->s_ntargcpu, stat->s_dtimeout); | ||
954 | seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ", | ||
955 | stat->s_retry_messages, stat->s_retriesok, | ||
956 | stat->s_resets_plug, stat->s_resets_timeout, | ||
957 | stat->s_giveup, stat->s_stimeout, | ||
958 | stat->s_busy, stat->s_throttles); | ||
959 | /* destination side statistics */ | ||
960 | seq_printf(file, | ||
961 | "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n", | ||
549 | uv_read_global_mmr64(uv_cpu_to_pnode(cpu), | 962 | uv_read_global_mmr64(uv_cpu_to_pnode(cpu), |
550 | UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE), | 963 | UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE), |
551 | stat->sflush, stat->dflush, | 964 | stat->d_requestee, cycles_2_us(stat->d_time), |
552 | stat->retriesok, stat->nomsg, | 965 | stat->d_alltlb, stat->d_onetlb, stat->d_multmsg, |
553 | stat->multmsg, stat->ntargeted); | 966 | stat->d_nomsg, stat->d_retries, stat->d_canceled, |
967 | stat->d_nocanceled, stat->d_resets, | ||
968 | stat->d_rcanceled); | ||
554 | } | 969 | } |
555 | 970 | ||
556 | return 0; | 971 | return 0; |
557 | } | 972 | } |
558 | 973 | ||
559 | /* | 974 | /* |
975 | * -1: resetf the statistics | ||
560 | * 0: display meaning of the statistics | 976 | * 0: display meaning of the statistics |
561 | * >0: retry limit | 977 | * >0: maximum concurrent active descriptors per uvhub (throttle) |
562 | */ | 978 | */ |
563 | static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user, | 979 | static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user, |
564 | size_t count, loff_t *data) | 980 | size_t count, loff_t *data) |
565 | { | 981 | { |
566 | long newmode; | 982 | int cpu; |
983 | long input_arg; | ||
567 | char optstr[64]; | 984 | char optstr[64]; |
985 | struct ptc_stats *stat; | ||
986 | struct bau_control *bcp; | ||
568 | 987 | ||
569 | if (count == 0 || count > sizeof(optstr)) | 988 | if (count == 0 || count > sizeof(optstr)) |
570 | return -EINVAL; | 989 | return -EINVAL; |
571 | if (copy_from_user(optstr, user, count)) | 990 | if (copy_from_user(optstr, user, count)) |
572 | return -EFAULT; | 991 | return -EFAULT; |
573 | optstr[count - 1] = '\0'; | 992 | optstr[count - 1] = '\0'; |
574 | if (strict_strtoul(optstr, 10, &newmode) < 0) { | 993 | if (strict_strtol(optstr, 10, &input_arg) < 0) { |
575 | printk(KERN_DEBUG "%s is invalid\n", optstr); | 994 | printk(KERN_DEBUG "%s is invalid\n", optstr); |
576 | return -EINVAL; | 995 | return -EINVAL; |
577 | } | 996 | } |
578 | 997 | ||
579 | if (newmode == 0) { | 998 | if (input_arg == 0) { |
580 | printk(KERN_DEBUG "# cpu: cpu number\n"); | 999 | printk(KERN_DEBUG "# cpu: cpu number\n"); |
1000 | printk(KERN_DEBUG "Sender statistics:\n"); | ||
1001 | printk(KERN_DEBUG | ||
1002 | "sent: number of shootdown messages sent\n"); | ||
1003 | printk(KERN_DEBUG | ||
1004 | "stime: time spent sending messages\n"); | ||
1005 | printk(KERN_DEBUG | ||
1006 | "numuvhubs: number of hubs targeted with shootdown\n"); | ||
1007 | printk(KERN_DEBUG | ||
1008 | "numuvhubs16: number times 16 or more hubs targeted\n"); | ||
1009 | printk(KERN_DEBUG | ||
1010 | "numuvhubs8: number times 8 or more hubs targeted\n"); | ||
1011 | printk(KERN_DEBUG | ||
1012 | "numuvhubs4: number times 4 or more hubs targeted\n"); | ||
1013 | printk(KERN_DEBUG | ||
1014 | "numuvhubs2: number times 2 or more hubs targeted\n"); | ||
1015 | printk(KERN_DEBUG | ||
1016 | "numuvhubs1: number times 1 hub targeted\n"); | ||
1017 | printk(KERN_DEBUG | ||
1018 | "numcpus: number of cpus targeted with shootdown\n"); | ||
1019 | printk(KERN_DEBUG | ||
1020 | "dto: number of destination timeouts\n"); | ||
1021 | printk(KERN_DEBUG | ||
1022 | "retries: destination timeout retries sent\n"); | ||
1023 | printk(KERN_DEBUG | ||
1024 | "rok: : destination timeouts successfully retried\n"); | ||
1025 | printk(KERN_DEBUG | ||
1026 | "resetp: ipi-style resource resets for plugs\n"); | ||
1027 | printk(KERN_DEBUG | ||
1028 | "resett: ipi-style resource resets for timeouts\n"); | ||
1029 | printk(KERN_DEBUG | ||
1030 | "giveup: fall-backs to ipi-style shootdowns\n"); | ||
1031 | printk(KERN_DEBUG | ||
1032 | "sto: number of source timeouts\n"); | ||
1033 | printk(KERN_DEBUG | ||
1034 | "bz: number of stay-busy's\n"); | ||
1035 | printk(KERN_DEBUG | ||
1036 | "throt: number times spun in throttle\n"); | ||
1037 | printk(KERN_DEBUG "Destination side statistics:\n"); | ||
581 | printk(KERN_DEBUG | 1038 | printk(KERN_DEBUG |
582 | "requestor: times this cpu was the flush requestor\n"); | 1039 | "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n"); |
583 | printk(KERN_DEBUG | 1040 | printk(KERN_DEBUG |
584 | "requestee: times this cpu was requested to flush its TLBs\n"); | 1041 | "recv: shootdown messages received\n"); |
585 | printk(KERN_DEBUG | 1042 | printk(KERN_DEBUG |
586 | "one: times requested to flush a single address\n"); | 1043 | "rtime: time spent processing messages\n"); |
587 | printk(KERN_DEBUG | 1044 | printk(KERN_DEBUG |
588 | "all: times requested to flush all TLB's\n"); | 1045 | "all: shootdown all-tlb messages\n"); |
589 | printk(KERN_DEBUG | 1046 | printk(KERN_DEBUG |
590 | "sretry: number of retries of source-side timeouts\n"); | 1047 | "one: shootdown one-tlb messages\n"); |
591 | printk(KERN_DEBUG | 1048 | printk(KERN_DEBUG |
592 | "dretry: number of retries of destination-side timeouts\n"); | 1049 | "mult: interrupts that found multiple messages\n"); |
593 | printk(KERN_DEBUG | 1050 | printk(KERN_DEBUG |
594 | "ptc_i: times UV fell through to IPI-style flushes\n"); | 1051 | "none: interrupts that found no messages\n"); |
595 | printk(KERN_DEBUG | 1052 | printk(KERN_DEBUG |
596 | "sw_ack: image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n"); | 1053 | "retry: number of retry messages processed\n"); |
597 | printk(KERN_DEBUG | 1054 | printk(KERN_DEBUG |
598 | "sflush_us: cycles spent in uv_flush_tlb_others()\n"); | 1055 | "canc: number messages canceled by retries\n"); |
599 | printk(KERN_DEBUG | 1056 | printk(KERN_DEBUG |
600 | "dflush_us: cycles spent in handling flush requests\n"); | 1057 | "nocan: number retries that found nothing to cancel\n"); |
601 | printk(KERN_DEBUG "sok: successes on retry\n"); | ||
602 | printk(KERN_DEBUG "dnomsg: interrupts with no message\n"); | ||
603 | printk(KERN_DEBUG | 1058 | printk(KERN_DEBUG |
604 | "dmult: interrupts with multiple messages\n"); | 1059 | "reset: number of ipi-style reset requests processed\n"); |
605 | printk(KERN_DEBUG "starget: nodes targeted\n"); | 1060 | printk(KERN_DEBUG |
1061 | "rcan: number messages canceled by reset requests\n"); | ||
1062 | } else if (input_arg == -1) { | ||
1063 | for_each_present_cpu(cpu) { | ||
1064 | stat = &per_cpu(ptcstats, cpu); | ||
1065 | memset(stat, 0, sizeof(struct ptc_stats)); | ||
1066 | } | ||
606 | } else { | 1067 | } else { |
607 | uv_bau_retry_limit = newmode; | 1068 | uv_bau_max_concurrent = input_arg; |
608 | printk(KERN_DEBUG "timeout retry limit:%d\n", | 1069 | bcp = &per_cpu(bau_control, smp_processor_id()); |
609 | uv_bau_retry_limit); | 1070 | if (uv_bau_max_concurrent < 1 || |
1071 | uv_bau_max_concurrent > bcp->cpus_in_uvhub) { | ||
1072 | printk(KERN_DEBUG | ||
1073 | "Error: BAU max concurrent %d; %d is invalid\n", | ||
1074 | bcp->max_concurrent, uv_bau_max_concurrent); | ||
1075 | return -EINVAL; | ||
1076 | } | ||
1077 | printk(KERN_DEBUG "Set BAU max concurrent:%d\n", | ||
1078 | uv_bau_max_concurrent); | ||
1079 | for_each_present_cpu(cpu) { | ||
1080 | bcp = &per_cpu(bau_control, cpu); | ||
1081 | bcp->max_concurrent = uv_bau_max_concurrent; | ||
1082 | } | ||
610 | } | 1083 | } |
611 | 1084 | ||
612 | return count; | 1085 | return count; |
@@ -650,79 +1123,30 @@ static int __init uv_ptc_init(void) | |||
650 | } | 1123 | } |
651 | 1124 | ||
652 | /* | 1125 | /* |
653 | * begin the initialization of the per-blade control structures | ||
654 | */ | ||
655 | static struct bau_control * __init uv_table_bases_init(int blade, int node) | ||
656 | { | ||
657 | int i; | ||
658 | struct bau_msg_status *msp; | ||
659 | struct bau_control *bau_tabp; | ||
660 | |||
661 | bau_tabp = | ||
662 | kmalloc_node(sizeof(struct bau_control), GFP_KERNEL, node); | ||
663 | BUG_ON(!bau_tabp); | ||
664 | |||
665 | bau_tabp->msg_statuses = | ||
666 | kmalloc_node(sizeof(struct bau_msg_status) * | ||
667 | DEST_Q_SIZE, GFP_KERNEL, node); | ||
668 | BUG_ON(!bau_tabp->msg_statuses); | ||
669 | |||
670 | for (i = 0, msp = bau_tabp->msg_statuses; i < DEST_Q_SIZE; i++, msp++) | ||
671 | bau_cpubits_clear(&msp->seen_by, (int) | ||
672 | uv_blade_nr_possible_cpus(blade)); | ||
673 | |||
674 | uv_bau_table_bases[blade] = bau_tabp; | ||
675 | |||
676 | return bau_tabp; | ||
677 | } | ||
678 | |||
679 | /* | ||
680 | * finish the initialization of the per-blade control structures | ||
681 | */ | ||
682 | static void __init | ||
683 | uv_table_bases_finish(int blade, | ||
684 | struct bau_control *bau_tablesp, | ||
685 | struct bau_desc *adp) | ||
686 | { | ||
687 | struct bau_control *bcp; | ||
688 | int cpu; | ||
689 | |||
690 | for_each_present_cpu(cpu) { | ||
691 | if (blade != uv_cpu_to_blade_id(cpu)) | ||
692 | continue; | ||
693 | |||
694 | bcp = (struct bau_control *)&per_cpu(bau_control, cpu); | ||
695 | bcp->bau_msg_head = bau_tablesp->va_queue_first; | ||
696 | bcp->va_queue_first = bau_tablesp->va_queue_first; | ||
697 | bcp->va_queue_last = bau_tablesp->va_queue_last; | ||
698 | bcp->msg_statuses = bau_tablesp->msg_statuses; | ||
699 | bcp->descriptor_base = adp; | ||
700 | } | ||
701 | } | ||
702 | |||
703 | /* | ||
704 | * initialize the sending side's sending buffers | 1126 | * initialize the sending side's sending buffers |
705 | */ | 1127 | */ |
706 | static struct bau_desc * __init | 1128 | static void |
707 | uv_activation_descriptor_init(int node, int pnode) | 1129 | uv_activation_descriptor_init(int node, int pnode) |
708 | { | 1130 | { |
709 | int i; | 1131 | int i; |
1132 | int cpu; | ||
710 | unsigned long pa; | 1133 | unsigned long pa; |
711 | unsigned long m; | 1134 | unsigned long m; |
712 | unsigned long n; | 1135 | unsigned long n; |
713 | struct bau_desc *adp; | 1136 | struct bau_desc *bau_desc; |
714 | struct bau_desc *ad2; | 1137 | struct bau_desc *bd2; |
1138 | struct bau_control *bcp; | ||
715 | 1139 | ||
716 | /* | 1140 | /* |
717 | * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR) | 1141 | * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR) |
718 | * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per blade | 1142 | * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub |
719 | */ | 1143 | */ |
720 | adp = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)* | 1144 | bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)* |
721 | UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node); | 1145 | UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node); |
722 | BUG_ON(!adp); | 1146 | BUG_ON(!bau_desc); |
723 | 1147 | ||
724 | pa = uv_gpa(adp); /* need the real nasid*/ | 1148 | pa = uv_gpa(bau_desc); /* need the real nasid*/ |
725 | n = uv_gpa_to_pnode(pa); | 1149 | n = pa >> uv_nshift; |
726 | m = pa & uv_mmask; | 1150 | m = pa & uv_mmask; |
727 | 1151 | ||
728 | uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE, | 1152 | uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE, |
@@ -731,96 +1155,188 @@ uv_activation_descriptor_init(int node, int pnode) | |||
731 | /* | 1155 | /* |
732 | * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each | 1156 | * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each |
733 | * cpu even though we only use the first one; one descriptor can | 1157 | * cpu even though we only use the first one; one descriptor can |
734 | * describe a broadcast to 256 nodes. | 1158 | * describe a broadcast to 256 uv hubs. |
735 | */ | 1159 | */ |
736 | for (i = 0, ad2 = adp; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR); | 1160 | for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR); |
737 | i++, ad2++) { | 1161 | i++, bd2++) { |
738 | memset(ad2, 0, sizeof(struct bau_desc)); | 1162 | memset(bd2, 0, sizeof(struct bau_desc)); |
739 | ad2->header.sw_ack_flag = 1; | 1163 | bd2->header.sw_ack_flag = 1; |
740 | /* | 1164 | /* |
741 | * base_dest_nodeid is the first node in the partition, so | 1165 | * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub |
742 | * the bit map will indicate partition-relative node numbers. | 1166 | * in the partition. The bit map will indicate uvhub numbers, |
743 | * note that base_dest_nodeid is actually a nasid. | 1167 | * which are 0-N in a partition. Pnodes are unique system-wide. |
744 | */ | 1168 | */ |
745 | ad2->header.base_dest_nodeid = uv_partition_base_pnode << 1; | 1169 | bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1; |
746 | ad2->header.dest_subnodeid = 0x10; /* the LB */ | 1170 | bd2->header.dest_subnodeid = 0x10; /* the LB */ |
747 | ad2->header.command = UV_NET_ENDPOINT_INTD; | 1171 | bd2->header.command = UV_NET_ENDPOINT_INTD; |
748 | ad2->header.int_both = 1; | 1172 | bd2->header.int_both = 1; |
749 | /* | 1173 | /* |
750 | * all others need to be set to zero: | 1174 | * all others need to be set to zero: |
751 | * fairness chaining multilevel count replied_to | 1175 | * fairness chaining multilevel count replied_to |
752 | */ | 1176 | */ |
753 | } | 1177 | } |
754 | return adp; | 1178 | for_each_present_cpu(cpu) { |
1179 | if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu))) | ||
1180 | continue; | ||
1181 | bcp = &per_cpu(bau_control, cpu); | ||
1182 | bcp->descriptor_base = bau_desc; | ||
1183 | } | ||
755 | } | 1184 | } |
756 | 1185 | ||
757 | /* | 1186 | /* |
758 | * initialize the destination side's receiving buffers | 1187 | * initialize the destination side's receiving buffers |
1188 | * entered for each uvhub in the partition | ||
1189 | * - node is first node (kernel memory notion) on the uvhub | ||
1190 | * - pnode is the uvhub's physical identifier | ||
759 | */ | 1191 | */ |
760 | static struct bau_payload_queue_entry * __init | 1192 | static void |
761 | uv_payload_queue_init(int node, int pnode, struct bau_control *bau_tablesp) | 1193 | uv_payload_queue_init(int node, int pnode) |
762 | { | 1194 | { |
763 | struct bau_payload_queue_entry *pqp; | ||
764 | unsigned long pa; | ||
765 | int pn; | 1195 | int pn; |
1196 | int cpu; | ||
766 | char *cp; | 1197 | char *cp; |
1198 | unsigned long pa; | ||
1199 | struct bau_payload_queue_entry *pqp; | ||
1200 | struct bau_payload_queue_entry *pqp_malloc; | ||
1201 | struct bau_control *bcp; | ||
767 | 1202 | ||
768 | pqp = (struct bau_payload_queue_entry *) kmalloc_node( | 1203 | pqp = (struct bau_payload_queue_entry *) kmalloc_node( |
769 | (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry), | 1204 | (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry), |
770 | GFP_KERNEL, node); | 1205 | GFP_KERNEL, node); |
771 | BUG_ON(!pqp); | 1206 | BUG_ON(!pqp); |
1207 | pqp_malloc = pqp; | ||
772 | 1208 | ||
773 | cp = (char *)pqp + 31; | 1209 | cp = (char *)pqp + 31; |
774 | pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5); | 1210 | pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5); |
775 | bau_tablesp->va_queue_first = pqp; | 1211 | |
1212 | for_each_present_cpu(cpu) { | ||
1213 | if (pnode != uv_cpu_to_pnode(cpu)) | ||
1214 | continue; | ||
1215 | /* for every cpu on this pnode: */ | ||
1216 | bcp = &per_cpu(bau_control, cpu); | ||
1217 | bcp->va_queue_first = pqp; | ||
1218 | bcp->bau_msg_head = pqp; | ||
1219 | bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1); | ||
1220 | } | ||
776 | /* | 1221 | /* |
777 | * need the pnode of where the memory was really allocated | 1222 | * need the pnode of where the memory was really allocated |
778 | */ | 1223 | */ |
779 | pa = uv_gpa(pqp); | 1224 | pa = uv_gpa(pqp); |
780 | pn = uv_gpa_to_pnode(pa); | 1225 | pn = pa >> uv_nshift; |
781 | uv_write_global_mmr64(pnode, | 1226 | uv_write_global_mmr64(pnode, |
782 | UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST, | 1227 | UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST, |
783 | ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | | 1228 | ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) | |
784 | uv_physnodeaddr(pqp)); | 1229 | uv_physnodeaddr(pqp)); |
785 | uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL, | 1230 | uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL, |
786 | uv_physnodeaddr(pqp)); | 1231 | uv_physnodeaddr(pqp)); |
787 | bau_tablesp->va_queue_last = pqp + (DEST_Q_SIZE - 1); | ||
788 | uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST, | 1232 | uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST, |
789 | (unsigned long) | 1233 | (unsigned long) |
790 | uv_physnodeaddr(bau_tablesp->va_queue_last)); | 1234 | uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1))); |
1235 | /* in effect, all msg_type's are set to MSG_NOOP */ | ||
791 | memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE); | 1236 | memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE); |
792 | |||
793 | return pqp; | ||
794 | } | 1237 | } |
795 | 1238 | ||
796 | /* | 1239 | /* |
797 | * Initialization of each UV blade's structures | 1240 | * Initialization of each UV hub's structures |
798 | */ | 1241 | */ |
799 | static int __init uv_init_blade(int blade) | 1242 | static void __init uv_init_uvhub(int uvhub, int vector) |
800 | { | 1243 | { |
801 | int node; | 1244 | int node; |
802 | int pnode; | 1245 | int pnode; |
803 | unsigned long pa; | ||
804 | unsigned long apicid; | 1246 | unsigned long apicid; |
805 | struct bau_desc *adp; | 1247 | |
806 | struct bau_payload_queue_entry *pqp; | 1248 | node = uvhub_to_first_node(uvhub); |
807 | struct bau_control *bau_tablesp; | 1249 | pnode = uv_blade_to_pnode(uvhub); |
808 | 1250 | uv_activation_descriptor_init(node, pnode); | |
809 | node = blade_to_first_node(blade); | 1251 | uv_payload_queue_init(node, pnode); |
810 | bau_tablesp = uv_table_bases_init(blade, node); | ||
811 | pnode = uv_blade_to_pnode(blade); | ||
812 | adp = uv_activation_descriptor_init(node, pnode); | ||
813 | pqp = uv_payload_queue_init(node, pnode, bau_tablesp); | ||
814 | uv_table_bases_finish(blade, bau_tablesp, adp); | ||
815 | /* | 1252 | /* |
816 | * the below initialization can't be in firmware because the | 1253 | * the below initialization can't be in firmware because the |
817 | * messaging IRQ will be determined by the OS | 1254 | * messaging IRQ will be determined by the OS |
818 | */ | 1255 | */ |
819 | apicid = blade_to_first_apicid(blade); | 1256 | apicid = uvhub_to_first_apicid(uvhub); |
820 | pa = uv_read_global_mmr64(pnode, UVH_BAU_DATA_CONFIG); | ||
821 | uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG, | 1257 | uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG, |
822 | ((apicid << 32) | UV_BAU_MESSAGE)); | 1258 | ((apicid << 32) | vector)); |
823 | return 0; | 1259 | } |
1260 | |||
1261 | /* | ||
1262 | * initialize the bau_control structure for each cpu | ||
1263 | */ | ||
1264 | static void uv_init_per_cpu(int nuvhubs) | ||
1265 | { | ||
1266 | int i, j, k; | ||
1267 | int cpu; | ||
1268 | int pnode; | ||
1269 | int uvhub; | ||
1270 | short socket = 0; | ||
1271 | struct bau_control *bcp; | ||
1272 | struct uvhub_desc *bdp; | ||
1273 | struct socket_desc *sdp; | ||
1274 | struct bau_control *hmaster = NULL; | ||
1275 | struct bau_control *smaster = NULL; | ||
1276 | struct socket_desc { | ||
1277 | short num_cpus; | ||
1278 | short cpu_number[16]; | ||
1279 | }; | ||
1280 | struct uvhub_desc { | ||
1281 | short num_sockets; | ||
1282 | short num_cpus; | ||
1283 | short uvhub; | ||
1284 | short pnode; | ||
1285 | struct socket_desc socket[2]; | ||
1286 | }; | ||
1287 | struct uvhub_desc *uvhub_descs; | ||
1288 | |||
1289 | uvhub_descs = (struct uvhub_desc *) | ||
1290 | kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL); | ||
1291 | memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc)); | ||
1292 | for_each_present_cpu(cpu) { | ||
1293 | bcp = &per_cpu(bau_control, cpu); | ||
1294 | memset(bcp, 0, sizeof(struct bau_control)); | ||
1295 | spin_lock_init(&bcp->masks_lock); | ||
1296 | bcp->max_concurrent = uv_bau_max_concurrent; | ||
1297 | pnode = uv_cpu_hub_info(cpu)->pnode; | ||
1298 | uvhub = uv_cpu_hub_info(cpu)->numa_blade_id; | ||
1299 | bdp = &uvhub_descs[uvhub]; | ||
1300 | bdp->num_cpus++; | ||
1301 | bdp->uvhub = uvhub; | ||
1302 | bdp->pnode = pnode; | ||
1303 | /* time interval to catch a hardware stay-busy bug */ | ||
1304 | bcp->timeout_interval = millisec_2_cycles(3); | ||
1305 | /* kludge: assume uv_hub.h is constant */ | ||
1306 | socket = (cpu_physical_id(cpu)>>5)&1; | ||
1307 | if (socket >= bdp->num_sockets) | ||
1308 | bdp->num_sockets = socket+1; | ||
1309 | sdp = &bdp->socket[socket]; | ||
1310 | sdp->cpu_number[sdp->num_cpus] = cpu; | ||
1311 | sdp->num_cpus++; | ||
1312 | } | ||
1313 | socket = 0; | ||
1314 | for_each_possible_blade(uvhub) { | ||
1315 | bdp = &uvhub_descs[uvhub]; | ||
1316 | for (i = 0; i < bdp->num_sockets; i++) { | ||
1317 | sdp = &bdp->socket[i]; | ||
1318 | for (j = 0; j < sdp->num_cpus; j++) { | ||
1319 | cpu = sdp->cpu_number[j]; | ||
1320 | bcp = &per_cpu(bau_control, cpu); | ||
1321 | bcp->cpu = cpu; | ||
1322 | if (j == 0) { | ||
1323 | smaster = bcp; | ||
1324 | if (i == 0) | ||
1325 | hmaster = bcp; | ||
1326 | } | ||
1327 | bcp->cpus_in_uvhub = bdp->num_cpus; | ||
1328 | bcp->cpus_in_socket = sdp->num_cpus; | ||
1329 | bcp->socket_master = smaster; | ||
1330 | bcp->uvhub_master = hmaster; | ||
1331 | for (k = 0; k < DEST_Q_SIZE; k++) | ||
1332 | bcp->socket_acknowledge_count[k] = 0; | ||
1333 | bcp->uvhub_cpu = | ||
1334 | uv_cpu_hub_info(cpu)->blade_processor_id; | ||
1335 | } | ||
1336 | socket++; | ||
1337 | } | ||
1338 | } | ||
1339 | kfree(uvhub_descs); | ||
824 | } | 1340 | } |
825 | 1341 | ||
826 | /* | 1342 | /* |
@@ -828,38 +1344,54 @@ static int __init uv_init_blade(int blade) | |||
828 | */ | 1344 | */ |
829 | static int __init uv_bau_init(void) | 1345 | static int __init uv_bau_init(void) |
830 | { | 1346 | { |
831 | int blade; | 1347 | int uvhub; |
832 | int nblades; | 1348 | int pnode; |
1349 | int nuvhubs; | ||
833 | int cur_cpu; | 1350 | int cur_cpu; |
1351 | int vector; | ||
1352 | unsigned long mmr; | ||
834 | 1353 | ||
835 | if (!is_uv_system()) | 1354 | if (!is_uv_system()) |
836 | return 0; | 1355 | return 0; |
837 | 1356 | ||
1357 | if (nobau) | ||
1358 | return 0; | ||
1359 | |||
838 | for_each_possible_cpu(cur_cpu) | 1360 | for_each_possible_cpu(cur_cpu) |
839 | zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu), | 1361 | zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu), |
840 | GFP_KERNEL, cpu_to_node(cur_cpu)); | 1362 | GFP_KERNEL, cpu_to_node(cur_cpu)); |
841 | 1363 | ||
842 | uv_bau_retry_limit = 1; | 1364 | uv_bau_max_concurrent = MAX_BAU_CONCURRENT; |
1365 | uv_nshift = uv_hub_info->m_val; | ||
843 | uv_mmask = (1UL << uv_hub_info->m_val) - 1; | 1366 | uv_mmask = (1UL << uv_hub_info->m_val) - 1; |
844 | nblades = uv_num_possible_blades(); | 1367 | nuvhubs = uv_num_possible_blades(); |
845 | 1368 | ||
846 | uv_bau_table_bases = (struct bau_control **) | 1369 | uv_init_per_cpu(nuvhubs); |
847 | kmalloc(nblades * sizeof(struct bau_control *), GFP_KERNEL); | ||
848 | BUG_ON(!uv_bau_table_bases); | ||
849 | 1370 | ||
850 | uv_partition_base_pnode = 0x7fffffff; | 1371 | uv_partition_base_pnode = 0x7fffffff; |
851 | for (blade = 0; blade < nblades; blade++) | 1372 | for (uvhub = 0; uvhub < nuvhubs; uvhub++) |
852 | if (uv_blade_nr_possible_cpus(blade) && | 1373 | if (uv_blade_nr_possible_cpus(uvhub) && |
853 | (uv_blade_to_pnode(blade) < uv_partition_base_pnode)) | 1374 | (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode)) |
854 | uv_partition_base_pnode = uv_blade_to_pnode(blade); | 1375 | uv_partition_base_pnode = uv_blade_to_pnode(uvhub); |
855 | for (blade = 0; blade < nblades; blade++) | 1376 | |
856 | if (uv_blade_nr_possible_cpus(blade)) | 1377 | vector = UV_BAU_MESSAGE; |
857 | uv_init_blade(blade); | 1378 | for_each_possible_blade(uvhub) |
858 | 1379 | if (uv_blade_nr_possible_cpus(uvhub)) | |
859 | alloc_intr_gate(UV_BAU_MESSAGE, uv_bau_message_intr1); | 1380 | uv_init_uvhub(uvhub, vector); |
1381 | |||
860 | uv_enable_timeouts(); | 1382 | uv_enable_timeouts(); |
1383 | alloc_intr_gate(vector, uv_bau_message_intr1); | ||
1384 | |||
1385 | for_each_possible_blade(uvhub) { | ||
1386 | pnode = uv_blade_to_pnode(uvhub); | ||
1387 | /* INIT the bau */ | ||
1388 | uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL, | ||
1389 | ((unsigned long)1 << 63)); | ||
1390 | mmr = 1; /* should be 1 to broadcast to both sockets */ | ||
1391 | uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr); | ||
1392 | } | ||
861 | 1393 | ||
862 | return 0; | 1394 | return 0; |
863 | } | 1395 | } |
864 | __initcall(uv_bau_init); | 1396 | core_initcall(uv_bau_init); |
865 | __initcall(uv_ptc_init); | 1397 | core_initcall(uv_ptc_init); |
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 1168e4454188..02cfb9b8f5b1 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c | |||
@@ -108,15 +108,6 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) | |||
108 | dec_preempt_count(); | 108 | dec_preempt_count(); |
109 | } | 109 | } |
110 | 110 | ||
111 | #ifdef CONFIG_X86_32 | ||
112 | static inline void | ||
113 | die_if_kernel(const char *str, struct pt_regs *regs, long err) | ||
114 | { | ||
115 | if (!user_mode_vm(regs)) | ||
116 | die(str, regs, err); | ||
117 | } | ||
118 | #endif | ||
119 | |||
120 | static void __kprobes | 111 | static void __kprobes |
121 | do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, | 112 | do_trap(int trapnr, int signr, char *str, struct pt_regs *regs, |
122 | long error_code, siginfo_t *info) | 113 | long error_code, siginfo_t *info) |
@@ -543,11 +534,11 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) | |||
543 | 534 | ||
544 | /* DR6 may or may not be cleared by the CPU */ | 535 | /* DR6 may or may not be cleared by the CPU */ |
545 | set_debugreg(0, 6); | 536 | set_debugreg(0, 6); |
537 | |||
546 | /* | 538 | /* |
547 | * The processor cleared BTF, so don't mark that we need it set. | 539 | * The processor cleared BTF, so don't mark that we need it set. |
548 | */ | 540 | */ |
549 | clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR); | 541 | clear_tsk_thread_flag(tsk, TIF_BLOCKSTEP); |
550 | tsk->thread.debugctlmsr = 0; | ||
551 | 542 | ||
552 | /* Store the virtualized DR6 value */ | 543 | /* Store the virtualized DR6 value */ |
553 | tsk->thread.debugreg6 = dr6; | 544 | tsk->thread.debugreg6 = dr6; |
@@ -585,55 +576,67 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code) | |||
585 | return; | 576 | return; |
586 | } | 577 | } |
587 | 578 | ||
588 | #ifdef CONFIG_X86_64 | ||
589 | static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr) | ||
590 | { | ||
591 | if (fixup_exception(regs)) | ||
592 | return 1; | ||
593 | |||
594 | notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE); | ||
595 | /* Illegal floating point operation in the kernel */ | ||
596 | current->thread.trap_no = trapnr; | ||
597 | die(str, regs, 0); | ||
598 | return 0; | ||
599 | } | ||
600 | #endif | ||
601 | |||
602 | /* | 579 | /* |
603 | * Note that we play around with the 'TS' bit in an attempt to get | 580 | * Note that we play around with the 'TS' bit in an attempt to get |
604 | * the correct behaviour even in the presence of the asynchronous | 581 | * the correct behaviour even in the presence of the asynchronous |
605 | * IRQ13 behaviour | 582 | * IRQ13 behaviour |
606 | */ | 583 | */ |
607 | void math_error(void __user *ip) | 584 | void math_error(struct pt_regs *regs, int error_code, int trapnr) |
608 | { | 585 | { |
609 | struct task_struct *task; | 586 | struct task_struct *task = current; |
610 | siginfo_t info; | 587 | siginfo_t info; |
611 | unsigned short cwd, swd, err; | 588 | unsigned short err; |
589 | char *str = (trapnr == 16) ? "fpu exception" : "simd exception"; | ||
590 | |||
591 | if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, SIGFPE) == NOTIFY_STOP) | ||
592 | return; | ||
593 | conditional_sti(regs); | ||
594 | |||
595 | if (!user_mode_vm(regs)) | ||
596 | { | ||
597 | if (!fixup_exception(regs)) { | ||
598 | task->thread.error_code = error_code; | ||
599 | task->thread.trap_no = trapnr; | ||
600 | die(str, regs, error_code); | ||
601 | } | ||
602 | return; | ||
603 | } | ||
612 | 604 | ||
613 | /* | 605 | /* |
614 | * Save the info for the exception handler and clear the error. | 606 | * Save the info for the exception handler and clear the error. |
615 | */ | 607 | */ |
616 | task = current; | ||
617 | save_init_fpu(task); | 608 | save_init_fpu(task); |
618 | task->thread.trap_no = 16; | 609 | task->thread.trap_no = trapnr; |
619 | task->thread.error_code = 0; | 610 | task->thread.error_code = error_code; |
620 | info.si_signo = SIGFPE; | 611 | info.si_signo = SIGFPE; |
621 | info.si_errno = 0; | 612 | info.si_errno = 0; |
622 | info.si_addr = ip; | 613 | info.si_addr = (void __user *)regs->ip; |
623 | /* | 614 | if (trapnr == 16) { |
624 | * (~cwd & swd) will mask out exceptions that are not set to unmasked | 615 | unsigned short cwd, swd; |
625 | * status. 0x3f is the exception bits in these regs, 0x200 is the | 616 | /* |
626 | * C1 reg you need in case of a stack fault, 0x040 is the stack | 617 | * (~cwd & swd) will mask out exceptions that are not set to unmasked |
627 | * fault bit. We should only be taking one exception at a time, | 618 | * status. 0x3f is the exception bits in these regs, 0x200 is the |
628 | * so if this combination doesn't produce any single exception, | 619 | * C1 reg you need in case of a stack fault, 0x040 is the stack |
629 | * then we have a bad program that isn't synchronizing its FPU usage | 620 | * fault bit. We should only be taking one exception at a time, |
630 | * and it will suffer the consequences since we won't be able to | 621 | * so if this combination doesn't produce any single exception, |
631 | * fully reproduce the context of the exception | 622 | * then we have a bad program that isn't synchronizing its FPU usage |
632 | */ | 623 | * and it will suffer the consequences since we won't be able to |
633 | cwd = get_fpu_cwd(task); | 624 | * fully reproduce the context of the exception |
634 | swd = get_fpu_swd(task); | 625 | */ |
626 | cwd = get_fpu_cwd(task); | ||
627 | swd = get_fpu_swd(task); | ||
635 | 628 | ||
636 | err = swd & ~cwd; | 629 | err = swd & ~cwd; |
630 | } else { | ||
631 | /* | ||
632 | * The SIMD FPU exceptions are handled a little differently, as there | ||
633 | * is only a single status/control register. Thus, to determine which | ||
634 | * unmasked exception was caught we must mask the exception mask bits | ||
635 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. | ||
636 | */ | ||
637 | unsigned short mxcsr = get_fpu_mxcsr(task); | ||
638 | err = ~(mxcsr >> 7) & mxcsr; | ||
639 | } | ||
637 | 640 | ||
638 | if (err & 0x001) { /* Invalid op */ | 641 | if (err & 0x001) { /* Invalid op */ |
639 | /* | 642 | /* |
@@ -662,97 +665,17 @@ void math_error(void __user *ip) | |||
662 | 665 | ||
663 | dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) | 666 | dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code) |
664 | { | 667 | { |
665 | conditional_sti(regs); | ||
666 | |||
667 | #ifdef CONFIG_X86_32 | 668 | #ifdef CONFIG_X86_32 |
668 | ignore_fpu_irq = 1; | 669 | ignore_fpu_irq = 1; |
669 | #else | ||
670 | if (!user_mode(regs) && | ||
671 | kernel_math_error(regs, "kernel x87 math error", 16)) | ||
672 | return; | ||
673 | #endif | 670 | #endif |
674 | 671 | ||
675 | math_error((void __user *)regs->ip); | 672 | math_error(regs, error_code, 16); |
676 | } | ||
677 | |||
678 | static void simd_math_error(void __user *ip) | ||
679 | { | ||
680 | struct task_struct *task; | ||
681 | siginfo_t info; | ||
682 | unsigned short mxcsr; | ||
683 | |||
684 | /* | ||
685 | * Save the info for the exception handler and clear the error. | ||
686 | */ | ||
687 | task = current; | ||
688 | save_init_fpu(task); | ||
689 | task->thread.trap_no = 19; | ||
690 | task->thread.error_code = 0; | ||
691 | info.si_signo = SIGFPE; | ||
692 | info.si_errno = 0; | ||
693 | info.si_code = __SI_FAULT; | ||
694 | info.si_addr = ip; | ||
695 | /* | ||
696 | * The SIMD FPU exceptions are handled a little differently, as there | ||
697 | * is only a single status/control register. Thus, to determine which | ||
698 | * unmasked exception was caught we must mask the exception mask bits | ||
699 | * at 0x1f80, and then use these to mask the exception bits at 0x3f. | ||
700 | */ | ||
701 | mxcsr = get_fpu_mxcsr(task); | ||
702 | switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) { | ||
703 | case 0x000: | ||
704 | default: | ||
705 | break; | ||
706 | case 0x001: /* Invalid Op */ | ||
707 | info.si_code = FPE_FLTINV; | ||
708 | break; | ||
709 | case 0x002: /* Denormalize */ | ||
710 | case 0x010: /* Underflow */ | ||
711 | info.si_code = FPE_FLTUND; | ||
712 | break; | ||
713 | case 0x004: /* Zero Divide */ | ||
714 | info.si_code = FPE_FLTDIV; | ||
715 | break; | ||
716 | case 0x008: /* Overflow */ | ||
717 | info.si_code = FPE_FLTOVF; | ||
718 | break; | ||
719 | case 0x020: /* Precision */ | ||
720 | info.si_code = FPE_FLTRES; | ||
721 | break; | ||
722 | } | ||
723 | force_sig_info(SIGFPE, &info, task); | ||
724 | } | 673 | } |
725 | 674 | ||
726 | dotraplinkage void | 675 | dotraplinkage void |
727 | do_simd_coprocessor_error(struct pt_regs *regs, long error_code) | 676 | do_simd_coprocessor_error(struct pt_regs *regs, long error_code) |
728 | { | 677 | { |
729 | conditional_sti(regs); | 678 | math_error(regs, error_code, 19); |
730 | |||
731 | #ifdef CONFIG_X86_32 | ||
732 | if (cpu_has_xmm) { | ||
733 | /* Handle SIMD FPU exceptions on PIII+ processors. */ | ||
734 | ignore_fpu_irq = 1; | ||
735 | simd_math_error((void __user *)regs->ip); | ||
736 | return; | ||
737 | } | ||
738 | /* | ||
739 | * Handle strange cache flush from user space exception | ||
740 | * in all other cases. This is undocumented behaviour. | ||
741 | */ | ||
742 | if (regs->flags & X86_VM_MASK) { | ||
743 | handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code); | ||
744 | return; | ||
745 | } | ||
746 | current->thread.trap_no = 19; | ||
747 | current->thread.error_code = error_code; | ||
748 | die_if_kernel("cache flush denied", regs, error_code); | ||
749 | force_sig(SIGSEGV, current); | ||
750 | #else | ||
751 | if (!user_mode(regs) && | ||
752 | kernel_math_error(regs, "kernel simd math error", 19)) | ||
753 | return; | ||
754 | simd_math_error((void __user *)regs->ip); | ||
755 | #endif | ||
756 | } | 679 | } |
757 | 680 | ||
758 | dotraplinkage void | 681 | dotraplinkage void |
diff --git a/arch/x86/kernel/uv_irq.c b/arch/x86/kernel/uv_irq.c index 1d40336b030a..1132129db792 100644 --- a/arch/x86/kernel/uv_irq.c +++ b/arch/x86/kernel/uv_irq.c | |||
@@ -44,7 +44,7 @@ static void uv_ack_apic(unsigned int irq) | |||
44 | ack_APIC_irq(); | 44 | ack_APIC_irq(); |
45 | } | 45 | } |
46 | 46 | ||
47 | struct irq_chip uv_irq_chip = { | 47 | static struct irq_chip uv_irq_chip = { |
48 | .name = "UV-CORE", | 48 | .name = "UV-CORE", |
49 | .startup = uv_noop_ret, | 49 | .startup = uv_noop_ret, |
50 | .shutdown = uv_noop, | 50 | .shutdown = uv_noop, |
@@ -141,7 +141,7 @@ int uv_irq_2_mmr_info(int irq, unsigned long *offset, int *pnode) | |||
141 | */ | 141 | */ |
142 | static int | 142 | static int |
143 | arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | 143 | arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, |
144 | unsigned long mmr_offset, int restrict) | 144 | unsigned long mmr_offset, int limit) |
145 | { | 145 | { |
146 | const struct cpumask *eligible_cpu = cpumask_of(cpu); | 146 | const struct cpumask *eligible_cpu = cpumask_of(cpu); |
147 | struct irq_desc *desc = irq_to_desc(irq); | 147 | struct irq_desc *desc = irq_to_desc(irq); |
@@ -160,7 +160,7 @@ arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, | |||
160 | if (err != 0) | 160 | if (err != 0) |
161 | return err; | 161 | return err; |
162 | 162 | ||
163 | if (restrict == UV_AFFINITY_CPU) | 163 | if (limit == UV_AFFINITY_CPU) |
164 | desc->status |= IRQ_NO_BALANCING; | 164 | desc->status |= IRQ_NO_BALANCING; |
165 | else | 165 | else |
166 | desc->status |= IRQ_MOVE_PCNTXT; | 166 | desc->status |= IRQ_MOVE_PCNTXT; |
@@ -214,7 +214,7 @@ static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask) | |||
214 | unsigned long mmr_value; | 214 | unsigned long mmr_value; |
215 | struct uv_IO_APIC_route_entry *entry; | 215 | struct uv_IO_APIC_route_entry *entry; |
216 | unsigned long mmr_offset; | 216 | unsigned long mmr_offset; |
217 | unsigned mmr_pnode; | 217 | int mmr_pnode; |
218 | 218 | ||
219 | if (set_desc_affinity(desc, mask, &dest)) | 219 | if (set_desc_affinity(desc, mask, &dest)) |
220 | return -1; | 220 | return -1; |
@@ -248,7 +248,7 @@ static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask) | |||
248 | * interrupt is raised. | 248 | * interrupt is raised. |
249 | */ | 249 | */ |
250 | int uv_setup_irq(char *irq_name, int cpu, int mmr_blade, | 250 | int uv_setup_irq(char *irq_name, int cpu, int mmr_blade, |
251 | unsigned long mmr_offset, int restrict) | 251 | unsigned long mmr_offset, int limit) |
252 | { | 252 | { |
253 | int irq, ret; | 253 | int irq, ret; |
254 | 254 | ||
@@ -258,7 +258,7 @@ int uv_setup_irq(char *irq_name, int cpu, int mmr_blade, | |||
258 | return -EBUSY; | 258 | return -EBUSY; |
259 | 259 | ||
260 | ret = arch_enable_uv_irq(irq_name, irq, cpu, mmr_blade, mmr_offset, | 260 | ret = arch_enable_uv_irq(irq_name, irq, cpu, mmr_blade, mmr_offset, |
261 | restrict); | 261 | limit); |
262 | if (ret == irq) | 262 | if (ret == irq) |
263 | uv_set_irq_2_mmr_info(irq, mmr_offset, mmr_blade); | 263 | uv_set_irq_2_mmr_info(irq, mmr_offset, mmr_blade); |
264 | else | 264 | else |
diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c index 693920b22496..1b950d151e58 100644 --- a/arch/x86/kernel/x8664_ksyms_64.c +++ b/arch/x86/kernel/x8664_ksyms_64.c | |||
@@ -54,7 +54,6 @@ EXPORT_SYMBOL(memcpy); | |||
54 | EXPORT_SYMBOL(__memcpy); | 54 | EXPORT_SYMBOL(__memcpy); |
55 | 55 | ||
56 | EXPORT_SYMBOL(empty_zero_page); | 56 | EXPORT_SYMBOL(empty_zero_page); |
57 | EXPORT_SYMBOL(init_level4_pgt); | ||
58 | #ifndef CONFIG_PARAVIRT | 57 | #ifndef CONFIG_PARAVIRT |
59 | EXPORT_SYMBOL(native_load_gs_index); | 58 | EXPORT_SYMBOL(native_load_gs_index); |
60 | #endif | 59 | #endif |
diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c index 782c3a362ec6..37e68fc5e24a 100644 --- a/arch/x86/kernel/xsave.c +++ b/arch/x86/kernel/xsave.c | |||
@@ -99,7 +99,7 @@ int save_i387_xstate(void __user *buf) | |||
99 | if (err) | 99 | if (err) |
100 | return err; | 100 | return err; |
101 | 101 | ||
102 | if (task_thread_info(tsk)->status & TS_XSAVE) | 102 | if (use_xsave()) |
103 | err = xsave_user(buf); | 103 | err = xsave_user(buf); |
104 | else | 104 | else |
105 | err = fxsave_user(buf); | 105 | err = fxsave_user(buf); |
@@ -109,14 +109,14 @@ int save_i387_xstate(void __user *buf) | |||
109 | task_thread_info(tsk)->status &= ~TS_USEDFPU; | 109 | task_thread_info(tsk)->status &= ~TS_USEDFPU; |
110 | stts(); | 110 | stts(); |
111 | } else { | 111 | } else { |
112 | if (__copy_to_user(buf, &tsk->thread.xstate->fxsave, | 112 | if (__copy_to_user(buf, &tsk->thread.fpu.state->fxsave, |
113 | xstate_size)) | 113 | xstate_size)) |
114 | return -1; | 114 | return -1; |
115 | } | 115 | } |
116 | 116 | ||
117 | clear_used_math(); /* trigger finit */ | 117 | clear_used_math(); /* trigger finit */ |
118 | 118 | ||
119 | if (task_thread_info(tsk)->status & TS_XSAVE) { | 119 | if (use_xsave()) { |
120 | struct _fpstate __user *fx = buf; | 120 | struct _fpstate __user *fx = buf; |
121 | struct _xstate __user *x = buf; | 121 | struct _xstate __user *x = buf; |
122 | u64 xstate_bv; | 122 | u64 xstate_bv; |
@@ -225,7 +225,7 @@ int restore_i387_xstate(void __user *buf) | |||
225 | clts(); | 225 | clts(); |
226 | task_thread_info(current)->status |= TS_USEDFPU; | 226 | task_thread_info(current)->status |= TS_USEDFPU; |
227 | } | 227 | } |
228 | if (task_thread_info(tsk)->status & TS_XSAVE) | 228 | if (use_xsave()) |
229 | err = restore_user_xstate(buf); | 229 | err = restore_user_xstate(buf); |
230 | else | 230 | else |
231 | err = fxrstor_checking((__force struct i387_fxsave_struct *) | 231 | err = fxrstor_checking((__force struct i387_fxsave_struct *) |
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 2ba58206812a..737361fcd503 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -2067,7 +2067,7 @@ static int cpuid_interception(struct vcpu_svm *svm) | |||
2067 | static int iret_interception(struct vcpu_svm *svm) | 2067 | static int iret_interception(struct vcpu_svm *svm) |
2068 | { | 2068 | { |
2069 | ++svm->vcpu.stat.nmi_window_exits; | 2069 | ++svm->vcpu.stat.nmi_window_exits; |
2070 | svm->vmcb->control.intercept &= ~(1UL << INTERCEPT_IRET); | 2070 | svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_IRET); |
2071 | svm->vcpu.arch.hflags |= HF_IRET_MASK; | 2071 | svm->vcpu.arch.hflags |= HF_IRET_MASK; |
2072 | return 1; | 2072 | return 1; |
2073 | } | 2073 | } |
@@ -2479,7 +2479,7 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) | |||
2479 | 2479 | ||
2480 | svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; | 2480 | svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI; |
2481 | vcpu->arch.hflags |= HF_NMI_MASK; | 2481 | vcpu->arch.hflags |= HF_NMI_MASK; |
2482 | svm->vmcb->control.intercept |= (1UL << INTERCEPT_IRET); | 2482 | svm->vmcb->control.intercept |= (1ULL << INTERCEPT_IRET); |
2483 | ++vcpu->stat.nmi_injections; | 2483 | ++vcpu->stat.nmi_injections; |
2484 | } | 2484 | } |
2485 | 2485 | ||
@@ -2539,10 +2539,10 @@ static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked) | |||
2539 | 2539 | ||
2540 | if (masked) { | 2540 | if (masked) { |
2541 | svm->vcpu.arch.hflags |= HF_NMI_MASK; | 2541 | svm->vcpu.arch.hflags |= HF_NMI_MASK; |
2542 | svm->vmcb->control.intercept |= (1UL << INTERCEPT_IRET); | 2542 | svm->vmcb->control.intercept |= (1ULL << INTERCEPT_IRET); |
2543 | } else { | 2543 | } else { |
2544 | svm->vcpu.arch.hflags &= ~HF_NMI_MASK; | 2544 | svm->vcpu.arch.hflags &= ~HF_NMI_MASK; |
2545 | svm->vmcb->control.intercept &= ~(1UL << INTERCEPT_IRET); | 2545 | svm->vmcb->control.intercept &= ~(1ULL << INTERCEPT_IRET); |
2546 | } | 2546 | } |
2547 | } | 2547 | } |
2548 | 2548 | ||
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index bc933cfb4e66..edca080407a5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -2703,8 +2703,7 @@ static int vmx_nmi_allowed(struct kvm_vcpu *vcpu) | |||
2703 | return 0; | 2703 | return 0; |
2704 | 2704 | ||
2705 | return !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & | 2705 | return !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & |
2706 | (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS | | 2706 | (GUEST_INTR_STATE_MOV_SS | GUEST_INTR_STATE_NMI)); |
2707 | GUEST_INTR_STATE_NMI)); | ||
2708 | } | 2707 | } |
2709 | 2708 | ||
2710 | static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu) | 2709 | static bool vmx_get_nmi_mask(struct kvm_vcpu *vcpu) |
@@ -3660,8 +3659,11 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx) | |||
3660 | 3659 | ||
3661 | /* We need to handle NMIs before interrupts are enabled */ | 3660 | /* We need to handle NMIs before interrupts are enabled */ |
3662 | if ((exit_intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR && | 3661 | if ((exit_intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR && |
3663 | (exit_intr_info & INTR_INFO_VALID_MASK)) | 3662 | (exit_intr_info & INTR_INFO_VALID_MASK)) { |
3663 | kvm_before_handle_nmi(&vmx->vcpu); | ||
3664 | asm("int $2"); | 3664 | asm("int $2"); |
3665 | kvm_after_handle_nmi(&vmx->vcpu); | ||
3666 | } | ||
3665 | 3667 | ||
3666 | idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK; | 3668 | idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK; |
3667 | 3669 | ||
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3c4ca98ad27f..dd9bc8fb81ab 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/user-return-notifier.h> | 40 | #include <linux/user-return-notifier.h> |
41 | #include <linux/srcu.h> | 41 | #include <linux/srcu.h> |
42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
43 | #include <linux/perf_event.h> | ||
43 | #include <trace/events/kvm.h> | 44 | #include <trace/events/kvm.h> |
44 | #undef TRACE_INCLUDE_FILE | 45 | #undef TRACE_INCLUDE_FILE |
45 | #define CREATE_TRACE_POINTS | 46 | #define CREATE_TRACE_POINTS |
@@ -1712,6 +1713,7 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, | |||
1712 | if (copy_from_user(cpuid_entries, entries, | 1713 | if (copy_from_user(cpuid_entries, entries, |
1713 | cpuid->nent * sizeof(struct kvm_cpuid_entry))) | 1714 | cpuid->nent * sizeof(struct kvm_cpuid_entry))) |
1714 | goto out_free; | 1715 | goto out_free; |
1716 | vcpu_load(vcpu); | ||
1715 | for (i = 0; i < cpuid->nent; i++) { | 1717 | for (i = 0; i < cpuid->nent; i++) { |
1716 | vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; | 1718 | vcpu->arch.cpuid_entries[i].function = cpuid_entries[i].function; |
1717 | vcpu->arch.cpuid_entries[i].eax = cpuid_entries[i].eax; | 1719 | vcpu->arch.cpuid_entries[i].eax = cpuid_entries[i].eax; |
@@ -1729,6 +1731,7 @@ static int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, | |||
1729 | r = 0; | 1731 | r = 0; |
1730 | kvm_apic_set_version(vcpu); | 1732 | kvm_apic_set_version(vcpu); |
1731 | kvm_x86_ops->cpuid_update(vcpu); | 1733 | kvm_x86_ops->cpuid_update(vcpu); |
1734 | vcpu_put(vcpu); | ||
1732 | 1735 | ||
1733 | out_free: | 1736 | out_free: |
1734 | vfree(cpuid_entries); | 1737 | vfree(cpuid_entries); |
@@ -1749,9 +1752,11 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, | |||
1749 | if (copy_from_user(&vcpu->arch.cpuid_entries, entries, | 1752 | if (copy_from_user(&vcpu->arch.cpuid_entries, entries, |
1750 | cpuid->nent * sizeof(struct kvm_cpuid_entry2))) | 1753 | cpuid->nent * sizeof(struct kvm_cpuid_entry2))) |
1751 | goto out; | 1754 | goto out; |
1755 | vcpu_load(vcpu); | ||
1752 | vcpu->arch.cpuid_nent = cpuid->nent; | 1756 | vcpu->arch.cpuid_nent = cpuid->nent; |
1753 | kvm_apic_set_version(vcpu); | 1757 | kvm_apic_set_version(vcpu); |
1754 | kvm_x86_ops->cpuid_update(vcpu); | 1758 | kvm_x86_ops->cpuid_update(vcpu); |
1759 | vcpu_put(vcpu); | ||
1755 | return 0; | 1760 | return 0; |
1756 | 1761 | ||
1757 | out: | 1762 | out: |
@@ -3743,6 +3748,51 @@ static void kvm_timer_init(void) | |||
3743 | } | 3748 | } |
3744 | } | 3749 | } |
3745 | 3750 | ||
3751 | static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu); | ||
3752 | |||
3753 | static int kvm_is_in_guest(void) | ||
3754 | { | ||
3755 | return percpu_read(current_vcpu) != NULL; | ||
3756 | } | ||
3757 | |||
3758 | static int kvm_is_user_mode(void) | ||
3759 | { | ||
3760 | int user_mode = 3; | ||
3761 | |||
3762 | if (percpu_read(current_vcpu)) | ||
3763 | user_mode = kvm_x86_ops->get_cpl(percpu_read(current_vcpu)); | ||
3764 | |||
3765 | return user_mode != 0; | ||
3766 | } | ||
3767 | |||
3768 | static unsigned long kvm_get_guest_ip(void) | ||
3769 | { | ||
3770 | unsigned long ip = 0; | ||
3771 | |||
3772 | if (percpu_read(current_vcpu)) | ||
3773 | ip = kvm_rip_read(percpu_read(current_vcpu)); | ||
3774 | |||
3775 | return ip; | ||
3776 | } | ||
3777 | |||
3778 | static struct perf_guest_info_callbacks kvm_guest_cbs = { | ||
3779 | .is_in_guest = kvm_is_in_guest, | ||
3780 | .is_user_mode = kvm_is_user_mode, | ||
3781 | .get_guest_ip = kvm_get_guest_ip, | ||
3782 | }; | ||
3783 | |||
3784 | void kvm_before_handle_nmi(struct kvm_vcpu *vcpu) | ||
3785 | { | ||
3786 | percpu_write(current_vcpu, vcpu); | ||
3787 | } | ||
3788 | EXPORT_SYMBOL_GPL(kvm_before_handle_nmi); | ||
3789 | |||
3790 | void kvm_after_handle_nmi(struct kvm_vcpu *vcpu) | ||
3791 | { | ||
3792 | percpu_write(current_vcpu, NULL); | ||
3793 | } | ||
3794 | EXPORT_SYMBOL_GPL(kvm_after_handle_nmi); | ||
3795 | |||
3746 | int kvm_arch_init(void *opaque) | 3796 | int kvm_arch_init(void *opaque) |
3747 | { | 3797 | { |
3748 | int r; | 3798 | int r; |
@@ -3779,6 +3829,8 @@ int kvm_arch_init(void *opaque) | |||
3779 | 3829 | ||
3780 | kvm_timer_init(); | 3830 | kvm_timer_init(); |
3781 | 3831 | ||
3832 | perf_register_guest_info_callbacks(&kvm_guest_cbs); | ||
3833 | |||
3782 | return 0; | 3834 | return 0; |
3783 | 3835 | ||
3784 | out: | 3836 | out: |
@@ -3787,6 +3839,8 @@ out: | |||
3787 | 3839 | ||
3788 | void kvm_arch_exit(void) | 3840 | void kvm_arch_exit(void) |
3789 | { | 3841 | { |
3842 | perf_unregister_guest_info_callbacks(&kvm_guest_cbs); | ||
3843 | |||
3790 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) | 3844 | if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) |
3791 | cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block, | 3845 | cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block, |
3792 | CPUFREQ_TRANSITION_NOTIFIER); | 3846 | CPUFREQ_TRANSITION_NOTIFIER); |
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 2d101639bd8d..b7a404722d2b 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h | |||
@@ -65,4 +65,7 @@ static inline int is_paging(struct kvm_vcpu *vcpu) | |||
65 | return kvm_read_cr0_bits(vcpu, X86_CR0_PG); | 65 | return kvm_read_cr0_bits(vcpu, X86_CR0_PG); |
66 | } | 66 | } |
67 | 67 | ||
68 | void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); | ||
69 | void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); | ||
70 | |||
68 | #endif | 71 | #endif |
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 419386c24b82..f871e04b6965 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile | |||
@@ -20,17 +20,18 @@ lib-y := delay.o | |||
20 | lib-y += thunk_$(BITS).o | 20 | lib-y += thunk_$(BITS).o |
21 | lib-y += usercopy_$(BITS).o getuser.o putuser.o | 21 | lib-y += usercopy_$(BITS).o getuser.o putuser.o |
22 | lib-y += memcpy_$(BITS).o | 22 | lib-y += memcpy_$(BITS).o |
23 | lib-$(CONFIG_KPROBES) += insn.o inat.o | 23 | lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o |
24 | 24 | ||
25 | obj-y += msr.o msr-reg.o msr-reg-export.o | 25 | obj-y += msr.o msr-reg.o msr-reg-export.o |
26 | 26 | ||
27 | ifeq ($(CONFIG_X86_32),y) | 27 | ifeq ($(CONFIG_X86_32),y) |
28 | obj-y += atomic64_32.o | 28 | obj-y += atomic64_32.o |
29 | lib-y += atomic64_cx8_32.o | ||
29 | lib-y += checksum_32.o | 30 | lib-y += checksum_32.o |
30 | lib-y += strstr_32.o | 31 | lib-y += strstr_32.o |
31 | lib-y += semaphore_32.o string_32.o | 32 | lib-y += semaphore_32.o string_32.o |
32 | ifneq ($(CONFIG_X86_CMPXCHG64),y) | 33 | ifneq ($(CONFIG_X86_CMPXCHG64),y) |
33 | lib-y += cmpxchg8b_emu.o | 34 | lib-y += cmpxchg8b_emu.o atomic64_386_32.o |
34 | endif | 35 | endif |
35 | lib-$(CONFIG_X86_USE_3DNOW) += mmx_32.o | 36 | lib-$(CONFIG_X86_USE_3DNOW) += mmx_32.o |
36 | else | 37 | else |
diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c index 824fa0be55a3..540179e8e9fa 100644 --- a/arch/x86/lib/atomic64_32.c +++ b/arch/x86/lib/atomic64_32.c | |||
@@ -6,225 +6,54 @@ | |||
6 | #include <asm/cmpxchg.h> | 6 | #include <asm/cmpxchg.h> |
7 | #include <asm/atomic.h> | 7 | #include <asm/atomic.h> |
8 | 8 | ||
9 | static noinline u64 cmpxchg8b(u64 *ptr, u64 old, u64 new) | 9 | long long atomic64_read_cx8(long long, const atomic64_t *v); |
10 | { | 10 | EXPORT_SYMBOL(atomic64_read_cx8); |
11 | u32 low = new; | 11 | long long atomic64_set_cx8(long long, const atomic64_t *v); |
12 | u32 high = new >> 32; | 12 | EXPORT_SYMBOL(atomic64_set_cx8); |
13 | 13 | long long atomic64_xchg_cx8(long long, unsigned high); | |
14 | asm volatile( | 14 | EXPORT_SYMBOL(atomic64_xchg_cx8); |
15 | LOCK_PREFIX "cmpxchg8b %1\n" | 15 | long long atomic64_add_return_cx8(long long a, atomic64_t *v); |
16 | : "+A" (old), "+m" (*ptr) | 16 | EXPORT_SYMBOL(atomic64_add_return_cx8); |
17 | : "b" (low), "c" (high) | 17 | long long atomic64_sub_return_cx8(long long a, atomic64_t *v); |
18 | ); | 18 | EXPORT_SYMBOL(atomic64_sub_return_cx8); |
19 | return old; | 19 | long long atomic64_inc_return_cx8(long long a, atomic64_t *v); |
20 | } | 20 | EXPORT_SYMBOL(atomic64_inc_return_cx8); |
21 | 21 | long long atomic64_dec_return_cx8(long long a, atomic64_t *v); | |
22 | u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val) | 22 | EXPORT_SYMBOL(atomic64_dec_return_cx8); |
23 | { | 23 | long long atomic64_dec_if_positive_cx8(atomic64_t *v); |
24 | return cmpxchg8b(&ptr->counter, old_val, new_val); | 24 | EXPORT_SYMBOL(atomic64_dec_if_positive_cx8); |
25 | } | 25 | int atomic64_inc_not_zero_cx8(atomic64_t *v); |
26 | EXPORT_SYMBOL(atomic64_cmpxchg); | 26 | EXPORT_SYMBOL(atomic64_inc_not_zero_cx8); |
27 | 27 | int atomic64_add_unless_cx8(atomic64_t *v, long long a, long long u); | |
28 | /** | 28 | EXPORT_SYMBOL(atomic64_add_unless_cx8); |
29 | * atomic64_xchg - xchg atomic64 variable | 29 | |
30 | * @ptr: pointer to type atomic64_t | 30 | #ifndef CONFIG_X86_CMPXCHG64 |
31 | * @new_val: value to assign | 31 | long long atomic64_read_386(long long, const atomic64_t *v); |
32 | * | 32 | EXPORT_SYMBOL(atomic64_read_386); |
33 | * Atomically xchgs the value of @ptr to @new_val and returns | 33 | long long atomic64_set_386(long long, const atomic64_t *v); |
34 | * the old value. | 34 | EXPORT_SYMBOL(atomic64_set_386); |
35 | */ | 35 | long long atomic64_xchg_386(long long, unsigned high); |
36 | u64 atomic64_xchg(atomic64_t *ptr, u64 new_val) | 36 | EXPORT_SYMBOL(atomic64_xchg_386); |
37 | { | 37 | long long atomic64_add_return_386(long long a, atomic64_t *v); |
38 | /* | 38 | EXPORT_SYMBOL(atomic64_add_return_386); |
39 | * Try first with a (possibly incorrect) assumption about | 39 | long long atomic64_sub_return_386(long long a, atomic64_t *v); |
40 | * what we have there. We'll do two loops most likely, | 40 | EXPORT_SYMBOL(atomic64_sub_return_386); |
41 | * but we'll get an ownership MESI transaction straight away | 41 | long long atomic64_inc_return_386(long long a, atomic64_t *v); |
42 | * instead of a read transaction followed by a | 42 | EXPORT_SYMBOL(atomic64_inc_return_386); |
43 | * flush-for-ownership transaction: | 43 | long long atomic64_dec_return_386(long long a, atomic64_t *v); |
44 | */ | 44 | EXPORT_SYMBOL(atomic64_dec_return_386); |
45 | u64 old_val, real_val = 0; | 45 | long long atomic64_add_386(long long a, atomic64_t *v); |
46 | 46 | EXPORT_SYMBOL(atomic64_add_386); | |
47 | do { | 47 | long long atomic64_sub_386(long long a, atomic64_t *v); |
48 | old_val = real_val; | 48 | EXPORT_SYMBOL(atomic64_sub_386); |
49 | 49 | long long atomic64_inc_386(long long a, atomic64_t *v); | |
50 | real_val = atomic64_cmpxchg(ptr, old_val, new_val); | 50 | EXPORT_SYMBOL(atomic64_inc_386); |
51 | 51 | long long atomic64_dec_386(long long a, atomic64_t *v); | |
52 | } while (real_val != old_val); | 52 | EXPORT_SYMBOL(atomic64_dec_386); |
53 | 53 | long long atomic64_dec_if_positive_386(atomic64_t *v); | |
54 | return old_val; | 54 | EXPORT_SYMBOL(atomic64_dec_if_positive_386); |
55 | } | 55 | int atomic64_inc_not_zero_386(atomic64_t *v); |
56 | EXPORT_SYMBOL(atomic64_xchg); | 56 | EXPORT_SYMBOL(atomic64_inc_not_zero_386); |
57 | 57 | int atomic64_add_unless_386(atomic64_t *v, long long a, long long u); | |
58 | /** | 58 | EXPORT_SYMBOL(atomic64_add_unless_386); |
59 | * atomic64_set - set atomic64 variable | 59 | #endif |
60 | * @ptr: pointer to type atomic64_t | ||
61 | * @new_val: value to assign | ||
62 | * | ||
63 | * Atomically sets the value of @ptr to @new_val. | ||
64 | */ | ||
65 | void atomic64_set(atomic64_t *ptr, u64 new_val) | ||
66 | { | ||
67 | atomic64_xchg(ptr, new_val); | ||
68 | } | ||
69 | EXPORT_SYMBOL(atomic64_set); | ||
70 | |||
71 | /** | ||
72 | EXPORT_SYMBOL(atomic64_read); | ||
73 | * atomic64_add_return - add and return | ||
74 | * @delta: integer value to add | ||
75 | * @ptr: pointer to type atomic64_t | ||
76 | * | ||
77 | * Atomically adds @delta to @ptr and returns @delta + *@ptr | ||
78 | */ | ||
79 | noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr) | ||
80 | { | ||
81 | /* | ||
82 | * Try first with a (possibly incorrect) assumption about | ||
83 | * what we have there. We'll do two loops most likely, | ||
84 | * but we'll get an ownership MESI transaction straight away | ||
85 | * instead of a read transaction followed by a | ||
86 | * flush-for-ownership transaction: | ||
87 | */ | ||
88 | u64 old_val, new_val, real_val = 0; | ||
89 | |||
90 | do { | ||
91 | old_val = real_val; | ||
92 | new_val = old_val + delta; | ||
93 | |||
94 | real_val = atomic64_cmpxchg(ptr, old_val, new_val); | ||
95 | |||
96 | } while (real_val != old_val); | ||
97 | |||
98 | return new_val; | ||
99 | } | ||
100 | EXPORT_SYMBOL(atomic64_add_return); | ||
101 | |||
102 | u64 atomic64_sub_return(u64 delta, atomic64_t *ptr) | ||
103 | { | ||
104 | return atomic64_add_return(-delta, ptr); | ||
105 | } | ||
106 | EXPORT_SYMBOL(atomic64_sub_return); | ||
107 | |||
108 | u64 atomic64_inc_return(atomic64_t *ptr) | ||
109 | { | ||
110 | return atomic64_add_return(1, ptr); | ||
111 | } | ||
112 | EXPORT_SYMBOL(atomic64_inc_return); | ||
113 | |||
114 | u64 atomic64_dec_return(atomic64_t *ptr) | ||
115 | { | ||
116 | return atomic64_sub_return(1, ptr); | ||
117 | } | ||
118 | EXPORT_SYMBOL(atomic64_dec_return); | ||
119 | |||
120 | /** | ||
121 | * atomic64_add - add integer to atomic64 variable | ||
122 | * @delta: integer value to add | ||
123 | * @ptr: pointer to type atomic64_t | ||
124 | * | ||
125 | * Atomically adds @delta to @ptr. | ||
126 | */ | ||
127 | void atomic64_add(u64 delta, atomic64_t *ptr) | ||
128 | { | ||
129 | atomic64_add_return(delta, ptr); | ||
130 | } | ||
131 | EXPORT_SYMBOL(atomic64_add); | ||
132 | |||
133 | /** | ||
134 | * atomic64_sub - subtract the atomic64 variable | ||
135 | * @delta: integer value to subtract | ||
136 | * @ptr: pointer to type atomic64_t | ||
137 | * | ||
138 | * Atomically subtracts @delta from @ptr. | ||
139 | */ | ||
140 | void atomic64_sub(u64 delta, atomic64_t *ptr) | ||
141 | { | ||
142 | atomic64_add(-delta, ptr); | ||
143 | } | ||
144 | EXPORT_SYMBOL(atomic64_sub); | ||
145 | |||
146 | /** | ||
147 | * atomic64_sub_and_test - subtract value from variable and test result | ||
148 | * @delta: integer value to subtract | ||
149 | * @ptr: pointer to type atomic64_t | ||
150 | * | ||
151 | * Atomically subtracts @delta from @ptr and returns | ||
152 | * true if the result is zero, or false for all | ||
153 | * other cases. | ||
154 | */ | ||
155 | int atomic64_sub_and_test(u64 delta, atomic64_t *ptr) | ||
156 | { | ||
157 | u64 new_val = atomic64_sub_return(delta, ptr); | ||
158 | |||
159 | return new_val == 0; | ||
160 | } | ||
161 | EXPORT_SYMBOL(atomic64_sub_and_test); | ||
162 | |||
163 | /** | ||
164 | * atomic64_inc - increment atomic64 variable | ||
165 | * @ptr: pointer to type atomic64_t | ||
166 | * | ||
167 | * Atomically increments @ptr by 1. | ||
168 | */ | ||
169 | void atomic64_inc(atomic64_t *ptr) | ||
170 | { | ||
171 | atomic64_add(1, ptr); | ||
172 | } | ||
173 | EXPORT_SYMBOL(atomic64_inc); | ||
174 | |||
175 | /** | ||
176 | * atomic64_dec - decrement atomic64 variable | ||
177 | * @ptr: pointer to type atomic64_t | ||
178 | * | ||
179 | * Atomically decrements @ptr by 1. | ||
180 | */ | ||
181 | void atomic64_dec(atomic64_t *ptr) | ||
182 | { | ||
183 | atomic64_sub(1, ptr); | ||
184 | } | ||
185 | EXPORT_SYMBOL(atomic64_dec); | ||
186 | |||
187 | /** | ||
188 | * atomic64_dec_and_test - decrement and test | ||
189 | * @ptr: pointer to type atomic64_t | ||
190 | * | ||
191 | * Atomically decrements @ptr by 1 and | ||
192 | * returns true if the result is 0, or false for all other | ||
193 | * cases. | ||
194 | */ | ||
195 | int atomic64_dec_and_test(atomic64_t *ptr) | ||
196 | { | ||
197 | return atomic64_sub_and_test(1, ptr); | ||
198 | } | ||
199 | EXPORT_SYMBOL(atomic64_dec_and_test); | ||
200 | |||
201 | /** | ||
202 | * atomic64_inc_and_test - increment and test | ||
203 | * @ptr: pointer to type atomic64_t | ||
204 | * | ||
205 | * Atomically increments @ptr by 1 | ||
206 | * and returns true if the result is zero, or false for all | ||
207 | * other cases. | ||
208 | */ | ||
209 | int atomic64_inc_and_test(atomic64_t *ptr) | ||
210 | { | ||
211 | return atomic64_sub_and_test(-1, ptr); | ||
212 | } | ||
213 | EXPORT_SYMBOL(atomic64_inc_and_test); | ||
214 | |||
215 | /** | ||
216 | * atomic64_add_negative - add and test if negative | ||
217 | * @delta: integer value to add | ||
218 | * @ptr: pointer to type atomic64_t | ||
219 | * | ||
220 | * Atomically adds @delta to @ptr and returns true | ||
221 | * if the result is negative, or false when | ||
222 | * result is greater than or equal to zero. | ||
223 | */ | ||
224 | int atomic64_add_negative(u64 delta, atomic64_t *ptr) | ||
225 | { | ||
226 | s64 new_val = atomic64_add_return(delta, ptr); | ||
227 | |||
228 | return new_val < 0; | ||
229 | } | ||
230 | EXPORT_SYMBOL(atomic64_add_negative); | ||
diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S new file mode 100644 index 000000000000..4a5979aa6883 --- /dev/null +++ b/arch/x86/lib/atomic64_386_32.S | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | * atomic64_t for 386/486 | ||
3 | * | ||
4 | * Copyright © 2010 Luca Barbieri | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/linkage.h> | ||
13 | #include <asm/alternative-asm.h> | ||
14 | #include <asm/dwarf2.h> | ||
15 | |||
16 | /* if you want SMP support, implement these with real spinlocks */ | ||
17 | .macro LOCK reg | ||
18 | pushfl | ||
19 | CFI_ADJUST_CFA_OFFSET 4 | ||
20 | cli | ||
21 | .endm | ||
22 | |||
23 | .macro UNLOCK reg | ||
24 | popfl | ||
25 | CFI_ADJUST_CFA_OFFSET -4 | ||
26 | .endm | ||
27 | |||
28 | .macro BEGIN func reg | ||
29 | $v = \reg | ||
30 | |||
31 | ENTRY(atomic64_\func\()_386) | ||
32 | CFI_STARTPROC | ||
33 | LOCK $v | ||
34 | |||
35 | .macro RETURN | ||
36 | UNLOCK $v | ||
37 | ret | ||
38 | .endm | ||
39 | |||
40 | .macro END_ | ||
41 | CFI_ENDPROC | ||
42 | ENDPROC(atomic64_\func\()_386) | ||
43 | .purgem RETURN | ||
44 | .purgem END_ | ||
45 | .purgem END | ||
46 | .endm | ||
47 | |||
48 | .macro END | ||
49 | RETURN | ||
50 | END_ | ||
51 | .endm | ||
52 | .endm | ||
53 | |||
54 | BEGIN read %ecx | ||
55 | movl ($v), %eax | ||
56 | movl 4($v), %edx | ||
57 | END | ||
58 | |||
59 | BEGIN set %esi | ||
60 | movl %ebx, ($v) | ||
61 | movl %ecx, 4($v) | ||
62 | END | ||
63 | |||
64 | BEGIN xchg %esi | ||
65 | movl ($v), %eax | ||
66 | movl 4($v), %edx | ||
67 | movl %ebx, ($v) | ||
68 | movl %ecx, 4($v) | ||
69 | END | ||
70 | |||
71 | BEGIN add %ecx | ||
72 | addl %eax, ($v) | ||
73 | adcl %edx, 4($v) | ||
74 | END | ||
75 | |||
76 | BEGIN add_return %ecx | ||
77 | addl ($v), %eax | ||
78 | adcl 4($v), %edx | ||
79 | movl %eax, ($v) | ||
80 | movl %edx, 4($v) | ||
81 | END | ||
82 | |||
83 | BEGIN sub %ecx | ||
84 | subl %eax, ($v) | ||
85 | sbbl %edx, 4($v) | ||
86 | END | ||
87 | |||
88 | BEGIN sub_return %ecx | ||
89 | negl %edx | ||
90 | negl %eax | ||
91 | sbbl $0, %edx | ||
92 | addl ($v), %eax | ||
93 | adcl 4($v), %edx | ||
94 | movl %eax, ($v) | ||
95 | movl %edx, 4($v) | ||
96 | END | ||
97 | |||
98 | BEGIN inc %esi | ||
99 | addl $1, ($v) | ||
100 | adcl $0, 4($v) | ||
101 | END | ||
102 | |||
103 | BEGIN inc_return %esi | ||
104 | movl ($v), %eax | ||
105 | movl 4($v), %edx | ||
106 | addl $1, %eax | ||
107 | adcl $0, %edx | ||
108 | movl %eax, ($v) | ||
109 | movl %edx, 4($v) | ||
110 | END | ||
111 | |||
112 | BEGIN dec %esi | ||
113 | subl $1, ($v) | ||
114 | sbbl $0, 4($v) | ||
115 | END | ||
116 | |||
117 | BEGIN dec_return %esi | ||
118 | movl ($v), %eax | ||
119 | movl 4($v), %edx | ||
120 | subl $1, %eax | ||
121 | sbbl $0, %edx | ||
122 | movl %eax, ($v) | ||
123 | movl %edx, 4($v) | ||
124 | END | ||
125 | |||
126 | BEGIN add_unless %ecx | ||
127 | addl %eax, %esi | ||
128 | adcl %edx, %edi | ||
129 | addl ($v), %eax | ||
130 | adcl 4($v), %edx | ||
131 | cmpl %eax, %esi | ||
132 | je 3f | ||
133 | 1: | ||
134 | movl %eax, ($v) | ||
135 | movl %edx, 4($v) | ||
136 | movl $1, %eax | ||
137 | 2: | ||
138 | RETURN | ||
139 | 3: | ||
140 | cmpl %edx, %edi | ||
141 | jne 1b | ||
142 | xorl %eax, %eax | ||
143 | jmp 2b | ||
144 | END_ | ||
145 | |||
146 | BEGIN inc_not_zero %esi | ||
147 | movl ($v), %eax | ||
148 | movl 4($v), %edx | ||
149 | testl %eax, %eax | ||
150 | je 3f | ||
151 | 1: | ||
152 | addl $1, %eax | ||
153 | adcl $0, %edx | ||
154 | movl %eax, ($v) | ||
155 | movl %edx, 4($v) | ||
156 | movl $1, %eax | ||
157 | 2: | ||
158 | RETURN | ||
159 | 3: | ||
160 | testl %edx, %edx | ||
161 | jne 1b | ||
162 | jmp 2b | ||
163 | END_ | ||
164 | |||
165 | BEGIN dec_if_positive %esi | ||
166 | movl ($v), %eax | ||
167 | movl 4($v), %edx | ||
168 | subl $1, %eax | ||
169 | sbbl $0, %edx | ||
170 | js 1f | ||
171 | movl %eax, ($v) | ||
172 | movl %edx, 4($v) | ||
173 | 1: | ||
174 | END | ||
diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S new file mode 100644 index 000000000000..71e080de3352 --- /dev/null +++ b/arch/x86/lib/atomic64_cx8_32.S | |||
@@ -0,0 +1,224 @@ | |||
1 | /* | ||
2 | * atomic64_t for 586+ | ||
3 | * | ||
4 | * Copyright © 2010 Luca Barbieri | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/linkage.h> | ||
13 | #include <asm/alternative-asm.h> | ||
14 | #include <asm/dwarf2.h> | ||
15 | |||
16 | .macro SAVE reg | ||
17 | pushl %\reg | ||
18 | CFI_ADJUST_CFA_OFFSET 4 | ||
19 | CFI_REL_OFFSET \reg, 0 | ||
20 | .endm | ||
21 | |||
22 | .macro RESTORE reg | ||
23 | popl %\reg | ||
24 | CFI_ADJUST_CFA_OFFSET -4 | ||
25 | CFI_RESTORE \reg | ||
26 | .endm | ||
27 | |||
28 | .macro read64 reg | ||
29 | movl %ebx, %eax | ||
30 | movl %ecx, %edx | ||
31 | /* we need LOCK_PREFIX since otherwise cmpxchg8b always does the write */ | ||
32 | LOCK_PREFIX | ||
33 | cmpxchg8b (\reg) | ||
34 | .endm | ||
35 | |||
36 | ENTRY(atomic64_read_cx8) | ||
37 | CFI_STARTPROC | ||
38 | |||
39 | read64 %ecx | ||
40 | ret | ||
41 | CFI_ENDPROC | ||
42 | ENDPROC(atomic64_read_cx8) | ||
43 | |||
44 | ENTRY(atomic64_set_cx8) | ||
45 | CFI_STARTPROC | ||
46 | |||
47 | 1: | ||
48 | /* we don't need LOCK_PREFIX since aligned 64-bit writes | ||
49 | * are atomic on 586 and newer */ | ||
50 | cmpxchg8b (%esi) | ||
51 | jne 1b | ||
52 | |||
53 | ret | ||
54 | CFI_ENDPROC | ||
55 | ENDPROC(atomic64_set_cx8) | ||
56 | |||
57 | ENTRY(atomic64_xchg_cx8) | ||
58 | CFI_STARTPROC | ||
59 | |||
60 | movl %ebx, %eax | ||
61 | movl %ecx, %edx | ||
62 | 1: | ||
63 | LOCK_PREFIX | ||
64 | cmpxchg8b (%esi) | ||
65 | jne 1b | ||
66 | |||
67 | ret | ||
68 | CFI_ENDPROC | ||
69 | ENDPROC(atomic64_xchg_cx8) | ||
70 | |||
71 | .macro addsub_return func ins insc | ||
72 | ENTRY(atomic64_\func\()_return_cx8) | ||
73 | CFI_STARTPROC | ||
74 | SAVE ebp | ||
75 | SAVE ebx | ||
76 | SAVE esi | ||
77 | SAVE edi | ||
78 | |||
79 | movl %eax, %esi | ||
80 | movl %edx, %edi | ||
81 | movl %ecx, %ebp | ||
82 | |||
83 | read64 %ebp | ||
84 | 1: | ||
85 | movl %eax, %ebx | ||
86 | movl %edx, %ecx | ||
87 | \ins\()l %esi, %ebx | ||
88 | \insc\()l %edi, %ecx | ||
89 | LOCK_PREFIX | ||
90 | cmpxchg8b (%ebp) | ||
91 | jne 1b | ||
92 | |||
93 | 10: | ||
94 | movl %ebx, %eax | ||
95 | movl %ecx, %edx | ||
96 | RESTORE edi | ||
97 | RESTORE esi | ||
98 | RESTORE ebx | ||
99 | RESTORE ebp | ||
100 | ret | ||
101 | CFI_ENDPROC | ||
102 | ENDPROC(atomic64_\func\()_return_cx8) | ||
103 | .endm | ||
104 | |||
105 | addsub_return add add adc | ||
106 | addsub_return sub sub sbb | ||
107 | |||
108 | .macro incdec_return func ins insc | ||
109 | ENTRY(atomic64_\func\()_return_cx8) | ||
110 | CFI_STARTPROC | ||
111 | SAVE ebx | ||
112 | |||
113 | read64 %esi | ||
114 | 1: | ||
115 | movl %eax, %ebx | ||
116 | movl %edx, %ecx | ||
117 | \ins\()l $1, %ebx | ||
118 | \insc\()l $0, %ecx | ||
119 | LOCK_PREFIX | ||
120 | cmpxchg8b (%esi) | ||
121 | jne 1b | ||
122 | |||
123 | 10: | ||
124 | movl %ebx, %eax | ||
125 | movl %ecx, %edx | ||
126 | RESTORE ebx | ||
127 | ret | ||
128 | CFI_ENDPROC | ||
129 | ENDPROC(atomic64_\func\()_return_cx8) | ||
130 | .endm | ||
131 | |||
132 | incdec_return inc add adc | ||
133 | incdec_return dec sub sbb | ||
134 | |||
135 | ENTRY(atomic64_dec_if_positive_cx8) | ||
136 | CFI_STARTPROC | ||
137 | SAVE ebx | ||
138 | |||
139 | read64 %esi | ||
140 | 1: | ||
141 | movl %eax, %ebx | ||
142 | movl %edx, %ecx | ||
143 | subl $1, %ebx | ||
144 | sbb $0, %ecx | ||
145 | js 2f | ||
146 | LOCK_PREFIX | ||
147 | cmpxchg8b (%esi) | ||
148 | jne 1b | ||
149 | |||
150 | 2: | ||
151 | movl %ebx, %eax | ||
152 | movl %ecx, %edx | ||
153 | RESTORE ebx | ||
154 | ret | ||
155 | CFI_ENDPROC | ||
156 | ENDPROC(atomic64_dec_if_positive_cx8) | ||
157 | |||
158 | ENTRY(atomic64_add_unless_cx8) | ||
159 | CFI_STARTPROC | ||
160 | SAVE ebp | ||
161 | SAVE ebx | ||
162 | /* these just push these two parameters on the stack */ | ||
163 | SAVE edi | ||
164 | SAVE esi | ||
165 | |||
166 | movl %ecx, %ebp | ||
167 | movl %eax, %esi | ||
168 | movl %edx, %edi | ||
169 | |||
170 | read64 %ebp | ||
171 | 1: | ||
172 | cmpl %eax, 0(%esp) | ||
173 | je 4f | ||
174 | 2: | ||
175 | movl %eax, %ebx | ||
176 | movl %edx, %ecx | ||
177 | addl %esi, %ebx | ||
178 | adcl %edi, %ecx | ||
179 | LOCK_PREFIX | ||
180 | cmpxchg8b (%ebp) | ||
181 | jne 1b | ||
182 | |||
183 | movl $1, %eax | ||
184 | 3: | ||
185 | addl $8, %esp | ||
186 | CFI_ADJUST_CFA_OFFSET -8 | ||
187 | RESTORE ebx | ||
188 | RESTORE ebp | ||
189 | ret | ||
190 | 4: | ||
191 | cmpl %edx, 4(%esp) | ||
192 | jne 2b | ||
193 | xorl %eax, %eax | ||
194 | jmp 3b | ||
195 | CFI_ENDPROC | ||
196 | ENDPROC(atomic64_add_unless_cx8) | ||
197 | |||
198 | ENTRY(atomic64_inc_not_zero_cx8) | ||
199 | CFI_STARTPROC | ||
200 | SAVE ebx | ||
201 | |||
202 | read64 %esi | ||
203 | 1: | ||
204 | testl %eax, %eax | ||
205 | je 4f | ||
206 | 2: | ||
207 | movl %eax, %ebx | ||
208 | movl %edx, %ecx | ||
209 | addl $1, %ebx | ||
210 | adcl $0, %ecx | ||
211 | LOCK_PREFIX | ||
212 | cmpxchg8b (%esi) | ||
213 | jne 1b | ||
214 | |||
215 | movl $1, %eax | ||
216 | 3: | ||
217 | RESTORE ebx | ||
218 | ret | ||
219 | 4: | ||
220 | testl %edx, %edx | ||
221 | jne 2b | ||
222 | jmp 3b | ||
223 | CFI_ENDPROC | ||
224 | ENDPROC(atomic64_inc_not_zero_cx8) | ||
diff --git a/arch/x86/math-emu/fpu_aux.c b/arch/x86/math-emu/fpu_aux.c index aa0987088774..dc8adad10a2f 100644 --- a/arch/x86/math-emu/fpu_aux.c +++ b/arch/x86/math-emu/fpu_aux.c | |||
@@ -30,10 +30,10 @@ static void fclex(void) | |||
30 | } | 30 | } |
31 | 31 | ||
32 | /* Needs to be externally visible */ | 32 | /* Needs to be externally visible */ |
33 | void finit_task(struct task_struct *tsk) | 33 | void finit_soft_fpu(struct i387_soft_struct *soft) |
34 | { | 34 | { |
35 | struct i387_soft_struct *soft = &tsk->thread.xstate->soft; | ||
36 | struct address *oaddr, *iaddr; | 35 | struct address *oaddr, *iaddr; |
36 | memset(soft, 0, sizeof(*soft)); | ||
37 | soft->cwd = 0x037f; | 37 | soft->cwd = 0x037f; |
38 | soft->swd = 0; | 38 | soft->swd = 0; |
39 | soft->ftop = 0; /* We don't keep top in the status word internally. */ | 39 | soft->ftop = 0; /* We don't keep top in the status word internally. */ |
@@ -52,7 +52,7 @@ void finit_task(struct task_struct *tsk) | |||
52 | 52 | ||
53 | void finit(void) | 53 | void finit(void) |
54 | { | 54 | { |
55 | finit_task(current); | 55 | finit_soft_fpu(¤t->thread.fpu.state->soft); |
56 | } | 56 | } |
57 | 57 | ||
58 | /* | 58 | /* |
diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c index 5d87f586f8d7..7718541541d4 100644 --- a/arch/x86/math-emu/fpu_entry.c +++ b/arch/x86/math-emu/fpu_entry.c | |||
@@ -681,7 +681,7 @@ int fpregs_soft_set(struct task_struct *target, | |||
681 | unsigned int pos, unsigned int count, | 681 | unsigned int pos, unsigned int count, |
682 | const void *kbuf, const void __user *ubuf) | 682 | const void *kbuf, const void __user *ubuf) |
683 | { | 683 | { |
684 | struct i387_soft_struct *s387 = &target->thread.xstate->soft; | 684 | struct i387_soft_struct *s387 = &target->thread.fpu.state->soft; |
685 | void *space = s387->st_space; | 685 | void *space = s387->st_space; |
686 | int ret; | 686 | int ret; |
687 | int offset, other, i, tags, regnr, tag, newtop; | 687 | int offset, other, i, tags, regnr, tag, newtop; |
@@ -733,7 +733,7 @@ int fpregs_soft_get(struct task_struct *target, | |||
733 | unsigned int pos, unsigned int count, | 733 | unsigned int pos, unsigned int count, |
734 | void *kbuf, void __user *ubuf) | 734 | void *kbuf, void __user *ubuf) |
735 | { | 735 | { |
736 | struct i387_soft_struct *s387 = &target->thread.xstate->soft; | 736 | struct i387_soft_struct *s387 = &target->thread.fpu.state->soft; |
737 | const void *space = s387->st_space; | 737 | const void *space = s387->st_space; |
738 | int ret; | 738 | int ret; |
739 | int offset = (S387->ftop & 7) * 10, other = 80 - offset; | 739 | int offset = (S387->ftop & 7) * 10, other = 80 - offset; |
diff --git a/arch/x86/math-emu/fpu_system.h b/arch/x86/math-emu/fpu_system.h index 50fa0ec2c8a5..2c614410a5f3 100644 --- a/arch/x86/math-emu/fpu_system.h +++ b/arch/x86/math-emu/fpu_system.h | |||
@@ -31,7 +31,7 @@ | |||
31 | #define SEG_EXPAND_DOWN(s) (((s).b & ((1 << 11) | (1 << 10))) \ | 31 | #define SEG_EXPAND_DOWN(s) (((s).b & ((1 << 11) | (1 << 10))) \ |
32 | == (1 << 10)) | 32 | == (1 << 10)) |
33 | 33 | ||
34 | #define I387 (current->thread.xstate) | 34 | #define I387 (current->thread.fpu.state) |
35 | #define FPU_info (I387->soft.info) | 35 | #define FPU_info (I387->soft.info) |
36 | 36 | ||
37 | #define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs)) | 37 | #define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs)) |
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index 06630d26e56d..a4c768397baa 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile | |||
@@ -6,6 +6,7 @@ nostackp := $(call cc-option, -fno-stack-protector) | |||
6 | CFLAGS_physaddr.o := $(nostackp) | 6 | CFLAGS_physaddr.o := $(nostackp) |
7 | CFLAGS_setup_nx.o := $(nostackp) | 7 | CFLAGS_setup_nx.o := $(nostackp) |
8 | 8 | ||
9 | obj-$(CONFIG_X86_PAT) += pat_rbtree.o | ||
9 | obj-$(CONFIG_SMP) += tlb.o | 10 | obj-$(CONFIG_SMP) += tlb.o |
10 | 11 | ||
11 | obj-$(CONFIG_X86_32) += pgtable_32.o iomap_32.o | 12 | obj-$(CONFIG_X86_32) += pgtable_32.o iomap_32.o |
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index edc8b95afc1a..bbe5502ee1cb 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include <asm/pat.h> | 30 | #include <asm/pat.h> |
31 | #include <asm/io.h> | 31 | #include <asm/io.h> |
32 | 32 | ||
33 | #include "pat_internal.h" | ||
34 | |||
33 | #ifdef CONFIG_X86_PAT | 35 | #ifdef CONFIG_X86_PAT |
34 | int __read_mostly pat_enabled = 1; | 36 | int __read_mostly pat_enabled = 1; |
35 | 37 | ||
@@ -53,19 +55,15 @@ static inline void pat_disable(const char *reason) | |||
53 | #endif | 55 | #endif |
54 | 56 | ||
55 | 57 | ||
56 | static int debug_enable; | 58 | int pat_debug_enable; |
57 | 59 | ||
58 | static int __init pat_debug_setup(char *str) | 60 | static int __init pat_debug_setup(char *str) |
59 | { | 61 | { |
60 | debug_enable = 1; | 62 | pat_debug_enable = 1; |
61 | return 0; | 63 | return 0; |
62 | } | 64 | } |
63 | __setup("debugpat", pat_debug_setup); | 65 | __setup("debugpat", pat_debug_setup); |
64 | 66 | ||
65 | #define dprintk(fmt, arg...) \ | ||
66 | do { if (debug_enable) printk(KERN_INFO fmt, ##arg); } while (0) | ||
67 | |||
68 | |||
69 | static u64 __read_mostly boot_pat_state; | 67 | static u64 __read_mostly boot_pat_state; |
70 | 68 | ||
71 | enum { | 69 | enum { |
@@ -132,84 +130,7 @@ void pat_init(void) | |||
132 | 130 | ||
133 | #undef PAT | 131 | #undef PAT |
134 | 132 | ||
135 | static char *cattr_name(unsigned long flags) | 133 | static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */ |
136 | { | ||
137 | switch (flags & _PAGE_CACHE_MASK) { | ||
138 | case _PAGE_CACHE_UC: return "uncached"; | ||
139 | case _PAGE_CACHE_UC_MINUS: return "uncached-minus"; | ||
140 | case _PAGE_CACHE_WB: return "write-back"; | ||
141 | case _PAGE_CACHE_WC: return "write-combining"; | ||
142 | default: return "broken"; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * The global memtype list keeps track of memory type for specific | ||
148 | * physical memory areas. Conflicting memory types in different | ||
149 | * mappings can cause CPU cache corruption. To avoid this we keep track. | ||
150 | * | ||
151 | * The list is sorted based on starting address and can contain multiple | ||
152 | * entries for each address (this allows reference counting for overlapping | ||
153 | * areas). All the aliases have the same cache attributes of course. | ||
154 | * Zero attributes are represented as holes. | ||
155 | * | ||
156 | * The data structure is a list that is also organized as an rbtree | ||
157 | * sorted on the start address of memtype range. | ||
158 | * | ||
159 | * memtype_lock protects both the linear list and rbtree. | ||
160 | */ | ||
161 | |||
162 | struct memtype { | ||
163 | u64 start; | ||
164 | u64 end; | ||
165 | unsigned long type; | ||
166 | struct list_head nd; | ||
167 | struct rb_node rb; | ||
168 | }; | ||
169 | |||
170 | static struct rb_root memtype_rbroot = RB_ROOT; | ||
171 | static LIST_HEAD(memtype_list); | ||
172 | static DEFINE_SPINLOCK(memtype_lock); /* protects memtype list */ | ||
173 | |||
174 | static struct memtype *memtype_rb_search(struct rb_root *root, u64 start) | ||
175 | { | ||
176 | struct rb_node *node = root->rb_node; | ||
177 | struct memtype *last_lower = NULL; | ||
178 | |||
179 | while (node) { | ||
180 | struct memtype *data = container_of(node, struct memtype, rb); | ||
181 | |||
182 | if (data->start < start) { | ||
183 | last_lower = data; | ||
184 | node = node->rb_right; | ||
185 | } else if (data->start > start) { | ||
186 | node = node->rb_left; | ||
187 | } else | ||
188 | return data; | ||
189 | } | ||
190 | |||
191 | /* Will return NULL if there is no entry with its start <= start */ | ||
192 | return last_lower; | ||
193 | } | ||
194 | |||
195 | static void memtype_rb_insert(struct rb_root *root, struct memtype *data) | ||
196 | { | ||
197 | struct rb_node **new = &(root->rb_node); | ||
198 | struct rb_node *parent = NULL; | ||
199 | |||
200 | while (*new) { | ||
201 | struct memtype *this = container_of(*new, struct memtype, rb); | ||
202 | |||
203 | parent = *new; | ||
204 | if (data->start <= this->start) | ||
205 | new = &((*new)->rb_left); | ||
206 | else if (data->start > this->start) | ||
207 | new = &((*new)->rb_right); | ||
208 | } | ||
209 | |||
210 | rb_link_node(&data->rb, parent, new); | ||
211 | rb_insert_color(&data->rb, root); | ||
212 | } | ||
213 | 134 | ||
214 | /* | 135 | /* |
215 | * Does intersection of PAT memory type and MTRR memory type and returns | 136 | * Does intersection of PAT memory type and MTRR memory type and returns |
@@ -237,33 +158,6 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end, unsigned long req_type) | |||
237 | return req_type; | 158 | return req_type; |
238 | } | 159 | } |
239 | 160 | ||
240 | static int | ||
241 | chk_conflict(struct memtype *new, struct memtype *entry, unsigned long *type) | ||
242 | { | ||
243 | if (new->type != entry->type) { | ||
244 | if (type) { | ||
245 | new->type = entry->type; | ||
246 | *type = entry->type; | ||
247 | } else | ||
248 | goto conflict; | ||
249 | } | ||
250 | |||
251 | /* check overlaps with more than one entry in the list */ | ||
252 | list_for_each_entry_continue(entry, &memtype_list, nd) { | ||
253 | if (new->end <= entry->start) | ||
254 | break; | ||
255 | else if (new->type != entry->type) | ||
256 | goto conflict; | ||
257 | } | ||
258 | return 0; | ||
259 | |||
260 | conflict: | ||
261 | printk(KERN_INFO "%s:%d conflicting memory types " | ||
262 | "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start, | ||
263 | new->end, cattr_name(new->type), cattr_name(entry->type)); | ||
264 | return -EBUSY; | ||
265 | } | ||
266 | |||
267 | static int pat_pagerange_is_ram(unsigned long start, unsigned long end) | 161 | static int pat_pagerange_is_ram(unsigned long start, unsigned long end) |
268 | { | 162 | { |
269 | int ram_page = 0, not_rampage = 0; | 163 | int ram_page = 0, not_rampage = 0; |
@@ -296,8 +190,6 @@ static int pat_pagerange_is_ram(unsigned long start, unsigned long end) | |||
296 | * Here we do two pass: | 190 | * Here we do two pass: |
297 | * - Find the memtype of all the pages in the range, look for any conflicts | 191 | * - Find the memtype of all the pages in the range, look for any conflicts |
298 | * - In case of no conflicts, set the new memtype for pages in the range | 192 | * - In case of no conflicts, set the new memtype for pages in the range |
299 | * | ||
300 | * Caller must hold memtype_lock for atomicity. | ||
301 | */ | 193 | */ |
302 | static int reserve_ram_pages_type(u64 start, u64 end, unsigned long req_type, | 194 | static int reserve_ram_pages_type(u64 start, u64 end, unsigned long req_type, |
303 | unsigned long *new_type) | 195 | unsigned long *new_type) |
@@ -364,9 +256,8 @@ static int free_ram_pages_type(u64 start, u64 end) | |||
364 | int reserve_memtype(u64 start, u64 end, unsigned long req_type, | 256 | int reserve_memtype(u64 start, u64 end, unsigned long req_type, |
365 | unsigned long *new_type) | 257 | unsigned long *new_type) |
366 | { | 258 | { |
367 | struct memtype *new, *entry; | 259 | struct memtype *new; |
368 | unsigned long actual_type; | 260 | unsigned long actual_type; |
369 | struct list_head *where; | ||
370 | int is_range_ram; | 261 | int is_range_ram; |
371 | int err = 0; | 262 | int err = 0; |
372 | 263 | ||
@@ -404,9 +295,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, | |||
404 | is_range_ram = pat_pagerange_is_ram(start, end); | 295 | is_range_ram = pat_pagerange_is_ram(start, end); |
405 | if (is_range_ram == 1) { | 296 | if (is_range_ram == 1) { |
406 | 297 | ||
407 | spin_lock(&memtype_lock); | ||
408 | err = reserve_ram_pages_type(start, end, req_type, new_type); | 298 | err = reserve_ram_pages_type(start, end, req_type, new_type); |
409 | spin_unlock(&memtype_lock); | ||
410 | 299 | ||
411 | return err; | 300 | return err; |
412 | } else if (is_range_ram < 0) { | 301 | } else if (is_range_ram < 0) { |
@@ -423,42 +312,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, | |||
423 | 312 | ||
424 | spin_lock(&memtype_lock); | 313 | spin_lock(&memtype_lock); |
425 | 314 | ||
426 | /* Search for existing mapping that overlaps the current range */ | 315 | err = rbt_memtype_check_insert(new, new_type); |
427 | where = NULL; | ||
428 | list_for_each_entry(entry, &memtype_list, nd) { | ||
429 | if (end <= entry->start) { | ||
430 | where = entry->nd.prev; | ||
431 | break; | ||
432 | } else if (start <= entry->start) { /* end > entry->start */ | ||
433 | err = chk_conflict(new, entry, new_type); | ||
434 | if (!err) { | ||
435 | dprintk("Overlap at 0x%Lx-0x%Lx\n", | ||
436 | entry->start, entry->end); | ||
437 | where = entry->nd.prev; | ||
438 | } | ||
439 | break; | ||
440 | } else if (start < entry->end) { /* start > entry->start */ | ||
441 | err = chk_conflict(new, entry, new_type); | ||
442 | if (!err) { | ||
443 | dprintk("Overlap at 0x%Lx-0x%Lx\n", | ||
444 | entry->start, entry->end); | ||
445 | |||
446 | /* | ||
447 | * Move to right position in the linked | ||
448 | * list to add this new entry | ||
449 | */ | ||
450 | list_for_each_entry_continue(entry, | ||
451 | &memtype_list, nd) { | ||
452 | if (start <= entry->start) { | ||
453 | where = entry->nd.prev; | ||
454 | break; | ||
455 | } | ||
456 | } | ||
457 | } | ||
458 | break; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | if (err) { | 316 | if (err) { |
463 | printk(KERN_INFO "reserve_memtype failed 0x%Lx-0x%Lx, " | 317 | printk(KERN_INFO "reserve_memtype failed 0x%Lx-0x%Lx, " |
464 | "track %s, req %s\n", | 318 | "track %s, req %s\n", |
@@ -469,13 +323,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, | |||
469 | return err; | 323 | return err; |
470 | } | 324 | } |
471 | 325 | ||
472 | if (where) | ||
473 | list_add(&new->nd, where); | ||
474 | else | ||
475 | list_add_tail(&new->nd, &memtype_list); | ||
476 | |||
477 | memtype_rb_insert(&memtype_rbroot, new); | ||
478 | |||
479 | spin_unlock(&memtype_lock); | 326 | spin_unlock(&memtype_lock); |
480 | 327 | ||
481 | dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n", | 328 | dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n", |
@@ -487,7 +334,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, | |||
487 | 334 | ||
488 | int free_memtype(u64 start, u64 end) | 335 | int free_memtype(u64 start, u64 end) |
489 | { | 336 | { |
490 | struct memtype *entry, *saved_entry; | ||
491 | int err = -EINVAL; | 337 | int err = -EINVAL; |
492 | int is_range_ram; | 338 | int is_range_ram; |
493 | 339 | ||
@@ -501,9 +347,7 @@ int free_memtype(u64 start, u64 end) | |||
501 | is_range_ram = pat_pagerange_is_ram(start, end); | 347 | is_range_ram = pat_pagerange_is_ram(start, end); |
502 | if (is_range_ram == 1) { | 348 | if (is_range_ram == 1) { |
503 | 349 | ||
504 | spin_lock(&memtype_lock); | ||
505 | err = free_ram_pages_type(start, end); | 350 | err = free_ram_pages_type(start, end); |
506 | spin_unlock(&memtype_lock); | ||
507 | 351 | ||
508 | return err; | 352 | return err; |
509 | } else if (is_range_ram < 0) { | 353 | } else if (is_range_ram < 0) { |
@@ -511,46 +355,7 @@ int free_memtype(u64 start, u64 end) | |||
511 | } | 355 | } |
512 | 356 | ||
513 | spin_lock(&memtype_lock); | 357 | spin_lock(&memtype_lock); |
514 | 358 | err = rbt_memtype_erase(start, end); | |
515 | entry = memtype_rb_search(&memtype_rbroot, start); | ||
516 | if (unlikely(entry == NULL)) | ||
517 | goto unlock_ret; | ||
518 | |||
519 | /* | ||
520 | * Saved entry points to an entry with start same or less than what | ||
521 | * we searched for. Now go through the list in both directions to look | ||
522 | * for the entry that matches with both start and end, with list stored | ||
523 | * in sorted start address | ||
524 | */ | ||
525 | saved_entry = entry; | ||
526 | list_for_each_entry_from(entry, &memtype_list, nd) { | ||
527 | if (entry->start == start && entry->end == end) { | ||
528 | rb_erase(&entry->rb, &memtype_rbroot); | ||
529 | list_del(&entry->nd); | ||
530 | kfree(entry); | ||
531 | err = 0; | ||
532 | break; | ||
533 | } else if (entry->start > start) { | ||
534 | break; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | if (!err) | ||
539 | goto unlock_ret; | ||
540 | |||
541 | entry = saved_entry; | ||
542 | list_for_each_entry_reverse(entry, &memtype_list, nd) { | ||
543 | if (entry->start == start && entry->end == end) { | ||
544 | rb_erase(&entry->rb, &memtype_rbroot); | ||
545 | list_del(&entry->nd); | ||
546 | kfree(entry); | ||
547 | err = 0; | ||
548 | break; | ||
549 | } else if (entry->start < start) { | ||
550 | break; | ||
551 | } | ||
552 | } | ||
553 | unlock_ret: | ||
554 | spin_unlock(&memtype_lock); | 359 | spin_unlock(&memtype_lock); |
555 | 360 | ||
556 | if (err) { | 361 | if (err) { |
@@ -583,10 +388,8 @@ static unsigned long lookup_memtype(u64 paddr) | |||
583 | 388 | ||
584 | if (pat_pagerange_is_ram(paddr, paddr + PAGE_SIZE)) { | 389 | if (pat_pagerange_is_ram(paddr, paddr + PAGE_SIZE)) { |
585 | struct page *page; | 390 | struct page *page; |
586 | spin_lock(&memtype_lock); | ||
587 | page = pfn_to_page(paddr >> PAGE_SHIFT); | 391 | page = pfn_to_page(paddr >> PAGE_SHIFT); |
588 | rettype = get_page_memtype(page); | 392 | rettype = get_page_memtype(page); |
589 | spin_unlock(&memtype_lock); | ||
590 | /* | 393 | /* |
591 | * -1 from get_page_memtype() implies RAM page is in its | 394 | * -1 from get_page_memtype() implies RAM page is in its |
592 | * default state and not reserved, and hence of type WB | 395 | * default state and not reserved, and hence of type WB |
@@ -599,7 +402,7 @@ static unsigned long lookup_memtype(u64 paddr) | |||
599 | 402 | ||
600 | spin_lock(&memtype_lock); | 403 | spin_lock(&memtype_lock); |
601 | 404 | ||
602 | entry = memtype_rb_search(&memtype_rbroot, paddr); | 405 | entry = rbt_memtype_lookup(paddr); |
603 | if (entry != NULL) | 406 | if (entry != NULL) |
604 | rettype = entry->type; | 407 | rettype = entry->type; |
605 | else | 408 | else |
@@ -936,29 +739,25 @@ EXPORT_SYMBOL_GPL(pgprot_writecombine); | |||
936 | 739 | ||
937 | #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT) | 740 | #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT) |
938 | 741 | ||
939 | /* get Nth element of the linked list */ | ||
940 | static struct memtype *memtype_get_idx(loff_t pos) | 742 | static struct memtype *memtype_get_idx(loff_t pos) |
941 | { | 743 | { |
942 | struct memtype *list_node, *print_entry; | 744 | struct memtype *print_entry; |
943 | int i = 1; | 745 | int ret; |
944 | 746 | ||
945 | print_entry = kmalloc(sizeof(struct memtype), GFP_KERNEL); | 747 | print_entry = kzalloc(sizeof(struct memtype), GFP_KERNEL); |
946 | if (!print_entry) | 748 | if (!print_entry) |
947 | return NULL; | 749 | return NULL; |
948 | 750 | ||
949 | spin_lock(&memtype_lock); | 751 | spin_lock(&memtype_lock); |
950 | list_for_each_entry(list_node, &memtype_list, nd) { | 752 | ret = rbt_memtype_copy_nth_element(print_entry, pos); |
951 | if (pos == i) { | ||
952 | *print_entry = *list_node; | ||
953 | spin_unlock(&memtype_lock); | ||
954 | return print_entry; | ||
955 | } | ||
956 | ++i; | ||
957 | } | ||
958 | spin_unlock(&memtype_lock); | 753 | spin_unlock(&memtype_lock); |
959 | kfree(print_entry); | ||
960 | 754 | ||
961 | return NULL; | 755 | if (!ret) { |
756 | return print_entry; | ||
757 | } else { | ||
758 | kfree(print_entry); | ||
759 | return NULL; | ||
760 | } | ||
962 | } | 761 | } |
963 | 762 | ||
964 | static void *memtype_seq_start(struct seq_file *seq, loff_t *pos) | 763 | static void *memtype_seq_start(struct seq_file *seq, loff_t *pos) |
diff --git a/arch/x86/mm/pat_internal.h b/arch/x86/mm/pat_internal.h new file mode 100644 index 000000000000..4f39eefa3e61 --- /dev/null +++ b/arch/x86/mm/pat_internal.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef __PAT_INTERNAL_H_ | ||
2 | #define __PAT_INTERNAL_H_ | ||
3 | |||
4 | extern int pat_debug_enable; | ||
5 | |||
6 | #define dprintk(fmt, arg...) \ | ||
7 | do { if (pat_debug_enable) printk(KERN_INFO fmt, ##arg); } while (0) | ||
8 | |||
9 | struct memtype { | ||
10 | u64 start; | ||
11 | u64 end; | ||
12 | u64 subtree_max_end; | ||
13 | unsigned long type; | ||
14 | struct rb_node rb; | ||
15 | }; | ||
16 | |||
17 | static inline char *cattr_name(unsigned long flags) | ||
18 | { | ||
19 | switch (flags & _PAGE_CACHE_MASK) { | ||
20 | case _PAGE_CACHE_UC: return "uncached"; | ||
21 | case _PAGE_CACHE_UC_MINUS: return "uncached-minus"; | ||
22 | case _PAGE_CACHE_WB: return "write-back"; | ||
23 | case _PAGE_CACHE_WC: return "write-combining"; | ||
24 | default: return "broken"; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | #ifdef CONFIG_X86_PAT | ||
29 | extern int rbt_memtype_check_insert(struct memtype *new, | ||
30 | unsigned long *new_type); | ||
31 | extern int rbt_memtype_erase(u64 start, u64 end); | ||
32 | extern struct memtype *rbt_memtype_lookup(u64 addr); | ||
33 | extern int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos); | ||
34 | #else | ||
35 | static inline int rbt_memtype_check_insert(struct memtype *new, | ||
36 | unsigned long *new_type) | ||
37 | { return 0; } | ||
38 | static inline int rbt_memtype_erase(u64 start, u64 end) | ||
39 | { return 0; } | ||
40 | static inline struct memtype *rbt_memtype_lookup(u64 addr) | ||
41 | { return NULL; } | ||
42 | static inline int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos) | ||
43 | { return 0; } | ||
44 | #endif | ||
45 | |||
46 | #endif /* __PAT_INTERNAL_H_ */ | ||
diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c new file mode 100644 index 000000000000..07de4cb8cc30 --- /dev/null +++ b/arch/x86/mm/pat_rbtree.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* | ||
2 | * Handle caching attributes in page tables (PAT) | ||
3 | * | ||
4 | * Authors: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> | ||
5 | * Suresh B Siddha <suresh.b.siddha@intel.com> | ||
6 | * | ||
7 | * Interval tree (augmented rbtree) used to store the PAT memory type | ||
8 | * reservations. | ||
9 | */ | ||
10 | |||
11 | #include <linux/seq_file.h> | ||
12 | #include <linux/debugfs.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/rbtree.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/gfp.h> | ||
18 | |||
19 | #include <asm/pgtable.h> | ||
20 | #include <asm/pat.h> | ||
21 | |||
22 | #include "pat_internal.h" | ||
23 | |||
24 | /* | ||
25 | * The memtype tree keeps track of memory type for specific | ||
26 | * physical memory areas. Without proper tracking, conflicting memory | ||
27 | * types in different mappings can cause CPU cache corruption. | ||
28 | * | ||
29 | * The tree is an interval tree (augmented rbtree) with tree ordered | ||
30 | * on starting address. Tree can contain multiple entries for | ||
31 | * different regions which overlap. All the aliases have the same | ||
32 | * cache attributes of course. | ||
33 | * | ||
34 | * memtype_lock protects the rbtree. | ||
35 | */ | ||
36 | |||
37 | static void memtype_rb_augment_cb(struct rb_node *node); | ||
38 | static struct rb_root memtype_rbroot = RB_AUGMENT_ROOT(&memtype_rb_augment_cb); | ||
39 | |||
40 | static int is_node_overlap(struct memtype *node, u64 start, u64 end) | ||
41 | { | ||
42 | if (node->start >= end || node->end <= start) | ||
43 | return 0; | ||
44 | |||
45 | return 1; | ||
46 | } | ||
47 | |||
48 | static u64 get_subtree_max_end(struct rb_node *node) | ||
49 | { | ||
50 | u64 ret = 0; | ||
51 | if (node) { | ||
52 | struct memtype *data = container_of(node, struct memtype, rb); | ||
53 | ret = data->subtree_max_end; | ||
54 | } | ||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | /* Update 'subtree_max_end' for a node, based on node and its children */ | ||
59 | static void update_node_max_end(struct rb_node *node) | ||
60 | { | ||
61 | struct memtype *data; | ||
62 | u64 max_end, child_max_end; | ||
63 | |||
64 | if (!node) | ||
65 | return; | ||
66 | |||
67 | data = container_of(node, struct memtype, rb); | ||
68 | max_end = data->end; | ||
69 | |||
70 | child_max_end = get_subtree_max_end(node->rb_right); | ||
71 | if (child_max_end > max_end) | ||
72 | max_end = child_max_end; | ||
73 | |||
74 | child_max_end = get_subtree_max_end(node->rb_left); | ||
75 | if (child_max_end > max_end) | ||
76 | max_end = child_max_end; | ||
77 | |||
78 | data->subtree_max_end = max_end; | ||
79 | } | ||
80 | |||
81 | /* Update 'subtree_max_end' for a node and all its ancestors */ | ||
82 | static void update_path_max_end(struct rb_node *node) | ||
83 | { | ||
84 | u64 old_max_end, new_max_end; | ||
85 | |||
86 | while (node) { | ||
87 | struct memtype *data = container_of(node, struct memtype, rb); | ||
88 | |||
89 | old_max_end = data->subtree_max_end; | ||
90 | update_node_max_end(node); | ||
91 | new_max_end = data->subtree_max_end; | ||
92 | |||
93 | if (new_max_end == old_max_end) | ||
94 | break; | ||
95 | |||
96 | node = rb_parent(node); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /* Find the first (lowest start addr) overlapping range from rb tree */ | ||
101 | static struct memtype *memtype_rb_lowest_match(struct rb_root *root, | ||
102 | u64 start, u64 end) | ||
103 | { | ||
104 | struct rb_node *node = root->rb_node; | ||
105 | struct memtype *last_lower = NULL; | ||
106 | |||
107 | while (node) { | ||
108 | struct memtype *data = container_of(node, struct memtype, rb); | ||
109 | |||
110 | if (get_subtree_max_end(node->rb_left) > start) { | ||
111 | /* Lowest overlap if any must be on left side */ | ||
112 | node = node->rb_left; | ||
113 | } else if (is_node_overlap(data, start, end)) { | ||
114 | last_lower = data; | ||
115 | break; | ||
116 | } else if (start >= data->start) { | ||
117 | /* Lowest overlap if any must be on right side */ | ||
118 | node = node->rb_right; | ||
119 | } else { | ||
120 | break; | ||
121 | } | ||
122 | } | ||
123 | return last_lower; /* Returns NULL if there is no overlap */ | ||
124 | } | ||
125 | |||
126 | static struct memtype *memtype_rb_exact_match(struct rb_root *root, | ||
127 | u64 start, u64 end) | ||
128 | { | ||
129 | struct memtype *match; | ||
130 | |||
131 | match = memtype_rb_lowest_match(root, start, end); | ||
132 | while (match != NULL && match->start < end) { | ||
133 | struct rb_node *node; | ||
134 | |||
135 | if (match->start == start && match->end == end) | ||
136 | return match; | ||
137 | |||
138 | node = rb_next(&match->rb); | ||
139 | if (node) | ||
140 | match = container_of(node, struct memtype, rb); | ||
141 | else | ||
142 | match = NULL; | ||
143 | } | ||
144 | |||
145 | return NULL; /* Returns NULL if there is no exact match */ | ||
146 | } | ||
147 | |||
148 | static int memtype_rb_check_conflict(struct rb_root *root, | ||
149 | u64 start, u64 end, | ||
150 | unsigned long reqtype, unsigned long *newtype) | ||
151 | { | ||
152 | struct rb_node *node; | ||
153 | struct memtype *match; | ||
154 | int found_type = reqtype; | ||
155 | |||
156 | match = memtype_rb_lowest_match(&memtype_rbroot, start, end); | ||
157 | if (match == NULL) | ||
158 | goto success; | ||
159 | |||
160 | if (match->type != found_type && newtype == NULL) | ||
161 | goto failure; | ||
162 | |||
163 | dprintk("Overlap at 0x%Lx-0x%Lx\n", match->start, match->end); | ||
164 | found_type = match->type; | ||
165 | |||
166 | node = rb_next(&match->rb); | ||
167 | while (node) { | ||
168 | match = container_of(node, struct memtype, rb); | ||
169 | |||
170 | if (match->start >= end) /* Checked all possible matches */ | ||
171 | goto success; | ||
172 | |||
173 | if (is_node_overlap(match, start, end) && | ||
174 | match->type != found_type) { | ||
175 | goto failure; | ||
176 | } | ||
177 | |||
178 | node = rb_next(&match->rb); | ||
179 | } | ||
180 | success: | ||
181 | if (newtype) | ||
182 | *newtype = found_type; | ||
183 | |||
184 | return 0; | ||
185 | |||
186 | failure: | ||
187 | printk(KERN_INFO "%s:%d conflicting memory types " | ||
188 | "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start, | ||
189 | end, cattr_name(found_type), cattr_name(match->type)); | ||
190 | return -EBUSY; | ||
191 | } | ||
192 | |||
193 | static void memtype_rb_augment_cb(struct rb_node *node) | ||
194 | { | ||
195 | if (node) | ||
196 | update_path_max_end(node); | ||
197 | } | ||
198 | |||
199 | static void memtype_rb_insert(struct rb_root *root, struct memtype *newdata) | ||
200 | { | ||
201 | struct rb_node **node = &(root->rb_node); | ||
202 | struct rb_node *parent = NULL; | ||
203 | |||
204 | while (*node) { | ||
205 | struct memtype *data = container_of(*node, struct memtype, rb); | ||
206 | |||
207 | parent = *node; | ||
208 | if (newdata->start <= data->start) | ||
209 | node = &((*node)->rb_left); | ||
210 | else if (newdata->start > data->start) | ||
211 | node = &((*node)->rb_right); | ||
212 | } | ||
213 | |||
214 | rb_link_node(&newdata->rb, parent, node); | ||
215 | rb_insert_color(&newdata->rb, root); | ||
216 | } | ||
217 | |||
218 | int rbt_memtype_check_insert(struct memtype *new, unsigned long *ret_type) | ||
219 | { | ||
220 | int err = 0; | ||
221 | |||
222 | err = memtype_rb_check_conflict(&memtype_rbroot, new->start, new->end, | ||
223 | new->type, ret_type); | ||
224 | |||
225 | if (!err) { | ||
226 | if (ret_type) | ||
227 | new->type = *ret_type; | ||
228 | |||
229 | memtype_rb_insert(&memtype_rbroot, new); | ||
230 | } | ||
231 | return err; | ||
232 | } | ||
233 | |||
234 | int rbt_memtype_erase(u64 start, u64 end) | ||
235 | { | ||
236 | struct memtype *data; | ||
237 | |||
238 | data = memtype_rb_exact_match(&memtype_rbroot, start, end); | ||
239 | if (!data) | ||
240 | return -EINVAL; | ||
241 | |||
242 | rb_erase(&data->rb, &memtype_rbroot); | ||
243 | return 0; | ||
244 | } | ||
245 | |||
246 | struct memtype *rbt_memtype_lookup(u64 addr) | ||
247 | { | ||
248 | struct memtype *data; | ||
249 | data = memtype_rb_lowest_match(&memtype_rbroot, addr, addr + PAGE_SIZE); | ||
250 | return data; | ||
251 | } | ||
252 | |||
253 | #if defined(CONFIG_DEBUG_FS) | ||
254 | int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos) | ||
255 | { | ||
256 | struct rb_node *node; | ||
257 | int i = 1; | ||
258 | |||
259 | node = rb_first(&memtype_rbroot); | ||
260 | while (node && pos != i) { | ||
261 | node = rb_next(node); | ||
262 | i++; | ||
263 | } | ||
264 | |||
265 | if (node) { /* pos == i */ | ||
266 | struct memtype *this = container_of(node, struct memtype, rb); | ||
267 | *out = *this; | ||
268 | return 0; | ||
269 | } else { | ||
270 | return 1; | ||
271 | } | ||
272 | } | ||
273 | #endif | ||
diff --git a/arch/x86/mm/srat_64.c b/arch/x86/mm/srat_64.c index 28c68762648f..f9897f7a9ef1 100644 --- a/arch/x86/mm/srat_64.c +++ b/arch/x86/mm/srat_64.c | |||
@@ -363,6 +363,54 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end) | |||
363 | for (i = 0; i < MAX_NUMNODES; i++) | 363 | for (i = 0; i < MAX_NUMNODES; i++) |
364 | cutoff_node(i, start, end); | 364 | cutoff_node(i, start, end); |
365 | 365 | ||
366 | /* | ||
367 | * Join together blocks on the same node, holes between | ||
368 | * which don't overlap with memory on other nodes. | ||
369 | */ | ||
370 | for (i = 0; i < num_node_memblks; ++i) { | ||
371 | int j, k; | ||
372 | |||
373 | for (j = i + 1; j < num_node_memblks; ++j) { | ||
374 | unsigned long start, end; | ||
375 | |||
376 | if (memblk_nodeid[i] != memblk_nodeid[j]) | ||
377 | continue; | ||
378 | start = min(node_memblk_range[i].end, | ||
379 | node_memblk_range[j].end); | ||
380 | end = max(node_memblk_range[i].start, | ||
381 | node_memblk_range[j].start); | ||
382 | for (k = 0; k < num_node_memblks; ++k) { | ||
383 | if (memblk_nodeid[i] == memblk_nodeid[k]) | ||
384 | continue; | ||
385 | if (start < node_memblk_range[k].end && | ||
386 | end > node_memblk_range[k].start) | ||
387 | break; | ||
388 | } | ||
389 | if (k < num_node_memblks) | ||
390 | continue; | ||
391 | start = min(node_memblk_range[i].start, | ||
392 | node_memblk_range[j].start); | ||
393 | end = max(node_memblk_range[i].end, | ||
394 | node_memblk_range[j].end); | ||
395 | printk(KERN_INFO "SRAT: Node %d " | ||
396 | "[%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n", | ||
397 | memblk_nodeid[i], | ||
398 | node_memblk_range[i].start, | ||
399 | node_memblk_range[i].end, | ||
400 | node_memblk_range[j].start, | ||
401 | node_memblk_range[j].end, | ||
402 | start, end); | ||
403 | node_memblk_range[i].start = start; | ||
404 | node_memblk_range[i].end = end; | ||
405 | k = --num_node_memblks - j; | ||
406 | memmove(memblk_nodeid + j, memblk_nodeid + j+1, | ||
407 | k * sizeof(*memblk_nodeid)); | ||
408 | memmove(node_memblk_range + j, node_memblk_range + j+1, | ||
409 | k * sizeof(*node_memblk_range)); | ||
410 | --j; | ||
411 | } | ||
412 | } | ||
413 | |||
366 | memnode_shift = compute_hash_shift(node_memblk_range, num_node_memblks, | 414 | memnode_shift = compute_hash_shift(node_memblk_range, num_node_memblks, |
367 | memblk_nodeid); | 415 | memblk_nodeid); |
368 | if (memnode_shift < 0) { | 416 | if (memnode_shift < 0) { |
@@ -461,7 +509,8 @@ void __init acpi_fake_nodes(const struct bootnode *fake_nodes, int num_nodes) | |||
461 | * node, it must now point to the fake node ID. | 509 | * node, it must now point to the fake node ID. |
462 | */ | 510 | */ |
463 | for (j = 0; j < MAX_LOCAL_APIC; j++) | 511 | for (j = 0; j < MAX_LOCAL_APIC; j++) |
464 | if (apicid_to_node[j] == nid) | 512 | if (apicid_to_node[j] == nid && |
513 | fake_apicid_to_node[j] == NUMA_NO_NODE) | ||
465 | fake_apicid_to_node[j] = i; | 514 | fake_apicid_to_node[j] = i; |
466 | } | 515 | } |
467 | for (i = 0; i < num_nodes; i++) | 516 | for (i = 0; i < num_nodes; i++) |
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c index 2c505ee71014..b28d2f1253bb 100644 --- a/arch/x86/oprofile/nmi_int.c +++ b/arch/x86/oprofile/nmi_int.c | |||
@@ -31,8 +31,9 @@ static struct op_x86_model_spec *model; | |||
31 | static DEFINE_PER_CPU(struct op_msrs, cpu_msrs); | 31 | static DEFINE_PER_CPU(struct op_msrs, cpu_msrs); |
32 | static DEFINE_PER_CPU(unsigned long, saved_lvtpc); | 32 | static DEFINE_PER_CPU(unsigned long, saved_lvtpc); |
33 | 33 | ||
34 | /* 0 == registered but off, 1 == registered and on */ | 34 | /* must be protected with get_online_cpus()/put_online_cpus(): */ |
35 | static int nmi_enabled = 0; | 35 | static int nmi_enabled; |
36 | static int ctr_running; | ||
36 | 37 | ||
37 | struct op_counter_config counter_config[OP_MAX_COUNTER]; | 38 | struct op_counter_config counter_config[OP_MAX_COUNTER]; |
38 | 39 | ||
@@ -61,12 +62,16 @@ static int profile_exceptions_notify(struct notifier_block *self, | |||
61 | { | 62 | { |
62 | struct die_args *args = (struct die_args *)data; | 63 | struct die_args *args = (struct die_args *)data; |
63 | int ret = NOTIFY_DONE; | 64 | int ret = NOTIFY_DONE; |
64 | int cpu = smp_processor_id(); | ||
65 | 65 | ||
66 | switch (val) { | 66 | switch (val) { |
67 | case DIE_NMI: | 67 | case DIE_NMI: |
68 | case DIE_NMI_IPI: | 68 | case DIE_NMI_IPI: |
69 | model->check_ctrs(args->regs, &per_cpu(cpu_msrs, cpu)); | 69 | if (ctr_running) |
70 | model->check_ctrs(args->regs, &__get_cpu_var(cpu_msrs)); | ||
71 | else if (!nmi_enabled) | ||
72 | break; | ||
73 | else | ||
74 | model->stop(&__get_cpu_var(cpu_msrs)); | ||
70 | ret = NOTIFY_STOP; | 75 | ret = NOTIFY_STOP; |
71 | break; | 76 | break; |
72 | default: | 77 | default: |
@@ -95,24 +100,36 @@ static void nmi_cpu_save_registers(struct op_msrs *msrs) | |||
95 | static void nmi_cpu_start(void *dummy) | 100 | static void nmi_cpu_start(void *dummy) |
96 | { | 101 | { |
97 | struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs); | 102 | struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs); |
98 | model->start(msrs); | 103 | if (!msrs->controls) |
104 | WARN_ON_ONCE(1); | ||
105 | else | ||
106 | model->start(msrs); | ||
99 | } | 107 | } |
100 | 108 | ||
101 | static int nmi_start(void) | 109 | static int nmi_start(void) |
102 | { | 110 | { |
111 | get_online_cpus(); | ||
103 | on_each_cpu(nmi_cpu_start, NULL, 1); | 112 | on_each_cpu(nmi_cpu_start, NULL, 1); |
113 | ctr_running = 1; | ||
114 | put_online_cpus(); | ||
104 | return 0; | 115 | return 0; |
105 | } | 116 | } |
106 | 117 | ||
107 | static void nmi_cpu_stop(void *dummy) | 118 | static void nmi_cpu_stop(void *dummy) |
108 | { | 119 | { |
109 | struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs); | 120 | struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs); |
110 | model->stop(msrs); | 121 | if (!msrs->controls) |
122 | WARN_ON_ONCE(1); | ||
123 | else | ||
124 | model->stop(msrs); | ||
111 | } | 125 | } |
112 | 126 | ||
113 | static void nmi_stop(void) | 127 | static void nmi_stop(void) |
114 | { | 128 | { |
129 | get_online_cpus(); | ||
115 | on_each_cpu(nmi_cpu_stop, NULL, 1); | 130 | on_each_cpu(nmi_cpu_stop, NULL, 1); |
131 | ctr_running = 0; | ||
132 | put_online_cpus(); | ||
116 | } | 133 | } |
117 | 134 | ||
118 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | 135 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
@@ -252,7 +269,10 @@ static int nmi_switch_event(void) | |||
252 | if (nmi_multiplex_on() < 0) | 269 | if (nmi_multiplex_on() < 0) |
253 | return -EINVAL; /* not necessary */ | 270 | return -EINVAL; /* not necessary */ |
254 | 271 | ||
255 | on_each_cpu(nmi_cpu_switch, NULL, 1); | 272 | get_online_cpus(); |
273 | if (ctr_running) | ||
274 | on_each_cpu(nmi_cpu_switch, NULL, 1); | ||
275 | put_online_cpus(); | ||
256 | 276 | ||
257 | return 0; | 277 | return 0; |
258 | } | 278 | } |
@@ -295,6 +315,7 @@ static void free_msrs(void) | |||
295 | kfree(per_cpu(cpu_msrs, i).controls); | 315 | kfree(per_cpu(cpu_msrs, i).controls); |
296 | per_cpu(cpu_msrs, i).controls = NULL; | 316 | per_cpu(cpu_msrs, i).controls = NULL; |
297 | } | 317 | } |
318 | nmi_shutdown_mux(); | ||
298 | } | 319 | } |
299 | 320 | ||
300 | static int allocate_msrs(void) | 321 | static int allocate_msrs(void) |
@@ -307,14 +328,21 @@ static int allocate_msrs(void) | |||
307 | per_cpu(cpu_msrs, i).counters = kzalloc(counters_size, | 328 | per_cpu(cpu_msrs, i).counters = kzalloc(counters_size, |
308 | GFP_KERNEL); | 329 | GFP_KERNEL); |
309 | if (!per_cpu(cpu_msrs, i).counters) | 330 | if (!per_cpu(cpu_msrs, i).counters) |
310 | return 0; | 331 | goto fail; |
311 | per_cpu(cpu_msrs, i).controls = kzalloc(controls_size, | 332 | per_cpu(cpu_msrs, i).controls = kzalloc(controls_size, |
312 | GFP_KERNEL); | 333 | GFP_KERNEL); |
313 | if (!per_cpu(cpu_msrs, i).controls) | 334 | if (!per_cpu(cpu_msrs, i).controls) |
314 | return 0; | 335 | goto fail; |
315 | } | 336 | } |
316 | 337 | ||
338 | if (!nmi_setup_mux()) | ||
339 | goto fail; | ||
340 | |||
317 | return 1; | 341 | return 1; |
342 | |||
343 | fail: | ||
344 | free_msrs(); | ||
345 | return 0; | ||
318 | } | 346 | } |
319 | 347 | ||
320 | static void nmi_cpu_setup(void *dummy) | 348 | static void nmi_cpu_setup(void *dummy) |
@@ -336,49 +364,6 @@ static struct notifier_block profile_exceptions_nb = { | |||
336 | .priority = 2 | 364 | .priority = 2 |
337 | }; | 365 | }; |
338 | 366 | ||
339 | static int nmi_setup(void) | ||
340 | { | ||
341 | int err = 0; | ||
342 | int cpu; | ||
343 | |||
344 | if (!allocate_msrs()) | ||
345 | err = -ENOMEM; | ||
346 | else if (!nmi_setup_mux()) | ||
347 | err = -ENOMEM; | ||
348 | else | ||
349 | err = register_die_notifier(&profile_exceptions_nb); | ||
350 | |||
351 | if (err) { | ||
352 | free_msrs(); | ||
353 | nmi_shutdown_mux(); | ||
354 | return err; | ||
355 | } | ||
356 | |||
357 | /* We need to serialize save and setup for HT because the subset | ||
358 | * of msrs are distinct for save and setup operations | ||
359 | */ | ||
360 | |||
361 | /* Assume saved/restored counters are the same on all CPUs */ | ||
362 | model->fill_in_addresses(&per_cpu(cpu_msrs, 0)); | ||
363 | for_each_possible_cpu(cpu) { | ||
364 | if (!cpu) | ||
365 | continue; | ||
366 | |||
367 | memcpy(per_cpu(cpu_msrs, cpu).counters, | ||
368 | per_cpu(cpu_msrs, 0).counters, | ||
369 | sizeof(struct op_msr) * model->num_counters); | ||
370 | |||
371 | memcpy(per_cpu(cpu_msrs, cpu).controls, | ||
372 | per_cpu(cpu_msrs, 0).controls, | ||
373 | sizeof(struct op_msr) * model->num_controls); | ||
374 | |||
375 | mux_clone(cpu); | ||
376 | } | ||
377 | on_each_cpu(nmi_cpu_setup, NULL, 1); | ||
378 | nmi_enabled = 1; | ||
379 | return 0; | ||
380 | } | ||
381 | |||
382 | static void nmi_cpu_restore_registers(struct op_msrs *msrs) | 367 | static void nmi_cpu_restore_registers(struct op_msrs *msrs) |
383 | { | 368 | { |
384 | struct op_msr *counters = msrs->counters; | 369 | struct op_msr *counters = msrs->counters; |
@@ -412,20 +397,24 @@ static void nmi_cpu_shutdown(void *dummy) | |||
412 | apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu)); | 397 | apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu)); |
413 | apic_write(APIC_LVTERR, v); | 398 | apic_write(APIC_LVTERR, v); |
414 | nmi_cpu_restore_registers(msrs); | 399 | nmi_cpu_restore_registers(msrs); |
400 | if (model->cpu_down) | ||
401 | model->cpu_down(); | ||
415 | } | 402 | } |
416 | 403 | ||
417 | static void nmi_shutdown(void) | 404 | static void nmi_cpu_up(void *dummy) |
418 | { | 405 | { |
419 | struct op_msrs *msrs; | 406 | if (nmi_enabled) |
407 | nmi_cpu_setup(dummy); | ||
408 | if (ctr_running) | ||
409 | nmi_cpu_start(dummy); | ||
410 | } | ||
420 | 411 | ||
421 | nmi_enabled = 0; | 412 | static void nmi_cpu_down(void *dummy) |
422 | on_each_cpu(nmi_cpu_shutdown, NULL, 1); | 413 | { |
423 | unregister_die_notifier(&profile_exceptions_nb); | 414 | if (ctr_running) |
424 | nmi_shutdown_mux(); | 415 | nmi_cpu_stop(dummy); |
425 | msrs = &get_cpu_var(cpu_msrs); | 416 | if (nmi_enabled) |
426 | model->shutdown(msrs); | 417 | nmi_cpu_shutdown(dummy); |
427 | free_msrs(); | ||
428 | put_cpu_var(cpu_msrs); | ||
429 | } | 418 | } |
430 | 419 | ||
431 | static int nmi_create_files(struct super_block *sb, struct dentry *root) | 420 | static int nmi_create_files(struct super_block *sb, struct dentry *root) |
@@ -457,7 +446,6 @@ static int nmi_create_files(struct super_block *sb, struct dentry *root) | |||
457 | return 0; | 446 | return 0; |
458 | } | 447 | } |
459 | 448 | ||
460 | #ifdef CONFIG_SMP | ||
461 | static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action, | 449 | static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action, |
462 | void *data) | 450 | void *data) |
463 | { | 451 | { |
@@ -465,10 +453,10 @@ static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action, | |||
465 | switch (action) { | 453 | switch (action) { |
466 | case CPU_DOWN_FAILED: | 454 | case CPU_DOWN_FAILED: |
467 | case CPU_ONLINE: | 455 | case CPU_ONLINE: |
468 | smp_call_function_single(cpu, nmi_cpu_start, NULL, 0); | 456 | smp_call_function_single(cpu, nmi_cpu_up, NULL, 0); |
469 | break; | 457 | break; |
470 | case CPU_DOWN_PREPARE: | 458 | case CPU_DOWN_PREPARE: |
471 | smp_call_function_single(cpu, nmi_cpu_stop, NULL, 1); | 459 | smp_call_function_single(cpu, nmi_cpu_down, NULL, 1); |
472 | break; | 460 | break; |
473 | } | 461 | } |
474 | return NOTIFY_DONE; | 462 | return NOTIFY_DONE; |
@@ -477,7 +465,75 @@ static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action, | |||
477 | static struct notifier_block oprofile_cpu_nb = { | 465 | static struct notifier_block oprofile_cpu_nb = { |
478 | .notifier_call = oprofile_cpu_notifier | 466 | .notifier_call = oprofile_cpu_notifier |
479 | }; | 467 | }; |
480 | #endif | 468 | |
469 | static int nmi_setup(void) | ||
470 | { | ||
471 | int err = 0; | ||
472 | int cpu; | ||
473 | |||
474 | if (!allocate_msrs()) | ||
475 | return -ENOMEM; | ||
476 | |||
477 | /* We need to serialize save and setup for HT because the subset | ||
478 | * of msrs are distinct for save and setup operations | ||
479 | */ | ||
480 | |||
481 | /* Assume saved/restored counters are the same on all CPUs */ | ||
482 | err = model->fill_in_addresses(&per_cpu(cpu_msrs, 0)); | ||
483 | if (err) | ||
484 | goto fail; | ||
485 | |||
486 | for_each_possible_cpu(cpu) { | ||
487 | if (!cpu) | ||
488 | continue; | ||
489 | |||
490 | memcpy(per_cpu(cpu_msrs, cpu).counters, | ||
491 | per_cpu(cpu_msrs, 0).counters, | ||
492 | sizeof(struct op_msr) * model->num_counters); | ||
493 | |||
494 | memcpy(per_cpu(cpu_msrs, cpu).controls, | ||
495 | per_cpu(cpu_msrs, 0).controls, | ||
496 | sizeof(struct op_msr) * model->num_controls); | ||
497 | |||
498 | mux_clone(cpu); | ||
499 | } | ||
500 | |||
501 | nmi_enabled = 0; | ||
502 | ctr_running = 0; | ||
503 | barrier(); | ||
504 | err = register_die_notifier(&profile_exceptions_nb); | ||
505 | if (err) | ||
506 | goto fail; | ||
507 | |||
508 | get_online_cpus(); | ||
509 | register_cpu_notifier(&oprofile_cpu_nb); | ||
510 | on_each_cpu(nmi_cpu_setup, NULL, 1); | ||
511 | nmi_enabled = 1; | ||
512 | put_online_cpus(); | ||
513 | |||
514 | return 0; | ||
515 | fail: | ||
516 | free_msrs(); | ||
517 | return err; | ||
518 | } | ||
519 | |||
520 | static void nmi_shutdown(void) | ||
521 | { | ||
522 | struct op_msrs *msrs; | ||
523 | |||
524 | get_online_cpus(); | ||
525 | unregister_cpu_notifier(&oprofile_cpu_nb); | ||
526 | on_each_cpu(nmi_cpu_shutdown, NULL, 1); | ||
527 | nmi_enabled = 0; | ||
528 | ctr_running = 0; | ||
529 | put_online_cpus(); | ||
530 | barrier(); | ||
531 | unregister_die_notifier(&profile_exceptions_nb); | ||
532 | msrs = &get_cpu_var(cpu_msrs); | ||
533 | model->shutdown(msrs); | ||
534 | free_msrs(); | ||
535 | put_cpu_var(cpu_msrs); | ||
536 | } | ||
481 | 537 | ||
482 | #ifdef CONFIG_PM | 538 | #ifdef CONFIG_PM |
483 | 539 | ||
@@ -687,9 +743,6 @@ int __init op_nmi_init(struct oprofile_operations *ops) | |||
687 | return -ENODEV; | 743 | return -ENODEV; |
688 | } | 744 | } |
689 | 745 | ||
690 | #ifdef CONFIG_SMP | ||
691 | register_cpu_notifier(&oprofile_cpu_nb); | ||
692 | #endif | ||
693 | /* default values, can be overwritten by model */ | 746 | /* default values, can be overwritten by model */ |
694 | ops->create_files = nmi_create_files; | 747 | ops->create_files = nmi_create_files; |
695 | ops->setup = nmi_setup; | 748 | ops->setup = nmi_setup; |
@@ -716,12 +769,6 @@ int __init op_nmi_init(struct oprofile_operations *ops) | |||
716 | 769 | ||
717 | void op_nmi_exit(void) | 770 | void op_nmi_exit(void) |
718 | { | 771 | { |
719 | if (using_nmi) { | 772 | if (using_nmi) |
720 | exit_sysfs(); | 773 | exit_sysfs(); |
721 | #ifdef CONFIG_SMP | ||
722 | unregister_cpu_notifier(&oprofile_cpu_nb); | ||
723 | #endif | ||
724 | } | ||
725 | if (model->exit) | ||
726 | model->exit(); | ||
727 | } | 774 | } |
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c index 090cbbec7dbd..b67a6b5aa8d4 100644 --- a/arch/x86/oprofile/op_model_amd.c +++ b/arch/x86/oprofile/op_model_amd.c | |||
@@ -30,13 +30,10 @@ | |||
30 | #include "op_counter.h" | 30 | #include "op_counter.h" |
31 | 31 | ||
32 | #define NUM_COUNTERS 4 | 32 | #define NUM_COUNTERS 4 |
33 | #define NUM_CONTROLS 4 | ||
34 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | 33 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX |
35 | #define NUM_VIRT_COUNTERS 32 | 34 | #define NUM_VIRT_COUNTERS 32 |
36 | #define NUM_VIRT_CONTROLS 32 | ||
37 | #else | 35 | #else |
38 | #define NUM_VIRT_COUNTERS NUM_COUNTERS | 36 | #define NUM_VIRT_COUNTERS NUM_COUNTERS |
39 | #define NUM_VIRT_CONTROLS NUM_CONTROLS | ||
40 | #endif | 37 | #endif |
41 | 38 | ||
42 | #define OP_EVENT_MASK 0x0FFF | 39 | #define OP_EVENT_MASK 0x0FFF |
@@ -105,102 +102,6 @@ static u32 get_ibs_caps(void) | |||
105 | return ibs_caps; | 102 | return ibs_caps; |
106 | } | 103 | } |
107 | 104 | ||
108 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | ||
109 | |||
110 | static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, | ||
111 | struct op_msrs const * const msrs) | ||
112 | { | ||
113 | u64 val; | ||
114 | int i; | ||
115 | |||
116 | /* enable active counters */ | ||
117 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
118 | int virt = op_x86_phys_to_virt(i); | ||
119 | if (!reset_value[virt]) | ||
120 | continue; | ||
121 | rdmsrl(msrs->controls[i].addr, val); | ||
122 | val &= model->reserved; | ||
123 | val |= op_x86_get_ctrl(model, &counter_config[virt]); | ||
124 | wrmsrl(msrs->controls[i].addr, val); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | #endif | ||
129 | |||
130 | /* functions for op_amd_spec */ | ||
131 | |||
132 | static void op_amd_fill_in_addresses(struct op_msrs * const msrs) | ||
133 | { | ||
134 | int i; | ||
135 | |||
136 | for (i = 0; i < NUM_COUNTERS; i++) { | ||
137 | if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) | ||
138 | msrs->counters[i].addr = MSR_K7_PERFCTR0 + i; | ||
139 | } | ||
140 | |||
141 | for (i = 0; i < NUM_CONTROLS; i++) { | ||
142 | if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) | ||
143 | msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | ||
148 | struct op_msrs const * const msrs) | ||
149 | { | ||
150 | u64 val; | ||
151 | int i; | ||
152 | |||
153 | /* setup reset_value */ | ||
154 | for (i = 0; i < NUM_VIRT_COUNTERS; ++i) { | ||
155 | if (counter_config[i].enabled | ||
156 | && msrs->counters[op_x86_virt_to_phys(i)].addr) | ||
157 | reset_value[i] = counter_config[i].count; | ||
158 | else | ||
159 | reset_value[i] = 0; | ||
160 | } | ||
161 | |||
162 | /* clear all counters */ | ||
163 | for (i = 0; i < NUM_CONTROLS; ++i) { | ||
164 | if (unlikely(!msrs->controls[i].addr)) { | ||
165 | if (counter_config[i].enabled && !smp_processor_id()) | ||
166 | /* | ||
167 | * counter is reserved, this is on all | ||
168 | * cpus, so report only for cpu #0 | ||
169 | */ | ||
170 | op_x86_warn_reserved(i); | ||
171 | continue; | ||
172 | } | ||
173 | rdmsrl(msrs->controls[i].addr, val); | ||
174 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | ||
175 | op_x86_warn_in_use(i); | ||
176 | val &= model->reserved; | ||
177 | wrmsrl(msrs->controls[i].addr, val); | ||
178 | } | ||
179 | |||
180 | /* avoid a false detection of ctr overflows in NMI handler */ | ||
181 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
182 | if (unlikely(!msrs->counters[i].addr)) | ||
183 | continue; | ||
184 | wrmsrl(msrs->counters[i].addr, -1LL); | ||
185 | } | ||
186 | |||
187 | /* enable active counters */ | ||
188 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
189 | int virt = op_x86_phys_to_virt(i); | ||
190 | if (!reset_value[virt]) | ||
191 | continue; | ||
192 | |||
193 | /* setup counter registers */ | ||
194 | wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]); | ||
195 | |||
196 | /* setup control registers */ | ||
197 | rdmsrl(msrs->controls[i].addr, val); | ||
198 | val &= model->reserved; | ||
199 | val |= op_x86_get_ctrl(model, &counter_config[virt]); | ||
200 | wrmsrl(msrs->controls[i].addr, val); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /* | 105 | /* |
205 | * 16-bit Linear Feedback Shift Register (LFSR) | 106 | * 16-bit Linear Feedback Shift Register (LFSR) |
206 | * | 107 | * |
@@ -365,6 +266,125 @@ static void op_amd_stop_ibs(void) | |||
365 | wrmsrl(MSR_AMD64_IBSOPCTL, 0); | 266 | wrmsrl(MSR_AMD64_IBSOPCTL, 0); |
366 | } | 267 | } |
367 | 268 | ||
269 | #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX | ||
270 | |||
271 | static void op_mux_switch_ctrl(struct op_x86_model_spec const *model, | ||
272 | struct op_msrs const * const msrs) | ||
273 | { | ||
274 | u64 val; | ||
275 | int i; | ||
276 | |||
277 | /* enable active counters */ | ||
278 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
279 | int virt = op_x86_phys_to_virt(i); | ||
280 | if (!reset_value[virt]) | ||
281 | continue; | ||
282 | rdmsrl(msrs->controls[i].addr, val); | ||
283 | val &= model->reserved; | ||
284 | val |= op_x86_get_ctrl(model, &counter_config[virt]); | ||
285 | wrmsrl(msrs->controls[i].addr, val); | ||
286 | } | ||
287 | } | ||
288 | |||
289 | #endif | ||
290 | |||
291 | /* functions for op_amd_spec */ | ||
292 | |||
293 | static void op_amd_shutdown(struct op_msrs const * const msrs) | ||
294 | { | ||
295 | int i; | ||
296 | |||
297 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
298 | if (!msrs->counters[i].addr) | ||
299 | continue; | ||
300 | release_perfctr_nmi(MSR_K7_PERFCTR0 + i); | ||
301 | release_evntsel_nmi(MSR_K7_EVNTSEL0 + i); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | static int op_amd_fill_in_addresses(struct op_msrs * const msrs) | ||
306 | { | ||
307 | int i; | ||
308 | |||
309 | for (i = 0; i < NUM_COUNTERS; i++) { | ||
310 | if (!reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i)) | ||
311 | goto fail; | ||
312 | if (!reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) { | ||
313 | release_perfctr_nmi(MSR_K7_PERFCTR0 + i); | ||
314 | goto fail; | ||
315 | } | ||
316 | /* both registers must be reserved */ | ||
317 | msrs->counters[i].addr = MSR_K7_PERFCTR0 + i; | ||
318 | msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i; | ||
319 | continue; | ||
320 | fail: | ||
321 | if (!counter_config[i].enabled) | ||
322 | continue; | ||
323 | op_x86_warn_reserved(i); | ||
324 | op_amd_shutdown(msrs); | ||
325 | return -EBUSY; | ||
326 | } | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | static void op_amd_setup_ctrs(struct op_x86_model_spec const *model, | ||
332 | struct op_msrs const * const msrs) | ||
333 | { | ||
334 | u64 val; | ||
335 | int i; | ||
336 | |||
337 | /* setup reset_value */ | ||
338 | for (i = 0; i < NUM_VIRT_COUNTERS; ++i) { | ||
339 | if (counter_config[i].enabled | ||
340 | && msrs->counters[op_x86_virt_to_phys(i)].addr) | ||
341 | reset_value[i] = counter_config[i].count; | ||
342 | else | ||
343 | reset_value[i] = 0; | ||
344 | } | ||
345 | |||
346 | /* clear all counters */ | ||
347 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
348 | if (!msrs->controls[i].addr) | ||
349 | continue; | ||
350 | rdmsrl(msrs->controls[i].addr, val); | ||
351 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | ||
352 | op_x86_warn_in_use(i); | ||
353 | val &= model->reserved; | ||
354 | wrmsrl(msrs->controls[i].addr, val); | ||
355 | /* | ||
356 | * avoid a false detection of ctr overflows in NMI | ||
357 | * handler | ||
358 | */ | ||
359 | wrmsrl(msrs->counters[i].addr, -1LL); | ||
360 | } | ||
361 | |||
362 | /* enable active counters */ | ||
363 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
364 | int virt = op_x86_phys_to_virt(i); | ||
365 | if (!reset_value[virt]) | ||
366 | continue; | ||
367 | |||
368 | /* setup counter registers */ | ||
369 | wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]); | ||
370 | |||
371 | /* setup control registers */ | ||
372 | rdmsrl(msrs->controls[i].addr, val); | ||
373 | val &= model->reserved; | ||
374 | val |= op_x86_get_ctrl(model, &counter_config[virt]); | ||
375 | wrmsrl(msrs->controls[i].addr, val); | ||
376 | } | ||
377 | |||
378 | if (ibs_caps) | ||
379 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0); | ||
380 | } | ||
381 | |||
382 | static void op_amd_cpu_shutdown(void) | ||
383 | { | ||
384 | if (ibs_caps) | ||
385 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); | ||
386 | } | ||
387 | |||
368 | static int op_amd_check_ctrs(struct pt_regs * const regs, | 388 | static int op_amd_check_ctrs(struct pt_regs * const regs, |
369 | struct op_msrs const * const msrs) | 389 | struct op_msrs const * const msrs) |
370 | { | 390 | { |
@@ -425,42 +445,16 @@ static void op_amd_stop(struct op_msrs const * const msrs) | |||
425 | op_amd_stop_ibs(); | 445 | op_amd_stop_ibs(); |
426 | } | 446 | } |
427 | 447 | ||
428 | static void op_amd_shutdown(struct op_msrs const * const msrs) | 448 | static int __init_ibs_nmi(void) |
429 | { | ||
430 | int i; | ||
431 | |||
432 | for (i = 0; i < NUM_COUNTERS; ++i) { | ||
433 | if (msrs->counters[i].addr) | ||
434 | release_perfctr_nmi(MSR_K7_PERFCTR0 + i); | ||
435 | } | ||
436 | for (i = 0; i < NUM_CONTROLS; ++i) { | ||
437 | if (msrs->controls[i].addr) | ||
438 | release_evntsel_nmi(MSR_K7_EVNTSEL0 + i); | ||
439 | } | ||
440 | } | ||
441 | |||
442 | static u8 ibs_eilvt_off; | ||
443 | |||
444 | static inline void apic_init_ibs_nmi_per_cpu(void *arg) | ||
445 | { | ||
446 | ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0); | ||
447 | } | ||
448 | |||
449 | static inline void apic_clear_ibs_nmi_per_cpu(void *arg) | ||
450 | { | ||
451 | setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); | ||
452 | } | ||
453 | |||
454 | static int init_ibs_nmi(void) | ||
455 | { | 449 | { |
456 | #define IBSCTL_LVTOFFSETVAL (1 << 8) | 450 | #define IBSCTL_LVTOFFSETVAL (1 << 8) |
457 | #define IBSCTL 0x1cc | 451 | #define IBSCTL 0x1cc |
458 | struct pci_dev *cpu_cfg; | 452 | struct pci_dev *cpu_cfg; |
459 | int nodes; | 453 | int nodes; |
460 | u32 value = 0; | 454 | u32 value = 0; |
455 | u8 ibs_eilvt_off; | ||
461 | 456 | ||
462 | /* per CPU setup */ | 457 | ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1); |
463 | on_each_cpu(apic_init_ibs_nmi_per_cpu, NULL, 1); | ||
464 | 458 | ||
465 | nodes = 0; | 459 | nodes = 0; |
466 | cpu_cfg = NULL; | 460 | cpu_cfg = NULL; |
@@ -490,22 +484,15 @@ static int init_ibs_nmi(void) | |||
490 | return 0; | 484 | return 0; |
491 | } | 485 | } |
492 | 486 | ||
493 | /* uninitialize the APIC for the IBS interrupts if needed */ | ||
494 | static void clear_ibs_nmi(void) | ||
495 | { | ||
496 | if (ibs_caps) | ||
497 | on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1); | ||
498 | } | ||
499 | |||
500 | /* initialize the APIC for the IBS interrupts if available */ | 487 | /* initialize the APIC for the IBS interrupts if available */ |
501 | static void ibs_init(void) | 488 | static void init_ibs(void) |
502 | { | 489 | { |
503 | ibs_caps = get_ibs_caps(); | 490 | ibs_caps = get_ibs_caps(); |
504 | 491 | ||
505 | if (!ibs_caps) | 492 | if (!ibs_caps) |
506 | return; | 493 | return; |
507 | 494 | ||
508 | if (init_ibs_nmi()) { | 495 | if (__init_ibs_nmi()) { |
509 | ibs_caps = 0; | 496 | ibs_caps = 0; |
510 | return; | 497 | return; |
511 | } | 498 | } |
@@ -514,14 +501,6 @@ static void ibs_init(void) | |||
514 | (unsigned)ibs_caps); | 501 | (unsigned)ibs_caps); |
515 | } | 502 | } |
516 | 503 | ||
517 | static void ibs_exit(void) | ||
518 | { | ||
519 | if (!ibs_caps) | ||
520 | return; | ||
521 | |||
522 | clear_ibs_nmi(); | ||
523 | } | ||
524 | |||
525 | static int (*create_arch_files)(struct super_block *sb, struct dentry *root); | 504 | static int (*create_arch_files)(struct super_block *sb, struct dentry *root); |
526 | 505 | ||
527 | static int setup_ibs_files(struct super_block *sb, struct dentry *root) | 506 | static int setup_ibs_files(struct super_block *sb, struct dentry *root) |
@@ -570,27 +549,22 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root) | |||
570 | 549 | ||
571 | static int op_amd_init(struct oprofile_operations *ops) | 550 | static int op_amd_init(struct oprofile_operations *ops) |
572 | { | 551 | { |
573 | ibs_init(); | 552 | init_ibs(); |
574 | create_arch_files = ops->create_files; | 553 | create_arch_files = ops->create_files; |
575 | ops->create_files = setup_ibs_files; | 554 | ops->create_files = setup_ibs_files; |
576 | return 0; | 555 | return 0; |
577 | } | 556 | } |
578 | 557 | ||
579 | static void op_amd_exit(void) | ||
580 | { | ||
581 | ibs_exit(); | ||
582 | } | ||
583 | |||
584 | struct op_x86_model_spec op_amd_spec = { | 558 | struct op_x86_model_spec op_amd_spec = { |
585 | .num_counters = NUM_COUNTERS, | 559 | .num_counters = NUM_COUNTERS, |
586 | .num_controls = NUM_CONTROLS, | 560 | .num_controls = NUM_COUNTERS, |
587 | .num_virt_counters = NUM_VIRT_COUNTERS, | 561 | .num_virt_counters = NUM_VIRT_COUNTERS, |
588 | .reserved = MSR_AMD_EVENTSEL_RESERVED, | 562 | .reserved = MSR_AMD_EVENTSEL_RESERVED, |
589 | .event_mask = OP_EVENT_MASK, | 563 | .event_mask = OP_EVENT_MASK, |
590 | .init = op_amd_init, | 564 | .init = op_amd_init, |
591 | .exit = op_amd_exit, | ||
592 | .fill_in_addresses = &op_amd_fill_in_addresses, | 565 | .fill_in_addresses = &op_amd_fill_in_addresses, |
593 | .setup_ctrs = &op_amd_setup_ctrs, | 566 | .setup_ctrs = &op_amd_setup_ctrs, |
567 | .cpu_down = &op_amd_cpu_shutdown, | ||
594 | .check_ctrs = &op_amd_check_ctrs, | 568 | .check_ctrs = &op_amd_check_ctrs, |
595 | .start = &op_amd_start, | 569 | .start = &op_amd_start, |
596 | .stop = &op_amd_stop, | 570 | .stop = &op_amd_stop, |
diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c index e6a160a4684a..182558dd5515 100644 --- a/arch/x86/oprofile/op_model_p4.c +++ b/arch/x86/oprofile/op_model_p4.c | |||
@@ -385,8 +385,26 @@ static unsigned int get_stagger(void) | |||
385 | 385 | ||
386 | static unsigned long reset_value[NUM_COUNTERS_NON_HT]; | 386 | static unsigned long reset_value[NUM_COUNTERS_NON_HT]; |
387 | 387 | ||
388 | static void p4_shutdown(struct op_msrs const * const msrs) | ||
389 | { | ||
390 | int i; | ||
388 | 391 | ||
389 | static void p4_fill_in_addresses(struct op_msrs * const msrs) | 392 | for (i = 0; i < num_counters; ++i) { |
393 | if (msrs->counters[i].addr) | ||
394 | release_perfctr_nmi(msrs->counters[i].addr); | ||
395 | } | ||
396 | /* | ||
397 | * some of the control registers are specially reserved in | ||
398 | * conjunction with the counter registers (hence the starting offset). | ||
399 | * This saves a few bits. | ||
400 | */ | ||
401 | for (i = num_counters; i < num_controls; ++i) { | ||
402 | if (msrs->controls[i].addr) | ||
403 | release_evntsel_nmi(msrs->controls[i].addr); | ||
404 | } | ||
405 | } | ||
406 | |||
407 | static int p4_fill_in_addresses(struct op_msrs * const msrs) | ||
390 | { | 408 | { |
391 | unsigned int i; | 409 | unsigned int i; |
392 | unsigned int addr, cccraddr, stag; | 410 | unsigned int addr, cccraddr, stag; |
@@ -468,6 +486,18 @@ static void p4_fill_in_addresses(struct op_msrs * const msrs) | |||
468 | msrs->controls[i++].addr = MSR_P4_CRU_ESCR5; | 486 | msrs->controls[i++].addr = MSR_P4_CRU_ESCR5; |
469 | } | 487 | } |
470 | } | 488 | } |
489 | |||
490 | for (i = 0; i < num_counters; ++i) { | ||
491 | if (!counter_config[i].enabled) | ||
492 | continue; | ||
493 | if (msrs->controls[i].addr) | ||
494 | continue; | ||
495 | op_x86_warn_reserved(i); | ||
496 | p4_shutdown(msrs); | ||
497 | return -EBUSY; | ||
498 | } | ||
499 | |||
500 | return 0; | ||
471 | } | 501 | } |
472 | 502 | ||
473 | 503 | ||
@@ -668,26 +698,6 @@ static void p4_stop(struct op_msrs const * const msrs) | |||
668 | } | 698 | } |
669 | } | 699 | } |
670 | 700 | ||
671 | static void p4_shutdown(struct op_msrs const * const msrs) | ||
672 | { | ||
673 | int i; | ||
674 | |||
675 | for (i = 0; i < num_counters; ++i) { | ||
676 | if (msrs->counters[i].addr) | ||
677 | release_perfctr_nmi(msrs->counters[i].addr); | ||
678 | } | ||
679 | /* | ||
680 | * some of the control registers are specially reserved in | ||
681 | * conjunction with the counter registers (hence the starting offset). | ||
682 | * This saves a few bits. | ||
683 | */ | ||
684 | for (i = num_counters; i < num_controls; ++i) { | ||
685 | if (msrs->controls[i].addr) | ||
686 | release_evntsel_nmi(msrs->controls[i].addr); | ||
687 | } | ||
688 | } | ||
689 | |||
690 | |||
691 | #ifdef CONFIG_SMP | 701 | #ifdef CONFIG_SMP |
692 | struct op_x86_model_spec op_p4_ht2_spec = { | 702 | struct op_x86_model_spec op_p4_ht2_spec = { |
693 | .num_counters = NUM_COUNTERS_HT2, | 703 | .num_counters = NUM_COUNTERS_HT2, |
diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c index 2bf90fafa7b5..d769cda54082 100644 --- a/arch/x86/oprofile/op_model_ppro.c +++ b/arch/x86/oprofile/op_model_ppro.c | |||
@@ -30,19 +30,46 @@ static int counter_width = 32; | |||
30 | 30 | ||
31 | static u64 *reset_value; | 31 | static u64 *reset_value; |
32 | 32 | ||
33 | static void ppro_fill_in_addresses(struct op_msrs * const msrs) | 33 | static void ppro_shutdown(struct op_msrs const * const msrs) |
34 | { | 34 | { |
35 | int i; | 35 | int i; |
36 | 36 | ||
37 | for (i = 0; i < num_counters; i++) { | 37 | for (i = 0; i < num_counters; ++i) { |
38 | if (reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i)) | 38 | if (!msrs->counters[i].addr) |
39 | msrs->counters[i].addr = MSR_P6_PERFCTR0 + i; | 39 | continue; |
40 | release_perfctr_nmi(MSR_P6_PERFCTR0 + i); | ||
41 | release_evntsel_nmi(MSR_P6_EVNTSEL0 + i); | ||
42 | } | ||
43 | if (reset_value) { | ||
44 | kfree(reset_value); | ||
45 | reset_value = NULL; | ||
40 | } | 46 | } |
47 | } | ||
48 | |||
49 | static int ppro_fill_in_addresses(struct op_msrs * const msrs) | ||
50 | { | ||
51 | int i; | ||
41 | 52 | ||
42 | for (i = 0; i < num_counters; i++) { | 53 | for (i = 0; i < num_counters; i++) { |
43 | if (reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i)) | 54 | if (!reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i)) |
44 | msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i; | 55 | goto fail; |
56 | if (!reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i)) { | ||
57 | release_perfctr_nmi(MSR_P6_PERFCTR0 + i); | ||
58 | goto fail; | ||
59 | } | ||
60 | /* both registers must be reserved */ | ||
61 | msrs->counters[i].addr = MSR_P6_PERFCTR0 + i; | ||
62 | msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i; | ||
63 | continue; | ||
64 | fail: | ||
65 | if (!counter_config[i].enabled) | ||
66 | continue; | ||
67 | op_x86_warn_reserved(i); | ||
68 | ppro_shutdown(msrs); | ||
69 | return -EBUSY; | ||
45 | } | 70 | } |
71 | |||
72 | return 0; | ||
46 | } | 73 | } |
47 | 74 | ||
48 | 75 | ||
@@ -78,26 +105,17 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model, | |||
78 | 105 | ||
79 | /* clear all counters */ | 106 | /* clear all counters */ |
80 | for (i = 0; i < num_counters; ++i) { | 107 | for (i = 0; i < num_counters; ++i) { |
81 | if (unlikely(!msrs->controls[i].addr)) { | 108 | if (!msrs->controls[i].addr) |
82 | if (counter_config[i].enabled && !smp_processor_id()) | ||
83 | /* | ||
84 | * counter is reserved, this is on all | ||
85 | * cpus, so report only for cpu #0 | ||
86 | */ | ||
87 | op_x86_warn_reserved(i); | ||
88 | continue; | 109 | continue; |
89 | } | ||
90 | rdmsrl(msrs->controls[i].addr, val); | 110 | rdmsrl(msrs->controls[i].addr, val); |
91 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) | 111 | if (val & ARCH_PERFMON_EVENTSEL_ENABLE) |
92 | op_x86_warn_in_use(i); | 112 | op_x86_warn_in_use(i); |
93 | val &= model->reserved; | 113 | val &= model->reserved; |
94 | wrmsrl(msrs->controls[i].addr, val); | 114 | wrmsrl(msrs->controls[i].addr, val); |
95 | } | 115 | /* |
96 | 116 | * avoid a false detection of ctr overflows in NMI * | |
97 | /* avoid a false detection of ctr overflows in NMI handler */ | 117 | * handler |
98 | for (i = 0; i < num_counters; ++i) { | 118 | */ |
99 | if (unlikely(!msrs->counters[i].addr)) | ||
100 | continue; | ||
101 | wrmsrl(msrs->counters[i].addr, -1LL); | 119 | wrmsrl(msrs->counters[i].addr, -1LL); |
102 | } | 120 | } |
103 | 121 | ||
@@ -189,25 +207,6 @@ static void ppro_stop(struct op_msrs const * const msrs) | |||
189 | } | 207 | } |
190 | } | 208 | } |
191 | 209 | ||
192 | static void ppro_shutdown(struct op_msrs const * const msrs) | ||
193 | { | ||
194 | int i; | ||
195 | |||
196 | for (i = 0; i < num_counters; ++i) { | ||
197 | if (msrs->counters[i].addr) | ||
198 | release_perfctr_nmi(MSR_P6_PERFCTR0 + i); | ||
199 | } | ||
200 | for (i = 0; i < num_counters; ++i) { | ||
201 | if (msrs->controls[i].addr) | ||
202 | release_evntsel_nmi(MSR_P6_EVNTSEL0 + i); | ||
203 | } | ||
204 | if (reset_value) { | ||
205 | kfree(reset_value); | ||
206 | reset_value = NULL; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | |||
211 | struct op_x86_model_spec op_ppro_spec = { | 210 | struct op_x86_model_spec op_ppro_spec = { |
212 | .num_counters = 2, | 211 | .num_counters = 2, |
213 | .num_controls = 2, | 212 | .num_controls = 2, |
@@ -239,11 +238,11 @@ static void arch_perfmon_setup_counters(void) | |||
239 | if (eax.split.version_id == 0 && current_cpu_data.x86 == 6 && | 238 | if (eax.split.version_id == 0 && current_cpu_data.x86 == 6 && |
240 | current_cpu_data.x86_model == 15) { | 239 | current_cpu_data.x86_model == 15) { |
241 | eax.split.version_id = 2; | 240 | eax.split.version_id = 2; |
242 | eax.split.num_events = 2; | 241 | eax.split.num_counters = 2; |
243 | eax.split.bit_width = 40; | 242 | eax.split.bit_width = 40; |
244 | } | 243 | } |
245 | 244 | ||
246 | num_counters = eax.split.num_events; | 245 | num_counters = eax.split.num_counters; |
247 | 246 | ||
248 | op_arch_perfmon_spec.num_counters = num_counters; | 247 | op_arch_perfmon_spec.num_counters = num_counters; |
249 | op_arch_perfmon_spec.num_controls = num_counters; | 248 | op_arch_perfmon_spec.num_controls = num_counters; |
diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h index ff82a755edd4..89017fa1fd63 100644 --- a/arch/x86/oprofile/op_x86_model.h +++ b/arch/x86/oprofile/op_x86_model.h | |||
@@ -40,10 +40,10 @@ struct op_x86_model_spec { | |||
40 | u64 reserved; | 40 | u64 reserved; |
41 | u16 event_mask; | 41 | u16 event_mask; |
42 | int (*init)(struct oprofile_operations *ops); | 42 | int (*init)(struct oprofile_operations *ops); |
43 | void (*exit)(void); | 43 | int (*fill_in_addresses)(struct op_msrs * const msrs); |
44 | void (*fill_in_addresses)(struct op_msrs * const msrs); | ||
45 | void (*setup_ctrs)(struct op_x86_model_spec const *model, | 44 | void (*setup_ctrs)(struct op_x86_model_spec const *model, |
46 | struct op_msrs const * const msrs); | 45 | struct op_msrs const * const msrs); |
46 | void (*cpu_down)(void); | ||
47 | int (*check_ctrs)(struct pt_regs * const regs, | 47 | int (*check_ctrs)(struct pt_regs * const regs, |
48 | struct op_msrs const * const msrs); | 48 | struct op_msrs const * const msrs); |
49 | void (*start)(struct op_msrs const * const msrs); | 49 | void (*start)(struct op_msrs const * const msrs); |
diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c index 8bf2fcb88d04..7ef3a2735df3 100644 --- a/arch/x86/pci/mrst.c +++ b/arch/x86/pci/mrst.c | |||
@@ -109,7 +109,7 @@ static int pci_device_update_fixed(struct pci_bus *bus, unsigned int devfn, | |||
109 | decode++; | 109 | decode++; |
110 | decode = ~(decode - 1); | 110 | decode = ~(decode - 1); |
111 | } else { | 111 | } else { |
112 | decode = ~0; | 112 | decode = 0; |
113 | } | 113 | } |
114 | 114 | ||
115 | /* | 115 | /* |
@@ -247,6 +247,10 @@ static void __devinit pci_fixed_bar_fixup(struct pci_dev *dev) | |||
247 | u32 size; | 247 | u32 size; |
248 | int i; | 248 | int i; |
249 | 249 | ||
250 | /* Must have extended configuration space */ | ||
251 | if (dev->cfg_size < PCIE_CAP_OFFSET + 4) | ||
252 | return; | ||
253 | |||
250 | /* Fixup the BAR sizes for fixed BAR devices and make them unmoveable */ | 254 | /* Fixup the BAR sizes for fixed BAR devices and make them unmoveable */ |
251 | offset = fixed_bar_cap(dev->bus, dev->devfn); | 255 | offset = fixed_bar_cap(dev->bus, dev->devfn); |
252 | if (!offset || PCI_DEVFN(2, 0) == dev->devfn || | 256 | if (!offset || PCI_DEVFN(2, 0) == dev->devfn || |
diff --git a/arch/xtensa/include/asm/atomic.h b/arch/xtensa/include/asm/atomic.h index 22d6dde42619..a96a0619d0b7 100644 --- a/arch/xtensa/include/asm/atomic.h +++ b/arch/xtensa/include/asm/atomic.h | |||
@@ -46,7 +46,7 @@ | |||
46 | * | 46 | * |
47 | * Atomically reads the value of @v. | 47 | * Atomically reads the value of @v. |
48 | */ | 48 | */ |
49 | #define atomic_read(v) ((v)->counter) | 49 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * atomic_set - set atomic variable | 52 | * atomic_set - set atomic variable |
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c index b0a71ecee682..e4804fb05e23 100644 --- a/drivers/acpi/pci_irq.c +++ b/drivers/acpi/pci_irq.c | |||
@@ -401,11 +401,13 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
401 | * driver reported one, then use it. Exit in any case. | 401 | * driver reported one, then use it. Exit in any case. |
402 | */ | 402 | */ |
403 | if (gsi < 0) { | 403 | if (gsi < 0) { |
404 | u32 dev_gsi; | ||
404 | dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin)); | 405 | dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin)); |
405 | /* Interrupt Line values above 0xF are forbidden */ | 406 | /* Interrupt Line values above 0xF are forbidden */ |
406 | if (dev->irq > 0 && (dev->irq <= 0xF)) { | 407 | if (dev->irq > 0 && (dev->irq <= 0xF) && |
407 | printk(" - using IRQ %d\n", dev->irq); | 408 | (acpi_isa_irq_to_gsi(dev->irq, &dev_gsi) == 0)) { |
408 | acpi_register_gsi(&dev->dev, dev->irq, | 409 | printk(" - using ISA IRQ %d\n", dev->irq); |
410 | acpi_register_gsi(&dev->dev, dev_gsi, | ||
409 | ACPI_LEVEL_SENSITIVE, | 411 | ACPI_LEVEL_SENSITIVE, |
410 | ACPI_ACTIVE_LOW); | 412 | ACPI_ACTIVE_LOW); |
411 | return 0; | 413 | return 0; |
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c index 8ad4ffea6920..6e6b6a11b3ce 100644 --- a/drivers/base/iommu.c +++ b/drivers/base/iommu.c | |||
@@ -80,20 +80,6 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev) | |||
80 | } | 80 | } |
81 | EXPORT_SYMBOL_GPL(iommu_detach_device); | 81 | EXPORT_SYMBOL_GPL(iommu_detach_device); |
82 | 82 | ||
83 | int iommu_map_range(struct iommu_domain *domain, unsigned long iova, | ||
84 | phys_addr_t paddr, size_t size, int prot) | ||
85 | { | ||
86 | return iommu_ops->map(domain, iova, paddr, size, prot); | ||
87 | } | ||
88 | EXPORT_SYMBOL_GPL(iommu_map_range); | ||
89 | |||
90 | void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova, | ||
91 | size_t size) | ||
92 | { | ||
93 | iommu_ops->unmap(domain, iova, size); | ||
94 | } | ||
95 | EXPORT_SYMBOL_GPL(iommu_unmap_range); | ||
96 | |||
97 | phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, | 83 | phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
98 | unsigned long iova) | 84 | unsigned long iova) |
99 | { | 85 | { |
@@ -107,3 +93,32 @@ int iommu_domain_has_cap(struct iommu_domain *domain, | |||
107 | return iommu_ops->domain_has_cap(domain, cap); | 93 | return iommu_ops->domain_has_cap(domain, cap); |
108 | } | 94 | } |
109 | EXPORT_SYMBOL_GPL(iommu_domain_has_cap); | 95 | EXPORT_SYMBOL_GPL(iommu_domain_has_cap); |
96 | |||
97 | int iommu_map(struct iommu_domain *domain, unsigned long iova, | ||
98 | phys_addr_t paddr, int gfp_order, int prot) | ||
99 | { | ||
100 | unsigned long invalid_mask; | ||
101 | size_t size; | ||
102 | |||
103 | size = 0x1000UL << gfp_order; | ||
104 | invalid_mask = size - 1; | ||
105 | |||
106 | BUG_ON((iova | paddr) & invalid_mask); | ||
107 | |||
108 | return iommu_ops->map(domain, iova, paddr, gfp_order, prot); | ||
109 | } | ||
110 | EXPORT_SYMBOL_GPL(iommu_map); | ||
111 | |||
112 | int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order) | ||
113 | { | ||
114 | unsigned long invalid_mask; | ||
115 | size_t size; | ||
116 | |||
117 | size = 0x1000UL << gfp_order; | ||
118 | invalid_mask = size - 1; | ||
119 | |||
120 | BUG_ON(iova & invalid_mask); | ||
121 | |||
122 | return iommu_ops->unmap(domain, iova, gfp_order); | ||
123 | } | ||
124 | EXPORT_SYMBOL_GPL(iommu_unmap); | ||
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 4b4b565c835f..c5fbe198fbdb 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -187,7 +187,7 @@ EXPORT_SYMBOL_GPL(platform_device_alloc); | |||
187 | * released. | 187 | * released. |
188 | */ | 188 | */ |
189 | int platform_device_add_resources(struct platform_device *pdev, | 189 | int platform_device_add_resources(struct platform_device *pdev, |
190 | struct resource *res, unsigned int num) | 190 | const struct resource *res, unsigned int num) |
191 | { | 191 | { |
192 | struct resource *r; | 192 | struct resource *r; |
193 | 193 | ||
@@ -367,7 +367,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister); | |||
367 | */ | 367 | */ |
368 | struct platform_device *platform_device_register_simple(const char *name, | 368 | struct platform_device *platform_device_register_simple(const char *name, |
369 | int id, | 369 | int id, |
370 | struct resource *res, | 370 | const struct resource *res, |
371 | unsigned int num) | 371 | unsigned int num) |
372 | { | 372 | { |
373 | struct platform_device *pdev; | 373 | struct platform_device *pdev; |
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index 0182a22c423a..832798aa14f6 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c | |||
@@ -66,6 +66,7 @@ | |||
66 | #include <linux/blkdev.h> | 66 | #include <linux/blkdev.h> |
67 | #include <linux/elevator.h> | 67 | #include <linux/elevator.h> |
68 | #include <linux/interrupt.h> | 68 | #include <linux/interrupt.h> |
69 | #include <linux/platform_device.h> | ||
69 | 70 | ||
70 | #include <asm/setup.h> | 71 | #include <asm/setup.h> |
71 | #include <asm/uaccess.h> | 72 | #include <asm/uaccess.h> |
@@ -1696,34 +1697,18 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data) | |||
1696 | return get_disk(unit[drive].gendisk); | 1697 | return get_disk(unit[drive].gendisk); |
1697 | } | 1698 | } |
1698 | 1699 | ||
1699 | static int __init amiga_floppy_init(void) | 1700 | static int __init amiga_floppy_probe(struct platform_device *pdev) |
1700 | { | 1701 | { |
1701 | int i, ret; | 1702 | int i, ret; |
1702 | 1703 | ||
1703 | if (!MACH_IS_AMIGA) | ||
1704 | return -ENODEV; | ||
1705 | |||
1706 | if (!AMIGAHW_PRESENT(AMI_FLOPPY)) | ||
1707 | return -ENODEV; | ||
1708 | |||
1709 | if (register_blkdev(FLOPPY_MAJOR,"fd")) | 1704 | if (register_blkdev(FLOPPY_MAJOR,"fd")) |
1710 | return -EBUSY; | 1705 | return -EBUSY; |
1711 | 1706 | ||
1712 | /* | ||
1713 | * We request DSKPTR, DSKLEN and DSKDATA only, because the other | ||
1714 | * floppy registers are too spreaded over the custom register space | ||
1715 | */ | ||
1716 | ret = -EBUSY; | ||
1717 | if (!request_mem_region(CUSTOM_PHYSADDR+0x20, 8, "amiflop [Paula]")) { | ||
1718 | printk("fd: cannot get floppy registers\n"); | ||
1719 | goto out_blkdev; | ||
1720 | } | ||
1721 | |||
1722 | ret = -ENOMEM; | 1707 | ret = -ENOMEM; |
1723 | if ((raw_buf = (char *)amiga_chip_alloc (RAW_BUF_SIZE, "Floppy")) == | 1708 | if ((raw_buf = (char *)amiga_chip_alloc (RAW_BUF_SIZE, "Floppy")) == |
1724 | NULL) { | 1709 | NULL) { |
1725 | printk("fd: cannot get chip mem buffer\n"); | 1710 | printk("fd: cannot get chip mem buffer\n"); |
1726 | goto out_memregion; | 1711 | goto out_blkdev; |
1727 | } | 1712 | } |
1728 | 1713 | ||
1729 | ret = -EBUSY; | 1714 | ret = -EBUSY; |
@@ -1792,18 +1777,13 @@ out_irq2: | |||
1792 | free_irq(IRQ_AMIGA_DSKBLK, NULL); | 1777 | free_irq(IRQ_AMIGA_DSKBLK, NULL); |
1793 | out_irq: | 1778 | out_irq: |
1794 | amiga_chip_free(raw_buf); | 1779 | amiga_chip_free(raw_buf); |
1795 | out_memregion: | ||
1796 | release_mem_region(CUSTOM_PHYSADDR+0x20, 8); | ||
1797 | out_blkdev: | 1780 | out_blkdev: |
1798 | unregister_blkdev(FLOPPY_MAJOR,"fd"); | 1781 | unregister_blkdev(FLOPPY_MAJOR,"fd"); |
1799 | return ret; | 1782 | return ret; |
1800 | } | 1783 | } |
1801 | 1784 | ||
1802 | module_init(amiga_floppy_init); | ||
1803 | #ifdef MODULE | ||
1804 | |||
1805 | #if 0 /* not safe to unload */ | 1785 | #if 0 /* not safe to unload */ |
1806 | void cleanup_module(void) | 1786 | static int __exit amiga_floppy_remove(struct platform_device *pdev) |
1807 | { | 1787 | { |
1808 | int i; | 1788 | int i; |
1809 | 1789 | ||
@@ -1820,12 +1800,25 @@ void cleanup_module(void) | |||
1820 | custom.dmacon = DMAF_DISK; /* disable DMA */ | 1800 | custom.dmacon = DMAF_DISK; /* disable DMA */ |
1821 | amiga_chip_free(raw_buf); | 1801 | amiga_chip_free(raw_buf); |
1822 | blk_cleanup_queue(floppy_queue); | 1802 | blk_cleanup_queue(floppy_queue); |
1823 | release_mem_region(CUSTOM_PHYSADDR+0x20, 8); | ||
1824 | unregister_blkdev(FLOPPY_MAJOR, "fd"); | 1803 | unregister_blkdev(FLOPPY_MAJOR, "fd"); |
1825 | } | 1804 | } |
1826 | #endif | 1805 | #endif |
1827 | 1806 | ||
1828 | #else | 1807 | static struct platform_driver amiga_floppy_driver = { |
1808 | .driver = { | ||
1809 | .name = "amiga-floppy", | ||
1810 | .owner = THIS_MODULE, | ||
1811 | }, | ||
1812 | }; | ||
1813 | |||
1814 | static int __init amiga_floppy_init(void) | ||
1815 | { | ||
1816 | return platform_driver_probe(&amiga_floppy_driver, amiga_floppy_probe); | ||
1817 | } | ||
1818 | |||
1819 | module_init(amiga_floppy_init); | ||
1820 | |||
1821 | #ifndef MODULE | ||
1829 | static int __init amiga_floppy_setup (char *str) | 1822 | static int __init amiga_floppy_setup (char *str) |
1830 | { | 1823 | { |
1831 | int n; | 1824 | int n; |
@@ -1840,3 +1833,5 @@ static int __init amiga_floppy_setup (char *str) | |||
1840 | 1833 | ||
1841 | __setup("floppy=", amiga_floppy_setup); | 1834 | __setup("floppy=", amiga_floppy_setup); |
1842 | #endif | 1835 | #endif |
1836 | |||
1837 | MODULE_ALIAS("platform:amiga-floppy"); | ||
diff --git a/drivers/block/hd.c b/drivers/block/hd.c index 034e6dfc878c..81c78b3ce2df 100644 --- a/drivers/block/hd.c +++ b/drivers/block/hd.c | |||
@@ -164,12 +164,12 @@ unsigned long read_timer(void) | |||
164 | unsigned long t, flags; | 164 | unsigned long t, flags; |
165 | int i; | 165 | int i; |
166 | 166 | ||
167 | spin_lock_irqsave(&i8253_lock, flags); | 167 | raw_spin_lock_irqsave(&i8253_lock, flags); |
168 | t = jiffies * 11932; | 168 | t = jiffies * 11932; |
169 | outb_p(0, 0x43); | 169 | outb_p(0, 0x43); |
170 | i = inb_p(0x40); | 170 | i = inb_p(0x40); |
171 | i |= inb(0x40) << 8; | 171 | i |= inb(0x40) << 8; |
172 | spin_unlock_irqrestore(&i8253_lock, flags); | 172 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
173 | return(t - i); | 173 | return(t - i); |
174 | } | 174 | } |
175 | #endif | 175 | #endif |
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c index 8dfd24721a82..78a62ebe75c7 100644 --- a/drivers/char/serial167.c +++ b/drivers/char/serial167.c | |||
@@ -627,7 +627,6 @@ static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id) | |||
627 | char data; | 627 | char data; |
628 | int char_count; | 628 | int char_count; |
629 | int save_cnt; | 629 | int save_cnt; |
630 | int len; | ||
631 | 630 | ||
632 | /* determine the channel and change to that context */ | 631 | /* determine the channel and change to that context */ |
633 | channel = (u_short) (base_addr[CyLICR] >> 2); | 632 | channel = (u_short) (base_addr[CyLICR] >> 2); |
@@ -1528,7 +1527,6 @@ static int | |||
1528 | cy_ioctl(struct tty_struct *tty, struct file *file, | 1527 | cy_ioctl(struct tty_struct *tty, struct file *file, |
1529 | unsigned int cmd, unsigned long arg) | 1528 | unsigned int cmd, unsigned long arg) |
1530 | { | 1529 | { |
1531 | unsigned long val; | ||
1532 | struct cyclades_port *info = tty->driver_data; | 1530 | struct cyclades_port *info = tty->driver_data; |
1533 | int ret_val = 0; | 1531 | int ret_val = 0; |
1534 | void __user *argp = (void __user *)arg; | 1532 | void __user *argp = (void __user *)arg; |
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index 59de2525d303..d4e8b213a462 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c | |||
@@ -289,7 +289,7 @@ static struct sysrq_key_op sysrq_showstate_blocked_op = { | |||
289 | 289 | ||
290 | static void sysrq_ftrace_dump(int key, struct tty_struct *tty) | 290 | static void sysrq_ftrace_dump(int key, struct tty_struct *tty) |
291 | { | 291 | { |
292 | ftrace_dump(); | 292 | ftrace_dump(DUMP_ALL); |
293 | } | 293 | } |
294 | static struct sysrq_key_op sysrq_ftrace_dump_op = { | 294 | static struct sysrq_key_op sysrq_ftrace_dump_op = { |
295 | .handler = sysrq_ftrace_dump, | 295 | .handler = sysrq_ftrace_dump, |
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 6da962c9b21c..d71f0fc34b46 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -1875,6 +1875,7 @@ got_driver: | |||
1875 | */ | 1875 | */ |
1876 | if (filp->f_op == &hung_up_tty_fops) | 1876 | if (filp->f_op == &hung_up_tty_fops) |
1877 | filp->f_op = &tty_fops; | 1877 | filp->f_op = &tty_fops; |
1878 | unlock_kernel(); | ||
1878 | goto retry_open; | 1879 | goto retry_open; |
1879 | } | 1880 | } |
1880 | unlock_kernel(); | 1881 | unlock_kernel(); |
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 75d293eeb3ee..063b2184caf5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -662,32 +662,20 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) | |||
662 | return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); | 662 | return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); |
663 | } | 663 | } |
664 | 664 | ||
665 | #define define_one_ro(_name) \ | 665 | cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400); |
666 | static struct freq_attr _name = \ | 666 | cpufreq_freq_attr_ro(cpuinfo_min_freq); |
667 | __ATTR(_name, 0444, show_##_name, NULL) | 667 | cpufreq_freq_attr_ro(cpuinfo_max_freq); |
668 | 668 | cpufreq_freq_attr_ro(cpuinfo_transition_latency); | |
669 | #define define_one_ro0400(_name) \ | 669 | cpufreq_freq_attr_ro(scaling_available_governors); |
670 | static struct freq_attr _name = \ | 670 | cpufreq_freq_attr_ro(scaling_driver); |
671 | __ATTR(_name, 0400, show_##_name, NULL) | 671 | cpufreq_freq_attr_ro(scaling_cur_freq); |
672 | 672 | cpufreq_freq_attr_ro(bios_limit); | |
673 | #define define_one_rw(_name) \ | 673 | cpufreq_freq_attr_ro(related_cpus); |
674 | static struct freq_attr _name = \ | 674 | cpufreq_freq_attr_ro(affected_cpus); |
675 | __ATTR(_name, 0644, show_##_name, store_##_name) | 675 | cpufreq_freq_attr_rw(scaling_min_freq); |
676 | 676 | cpufreq_freq_attr_rw(scaling_max_freq); | |
677 | define_one_ro0400(cpuinfo_cur_freq); | 677 | cpufreq_freq_attr_rw(scaling_governor); |
678 | define_one_ro(cpuinfo_min_freq); | 678 | cpufreq_freq_attr_rw(scaling_setspeed); |
679 | define_one_ro(cpuinfo_max_freq); | ||
680 | define_one_ro(cpuinfo_transition_latency); | ||
681 | define_one_ro(scaling_available_governors); | ||
682 | define_one_ro(scaling_driver); | ||
683 | define_one_ro(scaling_cur_freq); | ||
684 | define_one_ro(bios_limit); | ||
685 | define_one_ro(related_cpus); | ||
686 | define_one_ro(affected_cpus); | ||
687 | define_one_rw(scaling_min_freq); | ||
688 | define_one_rw(scaling_max_freq); | ||
689 | define_one_rw(scaling_governor); | ||
690 | define_one_rw(scaling_setspeed); | ||
691 | 679 | ||
692 | static struct attribute *default_attrs[] = { | 680 | static struct attribute *default_attrs[] = { |
693 | &cpuinfo_min_freq.attr, | 681 | &cpuinfo_min_freq.attr, |
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c index 3a147874a465..526bfbf69611 100644 --- a/drivers/cpufreq/cpufreq_conservative.c +++ b/drivers/cpufreq/cpufreq_conservative.c | |||
@@ -178,12 +178,8 @@ static ssize_t show_sampling_rate_min(struct kobject *kobj, | |||
178 | return sprintf(buf, "%u\n", min_sampling_rate); | 178 | return sprintf(buf, "%u\n", min_sampling_rate); |
179 | } | 179 | } |
180 | 180 | ||
181 | #define define_one_ro(_name) \ | 181 | define_one_global_ro(sampling_rate_max); |
182 | static struct global_attr _name = \ | 182 | define_one_global_ro(sampling_rate_min); |
183 | __ATTR(_name, 0444, show_##_name, NULL) | ||
184 | |||
185 | define_one_ro(sampling_rate_max); | ||
186 | define_one_ro(sampling_rate_min); | ||
187 | 183 | ||
188 | /* cpufreq_conservative Governor Tunables */ | 184 | /* cpufreq_conservative Governor Tunables */ |
189 | #define show_one(file_name, object) \ | 185 | #define show_one(file_name, object) \ |
@@ -221,12 +217,8 @@ show_one_old(freq_step); | |||
221 | show_one_old(sampling_rate_min); | 217 | show_one_old(sampling_rate_min); |
222 | show_one_old(sampling_rate_max); | 218 | show_one_old(sampling_rate_max); |
223 | 219 | ||
224 | #define define_one_ro_old(object, _name) \ | 220 | cpufreq_freq_attr_ro_old(sampling_rate_min); |
225 | static struct freq_attr object = \ | 221 | cpufreq_freq_attr_ro_old(sampling_rate_max); |
226 | __ATTR(_name, 0444, show_##_name##_old, NULL) | ||
227 | |||
228 | define_one_ro_old(sampling_rate_min_old, sampling_rate_min); | ||
229 | define_one_ro_old(sampling_rate_max_old, sampling_rate_max); | ||
230 | 222 | ||
231 | /*** delete after deprecation time ***/ | 223 | /*** delete after deprecation time ***/ |
232 | 224 | ||
@@ -364,16 +356,12 @@ static ssize_t store_freq_step(struct kobject *a, struct attribute *b, | |||
364 | return count; | 356 | return count; |
365 | } | 357 | } |
366 | 358 | ||
367 | #define define_one_rw(_name) \ | 359 | define_one_global_rw(sampling_rate); |
368 | static struct global_attr _name = \ | 360 | define_one_global_rw(sampling_down_factor); |
369 | __ATTR(_name, 0644, show_##_name, store_##_name) | 361 | define_one_global_rw(up_threshold); |
370 | 362 | define_one_global_rw(down_threshold); | |
371 | define_one_rw(sampling_rate); | 363 | define_one_global_rw(ignore_nice_load); |
372 | define_one_rw(sampling_down_factor); | 364 | define_one_global_rw(freq_step); |
373 | define_one_rw(up_threshold); | ||
374 | define_one_rw(down_threshold); | ||
375 | define_one_rw(ignore_nice_load); | ||
376 | define_one_rw(freq_step); | ||
377 | 365 | ||
378 | static struct attribute *dbs_attributes[] = { | 366 | static struct attribute *dbs_attributes[] = { |
379 | &sampling_rate_max.attr, | 367 | &sampling_rate_max.attr, |
@@ -409,16 +397,12 @@ write_one_old(down_threshold); | |||
409 | write_one_old(ignore_nice_load); | 397 | write_one_old(ignore_nice_load); |
410 | write_one_old(freq_step); | 398 | write_one_old(freq_step); |
411 | 399 | ||
412 | #define define_one_rw_old(object, _name) \ | 400 | cpufreq_freq_attr_rw_old(sampling_rate); |
413 | static struct freq_attr object = \ | 401 | cpufreq_freq_attr_rw_old(sampling_down_factor); |
414 | __ATTR(_name, 0644, show_##_name##_old, store_##_name##_old) | 402 | cpufreq_freq_attr_rw_old(up_threshold); |
415 | 403 | cpufreq_freq_attr_rw_old(down_threshold); | |
416 | define_one_rw_old(sampling_rate_old, sampling_rate); | 404 | cpufreq_freq_attr_rw_old(ignore_nice_load); |
417 | define_one_rw_old(sampling_down_factor_old, sampling_down_factor); | 405 | cpufreq_freq_attr_rw_old(freq_step); |
418 | define_one_rw_old(up_threshold_old, up_threshold); | ||
419 | define_one_rw_old(down_threshold_old, down_threshold); | ||
420 | define_one_rw_old(ignore_nice_load_old, ignore_nice_load); | ||
421 | define_one_rw_old(freq_step_old, freq_step); | ||
422 | 406 | ||
423 | static struct attribute *dbs_attributes_old[] = { | 407 | static struct attribute *dbs_attributes_old[] = { |
424 | &sampling_rate_max_old.attr, | 408 | &sampling_rate_max_old.attr, |
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c index bd444dc93cf2..e1314212d8d4 100644 --- a/drivers/cpufreq/cpufreq_ondemand.c +++ b/drivers/cpufreq/cpufreq_ondemand.c | |||
@@ -73,6 +73,7 @@ enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE}; | |||
73 | 73 | ||
74 | struct cpu_dbs_info_s { | 74 | struct cpu_dbs_info_s { |
75 | cputime64_t prev_cpu_idle; | 75 | cputime64_t prev_cpu_idle; |
76 | cputime64_t prev_cpu_iowait; | ||
76 | cputime64_t prev_cpu_wall; | 77 | cputime64_t prev_cpu_wall; |
77 | cputime64_t prev_cpu_nice; | 78 | cputime64_t prev_cpu_nice; |
78 | struct cpufreq_policy *cur_policy; | 79 | struct cpufreq_policy *cur_policy; |
@@ -108,6 +109,7 @@ static struct dbs_tuners { | |||
108 | unsigned int down_differential; | 109 | unsigned int down_differential; |
109 | unsigned int ignore_nice; | 110 | unsigned int ignore_nice; |
110 | unsigned int powersave_bias; | 111 | unsigned int powersave_bias; |
112 | unsigned int io_is_busy; | ||
111 | } dbs_tuners_ins = { | 113 | } dbs_tuners_ins = { |
112 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, | 114 | .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, |
113 | .down_differential = DEF_FREQUENCY_DOWN_DIFFERENTIAL, | 115 | .down_differential = DEF_FREQUENCY_DOWN_DIFFERENTIAL, |
@@ -148,6 +150,16 @@ static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall) | |||
148 | return idle_time; | 150 | return idle_time; |
149 | } | 151 | } |
150 | 152 | ||
153 | static inline cputime64_t get_cpu_iowait_time(unsigned int cpu, cputime64_t *wall) | ||
154 | { | ||
155 | u64 iowait_time = get_cpu_iowait_time_us(cpu, wall); | ||
156 | |||
157 | if (iowait_time == -1ULL) | ||
158 | return 0; | ||
159 | |||
160 | return iowait_time; | ||
161 | } | ||
162 | |||
151 | /* | 163 | /* |
152 | * Find right freq to be set now with powersave_bias on. | 164 | * Find right freq to be set now with powersave_bias on. |
153 | * Returns the freq_hi to be used right now and will set freq_hi_jiffies, | 165 | * Returns the freq_hi to be used right now and will set freq_hi_jiffies, |
@@ -234,12 +246,8 @@ static ssize_t show_sampling_rate_min(struct kobject *kobj, | |||
234 | return sprintf(buf, "%u\n", min_sampling_rate); | 246 | return sprintf(buf, "%u\n", min_sampling_rate); |
235 | } | 247 | } |
236 | 248 | ||
237 | #define define_one_ro(_name) \ | 249 | define_one_global_ro(sampling_rate_max); |
238 | static struct global_attr _name = \ | 250 | define_one_global_ro(sampling_rate_min); |
239 | __ATTR(_name, 0444, show_##_name, NULL) | ||
240 | |||
241 | define_one_ro(sampling_rate_max); | ||
242 | define_one_ro(sampling_rate_min); | ||
243 | 251 | ||
244 | /* cpufreq_ondemand Governor Tunables */ | 252 | /* cpufreq_ondemand Governor Tunables */ |
245 | #define show_one(file_name, object) \ | 253 | #define show_one(file_name, object) \ |
@@ -249,6 +257,7 @@ static ssize_t show_##file_name \ | |||
249 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ | 257 | return sprintf(buf, "%u\n", dbs_tuners_ins.object); \ |
250 | } | 258 | } |
251 | show_one(sampling_rate, sampling_rate); | 259 | show_one(sampling_rate, sampling_rate); |
260 | show_one(io_is_busy, io_is_busy); | ||
252 | show_one(up_threshold, up_threshold); | 261 | show_one(up_threshold, up_threshold); |
253 | show_one(ignore_nice_load, ignore_nice); | 262 | show_one(ignore_nice_load, ignore_nice); |
254 | show_one(powersave_bias, powersave_bias); | 263 | show_one(powersave_bias, powersave_bias); |
@@ -274,12 +283,8 @@ show_one_old(powersave_bias); | |||
274 | show_one_old(sampling_rate_min); | 283 | show_one_old(sampling_rate_min); |
275 | show_one_old(sampling_rate_max); | 284 | show_one_old(sampling_rate_max); |
276 | 285 | ||
277 | #define define_one_ro_old(object, _name) \ | 286 | cpufreq_freq_attr_ro_old(sampling_rate_min); |
278 | static struct freq_attr object = \ | 287 | cpufreq_freq_attr_ro_old(sampling_rate_max); |
279 | __ATTR(_name, 0444, show_##_name##_old, NULL) | ||
280 | |||
281 | define_one_ro_old(sampling_rate_min_old, sampling_rate_min); | ||
282 | define_one_ro_old(sampling_rate_max_old, sampling_rate_max); | ||
283 | 288 | ||
284 | /*** delete after deprecation time ***/ | 289 | /*** delete after deprecation time ***/ |
285 | 290 | ||
@@ -299,6 +304,23 @@ static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b, | |||
299 | return count; | 304 | return count; |
300 | } | 305 | } |
301 | 306 | ||
307 | static ssize_t store_io_is_busy(struct kobject *a, struct attribute *b, | ||
308 | const char *buf, size_t count) | ||
309 | { | ||
310 | unsigned int input; | ||
311 | int ret; | ||
312 | |||
313 | ret = sscanf(buf, "%u", &input); | ||
314 | if (ret != 1) | ||
315 | return -EINVAL; | ||
316 | |||
317 | mutex_lock(&dbs_mutex); | ||
318 | dbs_tuners_ins.io_is_busy = !!input; | ||
319 | mutex_unlock(&dbs_mutex); | ||
320 | |||
321 | return count; | ||
322 | } | ||
323 | |||
302 | static ssize_t store_up_threshold(struct kobject *a, struct attribute *b, | 324 | static ssize_t store_up_threshold(struct kobject *a, struct attribute *b, |
303 | const char *buf, size_t count) | 325 | const char *buf, size_t count) |
304 | { | 326 | { |
@@ -376,14 +398,11 @@ static ssize_t store_powersave_bias(struct kobject *a, struct attribute *b, | |||
376 | return count; | 398 | return count; |
377 | } | 399 | } |
378 | 400 | ||
379 | #define define_one_rw(_name) \ | 401 | define_one_global_rw(sampling_rate); |
380 | static struct global_attr _name = \ | 402 | define_one_global_rw(io_is_busy); |
381 | __ATTR(_name, 0644, show_##_name, store_##_name) | 403 | define_one_global_rw(up_threshold); |
382 | 404 | define_one_global_rw(ignore_nice_load); | |
383 | define_one_rw(sampling_rate); | 405 | define_one_global_rw(powersave_bias); |
384 | define_one_rw(up_threshold); | ||
385 | define_one_rw(ignore_nice_load); | ||
386 | define_one_rw(powersave_bias); | ||
387 | 406 | ||
388 | static struct attribute *dbs_attributes[] = { | 407 | static struct attribute *dbs_attributes[] = { |
389 | &sampling_rate_max.attr, | 408 | &sampling_rate_max.attr, |
@@ -392,6 +411,7 @@ static struct attribute *dbs_attributes[] = { | |||
392 | &up_threshold.attr, | 411 | &up_threshold.attr, |
393 | &ignore_nice_load.attr, | 412 | &ignore_nice_load.attr, |
394 | &powersave_bias.attr, | 413 | &powersave_bias.attr, |
414 | &io_is_busy.attr, | ||
395 | NULL | 415 | NULL |
396 | }; | 416 | }; |
397 | 417 | ||
@@ -415,14 +435,10 @@ write_one_old(up_threshold); | |||
415 | write_one_old(ignore_nice_load); | 435 | write_one_old(ignore_nice_load); |
416 | write_one_old(powersave_bias); | 436 | write_one_old(powersave_bias); |
417 | 437 | ||
418 | #define define_one_rw_old(object, _name) \ | 438 | cpufreq_freq_attr_rw_old(sampling_rate); |
419 | static struct freq_attr object = \ | 439 | cpufreq_freq_attr_rw_old(up_threshold); |
420 | __ATTR(_name, 0644, show_##_name##_old, store_##_name##_old) | 440 | cpufreq_freq_attr_rw_old(ignore_nice_load); |
421 | 441 | cpufreq_freq_attr_rw_old(powersave_bias); | |
422 | define_one_rw_old(sampling_rate_old, sampling_rate); | ||
423 | define_one_rw_old(up_threshold_old, up_threshold); | ||
424 | define_one_rw_old(ignore_nice_load_old, ignore_nice_load); | ||
425 | define_one_rw_old(powersave_bias_old, powersave_bias); | ||
426 | 442 | ||
427 | static struct attribute *dbs_attributes_old[] = { | 443 | static struct attribute *dbs_attributes_old[] = { |
428 | &sampling_rate_max_old.attr, | 444 | &sampling_rate_max_old.attr, |
@@ -470,14 +486,15 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info) | |||
470 | 486 | ||
471 | for_each_cpu(j, policy->cpus) { | 487 | for_each_cpu(j, policy->cpus) { |
472 | struct cpu_dbs_info_s *j_dbs_info; | 488 | struct cpu_dbs_info_s *j_dbs_info; |
473 | cputime64_t cur_wall_time, cur_idle_time; | 489 | cputime64_t cur_wall_time, cur_idle_time, cur_iowait_time; |
474 | unsigned int idle_time, wall_time; | 490 | unsigned int idle_time, wall_time, iowait_time; |
475 | unsigned int load, load_freq; | 491 | unsigned int load, load_freq; |
476 | int freq_avg; | 492 | int freq_avg; |
477 | 493 | ||
478 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); | 494 | j_dbs_info = &per_cpu(od_cpu_dbs_info, j); |
479 | 495 | ||
480 | cur_idle_time = get_cpu_idle_time(j, &cur_wall_time); | 496 | cur_idle_time = get_cpu_idle_time(j, &cur_wall_time); |
497 | cur_iowait_time = get_cpu_iowait_time(j, &cur_wall_time); | ||
481 | 498 | ||
482 | wall_time = (unsigned int) cputime64_sub(cur_wall_time, | 499 | wall_time = (unsigned int) cputime64_sub(cur_wall_time, |
483 | j_dbs_info->prev_cpu_wall); | 500 | j_dbs_info->prev_cpu_wall); |
@@ -487,6 +504,10 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info) | |||
487 | j_dbs_info->prev_cpu_idle); | 504 | j_dbs_info->prev_cpu_idle); |
488 | j_dbs_info->prev_cpu_idle = cur_idle_time; | 505 | j_dbs_info->prev_cpu_idle = cur_idle_time; |
489 | 506 | ||
507 | iowait_time = (unsigned int) cputime64_sub(cur_iowait_time, | ||
508 | j_dbs_info->prev_cpu_iowait); | ||
509 | j_dbs_info->prev_cpu_iowait = cur_iowait_time; | ||
510 | |||
490 | if (dbs_tuners_ins.ignore_nice) { | 511 | if (dbs_tuners_ins.ignore_nice) { |
491 | cputime64_t cur_nice; | 512 | cputime64_t cur_nice; |
492 | unsigned long cur_nice_jiffies; | 513 | unsigned long cur_nice_jiffies; |
@@ -504,6 +525,16 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info) | |||
504 | idle_time += jiffies_to_usecs(cur_nice_jiffies); | 525 | idle_time += jiffies_to_usecs(cur_nice_jiffies); |
505 | } | 526 | } |
506 | 527 | ||
528 | /* | ||
529 | * For the purpose of ondemand, waiting for disk IO is an | ||
530 | * indication that you're performance critical, and not that | ||
531 | * the system is actually idle. So subtract the iowait time | ||
532 | * from the cpu idle time. | ||
533 | */ | ||
534 | |||
535 | if (dbs_tuners_ins.io_is_busy && idle_time >= iowait_time) | ||
536 | idle_time -= iowait_time; | ||
537 | |||
507 | if (unlikely(!wall_time || wall_time < idle_time)) | 538 | if (unlikely(!wall_time || wall_time < idle_time)) |
508 | continue; | 539 | continue; |
509 | 540 | ||
@@ -617,6 +648,29 @@ static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) | |||
617 | cancel_delayed_work_sync(&dbs_info->work); | 648 | cancel_delayed_work_sync(&dbs_info->work); |
618 | } | 649 | } |
619 | 650 | ||
651 | /* | ||
652 | * Not all CPUs want IO time to be accounted as busy; this dependson how | ||
653 | * efficient idling at a higher frequency/voltage is. | ||
654 | * Pavel Machek says this is not so for various generations of AMD and old | ||
655 | * Intel systems. | ||
656 | * Mike Chan (androidlcom) calis this is also not true for ARM. | ||
657 | * Because of this, whitelist specific known (series) of CPUs by default, and | ||
658 | * leave all others up to the user. | ||
659 | */ | ||
660 | static int should_io_be_busy(void) | ||
661 | { | ||
662 | #if defined(CONFIG_X86) | ||
663 | /* | ||
664 | * For Intel, Core 2 (model 15) andl later have an efficient idle. | ||
665 | */ | ||
666 | if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL && | ||
667 | boot_cpu_data.x86 == 6 && | ||
668 | boot_cpu_data.x86_model >= 15) | ||
669 | return 1; | ||
670 | #endif | ||
671 | return 0; | ||
672 | } | ||
673 | |||
620 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | 674 | static int cpufreq_governor_dbs(struct cpufreq_policy *policy, |
621 | unsigned int event) | 675 | unsigned int event) |
622 | { | 676 | { |
@@ -679,6 +733,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy, | |||
679 | dbs_tuners_ins.sampling_rate = | 733 | dbs_tuners_ins.sampling_rate = |
680 | max(min_sampling_rate, | 734 | max(min_sampling_rate, |
681 | latency * LATENCY_MULTIPLIER); | 735 | latency * LATENCY_MULTIPLIER); |
736 | dbs_tuners_ins.io_is_busy = should_io_be_busy(); | ||
682 | } | 737 | } |
683 | mutex_unlock(&dbs_mutex); | 738 | mutex_unlock(&dbs_mutex); |
684 | 739 | ||
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index 7e18bcf05a66..46239e47a260 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c | |||
@@ -59,11 +59,11 @@ static unsigned int get_time_pit(void) | |||
59 | unsigned long flags; | 59 | unsigned long flags; |
60 | unsigned int count; | 60 | unsigned int count; |
61 | 61 | ||
62 | spin_lock_irqsave(&i8253_lock, flags); | 62 | raw_spin_lock_irqsave(&i8253_lock, flags); |
63 | outb_p(0x00, 0x43); | 63 | outb_p(0x00, 0x43); |
64 | count = inb_p(0x40); | 64 | count = inb_p(0x40); |
65 | count |= inb_p(0x40) << 8; | 65 | count |= inb_p(0x40) << 8; |
66 | spin_unlock_irqrestore(&i8253_lock, flags); | 66 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
67 | 67 | ||
68 | return count; | 68 | return count; |
69 | } | 69 | } |
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c index 1c0b529c06aa..4afe0a3b4884 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c | |||
@@ -146,11 +146,11 @@ static unsigned int get_time_pit(void) | |||
146 | unsigned long flags; | 146 | unsigned long flags; |
147 | unsigned int count; | 147 | unsigned int count; |
148 | 148 | ||
149 | spin_lock_irqsave(&i8253_lock, flags); | 149 | raw_spin_lock_irqsave(&i8253_lock, flags); |
150 | outb_p(0x00, 0x43); | 150 | outb_p(0x00, 0x43); |
151 | count = inb_p(0x40); | 151 | count = inb_p(0x40); |
152 | count |= inb_p(0x40) << 8; | 152 | count |= inb_p(0x40) << 8; |
153 | spin_unlock_irqrestore(&i8253_lock, flags); | 153 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
154 | 154 | ||
155 | return count; | 155 | return count; |
156 | } | 156 | } |
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index b1edd778639c..405febd94f24 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c | |||
@@ -54,6 +54,9 @@ static signed short btn_avb_wheel[] = | |||
54 | static signed short abs_joystick[] = | 54 | static signed short abs_joystick[] = |
55 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, -1 }; | 55 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, -1 }; |
56 | 56 | ||
57 | static signed short abs_joystick_rudder[] = | ||
58 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, -1 }; | ||
59 | |||
57 | static signed short abs_avb_pegasus[] = | 60 | static signed short abs_avb_pegasus[] = |
58 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, | 61 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, |
59 | ABS_HAT1X, ABS_HAT1Y, -1 }; | 62 | ABS_HAT1X, ABS_HAT1Y, -1 }; |
@@ -76,8 +79,9 @@ static struct iforce_device iforce_device[] = { | |||
76 | { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? | 79 | { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? |
77 | { 0x061c, 0xc084, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, | 80 | { 0x061c, 0xc084, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, |
78 | { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? | 81 | { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? |
82 | { 0x06f8, 0x0001, "Guillemot Jet Leader Force Feedback", btn_joystick, abs_joystick_rudder, ff_iforce }, | ||
79 | { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? | 83 | { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? |
80 | { 0x06f8, 0x0004, "Gullemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //? | 84 | { 0x06f8, 0xa302, "Guillemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //? |
81 | { 0x06d6, 0x29bc, "Trust Force Feedback Race Master", btn_wheel, abs_wheel, ff_iforce }, | 85 | { 0x06d6, 0x29bc, "Trust Force Feedback Race Master", btn_wheel, abs_wheel, ff_iforce }, |
82 | { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } | 86 | { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } |
83 | }; | 87 | }; |
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index b41303d3ec54..6c96631ae5d9 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c | |||
@@ -212,6 +212,7 @@ static struct usb_device_id iforce_usb_ids [] = { | |||
212 | { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ | 212 | { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ |
213 | { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */ | 213 | { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */ |
214 | { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ | 214 | { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ |
215 | { USB_DEVICE(0x06f8, 0x0003) }, /* Guillemot Jet Leader Force Feedback */ | ||
215 | { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ | 216 | { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ |
216 | { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */ | 217 | { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */ |
217 | { } /* Terminating entry */ | 218 | { } /* Terminating entry */ |
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c index ea4e1fd12651..f080dd31499b 100644 --- a/drivers/input/misc/pcspkr.c +++ b/drivers/input/misc/pcspkr.c | |||
@@ -30,7 +30,7 @@ MODULE_ALIAS("platform:pcspkr"); | |||
30 | #include <asm/i8253.h> | 30 | #include <asm/i8253.h> |
31 | #else | 31 | #else |
32 | #include <asm/8253pit.h> | 32 | #include <asm/8253pit.h> |
33 | static DEFINE_SPINLOCK(i8253_lock); | 33 | static DEFINE_RAW_SPINLOCK(i8253_lock); |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) | 36 | static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
@@ -50,7 +50,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c | |||
50 | if (value > 20 && value < 32767) | 50 | if (value > 20 && value < 32767) |
51 | count = PIT_TICK_RATE / value; | 51 | count = PIT_TICK_RATE / value; |
52 | 52 | ||
53 | spin_lock_irqsave(&i8253_lock, flags); | 53 | raw_spin_lock_irqsave(&i8253_lock, flags); |
54 | 54 | ||
55 | if (count) { | 55 | if (count) { |
56 | /* set command for counter 2, 2 byte write */ | 56 | /* set command for counter 2, 2 byte write */ |
@@ -65,7 +65,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c | |||
65 | outb(inb_p(0x61) & 0xFC, 0x61); | 65 | outb(inb_p(0x61) & 0xFC, 0x61); |
66 | } | 66 | } |
67 | 67 | ||
68 | spin_unlock_irqrestore(&i8253_lock, flags); | 68 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
69 | 69 | ||
70 | return 0; | 70 | return 0; |
71 | } | 71 | } |
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index 0520c2e19927..112b4ee52ff2 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c | |||
@@ -185,7 +185,7 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse) | |||
185 | int fingers; | 185 | int fingers; |
186 | static int old_fingers; | 186 | static int old_fingers; |
187 | 187 | ||
188 | if (etd->fw_version_maj == 0x01) { | 188 | if (etd->fw_version < 0x020000) { |
189 | /* | 189 | /* |
190 | * byte 0: D U p1 p2 1 p3 R L | 190 | * byte 0: D U p1 p2 1 p3 R L |
191 | * byte 1: f 0 th tw x9 x8 y9 y8 | 191 | * byte 1: f 0 th tw x9 x8 y9 y8 |
@@ -227,7 +227,7 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse) | |||
227 | input_report_key(dev, BTN_LEFT, packet[0] & 0x01); | 227 | input_report_key(dev, BTN_LEFT, packet[0] & 0x01); |
228 | input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); | 228 | input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); |
229 | 229 | ||
230 | if ((etd->fw_version_maj == 0x01) && | 230 | if (etd->fw_version < 0x020000 && |
231 | (etd->capabilities & ETP_CAP_HAS_ROCKER)) { | 231 | (etd->capabilities & ETP_CAP_HAS_ROCKER)) { |
232 | /* rocker up */ | 232 | /* rocker up */ |
233 | input_report_key(dev, BTN_FORWARD, packet[0] & 0x40); | 233 | input_report_key(dev, BTN_FORWARD, packet[0] & 0x40); |
@@ -321,7 +321,7 @@ static int elantech_check_parity_v1(struct psmouse *psmouse) | |||
321 | unsigned char p1, p2, p3; | 321 | unsigned char p1, p2, p3; |
322 | 322 | ||
323 | /* Parity bits are placed differently */ | 323 | /* Parity bits are placed differently */ |
324 | if (etd->fw_version_maj == 0x01) { | 324 | if (etd->fw_version < 0x020000) { |
325 | /* byte 0: D U p1 p2 1 p3 R L */ | 325 | /* byte 0: D U p1 p2 1 p3 R L */ |
326 | p1 = (packet[0] & 0x20) >> 5; | 326 | p1 = (packet[0] & 0x20) >> 5; |
327 | p2 = (packet[0] & 0x10) >> 4; | 327 | p2 = (packet[0] & 0x10) >> 4; |
@@ -457,7 +457,7 @@ static void elantech_set_input_params(struct psmouse *psmouse) | |||
457 | switch (etd->hw_version) { | 457 | switch (etd->hw_version) { |
458 | case 1: | 458 | case 1: |
459 | /* Rocker button */ | 459 | /* Rocker button */ |
460 | if ((etd->fw_version_maj == 0x01) && | 460 | if (etd->fw_version < 0x020000 && |
461 | (etd->capabilities & ETP_CAP_HAS_ROCKER)) { | 461 | (etd->capabilities & ETP_CAP_HAS_ROCKER)) { |
462 | __set_bit(BTN_FORWARD, dev->keybit); | 462 | __set_bit(BTN_FORWARD, dev->keybit); |
463 | __set_bit(BTN_BACK, dev->keybit); | 463 | __set_bit(BTN_BACK, dev->keybit); |
@@ -686,15 +686,14 @@ int elantech_init(struct psmouse *psmouse) | |||
686 | pr_err("elantech.c: failed to query firmware version.\n"); | 686 | pr_err("elantech.c: failed to query firmware version.\n"); |
687 | goto init_fail; | 687 | goto init_fail; |
688 | } | 688 | } |
689 | etd->fw_version_maj = param[0]; | 689 | |
690 | etd->fw_version_min = param[2]; | 690 | etd->fw_version = (param[0] << 16) | (param[1] << 8) | param[2]; |
691 | 691 | ||
692 | /* | 692 | /* |
693 | * Assume every version greater than this is new EeePC style | 693 | * Assume every version greater than this is new EeePC style |
694 | * hardware with 6 byte packets | 694 | * hardware with 6 byte packets |
695 | */ | 695 | */ |
696 | if ((etd->fw_version_maj == 0x02 && etd->fw_version_min >= 0x30) || | 696 | if (etd->fw_version >= 0x020030) { |
697 | etd->fw_version_maj > 0x02) { | ||
698 | etd->hw_version = 2; | 697 | etd->hw_version = 2; |
699 | /* For now show extra debug information */ | 698 | /* For now show extra debug information */ |
700 | etd->debug = 1; | 699 | etd->debug = 1; |
@@ -704,8 +703,9 @@ int elantech_init(struct psmouse *psmouse) | |||
704 | etd->hw_version = 1; | 703 | etd->hw_version = 1; |
705 | etd->paritycheck = 1; | 704 | etd->paritycheck = 1; |
706 | } | 705 | } |
707 | pr_info("elantech.c: assuming hardware version %d, firmware version %d.%d\n", | 706 | |
708 | etd->hw_version, etd->fw_version_maj, etd->fw_version_min); | 707 | pr_info("elantech.c: assuming hardware version %d, firmware version %d.%d.%d\n", |
708 | etd->hw_version, param[0], param[1], param[2]); | ||
709 | 709 | ||
710 | if (synaptics_send_cmd(psmouse, ETP_CAPABILITIES_QUERY, param)) { | 710 | if (synaptics_send_cmd(psmouse, ETP_CAPABILITIES_QUERY, param)) { |
711 | pr_err("elantech.c: failed to query capabilities.\n"); | 711 | pr_err("elantech.c: failed to query capabilities.\n"); |
@@ -720,8 +720,8 @@ int elantech_init(struct psmouse *psmouse) | |||
720 | * a touch action starts causing the mouse cursor or scrolled page | 720 | * a touch action starts causing the mouse cursor or scrolled page |
721 | * to jump. Enable a workaround. | 721 | * to jump. Enable a workaround. |
722 | */ | 722 | */ |
723 | if (etd->fw_version_maj == 0x02 && etd->fw_version_min == 0x22) { | 723 | if (etd->fw_version == 0x020022) { |
724 | pr_info("elantech.c: firmware version 2.34 detected, " | 724 | pr_info("elantech.c: firmware version 2.0.34 detected, " |
725 | "enabling jumpy cursor workaround\n"); | 725 | "enabling jumpy cursor workaround\n"); |
726 | etd->jumpy_cursor = 1; | 726 | etd->jumpy_cursor = 1; |
727 | } | 727 | } |
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h index feac5f7af966..ac57bde1bb9f 100644 --- a/drivers/input/mouse/elantech.h +++ b/drivers/input/mouse/elantech.h | |||
@@ -100,11 +100,10 @@ struct elantech_data { | |||
100 | unsigned char reg_26; | 100 | unsigned char reg_26; |
101 | unsigned char debug; | 101 | unsigned char debug; |
102 | unsigned char capabilities; | 102 | unsigned char capabilities; |
103 | unsigned char fw_version_maj; | ||
104 | unsigned char fw_version_min; | ||
105 | unsigned char hw_version; | ||
106 | unsigned char paritycheck; | 103 | unsigned char paritycheck; |
107 | unsigned char jumpy_cursor; | 104 | unsigned char jumpy_cursor; |
105 | unsigned char hw_version; | ||
106 | unsigned int fw_version; | ||
108 | unsigned char parity[256]; | 107 | unsigned char parity[256]; |
109 | }; | 108 | }; |
110 | 109 | ||
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index cbc807264940..a3c97315a473 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c | |||
@@ -1394,6 +1394,7 @@ static int psmouse_reconnect(struct serio *serio) | |||
1394 | struct psmouse *psmouse = serio_get_drvdata(serio); | 1394 | struct psmouse *psmouse = serio_get_drvdata(serio); |
1395 | struct psmouse *parent = NULL; | 1395 | struct psmouse *parent = NULL; |
1396 | struct serio_driver *drv = serio->drv; | 1396 | struct serio_driver *drv = serio->drv; |
1397 | unsigned char type; | ||
1397 | int rc = -1; | 1398 | int rc = -1; |
1398 | 1399 | ||
1399 | if (!drv || !psmouse) { | 1400 | if (!drv || !psmouse) { |
@@ -1413,10 +1414,15 @@ static int psmouse_reconnect(struct serio *serio) | |||
1413 | if (psmouse->reconnect) { | 1414 | if (psmouse->reconnect) { |
1414 | if (psmouse->reconnect(psmouse)) | 1415 | if (psmouse->reconnect(psmouse)) |
1415 | goto out; | 1416 | goto out; |
1416 | } else if (psmouse_probe(psmouse) < 0 || | 1417 | } else { |
1417 | psmouse->type != psmouse_extensions(psmouse, | 1418 | psmouse_reset(psmouse); |
1418 | psmouse_max_proto, false)) { | 1419 | |
1419 | goto out; | 1420 | if (psmouse_probe(psmouse) < 0) |
1421 | goto out; | ||
1422 | |||
1423 | type = psmouse_extensions(psmouse, psmouse_max_proto, false); | ||
1424 | if (psmouse->type != type) | ||
1425 | goto out; | ||
1420 | } | 1426 | } |
1421 | 1427 | ||
1422 | /* ok, the device type (and capabilities) match the old one, | 1428 | /* ok, the device type (and capabilities) match the old one, |
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index e019d53d1ab4..0d2d7e54b465 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c | |||
@@ -156,9 +156,14 @@ struct ser_req { | |||
156 | u16 reset; | 156 | u16 reset; |
157 | u16 ref_on; | 157 | u16 ref_on; |
158 | u16 command; | 158 | u16 command; |
159 | u16 sample; | ||
160 | struct spi_message msg; | 159 | struct spi_message msg; |
161 | struct spi_transfer xfer[6]; | 160 | struct spi_transfer xfer[6]; |
161 | |||
162 | /* | ||
163 | * DMA (thus cache coherency maintenance) requires the | ||
164 | * transfer buffers to live in their own cache lines. | ||
165 | */ | ||
166 | u16 sample ____cacheline_aligned; | ||
162 | }; | 167 | }; |
163 | 168 | ||
164 | struct ad7877 { | 169 | struct ad7877 { |
@@ -182,8 +187,6 @@ struct ad7877 { | |||
182 | u8 averaging; | 187 | u8 averaging; |
183 | u8 pen_down_acc_interval; | 188 | u8 pen_down_acc_interval; |
184 | 189 | ||
185 | u16 conversion_data[AD7877_NR_SENSE]; | ||
186 | |||
187 | struct spi_transfer xfer[AD7877_NR_SENSE + 2]; | 190 | struct spi_transfer xfer[AD7877_NR_SENSE + 2]; |
188 | struct spi_message msg; | 191 | struct spi_message msg; |
189 | 192 | ||
@@ -195,6 +198,12 @@ struct ad7877 { | |||
195 | spinlock_t lock; | 198 | spinlock_t lock; |
196 | struct timer_list timer; /* P: lock */ | 199 | struct timer_list timer; /* P: lock */ |
197 | unsigned pending:1; /* P: lock */ | 200 | unsigned pending:1; /* P: lock */ |
201 | |||
202 | /* | ||
203 | * DMA (thus cache coherency maintenance) requires the | ||
204 | * transfer buffers to live in their own cache lines. | ||
205 | */ | ||
206 | u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned; | ||
198 | }; | 207 | }; |
199 | 208 | ||
200 | static int gpio3; | 209 | static int gpio3; |
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index a3d5728b6449..f2ab025ad97a 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c | |||
@@ -349,6 +349,9 @@ int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input) | |||
349 | goto disable; | 349 | goto disable; |
350 | } | 350 | } |
351 | 351 | ||
352 | /* If an interrupt arrived late clean up after it */ | ||
353 | try_wait_for_completion(&wm831x->auxadc_done); | ||
354 | |||
352 | /* Ignore the result to allow us to soldier on without IRQ hookup */ | 355 | /* Ignore the result to allow us to soldier on without IRQ hookup */ |
353 | wait_for_completion_timeout(&wm831x->auxadc_done, msecs_to_jiffies(5)); | 356 | wait_for_completion_timeout(&wm831x->auxadc_done, msecs_to_jiffies(5)); |
354 | 357 | ||
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c index e400a3bed063..b5807484b4c9 100644 --- a/drivers/mfd/wm8350-core.c +++ b/drivers/mfd/wm8350-core.c | |||
@@ -363,6 +363,10 @@ int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) | |||
363 | reg |= 1 << channel | WM8350_AUXADC_POLL; | 363 | reg |= 1 << channel | WM8350_AUXADC_POLL; |
364 | wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg); | 364 | wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg); |
365 | 365 | ||
366 | /* If a late IRQ left the completion signalled then consume | ||
367 | * the completion. */ | ||
368 | try_wait_for_completion(&wm8350->auxadc_done); | ||
369 | |||
366 | /* We ignore the result of the completion and just check for a | 370 | /* We ignore the result of the completion and just check for a |
367 | * conversion result, allowing us to soldier on if the IRQ | 371 | * conversion result, allowing us to soldier on if the IRQ |
368 | * infrastructure is not set up for the chip. */ | 372 | * infrastructure is not set up for the chip. */ |
diff --git a/drivers/misc/vmware_balloon.c b/drivers/misc/vmware_balloon.c index e7161c4e3798..db9cd0240c6f 100644 --- a/drivers/misc/vmware_balloon.c +++ b/drivers/misc/vmware_balloon.c | |||
@@ -41,7 +41,7 @@ | |||
41 | #include <linux/workqueue.h> | 41 | #include <linux/workqueue.h> |
42 | #include <linux/debugfs.h> | 42 | #include <linux/debugfs.h> |
43 | #include <linux/seq_file.h> | 43 | #include <linux/seq_file.h> |
44 | #include <asm/vmware.h> | 44 | #include <asm/hypervisor.h> |
45 | 45 | ||
46 | MODULE_AUTHOR("VMware, Inc."); | 46 | MODULE_AUTHOR("VMware, Inc."); |
47 | MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver"); | 47 | MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver"); |
@@ -767,7 +767,7 @@ static int __init vmballoon_init(void) | |||
767 | * Check if we are running on VMware's hypervisor and bail out | 767 | * Check if we are running on VMware's hypervisor and bail out |
768 | * if we are not. | 768 | * if we are not. |
769 | */ | 769 | */ |
770 | if (!vmware_platform()) | 770 | if (x86_hyper != &x86_hyper_vmware) |
771 | return -ENODEV; | 771 | return -ENODEV; |
772 | 772 | ||
773 | vmballoon_wq = create_freezeable_workqueue("vmmemctl"); | 773 | vmballoon_wq = create_freezeable_workqueue("vmmemctl"); |
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c index a6dd7da37357..336d9f553f3e 100644 --- a/drivers/mmc/host/at91_mci.c +++ b/drivers/mmc/host/at91_mci.c | |||
@@ -314,8 +314,8 @@ static void at91_mci_post_dma_read(struct at91mci_host *host) | |||
314 | dmabuf = (unsigned *)tmpv; | 314 | dmabuf = (unsigned *)tmpv; |
315 | } | 315 | } |
316 | 316 | ||
317 | flush_kernel_dcache_page(sg_page(sg)); | ||
317 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); | 318 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); |
318 | dmac_flush_range((void *)sgbuffer, ((void *)sgbuffer) + amount); | ||
319 | data->bytes_xfered += amount; | 319 | data->bytes_xfered += amount; |
320 | if (size == 0) | 320 | if (size == 0) |
321 | break; | 321 | break; |
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c index 541f9a20f519..f142cc21e453 100644 --- a/drivers/net/a2065.c +++ b/drivers/net/a2065.c | |||
@@ -672,6 +672,7 @@ static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = { | |||
672 | { ZORRO_PROD_AMERISTAR_A2065 }, | 672 | { ZORRO_PROD_AMERISTAR_A2065 }, |
673 | { 0 } | 673 | { 0 } |
674 | }; | 674 | }; |
675 | MODULE_DEVICE_TABLE(zorro, a2065_zorro_tbl); | ||
675 | 676 | ||
676 | static struct zorro_driver a2065_driver = { | 677 | static struct zorro_driver a2065_driver = { |
677 | .name = "a2065", | 678 | .name = "a2065", |
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c index 705373a5308d..39214e512452 100644 --- a/drivers/net/ariadne.c +++ b/drivers/net/ariadne.c | |||
@@ -145,6 +145,7 @@ static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = { | |||
145 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE }, | 145 | { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE }, |
146 | { 0 } | 146 | { 0 } |
147 | }; | 147 | }; |
148 | MODULE_DEVICE_TABLE(zorro, ariadne_zorro_tbl); | ||
148 | 149 | ||
149 | static struct zorro_driver ariadne_driver = { | 150 | static struct zorro_driver ariadne_driver = { |
150 | .name = "ariadne", | 151 | .name = "ariadne", |
diff --git a/drivers/net/hydra.c b/drivers/net/hydra.c index 24724b4ad709..07d8e5b634f3 100644 --- a/drivers/net/hydra.c +++ b/drivers/net/hydra.c | |||
@@ -71,6 +71,7 @@ static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = { | |||
71 | { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET }, | 71 | { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET }, |
72 | { 0 } | 72 | { 0 } |
73 | }; | 73 | }; |
74 | MODULE_DEVICE_TABLE(zorro, hydra_zorro_tbl); | ||
74 | 75 | ||
75 | static struct zorro_driver hydra_driver = { | 76 | static struct zorro_driver hydra_driver = { |
76 | .name = "hydra", | 77 | .name = "hydra", |
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c index 4f7b9d6a087b..b78a38d9172a 100644 --- a/drivers/net/zorro8390.c +++ b/drivers/net/zorro8390.c | |||
@@ -102,6 +102,7 @@ static struct zorro_device_id zorro8390_zorro_tbl[] __devinitdata = { | |||
102 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, }, | 102 | { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, }, |
103 | { 0 } | 103 | { 0 } |
104 | }; | 104 | }; |
105 | MODULE_DEVICE_TABLE(zorro, zorro8390_zorro_tbl); | ||
105 | 106 | ||
106 | static struct zorro_driver zorro8390_driver = { | 107 | static struct zorro_driver zorro8390_driver = { |
107 | .name = "zorro8390", | 108 | .name = "zorro8390", |
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c index 166b67ea622f..219f79e2210a 100644 --- a/drivers/oprofile/cpu_buffer.c +++ b/drivers/oprofile/cpu_buffer.c | |||
@@ -30,23 +30,7 @@ | |||
30 | 30 | ||
31 | #define OP_BUFFER_FLAGS 0 | 31 | #define OP_BUFFER_FLAGS 0 |
32 | 32 | ||
33 | /* | 33 | static struct ring_buffer *op_ring_buffer; |
34 | * Read and write access is using spin locking. Thus, writing to the | ||
35 | * buffer by NMI handler (x86) could occur also during critical | ||
36 | * sections when reading the buffer. To avoid this, there are 2 | ||
37 | * buffers for independent read and write access. Read access is in | ||
38 | * process context only, write access only in the NMI handler. If the | ||
39 | * read buffer runs empty, both buffers are swapped atomically. There | ||
40 | * is potentially a small window during swapping where the buffers are | ||
41 | * disabled and samples could be lost. | ||
42 | * | ||
43 | * Using 2 buffers is a little bit overhead, but the solution is clear | ||
44 | * and does not require changes in the ring buffer implementation. It | ||
45 | * can be changed to a single buffer solution when the ring buffer | ||
46 | * access is implemented as non-locking atomic code. | ||
47 | */ | ||
48 | static struct ring_buffer *op_ring_buffer_read; | ||
49 | static struct ring_buffer *op_ring_buffer_write; | ||
50 | DEFINE_PER_CPU(struct oprofile_cpu_buffer, op_cpu_buffer); | 34 | DEFINE_PER_CPU(struct oprofile_cpu_buffer, op_cpu_buffer); |
51 | 35 | ||
52 | static void wq_sync_buffer(struct work_struct *work); | 36 | static void wq_sync_buffer(struct work_struct *work); |
@@ -68,12 +52,9 @@ void oprofile_cpu_buffer_inc_smpl_lost(void) | |||
68 | 52 | ||
69 | void free_cpu_buffers(void) | 53 | void free_cpu_buffers(void) |
70 | { | 54 | { |
71 | if (op_ring_buffer_read) | 55 | if (op_ring_buffer) |
72 | ring_buffer_free(op_ring_buffer_read); | 56 | ring_buffer_free(op_ring_buffer); |
73 | op_ring_buffer_read = NULL; | 57 | op_ring_buffer = NULL; |
74 | if (op_ring_buffer_write) | ||
75 | ring_buffer_free(op_ring_buffer_write); | ||
76 | op_ring_buffer_write = NULL; | ||
77 | } | 58 | } |
78 | 59 | ||
79 | #define RB_EVENT_HDR_SIZE 4 | 60 | #define RB_EVENT_HDR_SIZE 4 |
@@ -86,11 +67,8 @@ int alloc_cpu_buffers(void) | |||
86 | unsigned long byte_size = buffer_size * (sizeof(struct op_sample) + | 67 | unsigned long byte_size = buffer_size * (sizeof(struct op_sample) + |
87 | RB_EVENT_HDR_SIZE); | 68 | RB_EVENT_HDR_SIZE); |
88 | 69 | ||
89 | op_ring_buffer_read = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS); | 70 | op_ring_buffer = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS); |
90 | if (!op_ring_buffer_read) | 71 | if (!op_ring_buffer) |
91 | goto fail; | ||
92 | op_ring_buffer_write = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS); | ||
93 | if (!op_ring_buffer_write) | ||
94 | goto fail; | 72 | goto fail; |
95 | 73 | ||
96 | for_each_possible_cpu(i) { | 74 | for_each_possible_cpu(i) { |
@@ -162,16 +140,11 @@ struct op_sample | |||
162 | *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size) | 140 | *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size) |
163 | { | 141 | { |
164 | entry->event = ring_buffer_lock_reserve | 142 | entry->event = ring_buffer_lock_reserve |
165 | (op_ring_buffer_write, sizeof(struct op_sample) + | 143 | (op_ring_buffer, sizeof(struct op_sample) + |
166 | size * sizeof(entry->sample->data[0])); | 144 | size * sizeof(entry->sample->data[0])); |
167 | if (entry->event) | 145 | if (!entry->event) |
168 | entry->sample = ring_buffer_event_data(entry->event); | ||
169 | else | ||
170 | entry->sample = NULL; | ||
171 | |||
172 | if (!entry->sample) | ||
173 | return NULL; | 146 | return NULL; |
174 | 147 | entry->sample = ring_buffer_event_data(entry->event); | |
175 | entry->size = size; | 148 | entry->size = size; |
176 | entry->data = entry->sample->data; | 149 | entry->data = entry->sample->data; |
177 | 150 | ||
@@ -180,25 +153,16 @@ struct op_sample | |||
180 | 153 | ||
181 | int op_cpu_buffer_write_commit(struct op_entry *entry) | 154 | int op_cpu_buffer_write_commit(struct op_entry *entry) |
182 | { | 155 | { |
183 | return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event); | 156 | return ring_buffer_unlock_commit(op_ring_buffer, entry->event); |
184 | } | 157 | } |
185 | 158 | ||
186 | struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu) | 159 | struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu) |
187 | { | 160 | { |
188 | struct ring_buffer_event *e; | 161 | struct ring_buffer_event *e; |
189 | e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL); | 162 | e = ring_buffer_consume(op_ring_buffer, cpu, NULL, NULL); |
190 | if (e) | 163 | if (!e) |
191 | goto event; | ||
192 | if (ring_buffer_swap_cpu(op_ring_buffer_read, | ||
193 | op_ring_buffer_write, | ||
194 | cpu)) | ||
195 | return NULL; | 164 | return NULL; |
196 | e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL); | ||
197 | if (e) | ||
198 | goto event; | ||
199 | return NULL; | ||
200 | 165 | ||
201 | event: | ||
202 | entry->event = e; | 166 | entry->event = e; |
203 | entry->sample = ring_buffer_event_data(e); | 167 | entry->sample = ring_buffer_event_data(e); |
204 | entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample)) | 168 | entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample)) |
@@ -209,8 +173,7 @@ event: | |||
209 | 173 | ||
210 | unsigned long op_cpu_buffer_entries(int cpu) | 174 | unsigned long op_cpu_buffer_entries(int cpu) |
211 | { | 175 | { |
212 | return ring_buffer_entries_cpu(op_ring_buffer_read, cpu) | 176 | return ring_buffer_entries_cpu(op_ring_buffer, cpu); |
213 | + ring_buffer_entries_cpu(op_ring_buffer_write, cpu); | ||
214 | } | 177 | } |
215 | 178 | ||
216 | static int | 179 | static int |
@@ -356,8 +319,16 @@ void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, | |||
356 | 319 | ||
357 | void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) | 320 | void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) |
358 | { | 321 | { |
359 | int is_kernel = !user_mode(regs); | 322 | int is_kernel; |
360 | unsigned long pc = profile_pc(regs); | 323 | unsigned long pc; |
324 | |||
325 | if (likely(regs)) { | ||
326 | is_kernel = !user_mode(regs); | ||
327 | pc = profile_pc(regs); | ||
328 | } else { | ||
329 | is_kernel = 0; /* This value will not be used */ | ||
330 | pc = ESCAPE_CODE; /* as this causes an early return. */ | ||
331 | } | ||
361 | 332 | ||
362 | __oprofile_add_ext_sample(pc, regs, event, is_kernel); | 333 | __oprofile_add_ext_sample(pc, regs, event, is_kernel); |
363 | } | 334 | } |
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c index dc8a0428260d..b336cd9ee7a1 100644 --- a/drivers/oprofile/oprof.c +++ b/drivers/oprofile/oprof.c | |||
@@ -253,22 +253,26 @@ static int __init oprofile_init(void) | |||
253 | int err; | 253 | int err; |
254 | 254 | ||
255 | err = oprofile_arch_init(&oprofile_ops); | 255 | err = oprofile_arch_init(&oprofile_ops); |
256 | |||
257 | if (err < 0 || timer) { | 256 | if (err < 0 || timer) { |
258 | printk(KERN_INFO "oprofile: using timer interrupt.\n"); | 257 | printk(KERN_INFO "oprofile: using timer interrupt.\n"); |
259 | oprofile_timer_init(&oprofile_ops); | 258 | err = oprofile_timer_init(&oprofile_ops); |
259 | if (err) | ||
260 | goto out_arch; | ||
260 | } | 261 | } |
261 | |||
262 | err = oprofilefs_register(); | 262 | err = oprofilefs_register(); |
263 | if (err) | 263 | if (err) |
264 | oprofile_arch_exit(); | 264 | goto out_arch; |
265 | return 0; | ||
265 | 266 | ||
267 | out_arch: | ||
268 | oprofile_arch_exit(); | ||
266 | return err; | 269 | return err; |
267 | } | 270 | } |
268 | 271 | ||
269 | 272 | ||
270 | static void __exit oprofile_exit(void) | 273 | static void __exit oprofile_exit(void) |
271 | { | 274 | { |
275 | oprofile_timer_exit(); | ||
272 | oprofilefs_unregister(); | 276 | oprofilefs_unregister(); |
273 | oprofile_arch_exit(); | 277 | oprofile_arch_exit(); |
274 | } | 278 | } |
diff --git a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h index cb92f5c98c1a..47e12cb4ee8b 100644 --- a/drivers/oprofile/oprof.h +++ b/drivers/oprofile/oprof.h | |||
@@ -34,7 +34,8 @@ struct super_block; | |||
34 | struct dentry; | 34 | struct dentry; |
35 | 35 | ||
36 | void oprofile_create_files(struct super_block *sb, struct dentry *root); | 36 | void oprofile_create_files(struct super_block *sb, struct dentry *root); |
37 | void oprofile_timer_init(struct oprofile_operations *ops); | 37 | int oprofile_timer_init(struct oprofile_operations *ops); |
38 | void oprofile_timer_exit(void); | ||
38 | 39 | ||
39 | int oprofile_set_backtrace(unsigned long depth); | 40 | int oprofile_set_backtrace(unsigned long depth); |
40 | int oprofile_set_timeout(unsigned long time); | 41 | int oprofile_set_timeout(unsigned long time); |
diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c index 333f915568c7..dc0ae4d14dff 100644 --- a/drivers/oprofile/timer_int.c +++ b/drivers/oprofile/timer_int.c | |||
@@ -13,34 +13,94 @@ | |||
13 | #include <linux/oprofile.h> | 13 | #include <linux/oprofile.h> |
14 | #include <linux/profile.h> | 14 | #include <linux/profile.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/cpu.h> | ||
17 | #include <linux/hrtimer.h> | ||
18 | #include <asm/irq_regs.h> | ||
16 | #include <asm/ptrace.h> | 19 | #include <asm/ptrace.h> |
17 | 20 | ||
18 | #include "oprof.h" | 21 | #include "oprof.h" |
19 | 22 | ||
20 | static int timer_notify(struct pt_regs *regs) | 23 | static DEFINE_PER_CPU(struct hrtimer, oprofile_hrtimer); |
24 | |||
25 | static enum hrtimer_restart oprofile_hrtimer_notify(struct hrtimer *hrtimer) | ||
26 | { | ||
27 | oprofile_add_sample(get_irq_regs(), 0); | ||
28 | hrtimer_forward_now(hrtimer, ns_to_ktime(TICK_NSEC)); | ||
29 | return HRTIMER_RESTART; | ||
30 | } | ||
31 | |||
32 | static void __oprofile_hrtimer_start(void *unused) | ||
33 | { | ||
34 | struct hrtimer *hrtimer = &__get_cpu_var(oprofile_hrtimer); | ||
35 | |||
36 | hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
37 | hrtimer->function = oprofile_hrtimer_notify; | ||
38 | |||
39 | hrtimer_start(hrtimer, ns_to_ktime(TICK_NSEC), | ||
40 | HRTIMER_MODE_REL_PINNED); | ||
41 | } | ||
42 | |||
43 | static int oprofile_hrtimer_start(void) | ||
21 | { | 44 | { |
22 | oprofile_add_sample(regs, 0); | 45 | on_each_cpu(__oprofile_hrtimer_start, NULL, 1); |
23 | return 0; | 46 | return 0; |
24 | } | 47 | } |
25 | 48 | ||
26 | static int timer_start(void) | 49 | static void __oprofile_hrtimer_stop(int cpu) |
27 | { | 50 | { |
28 | return register_timer_hook(timer_notify); | 51 | struct hrtimer *hrtimer = &per_cpu(oprofile_hrtimer, cpu); |
52 | |||
53 | hrtimer_cancel(hrtimer); | ||
29 | } | 54 | } |
30 | 55 | ||
56 | static void oprofile_hrtimer_stop(void) | ||
57 | { | ||
58 | int cpu; | ||
59 | |||
60 | for_each_online_cpu(cpu) | ||
61 | __oprofile_hrtimer_stop(cpu); | ||
62 | } | ||
31 | 63 | ||
32 | static void timer_stop(void) | 64 | static int __cpuinit oprofile_cpu_notify(struct notifier_block *self, |
65 | unsigned long action, void *hcpu) | ||
33 | { | 66 | { |
34 | unregister_timer_hook(timer_notify); | 67 | long cpu = (long) hcpu; |
68 | |||
69 | switch (action) { | ||
70 | case CPU_ONLINE: | ||
71 | case CPU_ONLINE_FROZEN: | ||
72 | smp_call_function_single(cpu, __oprofile_hrtimer_start, | ||
73 | NULL, 1); | ||
74 | break; | ||
75 | case CPU_DEAD: | ||
76 | case CPU_DEAD_FROZEN: | ||
77 | __oprofile_hrtimer_stop(cpu); | ||
78 | break; | ||
79 | } | ||
80 | return NOTIFY_OK; | ||
35 | } | 81 | } |
36 | 82 | ||
83 | static struct notifier_block __refdata oprofile_cpu_notifier = { | ||
84 | .notifier_call = oprofile_cpu_notify, | ||
85 | }; | ||
37 | 86 | ||
38 | void __init oprofile_timer_init(struct oprofile_operations *ops) | 87 | int __init oprofile_timer_init(struct oprofile_operations *ops) |
39 | { | 88 | { |
89 | int rc; | ||
90 | |||
91 | rc = register_hotcpu_notifier(&oprofile_cpu_notifier); | ||
92 | if (rc) | ||
93 | return rc; | ||
40 | ops->create_files = NULL; | 94 | ops->create_files = NULL; |
41 | ops->setup = NULL; | 95 | ops->setup = NULL; |
42 | ops->shutdown = NULL; | 96 | ops->shutdown = NULL; |
43 | ops->start = timer_start; | 97 | ops->start = oprofile_hrtimer_start; |
44 | ops->stop = timer_stop; | 98 | ops->stop = oprofile_hrtimer_stop; |
45 | ops->cpu_type = "timer"; | 99 | ops->cpu_type = "timer"; |
100 | return 0; | ||
101 | } | ||
102 | |||
103 | void __exit oprofile_timer_exit(void) | ||
104 | { | ||
105 | unregister_hotcpu_notifier(&oprofile_cpu_notifier); | ||
46 | } | 106 | } |
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c index 417312528ddf..371dc564e2e4 100644 --- a/drivers/pci/intel-iommu.c +++ b/drivers/pci/intel-iommu.c | |||
@@ -3626,14 +3626,15 @@ static void intel_iommu_detach_device(struct iommu_domain *domain, | |||
3626 | domain_remove_one_dev_info(dmar_domain, pdev); | 3626 | domain_remove_one_dev_info(dmar_domain, pdev); |
3627 | } | 3627 | } |
3628 | 3628 | ||
3629 | static int intel_iommu_map_range(struct iommu_domain *domain, | 3629 | static int intel_iommu_map(struct iommu_domain *domain, |
3630 | unsigned long iova, phys_addr_t hpa, | 3630 | unsigned long iova, phys_addr_t hpa, |
3631 | size_t size, int iommu_prot) | 3631 | int gfp_order, int iommu_prot) |
3632 | { | 3632 | { |
3633 | struct dmar_domain *dmar_domain = domain->priv; | 3633 | struct dmar_domain *dmar_domain = domain->priv; |
3634 | u64 max_addr; | 3634 | u64 max_addr; |
3635 | int addr_width; | 3635 | int addr_width; |
3636 | int prot = 0; | 3636 | int prot = 0; |
3637 | size_t size; | ||
3637 | int ret; | 3638 | int ret; |
3638 | 3639 | ||
3639 | if (iommu_prot & IOMMU_READ) | 3640 | if (iommu_prot & IOMMU_READ) |
@@ -3643,6 +3644,7 @@ static int intel_iommu_map_range(struct iommu_domain *domain, | |||
3643 | if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) | 3644 | if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) |
3644 | prot |= DMA_PTE_SNP; | 3645 | prot |= DMA_PTE_SNP; |
3645 | 3646 | ||
3647 | size = PAGE_SIZE << gfp_order; | ||
3646 | max_addr = iova + size; | 3648 | max_addr = iova + size; |
3647 | if (dmar_domain->max_addr < max_addr) { | 3649 | if (dmar_domain->max_addr < max_addr) { |
3648 | int min_agaw; | 3650 | int min_agaw; |
@@ -3669,19 +3671,19 @@ static int intel_iommu_map_range(struct iommu_domain *domain, | |||
3669 | return ret; | 3671 | return ret; |
3670 | } | 3672 | } |
3671 | 3673 | ||
3672 | static void intel_iommu_unmap_range(struct iommu_domain *domain, | 3674 | static int intel_iommu_unmap(struct iommu_domain *domain, |
3673 | unsigned long iova, size_t size) | 3675 | unsigned long iova, int gfp_order) |
3674 | { | 3676 | { |
3675 | struct dmar_domain *dmar_domain = domain->priv; | 3677 | struct dmar_domain *dmar_domain = domain->priv; |
3676 | 3678 | size_t size = PAGE_SIZE << gfp_order; | |
3677 | if (!size) | ||
3678 | return; | ||
3679 | 3679 | ||
3680 | dma_pte_clear_range(dmar_domain, iova >> VTD_PAGE_SHIFT, | 3680 | dma_pte_clear_range(dmar_domain, iova >> VTD_PAGE_SHIFT, |
3681 | (iova + size - 1) >> VTD_PAGE_SHIFT); | 3681 | (iova + size - 1) >> VTD_PAGE_SHIFT); |
3682 | 3682 | ||
3683 | if (dmar_domain->max_addr == iova + size) | 3683 | if (dmar_domain->max_addr == iova + size) |
3684 | dmar_domain->max_addr = iova; | 3684 | dmar_domain->max_addr = iova; |
3685 | |||
3686 | return gfp_order; | ||
3685 | } | 3687 | } |
3686 | 3688 | ||
3687 | static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, | 3689 | static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, |
@@ -3714,8 +3716,8 @@ static struct iommu_ops intel_iommu_ops = { | |||
3714 | .domain_destroy = intel_iommu_domain_destroy, | 3716 | .domain_destroy = intel_iommu_domain_destroy, |
3715 | .attach_dev = intel_iommu_attach_device, | 3717 | .attach_dev = intel_iommu_attach_device, |
3716 | .detach_dev = intel_iommu_detach_device, | 3718 | .detach_dev = intel_iommu_detach_device, |
3717 | .map = intel_iommu_map_range, | 3719 | .map = intel_iommu_map, |
3718 | .unmap = intel_iommu_unmap_range, | 3720 | .unmap = intel_iommu_unmap, |
3719 | .iova_to_phys = intel_iommu_iova_to_phys, | 3721 | .iova_to_phys = intel_iommu_iova_to_phys, |
3720 | .domain_has_cap = intel_iommu_domain_has_cap, | 3722 | .domain_has_cap = intel_iommu_domain_has_cap, |
3721 | }; | 3723 | }; |
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 4fe36d2e1049..19b111383f62 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -838,65 +838,11 @@ static void pci_bus_dump_resources(struct pci_bus *bus) | |||
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | static int __init pci_bus_get_depth(struct pci_bus *bus) | ||
842 | { | ||
843 | int depth = 0; | ||
844 | struct pci_dev *dev; | ||
845 | |||
846 | list_for_each_entry(dev, &bus->devices, bus_list) { | ||
847 | int ret; | ||
848 | struct pci_bus *b = dev->subordinate; | ||
849 | if (!b) | ||
850 | continue; | ||
851 | |||
852 | ret = pci_bus_get_depth(b); | ||
853 | if (ret + 1 > depth) | ||
854 | depth = ret + 1; | ||
855 | } | ||
856 | |||
857 | return depth; | ||
858 | } | ||
859 | static int __init pci_get_max_depth(void) | ||
860 | { | ||
861 | int depth = 0; | ||
862 | struct pci_bus *bus; | ||
863 | |||
864 | list_for_each_entry(bus, &pci_root_buses, node) { | ||
865 | int ret; | ||
866 | |||
867 | ret = pci_bus_get_depth(bus); | ||
868 | if (ret > depth) | ||
869 | depth = ret; | ||
870 | } | ||
871 | |||
872 | return depth; | ||
873 | } | ||
874 | |||
875 | /* | ||
876 | * first try will not touch pci bridge res | ||
877 | * second and later try will clear small leaf bridge res | ||
878 | * will stop till to the max deepth if can not find good one | ||
879 | */ | ||
880 | void __init | 841 | void __init |
881 | pci_assign_unassigned_resources(void) | 842 | pci_assign_unassigned_resources(void) |
882 | { | 843 | { |
883 | struct pci_bus *bus; | 844 | struct pci_bus *bus; |
884 | int tried_times = 0; | ||
885 | enum release_type rel_type = leaf_only; | ||
886 | struct resource_list_x head, *list; | ||
887 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | | ||
888 | IORESOURCE_PREFETCH; | ||
889 | unsigned long failed_type; | ||
890 | int max_depth = pci_get_max_depth(); | ||
891 | int pci_try_num; | ||
892 | 845 | ||
893 | head.next = NULL; | ||
894 | |||
895 | pci_try_num = max_depth + 1; | ||
896 | printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n", | ||
897 | max_depth, pci_try_num); | ||
898 | |||
899 | again: | ||
900 | /* Depth first, calculate sizes and alignments of all | 846 | /* Depth first, calculate sizes and alignments of all |
901 | subordinate buses. */ | 847 | subordinate buses. */ |
902 | list_for_each_entry(bus, &pci_root_buses, node) { | 848 | list_for_each_entry(bus, &pci_root_buses, node) { |
@@ -904,65 +850,9 @@ again: | |||
904 | } | 850 | } |
905 | /* Depth last, allocate resources and update the hardware. */ | 851 | /* Depth last, allocate resources and update the hardware. */ |
906 | list_for_each_entry(bus, &pci_root_buses, node) { | 852 | list_for_each_entry(bus, &pci_root_buses, node) { |
907 | __pci_bus_assign_resources(bus, &head); | 853 | pci_bus_assign_resources(bus); |
908 | } | ||
909 | tried_times++; | ||
910 | |||
911 | /* any device complain? */ | ||
912 | if (!head.next) | ||
913 | goto enable_and_dump; | ||
914 | failed_type = 0; | ||
915 | for (list = head.next; list;) { | ||
916 | failed_type |= list->flags; | ||
917 | list = list->next; | ||
918 | } | ||
919 | /* | ||
920 | * io port are tight, don't try extra | ||
921 | * or if reach the limit, don't want to try more | ||
922 | */ | ||
923 | failed_type &= type_mask; | ||
924 | if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) { | ||
925 | free_failed_list(&head); | ||
926 | goto enable_and_dump; | ||
927 | } | ||
928 | |||
929 | printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n", | ||
930 | tried_times + 1); | ||
931 | |||
932 | /* third times and later will not check if it is leaf */ | ||
933 | if ((tried_times + 1) > 2) | ||
934 | rel_type = whole_subtree; | ||
935 | |||
936 | /* | ||
937 | * Try to release leaf bridge's resources that doesn't fit resource of | ||
938 | * child device under that bridge | ||
939 | */ | ||
940 | for (list = head.next; list;) { | ||
941 | bus = list->dev->bus; | ||
942 | pci_bus_release_bridge_resources(bus, list->flags & type_mask, | ||
943 | rel_type); | ||
944 | list = list->next; | ||
945 | } | ||
946 | /* restore size and flags */ | ||
947 | for (list = head.next; list;) { | ||
948 | struct resource *res = list->res; | ||
949 | |||
950 | res->start = list->start; | ||
951 | res->end = list->end; | ||
952 | res->flags = list->flags; | ||
953 | if (list->dev->subordinate) | ||
954 | res->flags = 0; | ||
955 | |||
956 | list = list->next; | ||
957 | } | ||
958 | free_failed_list(&head); | ||
959 | |||
960 | goto again; | ||
961 | |||
962 | enable_and_dump: | ||
963 | /* Depth last, update the hardware. */ | ||
964 | list_for_each_entry(bus, &pci_root_buses, node) | ||
965 | pci_enable_bridges(bus); | 854 | pci_enable_bridges(bus); |
855 | } | ||
966 | 856 | ||
967 | /* dump the resource on buses */ | 857 | /* dump the resource on buses */ |
968 | list_for_each_entry(bus, &pci_root_buses, node) { | 858 | list_for_each_entry(bus, &pci_root_buses, node) { |
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index acf222f91f5a..fa2339cb1681 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c | |||
@@ -37,6 +37,9 @@ | |||
37 | */ | 37 | */ |
38 | #define DASD_CHANQ_MAX_SIZE 4 | 38 | #define DASD_CHANQ_MAX_SIZE 4 |
39 | 39 | ||
40 | #define DASD_SLEEPON_START_TAG (void *) 1 | ||
41 | #define DASD_SLEEPON_END_TAG (void *) 2 | ||
42 | |||
40 | /* | 43 | /* |
41 | * SECTION: exported variables of dasd.c | 44 | * SECTION: exported variables of dasd.c |
42 | */ | 45 | */ |
@@ -1472,7 +1475,10 @@ void dasd_add_request_tail(struct dasd_ccw_req *cqr) | |||
1472 | */ | 1475 | */ |
1473 | static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) | 1476 | static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) |
1474 | { | 1477 | { |
1475 | wake_up((wait_queue_head_t *) data); | 1478 | spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev)); |
1479 | cqr->callback_data = DASD_SLEEPON_END_TAG; | ||
1480 | spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev)); | ||
1481 | wake_up(&generic_waitq); | ||
1476 | } | 1482 | } |
1477 | 1483 | ||
1478 | static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) | 1484 | static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) |
@@ -1482,10 +1488,7 @@ static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) | |||
1482 | 1488 | ||
1483 | device = cqr->startdev; | 1489 | device = cqr->startdev; |
1484 | spin_lock_irq(get_ccwdev_lock(device->cdev)); | 1490 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
1485 | rc = ((cqr->status == DASD_CQR_DONE || | 1491 | rc = (cqr->callback_data == DASD_SLEEPON_END_TAG); |
1486 | cqr->status == DASD_CQR_NEED_ERP || | ||
1487 | cqr->status == DASD_CQR_TERMINATED) && | ||
1488 | list_empty(&cqr->devlist)); | ||
1489 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); | 1492 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
1490 | return rc; | 1493 | return rc; |
1491 | } | 1494 | } |
@@ -1573,7 +1576,7 @@ static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible) | |||
1573 | wait_event(generic_waitq, !(device->stopped)); | 1576 | wait_event(generic_waitq, !(device->stopped)); |
1574 | 1577 | ||
1575 | cqr->callback = dasd_wakeup_cb; | 1578 | cqr->callback = dasd_wakeup_cb; |
1576 | cqr->callback_data = (void *) &generic_waitq; | 1579 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
1577 | dasd_add_request_tail(cqr); | 1580 | dasd_add_request_tail(cqr); |
1578 | if (interruptible) { | 1581 | if (interruptible) { |
1579 | rc = wait_event_interruptible( | 1582 | rc = wait_event_interruptible( |
@@ -1652,7 +1655,7 @@ int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) | |||
1652 | } | 1655 | } |
1653 | 1656 | ||
1654 | cqr->callback = dasd_wakeup_cb; | 1657 | cqr->callback = dasd_wakeup_cb; |
1655 | cqr->callback_data = (void *) &generic_waitq; | 1658 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
1656 | cqr->status = DASD_CQR_QUEUED; | 1659 | cqr->status = DASD_CQR_QUEUED; |
1657 | list_add(&cqr->devlist, &device->ccw_queue); | 1660 | list_add(&cqr->devlist, &device->ccw_queue); |
1658 | 1661 | ||
diff --git a/drivers/scsi/zorro7xx.c b/drivers/scsi/zorro7xx.c index 105449c15fa9..e17764d71476 100644 --- a/drivers/scsi/zorro7xx.c +++ b/drivers/scsi/zorro7xx.c | |||
@@ -69,6 +69,7 @@ static struct zorro_device_id zorro7xx_zorro_tbl[] __devinitdata = { | |||
69 | }, | 69 | }, |
70 | { 0 } | 70 | { 0 } |
71 | }; | 71 | }; |
72 | MODULE_DEVICE_TABLE(zorro, zorro7xx_zorro_tbl); | ||
72 | 73 | ||
73 | static int __devinit zorro7xx_init_one(struct zorro_dev *z, | 74 | static int __devinit zorro7xx_init_one(struct zorro_dev *z, |
74 | const struct zorro_device_id *ent) | 75 | const struct zorro_device_id *ent) |
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c index 4315b23590bd..eacb588a9345 100644 --- a/drivers/serial/imx.c +++ b/drivers/serial/imx.c | |||
@@ -120,7 +120,8 @@ | |||
120 | #define MX2_UCR3_RXDMUXSEL (1<<2) /* RXD Muxed Input Select, on mx2/mx3 */ | 120 | #define MX2_UCR3_RXDMUXSEL (1<<2) /* RXD Muxed Input Select, on mx2/mx3 */ |
121 | #define UCR3_INVT (1<<1) /* Inverted Infrared transmission */ | 121 | #define UCR3_INVT (1<<1) /* Inverted Infrared transmission */ |
122 | #define UCR3_BPEN (1<<0) /* Preset registers enable */ | 122 | #define UCR3_BPEN (1<<0) /* Preset registers enable */ |
123 | #define UCR4_CTSTL_32 (32<<10) /* CTS trigger level (32 chars) */ | 123 | #define UCR4_CTSTL_SHF 10 /* CTS trigger level shift */ |
124 | #define UCR4_CTSTL_MASK 0x3F /* CTS trigger is 6 bits wide */ | ||
124 | #define UCR4_INVR (1<<9) /* Inverted infrared reception */ | 125 | #define UCR4_INVR (1<<9) /* Inverted infrared reception */ |
125 | #define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */ | 126 | #define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */ |
126 | #define UCR4_WKEN (1<<7) /* Wake interrupt enable */ | 127 | #define UCR4_WKEN (1<<7) /* Wake interrupt enable */ |
@@ -591,6 +592,9 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) | |||
591 | return 0; | 592 | return 0; |
592 | } | 593 | } |
593 | 594 | ||
595 | /* half the RX buffer size */ | ||
596 | #define CTSTL 16 | ||
597 | |||
594 | static int imx_startup(struct uart_port *port) | 598 | static int imx_startup(struct uart_port *port) |
595 | { | 599 | { |
596 | struct imx_port *sport = (struct imx_port *)port; | 600 | struct imx_port *sport = (struct imx_port *)port; |
@@ -607,6 +611,10 @@ static int imx_startup(struct uart_port *port) | |||
607 | if (USE_IRDA(sport)) | 611 | if (USE_IRDA(sport)) |
608 | temp |= UCR4_IRSC; | 612 | temp |= UCR4_IRSC; |
609 | 613 | ||
614 | /* set the trigger level for CTS */ | ||
615 | temp &= ~(UCR4_CTSTL_MASK<< UCR4_CTSTL_SHF); | ||
616 | temp |= CTSTL<< UCR4_CTSTL_SHF; | ||
617 | |||
610 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); | 618 | writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); |
611 | 619 | ||
612 | if (USE_IRDA(sport)) { | 620 | if (USE_IRDA(sport)) { |
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c index a176ab4bd65b..02469c31bf0b 100644 --- a/drivers/serial/mpc52xx_uart.c +++ b/drivers/serial/mpc52xx_uart.c | |||
@@ -1467,7 +1467,7 @@ mpc52xx_uart_init(void) | |||
1467 | /* | 1467 | /* |
1468 | * Map the PSC FIFO Controller and init if on MPC512x. | 1468 | * Map the PSC FIFO Controller and init if on MPC512x. |
1469 | */ | 1469 | */ |
1470 | if (psc_ops->fifoc_init) { | 1470 | if (psc_ops && psc_ops->fifoc_init) { |
1471 | ret = psc_ops->fifoc_init(); | 1471 | ret = psc_ops->fifoc_init(); |
1472 | if (ret) | 1472 | if (ret) |
1473 | return ret; | 1473 | return ret; |
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c index 4a6366a42129..111a01a747fc 100644 --- a/drivers/usb/core/inode.c +++ b/drivers/usb/core/inode.c | |||
@@ -380,6 +380,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
380 | mutex_lock(&inode->i_mutex); | 380 | mutex_lock(&inode->i_mutex); |
381 | dentry_unhash(dentry); | 381 | dentry_unhash(dentry); |
382 | if (usbfs_empty(dentry)) { | 382 | if (usbfs_empty(dentry)) { |
383 | dont_mount(dentry); | ||
383 | drop_nlink(dentry->d_inode); | 384 | drop_nlink(dentry->d_inode); |
384 | drop_nlink(dentry->d_inode); | 385 | drop_nlink(dentry->d_inode); |
385 | dput(dentry); | 386 | dput(dentry); |
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c index dca48df98444..e5d6b56d4447 100644 --- a/drivers/video/amifb.c +++ b/drivers/video/amifb.c | |||
@@ -50,8 +50,9 @@ | |||
50 | #include <linux/fb.h> | 50 | #include <linux/fb.h> |
51 | #include <linux/init.h> | 51 | #include <linux/init.h> |
52 | #include <linux/ioport.h> | 52 | #include <linux/ioport.h> |
53 | 53 | #include <linux/platform_device.h> | |
54 | #include <linux/uaccess.h> | 54 | #include <linux/uaccess.h> |
55 | |||
55 | #include <asm/system.h> | 56 | #include <asm/system.h> |
56 | #include <asm/irq.h> | 57 | #include <asm/irq.h> |
57 | #include <asm/amigahw.h> | 58 | #include <asm/amigahw.h> |
@@ -1135,7 +1136,7 @@ static int amifb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg | |||
1135 | * Interface to the low level console driver | 1136 | * Interface to the low level console driver |
1136 | */ | 1137 | */ |
1137 | 1138 | ||
1138 | static void amifb_deinit(void); | 1139 | static void amifb_deinit(struct platform_device *pdev); |
1139 | 1140 | ||
1140 | /* | 1141 | /* |
1141 | * Internal routines | 1142 | * Internal routines |
@@ -2246,7 +2247,7 @@ static inline void chipfree(void) | |||
2246 | * Initialisation | 2247 | * Initialisation |
2247 | */ | 2248 | */ |
2248 | 2249 | ||
2249 | static int __init amifb_init(void) | 2250 | static int __init amifb_probe(struct platform_device *pdev) |
2250 | { | 2251 | { |
2251 | int tag, i, err = 0; | 2252 | int tag, i, err = 0; |
2252 | u_long chipptr; | 2253 | u_long chipptr; |
@@ -2261,16 +2262,6 @@ static int __init amifb_init(void) | |||
2261 | } | 2262 | } |
2262 | amifb_setup(option); | 2263 | amifb_setup(option); |
2263 | #endif | 2264 | #endif |
2264 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_VIDEO)) | ||
2265 | return -ENODEV; | ||
2266 | |||
2267 | /* | ||
2268 | * We request all registers starting from bplpt[0] | ||
2269 | */ | ||
2270 | if (!request_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120, | ||
2271 | "amifb [Denise/Lisa]")) | ||
2272 | return -EBUSY; | ||
2273 | |||
2274 | custom.dmacon = DMAF_ALL | DMAF_MASTER; | 2265 | custom.dmacon = DMAF_ALL | DMAF_MASTER; |
2275 | 2266 | ||
2276 | switch (amiga_chipset) { | 2267 | switch (amiga_chipset) { |
@@ -2377,6 +2368,7 @@ default_chipset: | |||
2377 | fb_info.fbops = &amifb_ops; | 2368 | fb_info.fbops = &amifb_ops; |
2378 | fb_info.par = ¤tpar; | 2369 | fb_info.par = ¤tpar; |
2379 | fb_info.flags = FBINFO_DEFAULT; | 2370 | fb_info.flags = FBINFO_DEFAULT; |
2371 | fb_info.device = &pdev->dev; | ||
2380 | 2372 | ||
2381 | if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, ami_modedb, | 2373 | if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, ami_modedb, |
2382 | NUM_TOTAL_MODES, &ami_modedb[defmode], 4)) { | 2374 | NUM_TOTAL_MODES, &ami_modedb[defmode], 4)) { |
@@ -2451,18 +2443,18 @@ default_chipset: | |||
2451 | return 0; | 2443 | return 0; |
2452 | 2444 | ||
2453 | amifb_error: | 2445 | amifb_error: |
2454 | amifb_deinit(); | 2446 | amifb_deinit(pdev); |
2455 | return err; | 2447 | return err; |
2456 | } | 2448 | } |
2457 | 2449 | ||
2458 | static void amifb_deinit(void) | 2450 | static void amifb_deinit(struct platform_device *pdev) |
2459 | { | 2451 | { |
2460 | if (fb_info.cmap.len) | 2452 | if (fb_info.cmap.len) |
2461 | fb_dealloc_cmap(&fb_info.cmap); | 2453 | fb_dealloc_cmap(&fb_info.cmap); |
2454 | fb_dealloc_cmap(&fb_info.cmap); | ||
2462 | chipfree(); | 2455 | chipfree(); |
2463 | if (videomemory) | 2456 | if (videomemory) |
2464 | iounmap((void*)videomemory); | 2457 | iounmap((void*)videomemory); |
2465 | release_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120); | ||
2466 | custom.dmacon = DMAF_ALL | DMAF_MASTER; | 2458 | custom.dmacon = DMAF_ALL | DMAF_MASTER; |
2467 | } | 2459 | } |
2468 | 2460 | ||
@@ -3794,14 +3786,35 @@ static void ami_rebuild_copper(void) | |||
3794 | } | 3786 | } |
3795 | } | 3787 | } |
3796 | 3788 | ||
3797 | static void __exit amifb_exit(void) | 3789 | static int __exit amifb_remove(struct platform_device *pdev) |
3798 | { | 3790 | { |
3799 | unregister_framebuffer(&fb_info); | 3791 | unregister_framebuffer(&fb_info); |
3800 | amifb_deinit(); | 3792 | amifb_deinit(pdev); |
3801 | amifb_video_off(); | 3793 | amifb_video_off(); |
3794 | return 0; | ||
3795 | } | ||
3796 | |||
3797 | static struct platform_driver amifb_driver = { | ||
3798 | .remove = __exit_p(amifb_remove), | ||
3799 | .driver = { | ||
3800 | .name = "amiga-video", | ||
3801 | .owner = THIS_MODULE, | ||
3802 | }, | ||
3803 | }; | ||
3804 | |||
3805 | static int __init amifb_init(void) | ||
3806 | { | ||
3807 | return platform_driver_probe(&amifb_driver, amifb_probe); | ||
3802 | } | 3808 | } |
3803 | 3809 | ||
3804 | module_init(amifb_init); | 3810 | module_init(amifb_init); |
3811 | |||
3812 | static void __exit amifb_exit(void) | ||
3813 | { | ||
3814 | platform_driver_unregister(&amifb_driver); | ||
3815 | } | ||
3816 | |||
3805 | module_exit(amifb_exit); | 3817 | module_exit(amifb_exit); |
3806 | 3818 | ||
3807 | MODULE_LICENSE("GPL"); | 3819 | MODULE_LICENSE("GPL"); |
3820 | MODULE_ALIAS("platform:amiga-video"); | ||
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c index 8d8dfda2f868..6df7c54db0a3 100644 --- a/drivers/video/cirrusfb.c +++ b/drivers/video/cirrusfb.c | |||
@@ -299,6 +299,7 @@ static const struct zorro_device_id cirrusfb_zorro_table[] = { | |||
299 | }, | 299 | }, |
300 | { 0 } | 300 | { 0 } |
301 | }; | 301 | }; |
302 | MODULE_DEVICE_TABLE(zorro, cirrusfb_zorro_table); | ||
302 | 303 | ||
303 | static const struct { | 304 | static const struct { |
304 | zorro_id id2; | 305 | zorro_id id2; |
diff --git a/drivers/video/fm2fb.c b/drivers/video/fm2fb.c index 6c91c61cdb63..1b0feb8e7244 100644 --- a/drivers/video/fm2fb.c +++ b/drivers/video/fm2fb.c | |||
@@ -219,6 +219,7 @@ static struct zorro_device_id fm2fb_devices[] __devinitdata = { | |||
219 | { ZORRO_PROD_HELFRICH_RAINBOW_II }, | 219 | { ZORRO_PROD_HELFRICH_RAINBOW_II }, |
220 | { 0 } | 220 | { 0 } |
221 | }; | 221 | }; |
222 | MODULE_DEVICE_TABLE(zorro, fm2fb_devices); | ||
222 | 223 | ||
223 | static struct zorro_driver fm2fb_driver = { | 224 | static struct zorro_driver fm2fb_driver = { |
224 | .name = "fm2fb", | 225 | .name = "fm2fb", |
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 0bf5020d0d32..b87ba23442d2 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
@@ -175,7 +175,7 @@ config SA1100_WATCHDOG | |||
175 | 175 | ||
176 | config MPCORE_WATCHDOG | 176 | config MPCORE_WATCHDOG |
177 | tristate "MPcore watchdog" | 177 | tristate "MPcore watchdog" |
178 | depends on ARM_MPCORE_PLATFORM && LOCAL_TIMERS | 178 | depends on HAVE_ARM_TWD |
179 | help | 179 | help |
180 | Watchdog timer embedded into the MPcore system. | 180 | Watchdog timer embedded into the MPcore system. |
181 | 181 | ||
diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c index 016c6a791cab..b8ec7aca3c8e 100644 --- a/drivers/watchdog/mpcore_wdt.c +++ b/drivers/watchdog/mpcore_wdt.c | |||
@@ -31,8 +31,9 @@ | |||
31 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
32 | #include <linux/uaccess.h> | 32 | #include <linux/uaccess.h> |
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <linux/io.h> | ||
34 | 35 | ||
35 | #include <asm/hardware/arm_twd.h> | 36 | #include <asm/smp_twd.h> |
36 | 37 | ||
37 | struct mpcore_wdt { | 38 | struct mpcore_wdt { |
38 | unsigned long timer_alive; | 39 | unsigned long timer_alive; |
@@ -44,7 +45,7 @@ struct mpcore_wdt { | |||
44 | }; | 45 | }; |
45 | 46 | ||
46 | static struct platform_device *mpcore_wdt_dev; | 47 | static struct platform_device *mpcore_wdt_dev; |
47 | extern unsigned int mpcore_timer_rate; | 48 | static DEFINE_SPINLOCK(wdt_lock); |
48 | 49 | ||
49 | #define TIMER_MARGIN 60 | 50 | #define TIMER_MARGIN 60 |
50 | static int mpcore_margin = TIMER_MARGIN; | 51 | static int mpcore_margin = TIMER_MARGIN; |
@@ -94,13 +95,15 @@ static irqreturn_t mpcore_wdt_fire(int irq, void *arg) | |||
94 | */ | 95 | */ |
95 | static void mpcore_wdt_keepalive(struct mpcore_wdt *wdt) | 96 | static void mpcore_wdt_keepalive(struct mpcore_wdt *wdt) |
96 | { | 97 | { |
97 | unsigned int count; | 98 | unsigned long count; |
98 | 99 | ||
100 | spin_lock(&wdt_lock); | ||
99 | /* Assume prescale is set to 256 */ | 101 | /* Assume prescale is set to 256 */ |
100 | count = (mpcore_timer_rate / 256) * mpcore_margin; | 102 | count = __raw_readl(wdt->base + TWD_WDOG_COUNTER); |
103 | count = (0xFFFFFFFFU - count) * (HZ / 5); | ||
104 | count = (count / 256) * mpcore_margin; | ||
101 | 105 | ||
102 | /* Reload the counter */ | 106 | /* Reload the counter */ |
103 | spin_lock(&wdt_lock); | ||
104 | writel(count + wdt->perturb, wdt->base + TWD_WDOG_LOAD); | 107 | writel(count + wdt->perturb, wdt->base + TWD_WDOG_LOAD); |
105 | wdt->perturb = wdt->perturb ? 0 : 1; | 108 | wdt->perturb = wdt->perturb ? 0 : 1; |
106 | spin_unlock(&wdt_lock); | 109 | spin_unlock(&wdt_lock); |
@@ -119,7 +122,6 @@ static void mpcore_wdt_start(struct mpcore_wdt *wdt) | |||
119 | { | 122 | { |
120 | dev_printk(KERN_INFO, wdt->dev, "enabling watchdog.\n"); | 123 | dev_printk(KERN_INFO, wdt->dev, "enabling watchdog.\n"); |
121 | 124 | ||
122 | spin_lock(&wdt_lock); | ||
123 | /* This loads the count register but does NOT start the count yet */ | 125 | /* This loads the count register but does NOT start the count yet */ |
124 | mpcore_wdt_keepalive(wdt); | 126 | mpcore_wdt_keepalive(wdt); |
125 | 127 | ||
@@ -130,7 +132,6 @@ static void mpcore_wdt_start(struct mpcore_wdt *wdt) | |||
130 | /* Enable watchdog - prescale=256, watchdog mode=1, enable=1 */ | 132 | /* Enable watchdog - prescale=256, watchdog mode=1, enable=1 */ |
131 | writel(0x0000FF09, wdt->base + TWD_WDOG_CONTROL); | 133 | writel(0x0000FF09, wdt->base + TWD_WDOG_CONTROL); |
132 | } | 134 | } |
133 | spin_unlock(&wdt_lock); | ||
134 | } | 135 | } |
135 | 136 | ||
136 | static int mpcore_wdt_set_heartbeat(int t) | 137 | static int mpcore_wdt_set_heartbeat(int t) |
@@ -360,7 +361,7 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev) | |||
360 | mpcore_wdt_miscdev.parent = &dev->dev; | 361 | mpcore_wdt_miscdev.parent = &dev->dev; |
361 | ret = misc_register(&mpcore_wdt_miscdev); | 362 | ret = misc_register(&mpcore_wdt_miscdev); |
362 | if (ret) { | 363 | if (ret) { |
363 | dev_printk(KERN_ERR, _dev, | 364 | dev_printk(KERN_ERR, wdt->dev, |
364 | "cannot register miscdev on minor=%d (err=%d)\n", | 365 | "cannot register miscdev on minor=%d (err=%d)\n", |
365 | WATCHDOG_MINOR, ret); | 366 | WATCHDOG_MINOR, ret); |
366 | goto err_misc; | 367 | goto err_misc; |
@@ -369,13 +370,13 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev) | |||
369 | ret = request_irq(wdt->irq, mpcore_wdt_fire, IRQF_DISABLED, | 370 | ret = request_irq(wdt->irq, mpcore_wdt_fire, IRQF_DISABLED, |
370 | "mpcore_wdt", wdt); | 371 | "mpcore_wdt", wdt); |
371 | if (ret) { | 372 | if (ret) { |
372 | dev_printk(KERN_ERR, _dev, | 373 | dev_printk(KERN_ERR, wdt->dev, |
373 | "cannot register IRQ%d for watchdog\n", wdt->irq); | 374 | "cannot register IRQ%d for watchdog\n", wdt->irq); |
374 | goto err_irq; | 375 | goto err_irq; |
375 | } | 376 | } |
376 | 377 | ||
377 | mpcore_wdt_stop(wdt); | 378 | mpcore_wdt_stop(wdt); |
378 | platform_set_drvdata(&dev->dev, wdt); | 379 | platform_set_drvdata(dev, wdt); |
379 | mpcore_wdt_dev = dev; | 380 | mpcore_wdt_dev = dev; |
380 | 381 | ||
381 | return 0; | 382 | return 0; |
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index 2ac4440e7b08..8943b8ccee1a 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
@@ -80,12 +80,6 @@ static void do_suspend(void) | |||
80 | 80 | ||
81 | shutting_down = SHUTDOWN_SUSPEND; | 81 | shutting_down = SHUTDOWN_SUSPEND; |
82 | 82 | ||
83 | err = stop_machine_create(); | ||
84 | if (err) { | ||
85 | printk(KERN_ERR "xen suspend: failed to setup stop_machine %d\n", err); | ||
86 | goto out; | ||
87 | } | ||
88 | |||
89 | #ifdef CONFIG_PREEMPT | 83 | #ifdef CONFIG_PREEMPT |
90 | /* If the kernel is preemptible, we need to freeze all the processes | 84 | /* If the kernel is preemptible, we need to freeze all the processes |
91 | to prevent them from being in the middle of a pagetable update | 85 | to prevent them from being in the middle of a pagetable update |
@@ -93,7 +87,7 @@ static void do_suspend(void) | |||
93 | err = freeze_processes(); | 87 | err = freeze_processes(); |
94 | if (err) { | 88 | if (err) { |
95 | printk(KERN_ERR "xen suspend: freeze failed %d\n", err); | 89 | printk(KERN_ERR "xen suspend: freeze failed %d\n", err); |
96 | goto out_destroy_sm; | 90 | goto out; |
97 | } | 91 | } |
98 | #endif | 92 | #endif |
99 | 93 | ||
@@ -136,12 +130,8 @@ out_resume: | |||
136 | out_thaw: | 130 | out_thaw: |
137 | #ifdef CONFIG_PREEMPT | 131 | #ifdef CONFIG_PREEMPT |
138 | thaw_processes(); | 132 | thaw_processes(); |
139 | |||
140 | out_destroy_sm: | ||
141 | #endif | ||
142 | stop_machine_destroy(); | ||
143 | |||
144 | out: | 133 | out: |
134 | #endif | ||
145 | shutting_down = SHUTDOWN_INVALID; | 135 | shutting_down = SHUTDOWN_INVALID; |
146 | } | 136 | } |
147 | #endif /* CONFIG_PM_SLEEP */ | 137 | #endif /* CONFIG_PM_SLEEP */ |
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c index d47c47fc048f..3c7046d79654 100644 --- a/drivers/zorro/proc.c +++ b/drivers/zorro/proc.c | |||
@@ -97,7 +97,7 @@ static void zorro_seq_stop(struct seq_file *m, void *v) | |||
97 | 97 | ||
98 | static int zorro_seq_show(struct seq_file *m, void *v) | 98 | static int zorro_seq_show(struct seq_file *m, void *v) |
99 | { | 99 | { |
100 | u_int slot = *(loff_t *)v; | 100 | unsigned int slot = *(loff_t *)v; |
101 | struct zorro_dev *z = &zorro_autocon[slot]; | 101 | struct zorro_dev *z = &zorro_autocon[slot]; |
102 | 102 | ||
103 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, | 103 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, |
@@ -129,7 +129,7 @@ static const struct file_operations zorro_devices_proc_fops = { | |||
129 | 129 | ||
130 | static struct proc_dir_entry *proc_bus_zorro_dir; | 130 | static struct proc_dir_entry *proc_bus_zorro_dir; |
131 | 131 | ||
132 | static int __init zorro_proc_attach_device(u_int slot) | 132 | static int __init zorro_proc_attach_device(unsigned int slot) |
133 | { | 133 | { |
134 | struct proc_dir_entry *entry; | 134 | struct proc_dir_entry *entry; |
135 | char name[4]; | 135 | char name[4]; |
@@ -146,7 +146,7 @@ static int __init zorro_proc_attach_device(u_int slot) | |||
146 | 146 | ||
147 | static int __init zorro_proc_init(void) | 147 | static int __init zorro_proc_init(void) |
148 | { | 148 | { |
149 | u_int slot; | 149 | unsigned int slot; |
150 | 150 | ||
151 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { | 151 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { |
152 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); | 152 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); |
diff --git a/drivers/zorro/zorro-driver.c b/drivers/zorro/zorro-driver.c index 53180a37cc9a..7ee2b6e71786 100644 --- a/drivers/zorro/zorro-driver.c +++ b/drivers/zorro/zorro-driver.c | |||
@@ -137,10 +137,34 @@ static int zorro_bus_match(struct device *dev, struct device_driver *drv) | |||
137 | return 0; | 137 | return 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env) | ||
141 | { | ||
142 | #ifdef CONFIG_HOTPLUG | ||
143 | struct zorro_dev *z; | ||
144 | |||
145 | if (!dev) | ||
146 | return -ENODEV; | ||
147 | |||
148 | z = to_zorro_dev(dev); | ||
149 | if (!z) | ||
150 | return -ENODEV; | ||
151 | |||
152 | if (add_uevent_var(env, "ZORRO_ID=%08X", z->id) || | ||
153 | add_uevent_var(env, "ZORRO_SLOT_NAME=%s", dev_name(dev)) || | ||
154 | add_uevent_var(env, "ZORRO_SLOT_ADDR=%04X", z->slotaddr) || | ||
155 | add_uevent_var(env, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT, z->id)) | ||
156 | return -ENOMEM; | ||
157 | |||
158 | return 0; | ||
159 | #else /* !CONFIG_HOTPLUG */ | ||
160 | return -ENODEV; | ||
161 | #endif /* !CONFIG_HOTPLUG */ | ||
162 | } | ||
140 | 163 | ||
141 | struct bus_type zorro_bus_type = { | 164 | struct bus_type zorro_bus_type = { |
142 | .name = "zorro", | 165 | .name = "zorro", |
143 | .match = zorro_bus_match, | 166 | .match = zorro_bus_match, |
167 | .uevent = zorro_uevent, | ||
144 | .probe = zorro_device_probe, | 168 | .probe = zorro_device_probe, |
145 | .remove = zorro_device_remove, | 169 | .remove = zorro_device_remove, |
146 | }; | 170 | }; |
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c index 1d2a772ea14c..eb924e0a64ce 100644 --- a/drivers/zorro/zorro-sysfs.c +++ b/drivers/zorro/zorro-sysfs.c | |||
@@ -77,6 +77,16 @@ static struct bin_attribute zorro_config_attr = { | |||
77 | .read = zorro_read_config, | 77 | .read = zorro_read_config, |
78 | }; | 78 | }; |
79 | 79 | ||
80 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | ||
81 | char *buf) | ||
82 | { | ||
83 | struct zorro_dev *z = to_zorro_dev(dev); | ||
84 | |||
85 | return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id); | ||
86 | } | ||
87 | |||
88 | static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL); | ||
89 | |||
80 | int zorro_create_sysfs_dev_files(struct zorro_dev *z) | 90 | int zorro_create_sysfs_dev_files(struct zorro_dev *z) |
81 | { | 91 | { |
82 | struct device *dev = &z->dev; | 92 | struct device *dev = &z->dev; |
@@ -89,6 +99,7 @@ int zorro_create_sysfs_dev_files(struct zorro_dev *z) | |||
89 | (error = device_create_file(dev, &dev_attr_slotaddr)) || | 99 | (error = device_create_file(dev, &dev_attr_slotaddr)) || |
90 | (error = device_create_file(dev, &dev_attr_slotsize)) || | 100 | (error = device_create_file(dev, &dev_attr_slotsize)) || |
91 | (error = device_create_file(dev, &dev_attr_resource)) || | 101 | (error = device_create_file(dev, &dev_attr_resource)) || |
102 | (error = device_create_file(dev, &dev_attr_modalias)) || | ||
92 | (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) | 103 | (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr))) |
93 | return error; | 104 | return error; |
94 | 105 | ||
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c index d45fb34e2d23..6455f3a244c5 100644 --- a/drivers/zorro/zorro.c +++ b/drivers/zorro/zorro.c | |||
@@ -15,6 +15,8 @@ | |||
15 | #include <linux/zorro.h> | 15 | #include <linux/zorro.h> |
16 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/string.h> | 17 | #include <linux/string.h> |
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/slab.h> | ||
18 | 20 | ||
19 | #include <asm/setup.h> | 21 | #include <asm/setup.h> |
20 | #include <asm/amigahw.h> | 22 | #include <asm/amigahw.h> |
@@ -26,24 +28,17 @@ | |||
26 | * Zorro Expansion Devices | 28 | * Zorro Expansion Devices |
27 | */ | 29 | */ |
28 | 30 | ||
29 | u_int zorro_num_autocon = 0; | 31 | unsigned int zorro_num_autocon; |
30 | struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO]; | 32 | struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO]; |
31 | 33 | ||
32 | 34 | ||
33 | /* | 35 | /* |
34 | * Single Zorro bus | 36 | * Zorro bus |
35 | */ | 37 | */ |
36 | 38 | ||
37 | struct zorro_bus zorro_bus = {\ | 39 | struct zorro_bus { |
38 | .resources = { | 40 | struct list_head devices; /* list of devices on this bus */ |
39 | /* Zorro II regions (on Zorro II/III) */ | 41 | struct device dev; |
40 | { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff }, | ||
41 | { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff }, | ||
42 | /* Zorro III regions (on Zorro III only) */ | ||
43 | { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff }, | ||
44 | { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff } | ||
45 | }, | ||
46 | .name = "Zorro bus" | ||
47 | }; | 42 | }; |
48 | 43 | ||
49 | 44 | ||
@@ -53,18 +48,19 @@ struct zorro_bus zorro_bus = {\ | |||
53 | 48 | ||
54 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) | 49 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) |
55 | { | 50 | { |
56 | struct zorro_dev *z; | 51 | struct zorro_dev *z; |
57 | 52 | ||
58 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) | 53 | if (!zorro_num_autocon) |
59 | return NULL; | 54 | return NULL; |
60 | 55 | ||
61 | for (z = from ? from+1 : &zorro_autocon[0]; | 56 | for (z = from ? from+1 : &zorro_autocon[0]; |
62 | z < zorro_autocon+zorro_num_autocon; | 57 | z < zorro_autocon+zorro_num_autocon; |
63 | z++) | 58 | z++) |
64 | if (id == ZORRO_WILDCARD || id == z->id) | 59 | if (id == ZORRO_WILDCARD || id == z->id) |
65 | return z; | 60 | return z; |
66 | return NULL; | 61 | return NULL; |
67 | } | 62 | } |
63 | EXPORT_SYMBOL(zorro_find_device); | ||
68 | 64 | ||
69 | 65 | ||
70 | /* | 66 | /* |
@@ -83,121 +79,138 @@ struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) | |||
83 | */ | 79 | */ |
84 | 80 | ||
85 | DECLARE_BITMAP(zorro_unused_z2ram, 128); | 81 | DECLARE_BITMAP(zorro_unused_z2ram, 128); |
82 | EXPORT_SYMBOL(zorro_unused_z2ram); | ||
86 | 83 | ||
87 | 84 | ||
88 | static void __init mark_region(unsigned long start, unsigned long end, | 85 | static void __init mark_region(unsigned long start, unsigned long end, |
89 | int flag) | 86 | int flag) |
90 | { | 87 | { |
91 | if (flag) | ||
92 | start += Z2RAM_CHUNKMASK; | ||
93 | else | ||
94 | end += Z2RAM_CHUNKMASK; | ||
95 | start &= ~Z2RAM_CHUNKMASK; | ||
96 | end &= ~Z2RAM_CHUNKMASK; | ||
97 | |||
98 | if (end <= Z2RAM_START || start >= Z2RAM_END) | ||
99 | return; | ||
100 | start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START; | ||
101 | end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START; | ||
102 | while (start < end) { | ||
103 | u32 chunk = start>>Z2RAM_CHUNKSHIFT; | ||
104 | if (flag) | 88 | if (flag) |
105 | set_bit(chunk, zorro_unused_z2ram); | 89 | start += Z2RAM_CHUNKMASK; |
106 | else | 90 | else |
107 | clear_bit(chunk, zorro_unused_z2ram); | 91 | end += Z2RAM_CHUNKMASK; |
108 | start += Z2RAM_CHUNKSIZE; | 92 | start &= ~Z2RAM_CHUNKMASK; |
109 | } | 93 | end &= ~Z2RAM_CHUNKMASK; |
94 | |||
95 | if (end <= Z2RAM_START || start >= Z2RAM_END) | ||
96 | return; | ||
97 | start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START; | ||
98 | end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START; | ||
99 | while (start < end) { | ||
100 | u32 chunk = start>>Z2RAM_CHUNKSHIFT; | ||
101 | if (flag) | ||
102 | set_bit(chunk, zorro_unused_z2ram); | ||
103 | else | ||
104 | clear_bit(chunk, zorro_unused_z2ram); | ||
105 | start += Z2RAM_CHUNKSIZE; | ||
106 | } | ||
110 | } | 107 | } |
111 | 108 | ||
112 | 109 | ||
113 | static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z) | 110 | static struct resource __init *zorro_find_parent_resource( |
111 | struct platform_device *bridge, struct zorro_dev *z) | ||
114 | { | 112 | { |
115 | int i; | 113 | int i; |
116 | 114 | ||
117 | for (i = 0; i < zorro_bus.num_resources; i++) | 115 | for (i = 0; i < bridge->num_resources; i++) { |
118 | if (zorro_resource_start(z) >= zorro_bus.resources[i].start && | 116 | struct resource *r = &bridge->resource[i]; |
119 | zorro_resource_end(z) <= zorro_bus.resources[i].end) | 117 | if (zorro_resource_start(z) >= r->start && |
120 | return &zorro_bus.resources[i]; | 118 | zorro_resource_end(z) <= r->end) |
121 | return &iomem_resource; | 119 | return r; |
120 | } | ||
121 | return &iomem_resource; | ||
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | /* | ||
126 | * Initialization | ||
127 | */ | ||
128 | 125 | ||
129 | static int __init zorro_init(void) | 126 | static int __init amiga_zorro_probe(struct platform_device *pdev) |
130 | { | 127 | { |
131 | struct zorro_dev *z; | 128 | struct zorro_bus *bus; |
132 | unsigned int i; | 129 | struct zorro_dev *z; |
133 | int error; | 130 | struct resource *r; |
134 | 131 | unsigned int i; | |
135 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) | 132 | int error; |
136 | return 0; | 133 | |
137 | 134 | /* Initialize the Zorro bus */ | |
138 | pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n", | 135 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); |
139 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); | 136 | if (!bus) |
140 | 137 | return -ENOMEM; | |
141 | /* Initialize the Zorro bus */ | 138 | |
142 | INIT_LIST_HEAD(&zorro_bus.devices); | 139 | INIT_LIST_HEAD(&bus->devices); |
143 | dev_set_name(&zorro_bus.dev, "zorro"); | 140 | bus->dev.parent = &pdev->dev; |
144 | error = device_register(&zorro_bus.dev); | 141 | dev_set_name(&bus->dev, "zorro"); |
145 | if (error) { | 142 | error = device_register(&bus->dev); |
146 | pr_err("Zorro: Error registering zorro_bus\n"); | ||
147 | return error; | ||
148 | } | ||
149 | |||
150 | /* Request the resources */ | ||
151 | zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2; | ||
152 | for (i = 0; i < zorro_bus.num_resources; i++) | ||
153 | request_resource(&iomem_resource, &zorro_bus.resources[i]); | ||
154 | |||
155 | /* Register all devices */ | ||
156 | for (i = 0; i < zorro_num_autocon; i++) { | ||
157 | z = &zorro_autocon[i]; | ||
158 | z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8); | ||
159 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { | ||
160 | /* GVP quirk */ | ||
161 | unsigned long magic = zorro_resource_start(z)+0x8000; | ||
162 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; | ||
163 | } | ||
164 | sprintf(z->name, "Zorro device %08x", z->id); | ||
165 | zorro_name_device(z); | ||
166 | z->resource.name = z->name; | ||
167 | if (request_resource(zorro_find_parent_resource(z), &z->resource)) | ||
168 | pr_err("Zorro: Address space collision on device %s %pR\n", | ||
169 | z->name, &z->resource); | ||
170 | dev_set_name(&z->dev, "%02x", i); | ||
171 | z->dev.parent = &zorro_bus.dev; | ||
172 | z->dev.bus = &zorro_bus_type; | ||
173 | error = device_register(&z->dev); | ||
174 | if (error) { | 143 | if (error) { |
175 | pr_err("Zorro: Error registering device %s\n", z->name); | 144 | pr_err("Zorro: Error registering zorro_bus\n"); |
176 | continue; | 145 | kfree(bus); |
146 | return error; | ||
177 | } | 147 | } |
178 | error = zorro_create_sysfs_dev_files(z); | 148 | platform_set_drvdata(pdev, bus); |
179 | if (error) | 149 | |
180 | dev_err(&z->dev, "Error creating sysfs files\n"); | 150 | /* Register all devices */ |
181 | } | 151 | pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n", |
182 | 152 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); | |
183 | /* Mark all available Zorro II memory */ | 153 | |
184 | zorro_for_each_dev(z) { | 154 | for (i = 0; i < zorro_num_autocon; i++) { |
185 | if (z->rom.er_Type & ERTF_MEMLIST) | 155 | z = &zorro_autocon[i]; |
186 | mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1); | 156 | z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8); |
187 | } | 157 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { |
188 | 158 | /* GVP quirk */ | |
189 | /* Unmark all used Zorro II memory */ | 159 | unsigned long magic = zorro_resource_start(z)+0x8000; |
190 | for (i = 0; i < m68k_num_memory; i++) | 160 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; |
191 | if (m68k_memory[i].addr < 16*1024*1024) | 161 | } |
192 | mark_region(m68k_memory[i].addr, | 162 | sprintf(z->name, "Zorro device %08x", z->id); |
193 | m68k_memory[i].addr+m68k_memory[i].size, 0); | 163 | zorro_name_device(z); |
194 | 164 | z->resource.name = z->name; | |
195 | return 0; | 165 | r = zorro_find_parent_resource(pdev, z); |
166 | error = request_resource(r, &z->resource); | ||
167 | if (error) | ||
168 | dev_err(&bus->dev, | ||
169 | "Address space collision on device %s %pR\n", | ||
170 | z->name, &z->resource); | ||
171 | dev_set_name(&z->dev, "%02x", i); | ||
172 | z->dev.parent = &bus->dev; | ||
173 | z->dev.bus = &zorro_bus_type; | ||
174 | error = device_register(&z->dev); | ||
175 | if (error) { | ||
176 | dev_err(&bus->dev, "Error registering device %s\n", | ||
177 | z->name); | ||
178 | continue; | ||
179 | } | ||
180 | error = zorro_create_sysfs_dev_files(z); | ||
181 | if (error) | ||
182 | dev_err(&z->dev, "Error creating sysfs files\n"); | ||
183 | } | ||
184 | |||
185 | /* Mark all available Zorro II memory */ | ||
186 | zorro_for_each_dev(z) { | ||
187 | if (z->rom.er_Type & ERTF_MEMLIST) | ||
188 | mark_region(zorro_resource_start(z), | ||
189 | zorro_resource_end(z)+1, 1); | ||
190 | } | ||
191 | |||
192 | /* Unmark all used Zorro II memory */ | ||
193 | for (i = 0; i < m68k_num_memory; i++) | ||
194 | if (m68k_memory[i].addr < 16*1024*1024) | ||
195 | mark_region(m68k_memory[i].addr, | ||
196 | m68k_memory[i].addr+m68k_memory[i].size, | ||
197 | 0); | ||
198 | |||
199 | return 0; | ||
196 | } | 200 | } |
197 | 201 | ||
198 | subsys_initcall(zorro_init); | 202 | static struct platform_driver amiga_zorro_driver = { |
203 | .driver = { | ||
204 | .name = "amiga-zorro", | ||
205 | .owner = THIS_MODULE, | ||
206 | }, | ||
207 | }; | ||
199 | 208 | ||
200 | EXPORT_SYMBOL(zorro_find_device); | 209 | static int __init amiga_zorro_init(void) |
201 | EXPORT_SYMBOL(zorro_unused_z2ram); | 210 | { |
211 | return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe); | ||
212 | } | ||
213 | |||
214 | module_init(amiga_zorro_init); | ||
202 | 215 | ||
203 | MODULE_LICENSE("GPL"); | 216 | MODULE_LICENSE("GPL"); |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index e84ef60ffe35..97a97839a867 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1481,12 +1481,17 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
1481 | ret = -EBADF; | 1481 | ret = -EBADF; |
1482 | goto out_drop_write; | 1482 | goto out_drop_write; |
1483 | } | 1483 | } |
1484 | |||
1484 | src = src_file->f_dentry->d_inode; | 1485 | src = src_file->f_dentry->d_inode; |
1485 | 1486 | ||
1486 | ret = -EINVAL; | 1487 | ret = -EINVAL; |
1487 | if (src == inode) | 1488 | if (src == inode) |
1488 | goto out_fput; | 1489 | goto out_fput; |
1489 | 1490 | ||
1491 | /* the src must be open for reading */ | ||
1492 | if (!(src_file->f_mode & FMODE_READ)) | ||
1493 | goto out_fput; | ||
1494 | |||
1490 | ret = -EISDIR; | 1495 | ret = -EISDIR; |
1491 | if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode)) | 1496 | if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode)) |
1492 | goto out_fput; | 1497 | goto out_fput; |
diff --git a/fs/cachefiles/security.c b/fs/cachefiles/security.c index b5808cdb2232..039b5011d83b 100644 --- a/fs/cachefiles/security.c +++ b/fs/cachefiles/security.c | |||
@@ -77,6 +77,8 @@ static int cachefiles_check_cache_dir(struct cachefiles_cache *cache, | |||
77 | /* | 77 | /* |
78 | * check the security details of the on-disk cache | 78 | * check the security details of the on-disk cache |
79 | * - must be called with security override in force | 79 | * - must be called with security override in force |
80 | * - must return with a security override in force - even in the case of an | ||
81 | * error | ||
80 | */ | 82 | */ |
81 | int cachefiles_determine_cache_security(struct cachefiles_cache *cache, | 83 | int cachefiles_determine_cache_security(struct cachefiles_cache *cache, |
82 | struct dentry *root, | 84 | struct dentry *root, |
@@ -99,6 +101,8 @@ int cachefiles_determine_cache_security(struct cachefiles_cache *cache, | |||
99 | * which create files */ | 101 | * which create files */ |
100 | ret = set_create_files_as(new, root->d_inode); | 102 | ret = set_create_files_as(new, root->d_inode); |
101 | if (ret < 0) { | 103 | if (ret < 0) { |
104 | abort_creds(new); | ||
105 | cachefiles_begin_secure(cache, _saved_cred); | ||
102 | _leave(" = %d [cfa]", ret); | 106 | _leave(" = %d [cfa]", ret); |
103 | return ret; | 107 | return ret; |
104 | } | 108 | } |
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 4b42c2bb603f..a9005d862ed4 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c | |||
@@ -504,7 +504,6 @@ static void writepages_finish(struct ceph_osd_request *req, | |||
504 | int i; | 504 | int i; |
505 | struct ceph_snap_context *snapc = req->r_snapc; | 505 | struct ceph_snap_context *snapc = req->r_snapc; |
506 | struct address_space *mapping = inode->i_mapping; | 506 | struct address_space *mapping = inode->i_mapping; |
507 | struct writeback_control *wbc = req->r_wbc; | ||
508 | __s32 rc = -EIO; | 507 | __s32 rc = -EIO; |
509 | u64 bytes = 0; | 508 | u64 bytes = 0; |
510 | struct ceph_client *client = ceph_inode_to_client(inode); | 509 | struct ceph_client *client = ceph_inode_to_client(inode); |
@@ -546,10 +545,6 @@ static void writepages_finish(struct ceph_osd_request *req, | |||
546 | clear_bdi_congested(&client->backing_dev_info, | 545 | clear_bdi_congested(&client->backing_dev_info, |
547 | BLK_RW_ASYNC); | 546 | BLK_RW_ASYNC); |
548 | 547 | ||
549 | if (i >= wrote) { | ||
550 | dout("inode %p skipping page %p\n", inode, page); | ||
551 | wbc->pages_skipped++; | ||
552 | } | ||
553 | ceph_put_snap_context((void *)page->private); | 548 | ceph_put_snap_context((void *)page->private); |
554 | page->private = 0; | 549 | page->private = 0; |
555 | ClearPagePrivate(page); | 550 | ClearPagePrivate(page); |
@@ -799,7 +794,6 @@ get_more_pages: | |||
799 | alloc_page_vec(client, req); | 794 | alloc_page_vec(client, req); |
800 | req->r_callback = writepages_finish; | 795 | req->r_callback = writepages_finish; |
801 | req->r_inode = inode; | 796 | req->r_inode = inode; |
802 | req->r_wbc = wbc; | ||
803 | } | 797 | } |
804 | 798 | ||
805 | /* note position of first page in pvec */ | 799 | /* note position of first page in pvec */ |
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 0c1681806867..d9400534b279 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c | |||
@@ -858,6 +858,8 @@ static int __ceph_is_any_caps(struct ceph_inode_info *ci) | |||
858 | } | 858 | } |
859 | 859 | ||
860 | /* | 860 | /* |
861 | * Remove a cap. Take steps to deal with a racing iterate_session_caps. | ||
862 | * | ||
861 | * caller should hold i_lock. | 863 | * caller should hold i_lock. |
862 | * caller will not hold session s_mutex if called from destroy_inode. | 864 | * caller will not hold session s_mutex if called from destroy_inode. |
863 | */ | 865 | */ |
@@ -866,15 +868,10 @@ void __ceph_remove_cap(struct ceph_cap *cap) | |||
866 | struct ceph_mds_session *session = cap->session; | 868 | struct ceph_mds_session *session = cap->session; |
867 | struct ceph_inode_info *ci = cap->ci; | 869 | struct ceph_inode_info *ci = cap->ci; |
868 | struct ceph_mds_client *mdsc = &ceph_client(ci->vfs_inode.i_sb)->mdsc; | 870 | struct ceph_mds_client *mdsc = &ceph_client(ci->vfs_inode.i_sb)->mdsc; |
871 | int removed = 0; | ||
869 | 872 | ||
870 | dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); | 873 | dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); |
871 | 874 | ||
872 | /* remove from inode list */ | ||
873 | rb_erase(&cap->ci_node, &ci->i_caps); | ||
874 | cap->ci = NULL; | ||
875 | if (ci->i_auth_cap == cap) | ||
876 | ci->i_auth_cap = NULL; | ||
877 | |||
878 | /* remove from session list */ | 875 | /* remove from session list */ |
879 | spin_lock(&session->s_cap_lock); | 876 | spin_lock(&session->s_cap_lock); |
880 | if (session->s_cap_iterator == cap) { | 877 | if (session->s_cap_iterator == cap) { |
@@ -885,10 +882,18 @@ void __ceph_remove_cap(struct ceph_cap *cap) | |||
885 | list_del_init(&cap->session_caps); | 882 | list_del_init(&cap->session_caps); |
886 | session->s_nr_caps--; | 883 | session->s_nr_caps--; |
887 | cap->session = NULL; | 884 | cap->session = NULL; |
885 | removed = 1; | ||
888 | } | 886 | } |
887 | /* protect backpointer with s_cap_lock: see iterate_session_caps */ | ||
888 | cap->ci = NULL; | ||
889 | spin_unlock(&session->s_cap_lock); | 889 | spin_unlock(&session->s_cap_lock); |
890 | 890 | ||
891 | if (cap->session == NULL) | 891 | /* remove from inode list */ |
892 | rb_erase(&cap->ci_node, &ci->i_caps); | ||
893 | if (ci->i_auth_cap == cap) | ||
894 | ci->i_auth_cap = NULL; | ||
895 | |||
896 | if (removed) | ||
892 | ceph_put_cap(cap); | 897 | ceph_put_cap(cap); |
893 | 898 | ||
894 | if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) { | 899 | if (!__ceph_is_any_caps(ci) && ci->i_snap_realm) { |
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 261f3e6c0bcf..85b4d2ffdeba 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c | |||
@@ -733,6 +733,10 @@ no_change: | |||
733 | __ceph_get_fmode(ci, cap_fmode); | 733 | __ceph_get_fmode(ci, cap_fmode); |
734 | spin_unlock(&inode->i_lock); | 734 | spin_unlock(&inode->i_lock); |
735 | } | 735 | } |
736 | } else if (cap_fmode >= 0) { | ||
737 | pr_warning("mds issued no caps on %llx.%llx\n", | ||
738 | ceph_vinop(inode)); | ||
739 | __ceph_get_fmode(ci, cap_fmode); | ||
736 | } | 740 | } |
737 | 741 | ||
738 | /* update delegation info? */ | 742 | /* update delegation info? */ |
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 60a9a4ae47be..24561a557e01 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c | |||
@@ -736,9 +736,10 @@ static void cleanup_cap_releases(struct ceph_mds_session *session) | |||
736 | } | 736 | } |
737 | 737 | ||
738 | /* | 738 | /* |
739 | * Helper to safely iterate over all caps associated with a session. | 739 | * Helper to safely iterate over all caps associated with a session, with |
740 | * special care taken to handle a racing __ceph_remove_cap(). | ||
740 | * | 741 | * |
741 | * caller must hold session s_mutex | 742 | * Caller must hold session s_mutex. |
742 | */ | 743 | */ |
743 | static int iterate_session_caps(struct ceph_mds_session *session, | 744 | static int iterate_session_caps(struct ceph_mds_session *session, |
744 | int (*cb)(struct inode *, struct ceph_cap *, | 745 | int (*cb)(struct inode *, struct ceph_cap *, |
@@ -2136,7 +2137,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, int mds) | |||
2136 | struct ceph_mds_session *session = NULL; | 2137 | struct ceph_mds_session *session = NULL; |
2137 | struct ceph_msg *reply; | 2138 | struct ceph_msg *reply; |
2138 | struct rb_node *p; | 2139 | struct rb_node *p; |
2139 | int err; | 2140 | int err = -ENOMEM; |
2140 | struct ceph_pagelist *pagelist; | 2141 | struct ceph_pagelist *pagelist; |
2141 | 2142 | ||
2142 | pr_info("reconnect to recovering mds%d\n", mds); | 2143 | pr_info("reconnect to recovering mds%d\n", mds); |
@@ -2185,7 +2186,7 @@ static void send_mds_reconnect(struct ceph_mds_client *mdsc, int mds) | |||
2185 | goto fail; | 2186 | goto fail; |
2186 | err = iterate_session_caps(session, encode_caps_cb, pagelist); | 2187 | err = iterate_session_caps(session, encode_caps_cb, pagelist); |
2187 | if (err < 0) | 2188 | if (err < 0) |
2188 | goto out; | 2189 | goto fail; |
2189 | 2190 | ||
2190 | /* | 2191 | /* |
2191 | * snaprealms. we provide mds with the ino, seq (version), and | 2192 | * snaprealms. we provide mds with the ino, seq (version), and |
@@ -2213,28 +2214,31 @@ send: | |||
2213 | reply->nr_pages = calc_pages_for(0, pagelist->length); | 2214 | reply->nr_pages = calc_pages_for(0, pagelist->length); |
2214 | ceph_con_send(&session->s_con, reply); | 2215 | ceph_con_send(&session->s_con, reply); |
2215 | 2216 | ||
2216 | if (session) { | 2217 | session->s_state = CEPH_MDS_SESSION_OPEN; |
2217 | session->s_state = CEPH_MDS_SESSION_OPEN; | 2218 | mutex_unlock(&session->s_mutex); |
2218 | __wake_requests(mdsc, &session->s_waiting); | 2219 | |
2219 | } | 2220 | mutex_lock(&mdsc->mutex); |
2221 | __wake_requests(mdsc, &session->s_waiting); | ||
2222 | mutex_unlock(&mdsc->mutex); | ||
2223 | |||
2224 | ceph_put_mds_session(session); | ||
2220 | 2225 | ||
2221 | out: | ||
2222 | up_read(&mdsc->snap_rwsem); | 2226 | up_read(&mdsc->snap_rwsem); |
2223 | if (session) { | ||
2224 | mutex_unlock(&session->s_mutex); | ||
2225 | ceph_put_mds_session(session); | ||
2226 | } | ||
2227 | mutex_lock(&mdsc->mutex); | 2227 | mutex_lock(&mdsc->mutex); |
2228 | return; | 2228 | return; |
2229 | 2229 | ||
2230 | fail: | 2230 | fail: |
2231 | ceph_msg_put(reply); | 2231 | ceph_msg_put(reply); |
2232 | up_read(&mdsc->snap_rwsem); | ||
2233 | mutex_unlock(&session->s_mutex); | ||
2234 | ceph_put_mds_session(session); | ||
2232 | fail_nomsg: | 2235 | fail_nomsg: |
2233 | ceph_pagelist_release(pagelist); | 2236 | ceph_pagelist_release(pagelist); |
2234 | kfree(pagelist); | 2237 | kfree(pagelist); |
2235 | fail_nopagelist: | 2238 | fail_nopagelist: |
2236 | pr_err("ENOMEM preparing reconnect for mds%d\n", mds); | 2239 | pr_err("error %d preparing reconnect for mds%d\n", err, mds); |
2237 | goto out; | 2240 | mutex_lock(&mdsc->mutex); |
2241 | return; | ||
2238 | } | 2242 | } |
2239 | 2243 | ||
2240 | 2244 | ||
diff --git a/fs/ceph/messenger.c b/fs/ceph/messenger.c index 509f57d9ccb3..cd4fadb6491a 100644 --- a/fs/ceph/messenger.c +++ b/fs/ceph/messenger.c | |||
@@ -492,7 +492,14 @@ static void prepare_write_message(struct ceph_connection *con) | |||
492 | list_move_tail(&m->list_head, &con->out_sent); | 492 | list_move_tail(&m->list_head, &con->out_sent); |
493 | } | 493 | } |
494 | 494 | ||
495 | m->hdr.seq = cpu_to_le64(++con->out_seq); | 495 | /* |
496 | * only assign outgoing seq # if we haven't sent this message | ||
497 | * yet. if it is requeued, resend with it's original seq. | ||
498 | */ | ||
499 | if (m->needs_out_seq) { | ||
500 | m->hdr.seq = cpu_to_le64(++con->out_seq); | ||
501 | m->needs_out_seq = false; | ||
502 | } | ||
496 | 503 | ||
497 | dout("prepare_write_message %p seq %lld type %d len %d+%d+%d %d pgs\n", | 504 | dout("prepare_write_message %p seq %lld type %d len %d+%d+%d %d pgs\n", |
498 | m, con->out_seq, le16_to_cpu(m->hdr.type), | 505 | m, con->out_seq, le16_to_cpu(m->hdr.type), |
@@ -1986,6 +1993,8 @@ void ceph_con_send(struct ceph_connection *con, struct ceph_msg *msg) | |||
1986 | 1993 | ||
1987 | BUG_ON(msg->front.iov_len != le32_to_cpu(msg->hdr.front_len)); | 1994 | BUG_ON(msg->front.iov_len != le32_to_cpu(msg->hdr.front_len)); |
1988 | 1995 | ||
1996 | msg->needs_out_seq = true; | ||
1997 | |||
1989 | /* queue */ | 1998 | /* queue */ |
1990 | mutex_lock(&con->mutex); | 1999 | mutex_lock(&con->mutex); |
1991 | BUG_ON(!list_empty(&msg->list_head)); | 2000 | BUG_ON(!list_empty(&msg->list_head)); |
@@ -2085,15 +2094,19 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, | |||
2085 | kref_init(&m->kref); | 2094 | kref_init(&m->kref); |
2086 | INIT_LIST_HEAD(&m->list_head); | 2095 | INIT_LIST_HEAD(&m->list_head); |
2087 | 2096 | ||
2097 | m->hdr.tid = 0; | ||
2088 | m->hdr.type = cpu_to_le16(type); | 2098 | m->hdr.type = cpu_to_le16(type); |
2099 | m->hdr.priority = cpu_to_le16(CEPH_MSG_PRIO_DEFAULT); | ||
2100 | m->hdr.version = 0; | ||
2089 | m->hdr.front_len = cpu_to_le32(front_len); | 2101 | m->hdr.front_len = cpu_to_le32(front_len); |
2090 | m->hdr.middle_len = 0; | 2102 | m->hdr.middle_len = 0; |
2091 | m->hdr.data_len = cpu_to_le32(page_len); | 2103 | m->hdr.data_len = cpu_to_le32(page_len); |
2092 | m->hdr.data_off = cpu_to_le16(page_off); | 2104 | m->hdr.data_off = cpu_to_le16(page_off); |
2093 | m->hdr.priority = cpu_to_le16(CEPH_MSG_PRIO_DEFAULT); | 2105 | m->hdr.reserved = 0; |
2094 | m->footer.front_crc = 0; | 2106 | m->footer.front_crc = 0; |
2095 | m->footer.middle_crc = 0; | 2107 | m->footer.middle_crc = 0; |
2096 | m->footer.data_crc = 0; | 2108 | m->footer.data_crc = 0; |
2109 | m->footer.flags = 0; | ||
2097 | m->front_max = front_len; | 2110 | m->front_max = front_len; |
2098 | m->front_is_vmalloc = false; | 2111 | m->front_is_vmalloc = false; |
2099 | m->more_to_follow = false; | 2112 | m->more_to_follow = false; |
diff --git a/fs/ceph/messenger.h b/fs/ceph/messenger.h index a343dae73cdc..a5caf91cc971 100644 --- a/fs/ceph/messenger.h +++ b/fs/ceph/messenger.h | |||
@@ -86,6 +86,7 @@ struct ceph_msg { | |||
86 | struct kref kref; | 86 | struct kref kref; |
87 | bool front_is_vmalloc; | 87 | bool front_is_vmalloc; |
88 | bool more_to_follow; | 88 | bool more_to_follow; |
89 | bool needs_out_seq; | ||
89 | int front_max; | 90 | int front_max; |
90 | 91 | ||
91 | struct ceph_msgpool *pool; | 92 | struct ceph_msgpool *pool; |
diff --git a/fs/ceph/osd_client.c b/fs/ceph/osd_client.c index c7b4dedaace6..3514f71ff85f 100644 --- a/fs/ceph/osd_client.c +++ b/fs/ceph/osd_client.c | |||
@@ -565,7 +565,8 @@ static int __map_osds(struct ceph_osd_client *osdc, | |||
565 | { | 565 | { |
566 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; | 566 | struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; |
567 | struct ceph_pg pgid; | 567 | struct ceph_pg pgid; |
568 | int o = -1; | 568 | int acting[CEPH_PG_MAX_SIZE]; |
569 | int o = -1, num = 0; | ||
569 | int err; | 570 | int err; |
570 | 571 | ||
571 | dout("map_osds %p tid %lld\n", req, req->r_tid); | 572 | dout("map_osds %p tid %lld\n", req, req->r_tid); |
@@ -576,10 +577,16 @@ static int __map_osds(struct ceph_osd_client *osdc, | |||
576 | pgid = reqhead->layout.ol_pgid; | 577 | pgid = reqhead->layout.ol_pgid; |
577 | req->r_pgid = pgid; | 578 | req->r_pgid = pgid; |
578 | 579 | ||
579 | o = ceph_calc_pg_primary(osdc->osdmap, pgid); | 580 | err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting); |
581 | if (err > 0) { | ||
582 | o = acting[0]; | ||
583 | num = err; | ||
584 | } | ||
580 | 585 | ||
581 | if ((req->r_osd && req->r_osd->o_osd == o && | 586 | if ((req->r_osd && req->r_osd->o_osd == o && |
582 | req->r_sent >= req->r_osd->o_incarnation) || | 587 | req->r_sent >= req->r_osd->o_incarnation && |
588 | req->r_num_pg_osds == num && | ||
589 | memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) || | ||
583 | (req->r_osd == NULL && o == -1)) | 590 | (req->r_osd == NULL && o == -1)) |
584 | return 0; /* no change */ | 591 | return 0; /* no change */ |
585 | 592 | ||
@@ -587,6 +594,10 @@ static int __map_osds(struct ceph_osd_client *osdc, | |||
587 | req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o, | 594 | req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o, |
588 | req->r_osd ? req->r_osd->o_osd : -1); | 595 | req->r_osd ? req->r_osd->o_osd : -1); |
589 | 596 | ||
597 | /* record full pg acting set */ | ||
598 | memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num); | ||
599 | req->r_num_pg_osds = num; | ||
600 | |||
590 | if (req->r_osd) { | 601 | if (req->r_osd) { |
591 | __cancel_request(req); | 602 | __cancel_request(req); |
592 | list_del_init(&req->r_osd_item); | 603 | list_del_init(&req->r_osd_item); |
@@ -612,7 +623,7 @@ static int __map_osds(struct ceph_osd_client *osdc, | |||
612 | __remove_osd_from_lru(req->r_osd); | 623 | __remove_osd_from_lru(req->r_osd); |
613 | list_add(&req->r_osd_item, &req->r_osd->o_requests); | 624 | list_add(&req->r_osd_item, &req->r_osd->o_requests); |
614 | } | 625 | } |
615 | err = 1; /* osd changed */ | 626 | err = 1; /* osd or pg changed */ |
616 | 627 | ||
617 | out: | 628 | out: |
618 | return err; | 629 | return err; |
@@ -779,16 +790,18 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, | |||
779 | struct ceph_osd_request *req; | 790 | struct ceph_osd_request *req; |
780 | u64 tid; | 791 | u64 tid; |
781 | int numops, object_len, flags; | 792 | int numops, object_len, flags; |
793 | s32 result; | ||
782 | 794 | ||
783 | tid = le64_to_cpu(msg->hdr.tid); | 795 | tid = le64_to_cpu(msg->hdr.tid); |
784 | if (msg->front.iov_len < sizeof(*rhead)) | 796 | if (msg->front.iov_len < sizeof(*rhead)) |
785 | goto bad; | 797 | goto bad; |
786 | numops = le32_to_cpu(rhead->num_ops); | 798 | numops = le32_to_cpu(rhead->num_ops); |
787 | object_len = le32_to_cpu(rhead->object_len); | 799 | object_len = le32_to_cpu(rhead->object_len); |
800 | result = le32_to_cpu(rhead->result); | ||
788 | if (msg->front.iov_len != sizeof(*rhead) + object_len + | 801 | if (msg->front.iov_len != sizeof(*rhead) + object_len + |
789 | numops * sizeof(struct ceph_osd_op)) | 802 | numops * sizeof(struct ceph_osd_op)) |
790 | goto bad; | 803 | goto bad; |
791 | dout("handle_reply %p tid %llu\n", msg, tid); | 804 | dout("handle_reply %p tid %llu result %d\n", msg, tid, (int)result); |
792 | 805 | ||
793 | /* lookup */ | 806 | /* lookup */ |
794 | mutex_lock(&osdc->request_mutex); | 807 | mutex_lock(&osdc->request_mutex); |
@@ -834,7 +847,8 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg, | |||
834 | dout("handle_reply tid %llu flags %d\n", tid, flags); | 847 | dout("handle_reply tid %llu flags %d\n", tid, flags); |
835 | 848 | ||
836 | /* either this is a read, or we got the safe response */ | 849 | /* either this is a read, or we got the safe response */ |
837 | if ((flags & CEPH_OSD_FLAG_ONDISK) || | 850 | if (result < 0 || |
851 | (flags & CEPH_OSD_FLAG_ONDISK) || | ||
838 | ((flags & CEPH_OSD_FLAG_WRITE) == 0)) | 852 | ((flags & CEPH_OSD_FLAG_WRITE) == 0)) |
839 | __unregister_request(osdc, req); | 853 | __unregister_request(osdc, req); |
840 | 854 | ||
diff --git a/fs/ceph/osd_client.h b/fs/ceph/osd_client.h index b0759911e7c3..ce776989ef6a 100644 --- a/fs/ceph/osd_client.h +++ b/fs/ceph/osd_client.h | |||
@@ -48,6 +48,8 @@ struct ceph_osd_request { | |||
48 | struct list_head r_osd_item; | 48 | struct list_head r_osd_item; |
49 | struct ceph_osd *r_osd; | 49 | struct ceph_osd *r_osd; |
50 | struct ceph_pg r_pgid; | 50 | struct ceph_pg r_pgid; |
51 | int r_pg_osds[CEPH_PG_MAX_SIZE]; | ||
52 | int r_num_pg_osds; | ||
51 | 53 | ||
52 | struct ceph_connection *r_con_filling_msg; | 54 | struct ceph_connection *r_con_filling_msg; |
53 | 55 | ||
@@ -66,7 +68,6 @@ struct ceph_osd_request { | |||
66 | struct list_head r_unsafe_item; | 68 | struct list_head r_unsafe_item; |
67 | 69 | ||
68 | struct inode *r_inode; /* for use by callbacks */ | 70 | struct inode *r_inode; /* for use by callbacks */ |
69 | struct writeback_control *r_wbc; /* ditto */ | ||
70 | 71 | ||
71 | char r_oid[40]; /* object name */ | 72 | char r_oid[40]; /* object name */ |
72 | int r_oid_len; | 73 | int r_oid_len; |
diff --git a/fs/ceph/osdmap.c b/fs/ceph/osdmap.c index 2e2c15eed82a..cfdd8f4388b7 100644 --- a/fs/ceph/osdmap.c +++ b/fs/ceph/osdmap.c | |||
@@ -1041,12 +1041,33 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid, | |||
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | /* | 1043 | /* |
1044 | * Return acting set for given pgid. | ||
1045 | */ | ||
1046 | int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid, | ||
1047 | int *acting) | ||
1048 | { | ||
1049 | int rawosds[CEPH_PG_MAX_SIZE], *osds; | ||
1050 | int i, o, num = CEPH_PG_MAX_SIZE; | ||
1051 | |||
1052 | osds = calc_pg_raw(osdmap, pgid, rawosds, &num); | ||
1053 | if (!osds) | ||
1054 | return -1; | ||
1055 | |||
1056 | /* primary is first up osd */ | ||
1057 | o = 0; | ||
1058 | for (i = 0; i < num; i++) | ||
1059 | if (ceph_osd_is_up(osdmap, osds[i])) | ||
1060 | acting[o++] = osds[i]; | ||
1061 | return o; | ||
1062 | } | ||
1063 | |||
1064 | /* | ||
1044 | * Return primary osd for given pgid, or -1 if none. | 1065 | * Return primary osd for given pgid, or -1 if none. |
1045 | */ | 1066 | */ |
1046 | int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid) | 1067 | int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid) |
1047 | { | 1068 | { |
1048 | int rawosds[10], *osds; | 1069 | int rawosds[CEPH_PG_MAX_SIZE], *osds; |
1049 | int i, num = ARRAY_SIZE(rawosds); | 1070 | int i, num = CEPH_PG_MAX_SIZE; |
1050 | 1071 | ||
1051 | osds = calc_pg_raw(osdmap, pgid, rawosds, &num); | 1072 | osds = calc_pg_raw(osdmap, pgid, rawosds, &num); |
1052 | if (!osds) | 1073 | if (!osds) |
@@ -1054,9 +1075,7 @@ int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid) | |||
1054 | 1075 | ||
1055 | /* primary is first up osd */ | 1076 | /* primary is first up osd */ |
1056 | for (i = 0; i < num; i++) | 1077 | for (i = 0; i < num; i++) |
1057 | if (ceph_osd_is_up(osdmap, osds[i])) { | 1078 | if (ceph_osd_is_up(osdmap, osds[i])) |
1058 | return osds[i]; | 1079 | return osds[i]; |
1059 | break; | ||
1060 | } | ||
1061 | return -1; | 1080 | return -1; |
1062 | } | 1081 | } |
diff --git a/fs/ceph/osdmap.h b/fs/ceph/osdmap.h index 8bc9f1e4f562..970b547e510d 100644 --- a/fs/ceph/osdmap.h +++ b/fs/ceph/osdmap.h | |||
@@ -120,6 +120,8 @@ extern int ceph_calc_object_layout(struct ceph_object_layout *ol, | |||
120 | const char *oid, | 120 | const char *oid, |
121 | struct ceph_file_layout *fl, | 121 | struct ceph_file_layout *fl, |
122 | struct ceph_osdmap *osdmap); | 122 | struct ceph_osdmap *osdmap); |
123 | extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid, | ||
124 | int *acting); | ||
123 | extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, | 125 | extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, |
124 | struct ceph_pg pgid); | 126 | struct ceph_pg pgid); |
125 | 127 | ||
diff --git a/fs/ceph/rados.h b/fs/ceph/rados.h index a1fc1d017b58..fd56451a871f 100644 --- a/fs/ceph/rados.h +++ b/fs/ceph/rados.h | |||
@@ -58,6 +58,7 @@ struct ceph_timespec { | |||
58 | #define CEPH_PG_LAYOUT_LINEAR 2 | 58 | #define CEPH_PG_LAYOUT_LINEAR 2 |
59 | #define CEPH_PG_LAYOUT_HYBRID 3 | 59 | #define CEPH_PG_LAYOUT_HYBRID 3 |
60 | 60 | ||
61 | #define CEPH_PG_MAX_SIZE 16 /* max # osds in a single pg */ | ||
61 | 62 | ||
62 | /* | 63 | /* |
63 | * placement group. | 64 | * placement group. |
diff --git a/fs/ceph/super.c b/fs/ceph/super.c index f888cf487b7c..110857ba9269 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c | |||
@@ -47,10 +47,20 @@ const char *ceph_file_part(const char *s, int len) | |||
47 | */ | 47 | */ |
48 | static void ceph_put_super(struct super_block *s) | 48 | static void ceph_put_super(struct super_block *s) |
49 | { | 49 | { |
50 | struct ceph_client *cl = ceph_client(s); | 50 | struct ceph_client *client = ceph_sb_to_client(s); |
51 | 51 | ||
52 | dout("put_super\n"); | 52 | dout("put_super\n"); |
53 | ceph_mdsc_close_sessions(&cl->mdsc); | 53 | ceph_mdsc_close_sessions(&client->mdsc); |
54 | |||
55 | /* | ||
56 | * ensure we release the bdi before put_anon_super releases | ||
57 | * the device name. | ||
58 | */ | ||
59 | if (s->s_bdi == &client->backing_dev_info) { | ||
60 | bdi_unregister(&client->backing_dev_info); | ||
61 | s->s_bdi = NULL; | ||
62 | } | ||
63 | |||
54 | return; | 64 | return; |
55 | } | 65 | } |
56 | 66 | ||
@@ -636,6 +646,8 @@ static void ceph_destroy_client(struct ceph_client *client) | |||
636 | destroy_workqueue(client->pg_inv_wq); | 646 | destroy_workqueue(client->pg_inv_wq); |
637 | destroy_workqueue(client->trunc_wq); | 647 | destroy_workqueue(client->trunc_wq); |
638 | 648 | ||
649 | bdi_destroy(&client->backing_dev_info); | ||
650 | |||
639 | if (client->msgr) | 651 | if (client->msgr) |
640 | ceph_messenger_destroy(client->msgr); | 652 | ceph_messenger_destroy(client->msgr); |
641 | mempool_destroy(client->wb_pagevec_pool); | 653 | mempool_destroy(client->wb_pagevec_pool); |
@@ -876,14 +888,14 @@ static int ceph_register_bdi(struct super_block *sb, struct ceph_client *client) | |||
876 | { | 888 | { |
877 | int err; | 889 | int err; |
878 | 890 | ||
879 | sb->s_bdi = &client->backing_dev_info; | ||
880 | |||
881 | /* set ra_pages based on rsize mount option? */ | 891 | /* set ra_pages based on rsize mount option? */ |
882 | if (client->mount_args->rsize >= PAGE_CACHE_SIZE) | 892 | if (client->mount_args->rsize >= PAGE_CACHE_SIZE) |
883 | client->backing_dev_info.ra_pages = | 893 | client->backing_dev_info.ra_pages = |
884 | (client->mount_args->rsize + PAGE_CACHE_SIZE - 1) | 894 | (client->mount_args->rsize + PAGE_CACHE_SIZE - 1) |
885 | >> PAGE_SHIFT; | 895 | >> PAGE_SHIFT; |
886 | err = bdi_register_dev(&client->backing_dev_info, sb->s_dev); | 896 | err = bdi_register_dev(&client->backing_dev_info, sb->s_dev); |
897 | if (!err) | ||
898 | sb->s_bdi = &client->backing_dev_info; | ||
887 | return err; | 899 | return err; |
888 | } | 900 | } |
889 | 901 | ||
@@ -957,9 +969,6 @@ static void ceph_kill_sb(struct super_block *s) | |||
957 | dout("kill_sb %p\n", s); | 969 | dout("kill_sb %p\n", s); |
958 | ceph_mdsc_pre_umount(&client->mdsc); | 970 | ceph_mdsc_pre_umount(&client->mdsc); |
959 | kill_anon_super(s); /* will call put_super after sb is r/o */ | 971 | kill_anon_super(s); /* will call put_super after sb is r/o */ |
960 | if (s->s_bdi == &client->backing_dev_info) | ||
961 | bdi_unregister(&client->backing_dev_info); | ||
962 | bdi_destroy(&client->backing_dev_info); | ||
963 | ceph_destroy_client(client); | 972 | ceph_destroy_client(client); |
964 | } | 973 | } |
965 | 974 | ||
diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c index a20bea598933..cfd1ce34e0bc 100644 --- a/fs/cifs/asn1.c +++ b/fs/cifs/asn1.c | |||
@@ -492,17 +492,13 @@ compare_oid(unsigned long *oid1, unsigned int oid1len, | |||
492 | 492 | ||
493 | int | 493 | int |
494 | decode_negTokenInit(unsigned char *security_blob, int length, | 494 | decode_negTokenInit(unsigned char *security_blob, int length, |
495 | enum securityEnum *secType) | 495 | struct TCP_Server_Info *server) |
496 | { | 496 | { |
497 | struct asn1_ctx ctx; | 497 | struct asn1_ctx ctx; |
498 | unsigned char *end; | 498 | unsigned char *end; |
499 | unsigned char *sequence_end; | 499 | unsigned char *sequence_end; |
500 | unsigned long *oid = NULL; | 500 | unsigned long *oid = NULL; |
501 | unsigned int cls, con, tag, oidlen, rc; | 501 | unsigned int cls, con, tag, oidlen, rc; |
502 | bool use_ntlmssp = false; | ||
503 | bool use_kerberos = false; | ||
504 | bool use_kerberosu2u = false; | ||
505 | bool use_mskerberos = false; | ||
506 | 502 | ||
507 | /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ | 503 | /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ |
508 | 504 | ||
@@ -510,11 +506,11 @@ decode_negTokenInit(unsigned char *security_blob, int length, | |||
510 | 506 | ||
511 | /* GSSAPI header */ | 507 | /* GSSAPI header */ |
512 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 508 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
513 | cFYI(1, ("Error decoding negTokenInit header")); | 509 | cFYI(1, "Error decoding negTokenInit header"); |
514 | return 0; | 510 | return 0; |
515 | } else if ((cls != ASN1_APL) || (con != ASN1_CON) | 511 | } else if ((cls != ASN1_APL) || (con != ASN1_CON) |
516 | || (tag != ASN1_EOC)) { | 512 | || (tag != ASN1_EOC)) { |
517 | cFYI(1, ("cls = %d con = %d tag = %d", cls, con, tag)); | 513 | cFYI(1, "cls = %d con = %d tag = %d", cls, con, tag); |
518 | return 0; | 514 | return 0; |
519 | } | 515 | } |
520 | 516 | ||
@@ -535,56 +531,52 @@ decode_negTokenInit(unsigned char *security_blob, int length, | |||
535 | 531 | ||
536 | /* SPNEGO OID not present or garbled -- bail out */ | 532 | /* SPNEGO OID not present or garbled -- bail out */ |
537 | if (!rc) { | 533 | if (!rc) { |
538 | cFYI(1, ("Error decoding negTokenInit header")); | 534 | cFYI(1, "Error decoding negTokenInit header"); |
539 | return 0; | 535 | return 0; |
540 | } | 536 | } |
541 | 537 | ||
542 | /* SPNEGO */ | 538 | /* SPNEGO */ |
543 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 539 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
544 | cFYI(1, ("Error decoding negTokenInit")); | 540 | cFYI(1, "Error decoding negTokenInit"); |
545 | return 0; | 541 | return 0; |
546 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON) | 542 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON) |
547 | || (tag != ASN1_EOC)) { | 543 | || (tag != ASN1_EOC)) { |
548 | cFYI(1, | 544 | cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", |
549 | ("cls = %d con = %d tag = %d end = %p (%d) exit 0", | 545 | cls, con, tag, end, *end); |
550 | cls, con, tag, end, *end)); | ||
551 | return 0; | 546 | return 0; |
552 | } | 547 | } |
553 | 548 | ||
554 | /* negTokenInit */ | 549 | /* negTokenInit */ |
555 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 550 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
556 | cFYI(1, ("Error decoding negTokenInit")); | 551 | cFYI(1, "Error decoding negTokenInit"); |
557 | return 0; | 552 | return 0; |
558 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) | 553 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) |
559 | || (tag != ASN1_SEQ)) { | 554 | || (tag != ASN1_SEQ)) { |
560 | cFYI(1, | 555 | cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", |
561 | ("cls = %d con = %d tag = %d end = %p (%d) exit 1", | 556 | cls, con, tag, end, *end); |
562 | cls, con, tag, end, *end)); | ||
563 | return 0; | 557 | return 0; |
564 | } | 558 | } |
565 | 559 | ||
566 | /* sequence */ | 560 | /* sequence */ |
567 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 561 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
568 | cFYI(1, ("Error decoding 2nd part of negTokenInit")); | 562 | cFYI(1, "Error decoding 2nd part of negTokenInit"); |
569 | return 0; | 563 | return 0; |
570 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON) | 564 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON) |
571 | || (tag != ASN1_EOC)) { | 565 | || (tag != ASN1_EOC)) { |
572 | cFYI(1, | 566 | cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0", |
573 | ("cls = %d con = %d tag = %d end = %p (%d) exit 0", | 567 | cls, con, tag, end, *end); |
574 | cls, con, tag, end, *end)); | ||
575 | return 0; | 568 | return 0; |
576 | } | 569 | } |
577 | 570 | ||
578 | /* sequence of */ | 571 | /* sequence of */ |
579 | if (asn1_header_decode | 572 | if (asn1_header_decode |
580 | (&ctx, &sequence_end, &cls, &con, &tag) == 0) { | 573 | (&ctx, &sequence_end, &cls, &con, &tag) == 0) { |
581 | cFYI(1, ("Error decoding 2nd part of negTokenInit")); | 574 | cFYI(1, "Error decoding 2nd part of negTokenInit"); |
582 | return 0; | 575 | return 0; |
583 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) | 576 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) |
584 | || (tag != ASN1_SEQ)) { | 577 | || (tag != ASN1_SEQ)) { |
585 | cFYI(1, | 578 | cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1", |
586 | ("cls = %d con = %d tag = %d end = %p (%d) exit 1", | 579 | cls, con, tag, end, *end); |
587 | cls, con, tag, end, *end)); | ||
588 | return 0; | 580 | return 0; |
589 | } | 581 | } |
590 | 582 | ||
@@ -592,37 +584,33 @@ decode_negTokenInit(unsigned char *security_blob, int length, | |||
592 | while (!asn1_eoc_decode(&ctx, sequence_end)) { | 584 | while (!asn1_eoc_decode(&ctx, sequence_end)) { |
593 | rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); | 585 | rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); |
594 | if (!rc) { | 586 | if (!rc) { |
595 | cFYI(1, | 587 | cFYI(1, "Error decoding negTokenInit hdr exit2"); |
596 | ("Error decoding negTokenInit hdr exit2")); | ||
597 | return 0; | 588 | return 0; |
598 | } | 589 | } |
599 | if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { | 590 | if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { |
600 | if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) { | 591 | if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) { |
601 | 592 | ||
602 | cFYI(1, ("OID len = %d oid = 0x%lx 0x%lx " | 593 | cFYI(1, "OID len = %d oid = 0x%lx 0x%lx " |
603 | "0x%lx 0x%lx", oidlen, *oid, | 594 | "0x%lx 0x%lx", oidlen, *oid, |
604 | *(oid + 1), *(oid + 2), *(oid + 3))); | 595 | *(oid + 1), *(oid + 2), *(oid + 3)); |
605 | 596 | ||
606 | if (compare_oid(oid, oidlen, MSKRB5_OID, | 597 | if (compare_oid(oid, oidlen, MSKRB5_OID, |
607 | MSKRB5_OID_LEN) && | 598 | MSKRB5_OID_LEN)) |
608 | !use_mskerberos) | 599 | server->sec_mskerberos = true; |
609 | use_mskerberos = true; | ||
610 | else if (compare_oid(oid, oidlen, KRB5U2U_OID, | 600 | else if (compare_oid(oid, oidlen, KRB5U2U_OID, |
611 | KRB5U2U_OID_LEN) && | 601 | KRB5U2U_OID_LEN)) |
612 | !use_kerberosu2u) | 602 | server->sec_kerberosu2u = true; |
613 | use_kerberosu2u = true; | ||
614 | else if (compare_oid(oid, oidlen, KRB5_OID, | 603 | else if (compare_oid(oid, oidlen, KRB5_OID, |
615 | KRB5_OID_LEN) && | 604 | KRB5_OID_LEN)) |
616 | !use_kerberos) | 605 | server->sec_kerberos = true; |
617 | use_kerberos = true; | ||
618 | else if (compare_oid(oid, oidlen, NTLMSSP_OID, | 606 | else if (compare_oid(oid, oidlen, NTLMSSP_OID, |
619 | NTLMSSP_OID_LEN)) | 607 | NTLMSSP_OID_LEN)) |
620 | use_ntlmssp = true; | 608 | server->sec_ntlmssp = true; |
621 | 609 | ||
622 | kfree(oid); | 610 | kfree(oid); |
623 | } | 611 | } |
624 | } else { | 612 | } else { |
625 | cFYI(1, ("Should be an oid what is going on?")); | 613 | cFYI(1, "Should be an oid what is going on?"); |
626 | } | 614 | } |
627 | } | 615 | } |
628 | 616 | ||
@@ -632,54 +620,47 @@ decode_negTokenInit(unsigned char *security_blob, int length, | |||
632 | no mechListMic (e.g. NTLMSSP instead of KRB5) */ | 620 | no mechListMic (e.g. NTLMSSP instead of KRB5) */ |
633 | if (ctx.error == ASN1_ERR_DEC_EMPTY) | 621 | if (ctx.error == ASN1_ERR_DEC_EMPTY) |
634 | goto decode_negtoken_exit; | 622 | goto decode_negtoken_exit; |
635 | cFYI(1, ("Error decoding last part negTokenInit exit3")); | 623 | cFYI(1, "Error decoding last part negTokenInit exit3"); |
636 | return 0; | 624 | return 0; |
637 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { | 625 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { |
638 | /* tag = 3 indicating mechListMIC */ | 626 | /* tag = 3 indicating mechListMIC */ |
639 | cFYI(1, ("Exit 4 cls = %d con = %d tag = %d end = %p (%d)", | 627 | cFYI(1, "Exit 4 cls = %d con = %d tag = %d end = %p (%d)", |
640 | cls, con, tag, end, *end)); | 628 | cls, con, tag, end, *end); |
641 | return 0; | 629 | return 0; |
642 | } | 630 | } |
643 | 631 | ||
644 | /* sequence */ | 632 | /* sequence */ |
645 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 633 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
646 | cFYI(1, ("Error decoding last part negTokenInit exit5")); | 634 | cFYI(1, "Error decoding last part negTokenInit exit5"); |
647 | return 0; | 635 | return 0; |
648 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) | 636 | } else if ((cls != ASN1_UNI) || (con != ASN1_CON) |
649 | || (tag != ASN1_SEQ)) { | 637 | || (tag != ASN1_SEQ)) { |
650 | cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d)", | 638 | cFYI(1, "cls = %d con = %d tag = %d end = %p (%d)", |
651 | cls, con, tag, end, *end)); | 639 | cls, con, tag, end, *end); |
652 | } | 640 | } |
653 | 641 | ||
654 | /* sequence of */ | 642 | /* sequence of */ |
655 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 643 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
656 | cFYI(1, ("Error decoding last part negTokenInit exit 7")); | 644 | cFYI(1, "Error decoding last part negTokenInit exit 7"); |
657 | return 0; | 645 | return 0; |
658 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { | 646 | } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { |
659 | cFYI(1, ("Exit 8 cls = %d con = %d tag = %d end = %p (%d)", | 647 | cFYI(1, "Exit 8 cls = %d con = %d tag = %d end = %p (%d)", |
660 | cls, con, tag, end, *end)); | 648 | cls, con, tag, end, *end); |
661 | return 0; | 649 | return 0; |
662 | } | 650 | } |
663 | 651 | ||
664 | /* general string */ | 652 | /* general string */ |
665 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { | 653 | if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { |
666 | cFYI(1, ("Error decoding last part negTokenInit exit9")); | 654 | cFYI(1, "Error decoding last part negTokenInit exit9"); |
667 | return 0; | 655 | return 0; |
668 | } else if ((cls != ASN1_UNI) || (con != ASN1_PRI) | 656 | } else if ((cls != ASN1_UNI) || (con != ASN1_PRI) |
669 | || (tag != ASN1_GENSTR)) { | 657 | || (tag != ASN1_GENSTR)) { |
670 | cFYI(1, ("Exit10 cls = %d con = %d tag = %d end = %p (%d)", | 658 | cFYI(1, "Exit10 cls = %d con = %d tag = %d end = %p (%d)", |
671 | cls, con, tag, end, *end)); | 659 | cls, con, tag, end, *end); |
672 | return 0; | 660 | return 0; |
673 | } | 661 | } |
674 | cFYI(1, ("Need to call asn1_octets_decode() function for %s", | 662 | cFYI(1, "Need to call asn1_octets_decode() function for %s", |
675 | ctx.pointer)); /* is this UTF-8 or ASCII? */ | 663 | ctx.pointer); /* is this UTF-8 or ASCII? */ |
676 | decode_negtoken_exit: | 664 | decode_negtoken_exit: |
677 | if (use_kerberos) | ||
678 | *secType = Kerberos; | ||
679 | else if (use_mskerberos) | ||
680 | *secType = MSKerberos; | ||
681 | else if (use_ntlmssp) | ||
682 | *secType = RawNTLMSSP; | ||
683 | |||
684 | return 1; | 665 | return 1; |
685 | } | 666 | } |
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index 42cec2a7c0cf..4fce6e61b34e 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c | |||
@@ -60,10 +60,10 @@ cifs_dump_mem(char *label, void *data, int length) | |||
60 | #ifdef CONFIG_CIFS_DEBUG2 | 60 | #ifdef CONFIG_CIFS_DEBUG2 |
61 | void cifs_dump_detail(struct smb_hdr *smb) | 61 | void cifs_dump_detail(struct smb_hdr *smb) |
62 | { | 62 | { |
63 | cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d", | 63 | cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d", |
64 | smb->Command, smb->Status.CifsError, | 64 | smb->Command, smb->Status.CifsError, |
65 | smb->Flags, smb->Flags2, smb->Mid, smb->Pid)); | 65 | smb->Flags, smb->Flags2, smb->Mid, smb->Pid); |
66 | cERROR(1, ("smb buf %p len %d", smb, smbCalcSize_LE(smb))); | 66 | cERROR(1, "smb buf %p len %d", smb, smbCalcSize_LE(smb)); |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
@@ -75,25 +75,25 @@ void cifs_dump_mids(struct TCP_Server_Info *server) | |||
75 | if (server == NULL) | 75 | if (server == NULL) |
76 | return; | 76 | return; |
77 | 77 | ||
78 | cERROR(1, ("Dump pending requests:")); | 78 | cERROR(1, "Dump pending requests:"); |
79 | spin_lock(&GlobalMid_Lock); | 79 | spin_lock(&GlobalMid_Lock); |
80 | list_for_each(tmp, &server->pending_mid_q) { | 80 | list_for_each(tmp, &server->pending_mid_q) { |
81 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); | 81 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
82 | cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d", | 82 | cERROR(1, "State: %d Cmd: %d Pid: %d Tsk: %p Mid %d", |
83 | mid_entry->midState, | 83 | mid_entry->midState, |
84 | (int)mid_entry->command, | 84 | (int)mid_entry->command, |
85 | mid_entry->pid, | 85 | mid_entry->pid, |
86 | mid_entry->tsk, | 86 | mid_entry->tsk, |
87 | mid_entry->mid)); | 87 | mid_entry->mid); |
88 | #ifdef CONFIG_CIFS_STATS2 | 88 | #ifdef CONFIG_CIFS_STATS2 |
89 | cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld", | 89 | cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld", |
90 | mid_entry->largeBuf, | 90 | mid_entry->largeBuf, |
91 | mid_entry->resp_buf, | 91 | mid_entry->resp_buf, |
92 | mid_entry->when_received, | 92 | mid_entry->when_received, |
93 | jiffies)); | 93 | jiffies); |
94 | #endif /* STATS2 */ | 94 | #endif /* STATS2 */ |
95 | cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp, | 95 | cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp, |
96 | mid_entry->multiEnd)); | 96 | mid_entry->multiEnd); |
97 | if (mid_entry->resp_buf) { | 97 | if (mid_entry->resp_buf) { |
98 | cifs_dump_detail(mid_entry->resp_buf); | 98 | cifs_dump_detail(mid_entry->resp_buf); |
99 | cifs_dump_mem("existing buf: ", | 99 | cifs_dump_mem("existing buf: ", |
@@ -716,7 +716,7 @@ static const struct file_operations cifs_multiuser_mount_proc_fops = { | |||
716 | 716 | ||
717 | static int cifs_security_flags_proc_show(struct seq_file *m, void *v) | 717 | static int cifs_security_flags_proc_show(struct seq_file *m, void *v) |
718 | { | 718 | { |
719 | seq_printf(m, "0x%x\n", extended_security); | 719 | seq_printf(m, "0x%x\n", global_secflags); |
720 | return 0; | 720 | return 0; |
721 | } | 721 | } |
722 | 722 | ||
@@ -744,13 +744,13 @@ static ssize_t cifs_security_flags_proc_write(struct file *file, | |||
744 | /* single char or single char followed by null */ | 744 | /* single char or single char followed by null */ |
745 | c = flags_string[0]; | 745 | c = flags_string[0]; |
746 | if (c == '0' || c == 'n' || c == 'N') { | 746 | if (c == '0' || c == 'n' || c == 'N') { |
747 | extended_security = CIFSSEC_DEF; /* default */ | 747 | global_secflags = CIFSSEC_DEF; /* default */ |
748 | return count; | 748 | return count; |
749 | } else if (c == '1' || c == 'y' || c == 'Y') { | 749 | } else if (c == '1' || c == 'y' || c == 'Y') { |
750 | extended_security = CIFSSEC_MAX; | 750 | global_secflags = CIFSSEC_MAX; |
751 | return count; | 751 | return count; |
752 | } else if (!isdigit(c)) { | 752 | } else if (!isdigit(c)) { |
753 | cERROR(1, ("invalid flag %c", c)); | 753 | cERROR(1, "invalid flag %c", c); |
754 | return -EINVAL; | 754 | return -EINVAL; |
755 | } | 755 | } |
756 | } | 756 | } |
@@ -758,26 +758,26 @@ static ssize_t cifs_security_flags_proc_write(struct file *file, | |||
758 | 758 | ||
759 | flags = simple_strtoul(flags_string, NULL, 0); | 759 | flags = simple_strtoul(flags_string, NULL, 0); |
760 | 760 | ||
761 | cFYI(1, ("sec flags 0x%x", flags)); | 761 | cFYI(1, "sec flags 0x%x", flags); |
762 | 762 | ||
763 | if (flags <= 0) { | 763 | if (flags <= 0) { |
764 | cERROR(1, ("invalid security flags %s", flags_string)); | 764 | cERROR(1, "invalid security flags %s", flags_string); |
765 | return -EINVAL; | 765 | return -EINVAL; |
766 | } | 766 | } |
767 | 767 | ||
768 | if (flags & ~CIFSSEC_MASK) { | 768 | if (flags & ~CIFSSEC_MASK) { |
769 | cERROR(1, ("attempt to set unsupported security flags 0x%x", | 769 | cERROR(1, "attempt to set unsupported security flags 0x%x", |
770 | flags & ~CIFSSEC_MASK)); | 770 | flags & ~CIFSSEC_MASK); |
771 | return -EINVAL; | 771 | return -EINVAL; |
772 | } | 772 | } |
773 | /* flags look ok - update the global security flags for cifs module */ | 773 | /* flags look ok - update the global security flags for cifs module */ |
774 | extended_security = flags; | 774 | global_secflags = flags; |
775 | if (extended_security & CIFSSEC_MUST_SIGN) { | 775 | if (global_secflags & CIFSSEC_MUST_SIGN) { |
776 | /* requiring signing implies signing is allowed */ | 776 | /* requiring signing implies signing is allowed */ |
777 | extended_security |= CIFSSEC_MAY_SIGN; | 777 | global_secflags |= CIFSSEC_MAY_SIGN; |
778 | cFYI(1, ("packet signing now required")); | 778 | cFYI(1, "packet signing now required"); |
779 | } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) { | 779 | } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) { |
780 | cFYI(1, ("packet signing disabled")); | 780 | cFYI(1, "packet signing disabled"); |
781 | } | 781 | } |
782 | /* BB should we turn on MAY flags for other MUST options? */ | 782 | /* BB should we turn on MAY flags for other MUST options? */ |
783 | return count; | 783 | return count; |
diff --git a/fs/cifs/cifs_debug.h b/fs/cifs/cifs_debug.h index 5eb3b83bbfa7..aa316891ac0c 100644 --- a/fs/cifs/cifs_debug.h +++ b/fs/cifs/cifs_debug.h | |||
@@ -43,34 +43,54 @@ void dump_smb(struct smb_hdr *, int); | |||
43 | */ | 43 | */ |
44 | #ifdef CIFS_DEBUG | 44 | #ifdef CIFS_DEBUG |
45 | 45 | ||
46 | |||
47 | /* information message: e.g., configuration, major event */ | 46 | /* information message: e.g., configuration, major event */ |
48 | extern int cifsFYI; | 47 | extern int cifsFYI; |
49 | #define cifsfyi(format,arg...) if (cifsFYI & CIFS_INFO) printk(KERN_DEBUG " " __FILE__ ": " format "\n" "" , ## arg) | 48 | #define cifsfyi(fmt, arg...) \ |
49 | do { \ | ||
50 | if (cifsFYI & CIFS_INFO) \ | ||
51 | printk(KERN_DEBUG "%s: " fmt "\n", __FILE__, ##arg); \ | ||
52 | } while (0) | ||
50 | 53 | ||
51 | #define cFYI(button,prspec) if (button) cifsfyi prspec | 54 | #define cFYI(set, fmt, arg...) \ |
55 | do { \ | ||
56 | if (set) \ | ||
57 | cifsfyi(fmt, ##arg); \ | ||
58 | } while (0) | ||
52 | 59 | ||
53 | #define cifswarn(format, arg...) printk(KERN_WARNING ": " format "\n" , ## arg) | 60 | #define cifswarn(fmt, arg...) \ |
61 | printk(KERN_WARNING fmt "\n", ##arg) | ||
54 | 62 | ||
55 | /* debug event message: */ | 63 | /* debug event message: */ |
56 | extern int cifsERROR; | 64 | extern int cifsERROR; |
57 | 65 | ||
58 | #define cEVENT(format,arg...) if (cifsERROR) printk(KERN_EVENT __FILE__ ": " format "\n" , ## arg) | 66 | #define cEVENT(fmt, arg...) \ |
67 | do { \ | ||
68 | if (cifsERROR) \ | ||
69 | printk(KERN_EVENT "%s: " fmt "\n", __FILE__, ##arg); \ | ||
70 | } while (0) | ||
59 | 71 | ||
60 | /* error event message: e.g., i/o error */ | 72 | /* error event message: e.g., i/o error */ |
61 | #define cifserror(format,arg...) if (cifsERROR) printk(KERN_ERR " CIFS VFS: " format "\n" "" , ## arg) | 73 | #define cifserror(fmt, arg...) \ |
74 | do { \ | ||
75 | if (cifsERROR) \ | ||
76 | printk(KERN_ERR "CIFS VFS: " fmt "\n", ##arg); \ | ||
77 | } while (0) | ||
62 | 78 | ||
63 | #define cERROR(button, prspec) if (button) cifserror prspec | 79 | #define cERROR(set, fmt, arg...) \ |
80 | do { \ | ||
81 | if (set) \ | ||
82 | cifserror(fmt, ##arg); \ | ||
83 | } while (0) | ||
64 | 84 | ||
65 | /* | 85 | /* |
66 | * debug OFF | 86 | * debug OFF |
67 | * --------- | 87 | * --------- |
68 | */ | 88 | */ |
69 | #else /* _CIFS_DEBUG */ | 89 | #else /* _CIFS_DEBUG */ |
70 | #define cERROR(button, prspec) | 90 | #define cERROR(set, fmt, arg...) |
71 | #define cEVENT(format, arg...) | 91 | #define cEVENT(fmt, arg...) |
72 | #define cFYI(button, prspec) | 92 | #define cFYI(set, fmt, arg...) |
73 | #define cifserror(format, arg...) | 93 | #define cifserror(fmt, arg...) |
74 | #endif /* _CIFS_DEBUG */ | 94 | #endif /* _CIFS_DEBUG */ |
75 | 95 | ||
76 | #endif /* _H_CIFS_DEBUG */ | 96 | #endif /* _H_CIFS_DEBUG */ |
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c index 78e4d2a3a68b..ac19a6f3dae0 100644 --- a/fs/cifs/cifs_dfs_ref.c +++ b/fs/cifs/cifs_dfs_ref.c | |||
@@ -85,8 +85,8 @@ static char *cifs_get_share_name(const char *node_name) | |||
85 | /* find server name end */ | 85 | /* find server name end */ |
86 | pSep = memchr(UNC+2, '\\', len-2); | 86 | pSep = memchr(UNC+2, '\\', len-2); |
87 | if (!pSep) { | 87 | if (!pSep) { |
88 | cERROR(1, ("%s: no server name end in node name: %s", | 88 | cERROR(1, "%s: no server name end in node name: %s", |
89 | __func__, node_name)); | 89 | __func__, node_name); |
90 | kfree(UNC); | 90 | kfree(UNC); |
91 | return ERR_PTR(-EINVAL); | 91 | return ERR_PTR(-EINVAL); |
92 | } | 92 | } |
@@ -142,8 +142,8 @@ char *cifs_compose_mount_options(const char *sb_mountdata, | |||
142 | 142 | ||
143 | rc = dns_resolve_server_name_to_ip(*devname, &srvIP); | 143 | rc = dns_resolve_server_name_to_ip(*devname, &srvIP); |
144 | if (rc != 0) { | 144 | if (rc != 0) { |
145 | cERROR(1, ("%s: Failed to resolve server part of %s to IP: %d", | 145 | cERROR(1, "%s: Failed to resolve server part of %s to IP: %d", |
146 | __func__, *devname, rc)); | 146 | __func__, *devname, rc); |
147 | goto compose_mount_options_err; | 147 | goto compose_mount_options_err; |
148 | } | 148 | } |
149 | /* md_len = strlen(...) + 12 for 'sep+prefixpath=' | 149 | /* md_len = strlen(...) + 12 for 'sep+prefixpath=' |
@@ -217,8 +217,8 @@ char *cifs_compose_mount_options(const char *sb_mountdata, | |||
217 | strcat(mountdata, fullpath + ref->path_consumed); | 217 | strcat(mountdata, fullpath + ref->path_consumed); |
218 | } | 218 | } |
219 | 219 | ||
220 | /*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/ | 220 | /*cFYI(1, "%s: parent mountdata: %s", __func__,sb_mountdata);*/ |
221 | /*cFYI(1, ("%s: submount mountdata: %s", __func__, mountdata ));*/ | 221 | /*cFYI(1, "%s: submount mountdata: %s", __func__, mountdata );*/ |
222 | 222 | ||
223 | compose_mount_options_out: | 223 | compose_mount_options_out: |
224 | kfree(srvIP); | 224 | kfree(srvIP); |
@@ -294,11 +294,11 @@ static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd, | |||
294 | 294 | ||
295 | static void dump_referral(const struct dfs_info3_param *ref) | 295 | static void dump_referral(const struct dfs_info3_param *ref) |
296 | { | 296 | { |
297 | cFYI(1, ("DFS: ref path: %s", ref->path_name)); | 297 | cFYI(1, "DFS: ref path: %s", ref->path_name); |
298 | cFYI(1, ("DFS: node path: %s", ref->node_name)); | 298 | cFYI(1, "DFS: node path: %s", ref->node_name); |
299 | cFYI(1, ("DFS: fl: %hd, srv_type: %hd", ref->flags, ref->server_type)); | 299 | cFYI(1, "DFS: fl: %hd, srv_type: %hd", ref->flags, ref->server_type); |
300 | cFYI(1, ("DFS: ref_flags: %hd, path_consumed: %hd", ref->ref_flag, | 300 | cFYI(1, "DFS: ref_flags: %hd, path_consumed: %hd", ref->ref_flag, |
301 | ref->path_consumed)); | 301 | ref->path_consumed); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
@@ -314,7 +314,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd) | |||
314 | int rc = 0; | 314 | int rc = 0; |
315 | struct vfsmount *mnt = ERR_PTR(-ENOENT); | 315 | struct vfsmount *mnt = ERR_PTR(-ENOENT); |
316 | 316 | ||
317 | cFYI(1, ("in %s", __func__)); | 317 | cFYI(1, "in %s", __func__); |
318 | BUG_ON(IS_ROOT(dentry)); | 318 | BUG_ON(IS_ROOT(dentry)); |
319 | 319 | ||
320 | xid = GetXid(); | 320 | xid = GetXid(); |
@@ -352,15 +352,15 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd) | |||
352 | /* connect to a node */ | 352 | /* connect to a node */ |
353 | len = strlen(referrals[i].node_name); | 353 | len = strlen(referrals[i].node_name); |
354 | if (len < 2) { | 354 | if (len < 2) { |
355 | cERROR(1, ("%s: Net Address path too short: %s", | 355 | cERROR(1, "%s: Net Address path too short: %s", |
356 | __func__, referrals[i].node_name)); | 356 | __func__, referrals[i].node_name); |
357 | rc = -EINVAL; | 357 | rc = -EINVAL; |
358 | goto out_err; | 358 | goto out_err; |
359 | } | 359 | } |
360 | mnt = cifs_dfs_do_refmount(nd->path.mnt, | 360 | mnt = cifs_dfs_do_refmount(nd->path.mnt, |
361 | nd->path.dentry, referrals + i); | 361 | nd->path.dentry, referrals + i); |
362 | cFYI(1, ("%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__, | 362 | cFYI(1, "%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__, |
363 | referrals[i].node_name, mnt)); | 363 | referrals[i].node_name, mnt); |
364 | 364 | ||
365 | /* complete mount procedure if we accured submount */ | 365 | /* complete mount procedure if we accured submount */ |
366 | if (!IS_ERR(mnt)) | 366 | if (!IS_ERR(mnt)) |
@@ -378,7 +378,7 @@ out: | |||
378 | FreeXid(xid); | 378 | FreeXid(xid); |
379 | free_dfs_info_array(referrals, num_referrals); | 379 | free_dfs_info_array(referrals, num_referrals); |
380 | kfree(full_path); | 380 | kfree(full_path); |
381 | cFYI(1, ("leaving %s" , __func__)); | 381 | cFYI(1, "leaving %s" , __func__); |
382 | return ERR_PTR(rc); | 382 | return ERR_PTR(rc); |
383 | out_err: | 383 | out_err: |
384 | path_put(&nd->path); | 384 | path_put(&nd->path); |
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c index 310d12f69a92..379bd7d9c05f 100644 --- a/fs/cifs/cifs_spnego.c +++ b/fs/cifs/cifs_spnego.c | |||
@@ -133,9 +133,9 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) | |||
133 | dp = description + strlen(description); | 133 | dp = description + strlen(description); |
134 | 134 | ||
135 | /* for now, only sec=krb5 and sec=mskrb5 are valid */ | 135 | /* for now, only sec=krb5 and sec=mskrb5 are valid */ |
136 | if (server->secType == Kerberos) | 136 | if (server->sec_kerberos) |
137 | sprintf(dp, ";sec=krb5"); | 137 | sprintf(dp, ";sec=krb5"); |
138 | else if (server->secType == MSKerberos) | 138 | else if (server->sec_mskerberos) |
139 | sprintf(dp, ";sec=mskrb5"); | 139 | sprintf(dp, ";sec=mskrb5"); |
140 | else | 140 | else |
141 | goto out; | 141 | goto out; |
@@ -149,7 +149,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) | |||
149 | dp = description + strlen(description); | 149 | dp = description + strlen(description); |
150 | sprintf(dp, ";pid=0x%x", current->pid); | 150 | sprintf(dp, ";pid=0x%x", current->pid); |
151 | 151 | ||
152 | cFYI(1, ("key description = %s", description)); | 152 | cFYI(1, "key description = %s", description); |
153 | spnego_key = request_key(&cifs_spnego_key_type, description, ""); | 153 | spnego_key = request_key(&cifs_spnego_key_type, description, ""); |
154 | 154 | ||
155 | #ifdef CONFIG_CIFS_DEBUG2 | 155 | #ifdef CONFIG_CIFS_DEBUG2 |
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index d07676bd76d2..430f510a1720 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c | |||
@@ -200,9 +200,8 @@ cifs_strtoUCS(__le16 *to, const char *from, int len, | |||
200 | /* works for 2.4.0 kernel or later */ | 200 | /* works for 2.4.0 kernel or later */ |
201 | charlen = codepage->char2uni(from, len, &wchar_to[i]); | 201 | charlen = codepage->char2uni(from, len, &wchar_to[i]); |
202 | if (charlen < 1) { | 202 | if (charlen < 1) { |
203 | cERROR(1, | 203 | cERROR(1, "strtoUCS: char2uni of %d returned %d", |
204 | ("strtoUCS: char2uni of %d returned %d", | 204 | (int)*from, charlen); |
205 | (int)*from, charlen)); | ||
206 | /* A question mark */ | 205 | /* A question mark */ |
207 | to[i] = cpu_to_le16(0x003f); | 206 | to[i] = cpu_to_le16(0x003f); |
208 | charlen = 1; | 207 | charlen = 1; |
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c index 9b716d044bbd..85d7cf7ff2c8 100644 --- a/fs/cifs/cifsacl.c +++ b/fs/cifs/cifsacl.c | |||
@@ -87,11 +87,11 @@ int match_sid(struct cifs_sid *ctsid) | |||
87 | continue; /* all sub_auth values do not match */ | 87 | continue; /* all sub_auth values do not match */ |
88 | } | 88 | } |
89 | 89 | ||
90 | cFYI(1, ("matching sid: %s\n", wksidarr[i].sidname)); | 90 | cFYI(1, "matching sid: %s\n", wksidarr[i].sidname); |
91 | return 0; /* sids compare/match */ | 91 | return 0; /* sids compare/match */ |
92 | } | 92 | } |
93 | 93 | ||
94 | cFYI(1, ("No matching sid")); | 94 | cFYI(1, "No matching sid"); |
95 | return -1; | 95 | return -1; |
96 | } | 96 | } |
97 | 97 | ||
@@ -208,14 +208,14 @@ static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode, | |||
208 | *pbits_to_set &= ~S_IXUGO; | 208 | *pbits_to_set &= ~S_IXUGO; |
209 | return; | 209 | return; |
210 | } else if (type != ACCESS_ALLOWED) { | 210 | } else if (type != ACCESS_ALLOWED) { |
211 | cERROR(1, ("unknown access control type %d", type)); | 211 | cERROR(1, "unknown access control type %d", type); |
212 | return; | 212 | return; |
213 | } | 213 | } |
214 | /* else ACCESS_ALLOWED type */ | 214 | /* else ACCESS_ALLOWED type */ |
215 | 215 | ||
216 | if (flags & GENERIC_ALL) { | 216 | if (flags & GENERIC_ALL) { |
217 | *pmode |= (S_IRWXUGO & (*pbits_to_set)); | 217 | *pmode |= (S_IRWXUGO & (*pbits_to_set)); |
218 | cFYI(DBG2, ("all perms")); | 218 | cFYI(DBG2, "all perms"); |
219 | return; | 219 | return; |
220 | } | 220 | } |
221 | if ((flags & GENERIC_WRITE) || | 221 | if ((flags & GENERIC_WRITE) || |
@@ -228,7 +228,7 @@ static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode, | |||
228 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) | 228 | ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS)) |
229 | *pmode |= (S_IXUGO & (*pbits_to_set)); | 229 | *pmode |= (S_IXUGO & (*pbits_to_set)); |
230 | 230 | ||
231 | cFYI(DBG2, ("access flags 0x%x mode now 0x%x", flags, *pmode)); | 231 | cFYI(DBG2, "access flags 0x%x mode now 0x%x", flags, *pmode); |
232 | return; | 232 | return; |
233 | } | 233 | } |
234 | 234 | ||
@@ -257,7 +257,7 @@ static void mode_to_access_flags(umode_t mode, umode_t bits_to_use, | |||
257 | if (mode & S_IXUGO) | 257 | if (mode & S_IXUGO) |
258 | *pace_flags |= SET_FILE_EXEC_RIGHTS; | 258 | *pace_flags |= SET_FILE_EXEC_RIGHTS; |
259 | 259 | ||
260 | cFYI(DBG2, ("mode: 0x%x, access flags now 0x%x", mode, *pace_flags)); | 260 | cFYI(DBG2, "mode: 0x%x, access flags now 0x%x", mode, *pace_flags); |
261 | return; | 261 | return; |
262 | } | 262 | } |
263 | 263 | ||
@@ -297,24 +297,24 @@ static void dump_ace(struct cifs_ace *pace, char *end_of_acl) | |||
297 | /* validate that we do not go past end of acl */ | 297 | /* validate that we do not go past end of acl */ |
298 | 298 | ||
299 | if (le16_to_cpu(pace->size) < 16) { | 299 | if (le16_to_cpu(pace->size) < 16) { |
300 | cERROR(1, ("ACE too small, %d", le16_to_cpu(pace->size))); | 300 | cERROR(1, "ACE too small %d", le16_to_cpu(pace->size)); |
301 | return; | 301 | return; |
302 | } | 302 | } |
303 | 303 | ||
304 | if (end_of_acl < (char *)pace + le16_to_cpu(pace->size)) { | 304 | if (end_of_acl < (char *)pace + le16_to_cpu(pace->size)) { |
305 | cERROR(1, ("ACL too small to parse ACE")); | 305 | cERROR(1, "ACL too small to parse ACE"); |
306 | return; | 306 | return; |
307 | } | 307 | } |
308 | 308 | ||
309 | num_subauth = pace->sid.num_subauth; | 309 | num_subauth = pace->sid.num_subauth; |
310 | if (num_subauth) { | 310 | if (num_subauth) { |
311 | int i; | 311 | int i; |
312 | cFYI(1, ("ACE revision %d num_auth %d type %d flags %d size %d", | 312 | cFYI(1, "ACE revision %d num_auth %d type %d flags %d size %d", |
313 | pace->sid.revision, pace->sid.num_subauth, pace->type, | 313 | pace->sid.revision, pace->sid.num_subauth, pace->type, |
314 | pace->flags, le16_to_cpu(pace->size))); | 314 | pace->flags, le16_to_cpu(pace->size)); |
315 | for (i = 0; i < num_subauth; ++i) { | 315 | for (i = 0; i < num_subauth; ++i) { |
316 | cFYI(1, ("ACE sub_auth[%d]: 0x%x", i, | 316 | cFYI(1, "ACE sub_auth[%d]: 0x%x", i, |
317 | le32_to_cpu(pace->sid.sub_auth[i]))); | 317 | le32_to_cpu(pace->sid.sub_auth[i])); |
318 | } | 318 | } |
319 | 319 | ||
320 | /* BB add length check to make sure that we do not have huge | 320 | /* BB add length check to make sure that we do not have huge |
@@ -347,13 +347,13 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, | |||
347 | 347 | ||
348 | /* validate that we do not go past end of acl */ | 348 | /* validate that we do not go past end of acl */ |
349 | if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) { | 349 | if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) { |
350 | cERROR(1, ("ACL too small to parse DACL")); | 350 | cERROR(1, "ACL too small to parse DACL"); |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | 353 | ||
354 | cFYI(DBG2, ("DACL revision %d size %d num aces %d", | 354 | cFYI(DBG2, "DACL revision %d size %d num aces %d", |
355 | le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size), | 355 | le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size), |
356 | le32_to_cpu(pdacl->num_aces))); | 356 | le32_to_cpu(pdacl->num_aces)); |
357 | 357 | ||
358 | /* reset rwx permissions for user/group/other. | 358 | /* reset rwx permissions for user/group/other. |
359 | Also, if num_aces is 0 i.e. DACL has no ACEs, | 359 | Also, if num_aces is 0 i.e. DACL has no ACEs, |
@@ -437,25 +437,25 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl) | |||
437 | /* validate that we do not go past end of ACL - sid must be at least 8 | 437 | /* validate that we do not go past end of ACL - sid must be at least 8 |
438 | bytes long (assuming no sub-auths - e.g. the null SID */ | 438 | bytes long (assuming no sub-auths - e.g. the null SID */ |
439 | if (end_of_acl < (char *)psid + 8) { | 439 | if (end_of_acl < (char *)psid + 8) { |
440 | cERROR(1, ("ACL too small to parse SID %p", psid)); | 440 | cERROR(1, "ACL too small to parse SID %p", psid); |
441 | return -EINVAL; | 441 | return -EINVAL; |
442 | } | 442 | } |
443 | 443 | ||
444 | if (psid->num_subauth) { | 444 | if (psid->num_subauth) { |
445 | #ifdef CONFIG_CIFS_DEBUG2 | 445 | #ifdef CONFIG_CIFS_DEBUG2 |
446 | int i; | 446 | int i; |
447 | cFYI(1, ("SID revision %d num_auth %d", | 447 | cFYI(1, "SID revision %d num_auth %d", |
448 | psid->revision, psid->num_subauth)); | 448 | psid->revision, psid->num_subauth); |
449 | 449 | ||
450 | for (i = 0; i < psid->num_subauth; i++) { | 450 | for (i = 0; i < psid->num_subauth; i++) { |
451 | cFYI(1, ("SID sub_auth[%d]: 0x%x ", i, | 451 | cFYI(1, "SID sub_auth[%d]: 0x%x ", i, |
452 | le32_to_cpu(psid->sub_auth[i]))); | 452 | le32_to_cpu(psid->sub_auth[i])); |
453 | } | 453 | } |
454 | 454 | ||
455 | /* BB add length check to make sure that we do not have huge | 455 | /* BB add length check to make sure that we do not have huge |
456 | num auths and therefore go off the end */ | 456 | num auths and therefore go off the end */ |
457 | cFYI(1, ("RID 0x%x", | 457 | cFYI(1, "RID 0x%x", |
458 | le32_to_cpu(psid->sub_auth[psid->num_subauth-1]))); | 458 | le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); |
459 | #endif | 459 | #endif |
460 | } | 460 | } |
461 | 461 | ||
@@ -482,11 +482,11 @@ static int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len, | |||
482 | le32_to_cpu(pntsd->gsidoffset)); | 482 | le32_to_cpu(pntsd->gsidoffset)); |
483 | dacloffset = le32_to_cpu(pntsd->dacloffset); | 483 | dacloffset = le32_to_cpu(pntsd->dacloffset); |
484 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); | 484 | dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); |
485 | cFYI(DBG2, ("revision %d type 0x%x ooffset 0x%x goffset 0x%x " | 485 | cFYI(DBG2, "revision %d type 0x%x ooffset 0x%x goffset 0x%x " |
486 | "sacloffset 0x%x dacloffset 0x%x", | 486 | "sacloffset 0x%x dacloffset 0x%x", |
487 | pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset), | 487 | pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset), |
488 | le32_to_cpu(pntsd->gsidoffset), | 488 | le32_to_cpu(pntsd->gsidoffset), |
489 | le32_to_cpu(pntsd->sacloffset), dacloffset)); | 489 | le32_to_cpu(pntsd->sacloffset), dacloffset); |
490 | /* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ | 490 | /* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ |
491 | rc = parse_sid(owner_sid_ptr, end_of_acl); | 491 | rc = parse_sid(owner_sid_ptr, end_of_acl); |
492 | if (rc) | 492 | if (rc) |
@@ -500,7 +500,7 @@ static int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len, | |||
500 | parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr, | 500 | parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr, |
501 | group_sid_ptr, fattr); | 501 | group_sid_ptr, fattr); |
502 | else | 502 | else |
503 | cFYI(1, ("no ACL")); /* BB grant all or default perms? */ | 503 | cFYI(1, "no ACL"); /* BB grant all or default perms? */ |
504 | 504 | ||
505 | /* cifscred->uid = owner_sid_ptr->rid; | 505 | /* cifscred->uid = owner_sid_ptr->rid; |
506 | cifscred->gid = group_sid_ptr->rid; | 506 | cifscred->gid = group_sid_ptr->rid; |
@@ -563,7 +563,7 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, | |||
563 | FreeXid(xid); | 563 | FreeXid(xid); |
564 | 564 | ||
565 | 565 | ||
566 | cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen)); | 566 | cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen); |
567 | return pntsd; | 567 | return pntsd; |
568 | } | 568 | } |
569 | 569 | ||
@@ -581,12 +581,12 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, | |||
581 | &fid, &oplock, NULL, cifs_sb->local_nls, | 581 | &fid, &oplock, NULL, cifs_sb->local_nls, |
582 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 582 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
583 | if (rc) { | 583 | if (rc) { |
584 | cERROR(1, ("Unable to open file to get ACL")); | 584 | cERROR(1, "Unable to open file to get ACL"); |
585 | goto out; | 585 | goto out; |
586 | } | 586 | } |
587 | 587 | ||
588 | rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen); | 588 | rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen); |
589 | cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen)); | 589 | cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen); |
590 | 590 | ||
591 | CIFSSMBClose(xid, cifs_sb->tcon, fid); | 591 | CIFSSMBClose(xid, cifs_sb->tcon, fid); |
592 | out: | 592 | out: |
@@ -621,7 +621,7 @@ static int set_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, __u16 fid, | |||
621 | rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen); | 621 | rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen); |
622 | FreeXid(xid); | 622 | FreeXid(xid); |
623 | 623 | ||
624 | cFYI(DBG2, ("SetCIFSACL rc = %d", rc)); | 624 | cFYI(DBG2, "SetCIFSACL rc = %d", rc); |
625 | return rc; | 625 | return rc; |
626 | } | 626 | } |
627 | 627 | ||
@@ -638,12 +638,12 @@ static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path, | |||
638 | &fid, &oplock, NULL, cifs_sb->local_nls, | 638 | &fid, &oplock, NULL, cifs_sb->local_nls, |
639 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 639 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
640 | if (rc) { | 640 | if (rc) { |
641 | cERROR(1, ("Unable to open file to set ACL")); | 641 | cERROR(1, "Unable to open file to set ACL"); |
642 | goto out; | 642 | goto out; |
643 | } | 643 | } |
644 | 644 | ||
645 | rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen); | 645 | rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen); |
646 | cFYI(DBG2, ("SetCIFSACL rc = %d", rc)); | 646 | cFYI(DBG2, "SetCIFSACL rc = %d", rc); |
647 | 647 | ||
648 | CIFSSMBClose(xid, cifs_sb->tcon, fid); | 648 | CIFSSMBClose(xid, cifs_sb->tcon, fid); |
649 | out: | 649 | out: |
@@ -659,7 +659,7 @@ static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, | |||
659 | struct cifsFileInfo *open_file; | 659 | struct cifsFileInfo *open_file; |
660 | int rc; | 660 | int rc; |
661 | 661 | ||
662 | cFYI(DBG2, ("set ACL for %s from mode 0x%x", path, inode->i_mode)); | 662 | cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode); |
663 | 663 | ||
664 | open_file = find_readable_file(CIFS_I(inode)); | 664 | open_file = find_readable_file(CIFS_I(inode)); |
665 | if (!open_file) | 665 | if (!open_file) |
@@ -679,7 +679,7 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, | |||
679 | u32 acllen = 0; | 679 | u32 acllen = 0; |
680 | int rc = 0; | 680 | int rc = 0; |
681 | 681 | ||
682 | cFYI(DBG2, ("converting ACL to mode for %s", path)); | 682 | cFYI(DBG2, "converting ACL to mode for %s", path); |
683 | 683 | ||
684 | if (pfid) | 684 | if (pfid) |
685 | pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); | 685 | pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); |
@@ -690,7 +690,7 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, | |||
690 | if (pntsd) | 690 | if (pntsd) |
691 | rc = parse_sec_desc(pntsd, acllen, fattr); | 691 | rc = parse_sec_desc(pntsd, acllen, fattr); |
692 | if (rc) | 692 | if (rc) |
693 | cFYI(1, ("parse sec desc failed rc = %d", rc)); | 693 | cFYI(1, "parse sec desc failed rc = %d", rc); |
694 | 694 | ||
695 | kfree(pntsd); | 695 | kfree(pntsd); |
696 | return; | 696 | return; |
@@ -704,7 +704,7 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode) | |||
704 | struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ | 704 | struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ |
705 | struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ | 705 | struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ |
706 | 706 | ||
707 | cFYI(DBG2, ("set ACL from mode for %s", path)); | 707 | cFYI(DBG2, "set ACL from mode for %s", path); |
708 | 708 | ||
709 | /* Get the security descriptor */ | 709 | /* Get the security descriptor */ |
710 | pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen); | 710 | pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen); |
@@ -721,19 +721,19 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode) | |||
721 | DEFSECDESCLEN : secdesclen; | 721 | DEFSECDESCLEN : secdesclen; |
722 | pnntsd = kmalloc(secdesclen, GFP_KERNEL); | 722 | pnntsd = kmalloc(secdesclen, GFP_KERNEL); |
723 | if (!pnntsd) { | 723 | if (!pnntsd) { |
724 | cERROR(1, ("Unable to allocate security descriptor")); | 724 | cERROR(1, "Unable to allocate security descriptor"); |
725 | kfree(pntsd); | 725 | kfree(pntsd); |
726 | return -ENOMEM; | 726 | return -ENOMEM; |
727 | } | 727 | } |
728 | 728 | ||
729 | rc = build_sec_desc(pntsd, pnntsd, inode, nmode); | 729 | rc = build_sec_desc(pntsd, pnntsd, inode, nmode); |
730 | 730 | ||
731 | cFYI(DBG2, ("build_sec_desc rc: %d", rc)); | 731 | cFYI(DBG2, "build_sec_desc rc: %d", rc); |
732 | 732 | ||
733 | if (!rc) { | 733 | if (!rc) { |
734 | /* Set the security descriptor */ | 734 | /* Set the security descriptor */ |
735 | rc = set_cifs_acl(pnntsd, secdesclen, inode, path); | 735 | rc = set_cifs_acl(pnntsd, secdesclen, inode, path); |
736 | cFYI(DBG2, ("set_cifs_acl rc: %d", rc)); | 736 | cFYI(DBG2, "set_cifs_acl rc: %d", rc); |
737 | } | 737 | } |
738 | 738 | ||
739 | kfree(pnntsd); | 739 | kfree(pnntsd); |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index fbe986430d0c..847628dfdc44 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -103,7 +103,7 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec, | |||
103 | if (iov[i].iov_len == 0) | 103 | if (iov[i].iov_len == 0) |
104 | continue; | 104 | continue; |
105 | if (iov[i].iov_base == NULL) { | 105 | if (iov[i].iov_base == NULL) { |
106 | cERROR(1, ("null iovec entry")); | 106 | cERROR(1, "null iovec entry"); |
107 | return -EIO; | 107 | return -EIO; |
108 | } | 108 | } |
109 | /* The first entry includes a length field (which does not get | 109 | /* The first entry includes a length field (which does not get |
@@ -181,8 +181,8 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, | |||
181 | 181 | ||
182 | /* Do not need to verify session setups with signature "BSRSPYL " */ | 182 | /* Do not need to verify session setups with signature "BSRSPYL " */ |
183 | if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0) | 183 | if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0) |
184 | cFYI(1, ("dummy signature received for smb command 0x%x", | 184 | cFYI(1, "dummy signature received for smb command 0x%x", |
185 | cifs_pdu->Command)); | 185 | cifs_pdu->Command); |
186 | 186 | ||
187 | /* save off the origiginal signature so we can modify the smb and check | 187 | /* save off the origiginal signature so we can modify the smb and check |
188 | its signature against what the server sent */ | 188 | its signature against what the server sent */ |
@@ -291,7 +291,7 @@ void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt, | |||
291 | if (password) | 291 | if (password) |
292 | strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE); | 292 | strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE); |
293 | 293 | ||
294 | if (!encrypt && extended_security & CIFSSEC_MAY_PLNTXT) { | 294 | if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) { |
295 | memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE); | 295 | memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE); |
296 | memcpy(lnm_session_key, password_with_pad, | 296 | memcpy(lnm_session_key, password_with_pad, |
297 | CIFS_ENCPWD_SIZE); | 297 | CIFS_ENCPWD_SIZE); |
@@ -398,7 +398,7 @@ void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf, | |||
398 | /* calculate buf->ntlmv2_hash */ | 398 | /* calculate buf->ntlmv2_hash */ |
399 | rc = calc_ntlmv2_hash(ses, nls_cp); | 399 | rc = calc_ntlmv2_hash(ses, nls_cp); |
400 | if (rc) | 400 | if (rc) |
401 | cERROR(1, ("could not get v2 hash rc %d", rc)); | 401 | cERROR(1, "could not get v2 hash rc %d", rc); |
402 | CalcNTLMv2_response(ses, resp_buf); | 402 | CalcNTLMv2_response(ses, resp_buf); |
403 | 403 | ||
404 | /* now calculate the MAC key for NTLMv2 */ | 404 | /* now calculate the MAC key for NTLMv2 */ |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index ad235d604a0b..78c02eb4cb1f 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -49,10 +49,6 @@ | |||
49 | #include "cifs_spnego.h" | 49 | #include "cifs_spnego.h" |
50 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ | 50 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */ |
51 | 51 | ||
52 | #ifdef CONFIG_CIFS_QUOTA | ||
53 | static const struct quotactl_ops cifs_quotactl_ops; | ||
54 | #endif /* QUOTA */ | ||
55 | |||
56 | int cifsFYI = 0; | 52 | int cifsFYI = 0; |
57 | int cifsERROR = 1; | 53 | int cifsERROR = 1; |
58 | int traceSMB = 0; | 54 | int traceSMB = 0; |
@@ -61,7 +57,7 @@ unsigned int experimEnabled = 0; | |||
61 | unsigned int linuxExtEnabled = 1; | 57 | unsigned int linuxExtEnabled = 1; |
62 | unsigned int lookupCacheEnabled = 1; | 58 | unsigned int lookupCacheEnabled = 1; |
63 | unsigned int multiuser_mount = 0; | 59 | unsigned int multiuser_mount = 0; |
64 | unsigned int extended_security = CIFSSEC_DEF; | 60 | unsigned int global_secflags = CIFSSEC_DEF; |
65 | /* unsigned int ntlmv2_support = 0; */ | 61 | /* unsigned int ntlmv2_support = 0; */ |
66 | unsigned int sign_CIFS_PDUs = 1; | 62 | unsigned int sign_CIFS_PDUs = 1; |
67 | static const struct super_operations cifs_super_ops; | 63 | static const struct super_operations cifs_super_ops; |
@@ -86,8 +82,6 @@ extern mempool_t *cifs_sm_req_poolp; | |||
86 | extern mempool_t *cifs_req_poolp; | 82 | extern mempool_t *cifs_req_poolp; |
87 | extern mempool_t *cifs_mid_poolp; | 83 | extern mempool_t *cifs_mid_poolp; |
88 | 84 | ||
89 | extern struct kmem_cache *cifs_oplock_cachep; | ||
90 | |||
91 | static int | 85 | static int |
92 | cifs_read_super(struct super_block *sb, void *data, | 86 | cifs_read_super(struct super_block *sb, void *data, |
93 | const char *devname, int silent) | 87 | const char *devname, int silent) |
@@ -135,8 +129,7 @@ cifs_read_super(struct super_block *sb, void *data, | |||
135 | 129 | ||
136 | if (rc) { | 130 | if (rc) { |
137 | if (!silent) | 131 | if (!silent) |
138 | cERROR(1, | 132 | cERROR(1, "cifs_mount failed w/return code = %d", rc); |
139 | ("cifs_mount failed w/return code = %d", rc)); | ||
140 | goto out_mount_failed; | 133 | goto out_mount_failed; |
141 | } | 134 | } |
142 | 135 | ||
@@ -146,9 +139,6 @@ cifs_read_super(struct super_block *sb, void *data, | |||
146 | /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512) | 139 | /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512) |
147 | sb->s_blocksize = | 140 | sb->s_blocksize = |
148 | cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */ | 141 | cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */ |
149 | #ifdef CONFIG_CIFS_QUOTA | ||
150 | sb->s_qcop = &cifs_quotactl_ops; | ||
151 | #endif | ||
152 | sb->s_blocksize = CIFS_MAX_MSGSIZE; | 142 | sb->s_blocksize = CIFS_MAX_MSGSIZE; |
153 | sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ | 143 | sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ |
154 | inode = cifs_root_iget(sb, ROOT_I); | 144 | inode = cifs_root_iget(sb, ROOT_I); |
@@ -168,7 +158,7 @@ cifs_read_super(struct super_block *sb, void *data, | |||
168 | 158 | ||
169 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 159 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
170 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | 160 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
171 | cFYI(1, ("export ops supported")); | 161 | cFYI(1, "export ops supported"); |
172 | sb->s_export_op = &cifs_export_ops; | 162 | sb->s_export_op = &cifs_export_ops; |
173 | } | 163 | } |
174 | #endif /* EXPERIMENTAL */ | 164 | #endif /* EXPERIMENTAL */ |
@@ -176,7 +166,7 @@ cifs_read_super(struct super_block *sb, void *data, | |||
176 | return 0; | 166 | return 0; |
177 | 167 | ||
178 | out_no_root: | 168 | out_no_root: |
179 | cERROR(1, ("cifs_read_super: get root inode failed")); | 169 | cERROR(1, "cifs_read_super: get root inode failed"); |
180 | if (inode) | 170 | if (inode) |
181 | iput(inode); | 171 | iput(inode); |
182 | 172 | ||
@@ -203,10 +193,10 @@ cifs_put_super(struct super_block *sb) | |||
203 | int rc = 0; | 193 | int rc = 0; |
204 | struct cifs_sb_info *cifs_sb; | 194 | struct cifs_sb_info *cifs_sb; |
205 | 195 | ||
206 | cFYI(1, ("In cifs_put_super")); | 196 | cFYI(1, "In cifs_put_super"); |
207 | cifs_sb = CIFS_SB(sb); | 197 | cifs_sb = CIFS_SB(sb); |
208 | if (cifs_sb == NULL) { | 198 | if (cifs_sb == NULL) { |
209 | cFYI(1, ("Empty cifs superblock info passed to unmount")); | 199 | cFYI(1, "Empty cifs superblock info passed to unmount"); |
210 | return; | 200 | return; |
211 | } | 201 | } |
212 | 202 | ||
@@ -214,7 +204,7 @@ cifs_put_super(struct super_block *sb) | |||
214 | 204 | ||
215 | rc = cifs_umount(sb, cifs_sb); | 205 | rc = cifs_umount(sb, cifs_sb); |
216 | if (rc) | 206 | if (rc) |
217 | cERROR(1, ("cifs_umount failed with return code %d", rc)); | 207 | cERROR(1, "cifs_umount failed with return code %d", rc); |
218 | #ifdef CONFIG_CIFS_DFS_UPCALL | 208 | #ifdef CONFIG_CIFS_DFS_UPCALL |
219 | if (cifs_sb->mountdata) { | 209 | if (cifs_sb->mountdata) { |
220 | kfree(cifs_sb->mountdata); | 210 | kfree(cifs_sb->mountdata); |
@@ -300,7 +290,6 @@ static int cifs_permission(struct inode *inode, int mask) | |||
300 | static struct kmem_cache *cifs_inode_cachep; | 290 | static struct kmem_cache *cifs_inode_cachep; |
301 | static struct kmem_cache *cifs_req_cachep; | 291 | static struct kmem_cache *cifs_req_cachep; |
302 | static struct kmem_cache *cifs_mid_cachep; | 292 | static struct kmem_cache *cifs_mid_cachep; |
303 | struct kmem_cache *cifs_oplock_cachep; | ||
304 | static struct kmem_cache *cifs_sm_req_cachep; | 293 | static struct kmem_cache *cifs_sm_req_cachep; |
305 | mempool_t *cifs_sm_req_poolp; | 294 | mempool_t *cifs_sm_req_poolp; |
306 | mempool_t *cifs_req_poolp; | 295 | mempool_t *cifs_req_poolp; |
@@ -432,106 +421,6 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m) | |||
432 | return 0; | 421 | return 0; |
433 | } | 422 | } |
434 | 423 | ||
435 | #ifdef CONFIG_CIFS_QUOTA | ||
436 | int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid, | ||
437 | struct fs_disk_quota *pdquota) | ||
438 | { | ||
439 | int xid; | ||
440 | int rc = 0; | ||
441 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | ||
442 | struct cifsTconInfo *pTcon; | ||
443 | |||
444 | if (cifs_sb) | ||
445 | pTcon = cifs_sb->tcon; | ||
446 | else | ||
447 | return -EIO; | ||
448 | |||
449 | |||
450 | xid = GetXid(); | ||
451 | if (pTcon) { | ||
452 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); | ||
453 | } else | ||
454 | rc = -EIO; | ||
455 | |||
456 | FreeXid(xid); | ||
457 | return rc; | ||
458 | } | ||
459 | |||
460 | int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid, | ||
461 | struct fs_disk_quota *pdquota) | ||
462 | { | ||
463 | int xid; | ||
464 | int rc = 0; | ||
465 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | ||
466 | struct cifsTconInfo *pTcon; | ||
467 | |||
468 | if (cifs_sb) | ||
469 | pTcon = cifs_sb->tcon; | ||
470 | else | ||
471 | return -EIO; | ||
472 | |||
473 | xid = GetXid(); | ||
474 | if (pTcon) { | ||
475 | cFYI(1, ("set type: 0x%x id: %d", quota_type, qid)); | ||
476 | } else | ||
477 | rc = -EIO; | ||
478 | |||
479 | FreeXid(xid); | ||
480 | return rc; | ||
481 | } | ||
482 | |||
483 | int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation) | ||
484 | { | ||
485 | int xid; | ||
486 | int rc = 0; | ||
487 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | ||
488 | struct cifsTconInfo *pTcon; | ||
489 | |||
490 | if (cifs_sb) | ||
491 | pTcon = cifs_sb->tcon; | ||
492 | else | ||
493 | return -EIO; | ||
494 | |||
495 | xid = GetXid(); | ||
496 | if (pTcon) { | ||
497 | cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation)); | ||
498 | } else | ||
499 | rc = -EIO; | ||
500 | |||
501 | FreeXid(xid); | ||
502 | return rc; | ||
503 | } | ||
504 | |||
505 | int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats) | ||
506 | { | ||
507 | int xid; | ||
508 | int rc = 0; | ||
509 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | ||
510 | struct cifsTconInfo *pTcon; | ||
511 | |||
512 | if (cifs_sb) | ||
513 | pTcon = cifs_sb->tcon; | ||
514 | else | ||
515 | return -EIO; | ||
516 | |||
517 | xid = GetXid(); | ||
518 | if (pTcon) { | ||
519 | cFYI(1, ("pqstats %p", qstats)); | ||
520 | } else | ||
521 | rc = -EIO; | ||
522 | |||
523 | FreeXid(xid); | ||
524 | return rc; | ||
525 | } | ||
526 | |||
527 | static const struct quotactl_ops cifs_quotactl_ops = { | ||
528 | .set_xquota = cifs_xquota_set, | ||
529 | .get_xquota = cifs_xquota_get, | ||
530 | .set_xstate = cifs_xstate_set, | ||
531 | .get_xstate = cifs_xstate_get, | ||
532 | }; | ||
533 | #endif | ||
534 | |||
535 | static void cifs_umount_begin(struct super_block *sb) | 424 | static void cifs_umount_begin(struct super_block *sb) |
536 | { | 425 | { |
537 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 426 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
@@ -558,7 +447,7 @@ static void cifs_umount_begin(struct super_block *sb) | |||
558 | /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ | 447 | /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ |
559 | /* cancel_notify_requests(tcon); */ | 448 | /* cancel_notify_requests(tcon); */ |
560 | if (tcon->ses && tcon->ses->server) { | 449 | if (tcon->ses && tcon->ses->server) { |
561 | cFYI(1, ("wake up tasks now - umount begin not complete")); | 450 | cFYI(1, "wake up tasks now - umount begin not complete"); |
562 | wake_up_all(&tcon->ses->server->request_q); | 451 | wake_up_all(&tcon->ses->server->request_q); |
563 | wake_up_all(&tcon->ses->server->response_q); | 452 | wake_up_all(&tcon->ses->server->response_q); |
564 | msleep(1); /* yield */ | 453 | msleep(1); /* yield */ |
@@ -609,7 +498,7 @@ cifs_get_sb(struct file_system_type *fs_type, | |||
609 | int rc; | 498 | int rc; |
610 | struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL); | 499 | struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL); |
611 | 500 | ||
612 | cFYI(1, ("Devname: %s flags: %d ", dev_name, flags)); | 501 | cFYI(1, "Devname: %s flags: %d ", dev_name, flags); |
613 | 502 | ||
614 | if (IS_ERR(sb)) | 503 | if (IS_ERR(sb)) |
615 | return PTR_ERR(sb); | 504 | return PTR_ERR(sb); |
@@ -656,7 +545,6 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin) | |||
656 | return generic_file_llseek_unlocked(file, offset, origin); | 545 | return generic_file_llseek_unlocked(file, offset, origin); |
657 | } | 546 | } |
658 | 547 | ||
659 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
660 | static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) | 548 | static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) |
661 | { | 549 | { |
662 | /* note that this is called by vfs setlease with the BKL held | 550 | /* note that this is called by vfs setlease with the BKL held |
@@ -685,7 +573,6 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) | |||
685 | else | 573 | else |
686 | return -EAGAIN; | 574 | return -EAGAIN; |
687 | } | 575 | } |
688 | #endif | ||
689 | 576 | ||
690 | struct file_system_type cifs_fs_type = { | 577 | struct file_system_type cifs_fs_type = { |
691 | .owner = THIS_MODULE, | 578 | .owner = THIS_MODULE, |
@@ -762,10 +649,7 @@ const struct file_operations cifs_file_ops = { | |||
762 | #ifdef CONFIG_CIFS_POSIX | 649 | #ifdef CONFIG_CIFS_POSIX |
763 | .unlocked_ioctl = cifs_ioctl, | 650 | .unlocked_ioctl = cifs_ioctl, |
764 | #endif /* CONFIG_CIFS_POSIX */ | 651 | #endif /* CONFIG_CIFS_POSIX */ |
765 | |||
766 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
767 | .setlease = cifs_setlease, | 652 | .setlease = cifs_setlease, |
768 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | ||
769 | }; | 653 | }; |
770 | 654 | ||
771 | const struct file_operations cifs_file_direct_ops = { | 655 | const struct file_operations cifs_file_direct_ops = { |
@@ -784,9 +668,7 @@ const struct file_operations cifs_file_direct_ops = { | |||
784 | .unlocked_ioctl = cifs_ioctl, | 668 | .unlocked_ioctl = cifs_ioctl, |
785 | #endif /* CONFIG_CIFS_POSIX */ | 669 | #endif /* CONFIG_CIFS_POSIX */ |
786 | .llseek = cifs_llseek, | 670 | .llseek = cifs_llseek, |
787 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
788 | .setlease = cifs_setlease, | 671 | .setlease = cifs_setlease, |
789 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | ||
790 | }; | 672 | }; |
791 | const struct file_operations cifs_file_nobrl_ops = { | 673 | const struct file_operations cifs_file_nobrl_ops = { |
792 | .read = do_sync_read, | 674 | .read = do_sync_read, |
@@ -803,10 +685,7 @@ const struct file_operations cifs_file_nobrl_ops = { | |||
803 | #ifdef CONFIG_CIFS_POSIX | 685 | #ifdef CONFIG_CIFS_POSIX |
804 | .unlocked_ioctl = cifs_ioctl, | 686 | .unlocked_ioctl = cifs_ioctl, |
805 | #endif /* CONFIG_CIFS_POSIX */ | 687 | #endif /* CONFIG_CIFS_POSIX */ |
806 | |||
807 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
808 | .setlease = cifs_setlease, | 688 | .setlease = cifs_setlease, |
809 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | ||
810 | }; | 689 | }; |
811 | 690 | ||
812 | const struct file_operations cifs_file_direct_nobrl_ops = { | 691 | const struct file_operations cifs_file_direct_nobrl_ops = { |
@@ -824,9 +703,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { | |||
824 | .unlocked_ioctl = cifs_ioctl, | 703 | .unlocked_ioctl = cifs_ioctl, |
825 | #endif /* CONFIG_CIFS_POSIX */ | 704 | #endif /* CONFIG_CIFS_POSIX */ |
826 | .llseek = cifs_llseek, | 705 | .llseek = cifs_llseek, |
827 | #ifdef CONFIG_CIFS_EXPERIMENTAL | ||
828 | .setlease = cifs_setlease, | 706 | .setlease = cifs_setlease, |
829 | #endif /* CONFIG_CIFS_EXPERIMENTAL */ | ||
830 | }; | 707 | }; |
831 | 708 | ||
832 | const struct file_operations cifs_dir_ops = { | 709 | const struct file_operations cifs_dir_ops = { |
@@ -878,7 +755,7 @@ cifs_init_request_bufs(void) | |||
878 | } else { | 755 | } else { |
879 | CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/ | 756 | CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/ |
880 | } | 757 | } |
881 | /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */ | 758 | /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */ |
882 | cifs_req_cachep = kmem_cache_create("cifs_request", | 759 | cifs_req_cachep = kmem_cache_create("cifs_request", |
883 | CIFSMaxBufSize + | 760 | CIFSMaxBufSize + |
884 | MAX_CIFS_HDR_SIZE, 0, | 761 | MAX_CIFS_HDR_SIZE, 0, |
@@ -890,7 +767,7 @@ cifs_init_request_bufs(void) | |||
890 | cifs_min_rcv = 1; | 767 | cifs_min_rcv = 1; |
891 | else if (cifs_min_rcv > 64) { | 768 | else if (cifs_min_rcv > 64) { |
892 | cifs_min_rcv = 64; | 769 | cifs_min_rcv = 64; |
893 | cERROR(1, ("cifs_min_rcv set to maximum (64)")); | 770 | cERROR(1, "cifs_min_rcv set to maximum (64)"); |
894 | } | 771 | } |
895 | 772 | ||
896 | cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, | 773 | cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, |
@@ -921,7 +798,7 @@ cifs_init_request_bufs(void) | |||
921 | cifs_min_small = 2; | 798 | cifs_min_small = 2; |
922 | else if (cifs_min_small > 256) { | 799 | else if (cifs_min_small > 256) { |
923 | cifs_min_small = 256; | 800 | cifs_min_small = 256; |
924 | cFYI(1, ("cifs_min_small set to maximum (256)")); | 801 | cFYI(1, "cifs_min_small set to maximum (256)"); |
925 | } | 802 | } |
926 | 803 | ||
927 | cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small, | 804 | cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small, |
@@ -962,15 +839,6 @@ cifs_init_mids(void) | |||
962 | return -ENOMEM; | 839 | return -ENOMEM; |
963 | } | 840 | } |
964 | 841 | ||
965 | cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs", | ||
966 | sizeof(struct oplock_q_entry), 0, | ||
967 | SLAB_HWCACHE_ALIGN, NULL); | ||
968 | if (cifs_oplock_cachep == NULL) { | ||
969 | mempool_destroy(cifs_mid_poolp); | ||
970 | kmem_cache_destroy(cifs_mid_cachep); | ||
971 | return -ENOMEM; | ||
972 | } | ||
973 | |||
974 | return 0; | 842 | return 0; |
975 | } | 843 | } |
976 | 844 | ||
@@ -979,7 +847,6 @@ cifs_destroy_mids(void) | |||
979 | { | 847 | { |
980 | mempool_destroy(cifs_mid_poolp); | 848 | mempool_destroy(cifs_mid_poolp); |
981 | kmem_cache_destroy(cifs_mid_cachep); | 849 | kmem_cache_destroy(cifs_mid_cachep); |
982 | kmem_cache_destroy(cifs_oplock_cachep); | ||
983 | } | 850 | } |
984 | 851 | ||
985 | static int __init | 852 | static int __init |
@@ -1019,10 +886,10 @@ init_cifs(void) | |||
1019 | 886 | ||
1020 | if (cifs_max_pending < 2) { | 887 | if (cifs_max_pending < 2) { |
1021 | cifs_max_pending = 2; | 888 | cifs_max_pending = 2; |
1022 | cFYI(1, ("cifs_max_pending set to min of 2")); | 889 | cFYI(1, "cifs_max_pending set to min of 2"); |
1023 | } else if (cifs_max_pending > 256) { | 890 | } else if (cifs_max_pending > 256) { |
1024 | cifs_max_pending = 256; | 891 | cifs_max_pending = 256; |
1025 | cFYI(1, ("cifs_max_pending set to max of 256")); | 892 | cFYI(1, "cifs_max_pending set to max of 256"); |
1026 | } | 893 | } |
1027 | 894 | ||
1028 | rc = cifs_init_inodecache(); | 895 | rc = cifs_init_inodecache(); |
@@ -1080,7 +947,7 @@ init_cifs(void) | |||
1080 | static void __exit | 947 | static void __exit |
1081 | exit_cifs(void) | 948 | exit_cifs(void) |
1082 | { | 949 | { |
1083 | cFYI(DBG2, ("exit_cifs")); | 950 | cFYI(DBG2, "exit_cifs"); |
1084 | cifs_proc_clean(); | 951 | cifs_proc_clean(); |
1085 | #ifdef CONFIG_CIFS_DFS_UPCALL | 952 | #ifdef CONFIG_CIFS_DFS_UPCALL |
1086 | cifs_dfs_release_automount_timer(); | 953 | cifs_dfs_release_automount_timer(); |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 7aa57ecdc437..0242ff9cbf41 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -114,5 +114,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | |||
114 | extern const struct export_operations cifs_export_ops; | 114 | extern const struct export_operations cifs_export_ops; |
115 | #endif /* EXPERIMENTAL */ | 115 | #endif /* EXPERIMENTAL */ |
116 | 116 | ||
117 | #define CIFS_VERSION "1.62" | 117 | #define CIFS_VERSION "1.64" |
118 | #endif /* _CIFSFS_H */ | 118 | #endif /* _CIFSFS_H */ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index ecf0ffbe2b64..a88479ceaad5 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -87,7 +87,6 @@ enum securityEnum { | |||
87 | RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */ | 87 | RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */ |
88 | /* NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */ | 88 | /* NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */ |
89 | Kerberos, /* Kerberos via SPNEGO */ | 89 | Kerberos, /* Kerberos via SPNEGO */ |
90 | MSKerberos, /* MS Kerberos via SPNEGO */ | ||
91 | }; | 90 | }; |
92 | 91 | ||
93 | enum protocolEnum { | 92 | enum protocolEnum { |
@@ -185,6 +184,12 @@ struct TCP_Server_Info { | |||
185 | struct mac_key mac_signing_key; | 184 | struct mac_key mac_signing_key; |
186 | char ntlmv2_hash[16]; | 185 | char ntlmv2_hash[16]; |
187 | unsigned long lstrp; /* when we got last response from this server */ | 186 | unsigned long lstrp; /* when we got last response from this server */ |
187 | u16 dialect; /* dialect index that server chose */ | ||
188 | /* extended security flavors that server supports */ | ||
189 | bool sec_kerberos; /* supports plain Kerberos */ | ||
190 | bool sec_mskerberos; /* supports legacy MS Kerberos */ | ||
191 | bool sec_kerberosu2u; /* supports U2U Kerberos */ | ||
192 | bool sec_ntlmssp; /* supports NTLMSSP */ | ||
188 | }; | 193 | }; |
189 | 194 | ||
190 | /* | 195 | /* |
@@ -502,6 +507,7 @@ struct dfs_info3_param { | |||
502 | #define CIFS_FATTR_DFS_REFERRAL 0x1 | 507 | #define CIFS_FATTR_DFS_REFERRAL 0x1 |
503 | #define CIFS_FATTR_DELETE_PENDING 0x2 | 508 | #define CIFS_FATTR_DELETE_PENDING 0x2 |
504 | #define CIFS_FATTR_NEED_REVAL 0x4 | 509 | #define CIFS_FATTR_NEED_REVAL 0x4 |
510 | #define CIFS_FATTR_INO_COLLISION 0x8 | ||
505 | 511 | ||
506 | struct cifs_fattr { | 512 | struct cifs_fattr { |
507 | u32 cf_flags; | 513 | u32 cf_flags; |
@@ -717,7 +723,7 @@ GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions | |||
717 | GLOBAL_EXTERN unsigned int oplockEnabled; | 723 | GLOBAL_EXTERN unsigned int oplockEnabled; |
718 | GLOBAL_EXTERN unsigned int experimEnabled; | 724 | GLOBAL_EXTERN unsigned int experimEnabled; |
719 | GLOBAL_EXTERN unsigned int lookupCacheEnabled; | 725 | GLOBAL_EXTERN unsigned int lookupCacheEnabled; |
720 | GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent | 726 | GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent |
721 | with more secure ntlmssp2 challenge/resp */ | 727 | with more secure ntlmssp2 challenge/resp */ |
722 | GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ | 728 | GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ |
723 | GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ | 729 | GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 39e47f46dea5..fb1657e0fdb8 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -39,8 +39,20 @@ extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, | |||
39 | unsigned int /* length */); | 39 | unsigned int /* length */); |
40 | extern unsigned int _GetXid(void); | 40 | extern unsigned int _GetXid(void); |
41 | extern void _FreeXid(unsigned int); | 41 | extern void _FreeXid(unsigned int); |
42 | #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid())); | 42 | #define GetXid() \ |
43 | #define FreeXid(curr_xid) {_FreeXid(curr_xid); cFYI(1,("CIFS VFS: leaving %s (xid = %d) rc = %d",__func__,curr_xid,(int)rc));} | 43 | ({ \ |
44 | int __xid = (int)_GetXid(); \ | ||
45 | cFYI(1, "CIFS VFS: in %s as Xid: %d with uid: %d", \ | ||
46 | __func__, __xid, current_fsuid()); \ | ||
47 | __xid; \ | ||
48 | }) | ||
49 | |||
50 | #define FreeXid(curr_xid) \ | ||
51 | do { \ | ||
52 | _FreeXid(curr_xid); \ | ||
53 | cFYI(1, "CIFS VFS: leaving %s (xid = %d) rc = %d", \ | ||
54 | __func__, curr_xid, (int)rc); \ | ||
55 | } while (0) | ||
44 | extern char *build_path_from_dentry(struct dentry *); | 56 | extern char *build_path_from_dentry(struct dentry *); |
45 | extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb); | 57 | extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb); |
46 | extern char *build_wildcard_path_from_dentry(struct dentry *direntry); | 58 | extern char *build_wildcard_path_from_dentry(struct dentry *direntry); |
@@ -73,7 +85,7 @@ extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *); | |||
73 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); | 85 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); |
74 | extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr); | 86 | extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr); |
75 | extern int decode_negTokenInit(unsigned char *security_blob, int length, | 87 | extern int decode_negTokenInit(unsigned char *security_blob, int length, |
76 | enum securityEnum *secType); | 88 | struct TCP_Server_Info *server); |
77 | extern int cifs_convert_address(char *src, void *dst); | 89 | extern int cifs_convert_address(char *src, void *dst); |
78 | extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr); | 90 | extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr); |
79 | extern void header_assemble(struct smb_hdr *, char /* command */ , | 91 | extern void header_assemble(struct smb_hdr *, char /* command */ , |
@@ -83,7 +95,6 @@ extern int small_smb_init_no_tc(const int smb_cmd, const int wct, | |||
83 | struct cifsSesInfo *ses, | 95 | struct cifsSesInfo *ses, |
84 | void **request_buf); | 96 | void **request_buf); |
85 | extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, | 97 | extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, |
86 | const int stage, | ||
87 | const struct nls_table *nls_cp); | 98 | const struct nls_table *nls_cp); |
88 | extern __u16 GetNextMid(struct TCP_Server_Info *server); | 99 | extern __u16 GetNextMid(struct TCP_Server_Info *server); |
89 | extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); | 100 | extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); |
@@ -95,8 +106,11 @@ extern struct cifsFileInfo *cifs_new_fileinfo(struct inode *newinode, | |||
95 | __u16 fileHandle, struct file *file, | 106 | __u16 fileHandle, struct file *file, |
96 | struct vfsmount *mnt, unsigned int oflags); | 107 | struct vfsmount *mnt, unsigned int oflags); |
97 | extern int cifs_posix_open(char *full_path, struct inode **pinode, | 108 | extern int cifs_posix_open(char *full_path, struct inode **pinode, |
98 | struct vfsmount *mnt, int mode, int oflags, | 109 | struct vfsmount *mnt, |
99 | __u32 *poplock, __u16 *pnetfid, int xid); | 110 | struct super_block *sb, |
111 | int mode, int oflags, | ||
112 | __u32 *poplock, __u16 *pnetfid, int xid); | ||
113 | void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); | ||
100 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, | 114 | extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, |
101 | FILE_UNIX_BASIC_INFO *info, | 115 | FILE_UNIX_BASIC_INFO *info, |
102 | struct cifs_sb_info *cifs_sb); | 116 | struct cifs_sb_info *cifs_sb); |
@@ -125,7 +139,9 @@ extern void cifs_dfs_release_automount_timer(void); | |||
125 | void cifs_proc_init(void); | 139 | void cifs_proc_init(void); |
126 | void cifs_proc_clean(void); | 140 | void cifs_proc_clean(void); |
127 | 141 | ||
128 | extern int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo, | 142 | extern int cifs_negotiate_protocol(unsigned int xid, |
143 | struct cifsSesInfo *ses); | ||
144 | extern int cifs_setup_session(unsigned int xid, struct cifsSesInfo *ses, | ||
129 | struct nls_table *nls_info); | 145 | struct nls_table *nls_info); |
130 | extern int CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses); | 146 | extern int CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses); |
131 | 147 | ||
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 5d3f29fef532..c65c3419dd37 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * fs/cifs/cifssmb.c | 2 | * fs/cifs/cifssmb.c |
3 | * | 3 | * |
4 | * Copyright (C) International Business Machines Corp., 2002,2009 | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
5 | * Author(s): Steve French (sfrench@us.ibm.com) | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
6 | * | 6 | * |
7 | * Contains the routines for constructing the SMB PDUs themselves | 7 | * Contains the routines for constructing the SMB PDUs themselves |
@@ -130,8 +130,8 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) | |||
130 | if (smb_command != SMB_COM_WRITE_ANDX && | 130 | if (smb_command != SMB_COM_WRITE_ANDX && |
131 | smb_command != SMB_COM_OPEN_ANDX && | 131 | smb_command != SMB_COM_OPEN_ANDX && |
132 | smb_command != SMB_COM_TREE_DISCONNECT) { | 132 | smb_command != SMB_COM_TREE_DISCONNECT) { |
133 | cFYI(1, ("can not send cmd %d while umounting", | 133 | cFYI(1, "can not send cmd %d while umounting", |
134 | smb_command)); | 134 | smb_command); |
135 | return -ENODEV; | 135 | return -ENODEV; |
136 | } | 136 | } |
137 | } | 137 | } |
@@ -157,7 +157,7 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) | |||
157 | * back on-line | 157 | * back on-line |
158 | */ | 158 | */ |
159 | if (!tcon->retry || ses->status == CifsExiting) { | 159 | if (!tcon->retry || ses->status == CifsExiting) { |
160 | cFYI(1, ("gave up waiting on reconnect in smb_init")); | 160 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
161 | return -EHOSTDOWN; | 161 | return -EHOSTDOWN; |
162 | } | 162 | } |
163 | } | 163 | } |
@@ -172,7 +172,8 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) | |||
172 | * reconnect the same SMB session | 172 | * reconnect the same SMB session |
173 | */ | 173 | */ |
174 | mutex_lock(&ses->session_mutex); | 174 | mutex_lock(&ses->session_mutex); |
175 | if (ses->need_reconnect) | 175 | rc = cifs_negotiate_protocol(0, ses); |
176 | if (rc == 0 && ses->need_reconnect) | ||
176 | rc = cifs_setup_session(0, ses, nls_codepage); | 177 | rc = cifs_setup_session(0, ses, nls_codepage); |
177 | 178 | ||
178 | /* do we need to reconnect tcon? */ | 179 | /* do we need to reconnect tcon? */ |
@@ -184,7 +185,7 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) | |||
184 | mark_open_files_invalid(tcon); | 185 | mark_open_files_invalid(tcon); |
185 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); | 186 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
186 | mutex_unlock(&ses->session_mutex); | 187 | mutex_unlock(&ses->session_mutex); |
187 | cFYI(1, ("reconnect tcon rc = %d", rc)); | 188 | cFYI(1, "reconnect tcon rc = %d", rc); |
188 | 189 | ||
189 | if (rc) | 190 | if (rc) |
190 | goto out; | 191 | goto out; |
@@ -355,7 +356,6 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
355 | struct TCP_Server_Info *server; | 356 | struct TCP_Server_Info *server; |
356 | u16 count; | 357 | u16 count; |
357 | unsigned int secFlags; | 358 | unsigned int secFlags; |
358 | u16 dialect; | ||
359 | 359 | ||
360 | if (ses->server) | 360 | if (ses->server) |
361 | server = ses->server; | 361 | server = ses->server; |
@@ -372,9 +372,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
372 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) | 372 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
373 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ | 373 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
374 | else /* if override flags set only sign/seal OR them with global auth */ | 374 | else /* if override flags set only sign/seal OR them with global auth */ |
375 | secFlags = extended_security | ses->overrideSecFlg; | 375 | secFlags = global_secflags | ses->overrideSecFlg; |
376 | 376 | ||
377 | cFYI(1, ("secFlags 0x%x", secFlags)); | 377 | cFYI(1, "secFlags 0x%x", secFlags); |
378 | 378 | ||
379 | pSMB->hdr.Mid = GetNextMid(server); | 379 | pSMB->hdr.Mid = GetNextMid(server); |
380 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); | 380 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
@@ -382,14 +382,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
382 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) | 382 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
383 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; | 383 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
384 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { | 384 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
385 | cFYI(1, ("Kerberos only mechanism, enable extended security")); | 385 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
386 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; | 386 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
387 | } | 387 | } |
388 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 388 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
389 | else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) | 389 | else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
390 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; | 390 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
391 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { | 391 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
392 | cFYI(1, ("NTLMSSP only mechanism, enable extended security")); | 392 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
393 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; | 393 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
394 | } | 394 | } |
395 | #endif | 395 | #endif |
@@ -408,10 +408,10 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
408 | if (rc != 0) | 408 | if (rc != 0) |
409 | goto neg_err_exit; | 409 | goto neg_err_exit; |
410 | 410 | ||
411 | dialect = le16_to_cpu(pSMBr->DialectIndex); | 411 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
412 | cFYI(1, ("Dialect: %d", dialect)); | 412 | cFYI(1, "Dialect: %d", server->dialect); |
413 | /* Check wct = 1 error case */ | 413 | /* Check wct = 1 error case */ |
414 | if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) { | 414 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
415 | /* core returns wct = 1, but we do not ask for core - otherwise | 415 | /* core returns wct = 1, but we do not ask for core - otherwise |
416 | small wct just comes when dialect index is -1 indicating we | 416 | small wct just comes when dialect index is -1 indicating we |
417 | could not negotiate a common dialect */ | 417 | could not negotiate a common dialect */ |
@@ -419,8 +419,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
419 | goto neg_err_exit; | 419 | goto neg_err_exit; |
420 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 420 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
421 | } else if ((pSMBr->hdr.WordCount == 13) | 421 | } else if ((pSMBr->hdr.WordCount == 13) |
422 | && ((dialect == LANMAN_PROT) | 422 | && ((server->dialect == LANMAN_PROT) |
423 | || (dialect == LANMAN2_PROT))) { | 423 | || (server->dialect == LANMAN2_PROT))) { |
424 | __s16 tmp; | 424 | __s16 tmp; |
425 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; | 425 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
426 | 426 | ||
@@ -428,8 +428,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
428 | (secFlags & CIFSSEC_MAY_PLNTXT)) | 428 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
429 | server->secType = LANMAN; | 429 | server->secType = LANMAN; |
430 | else { | 430 | else { |
431 | cERROR(1, ("mount failed weak security disabled" | 431 | cERROR(1, "mount failed weak security disabled" |
432 | " in /proc/fs/cifs/SecurityFlags")); | 432 | " in /proc/fs/cifs/SecurityFlags"); |
433 | rc = -EOPNOTSUPP; | 433 | rc = -EOPNOTSUPP; |
434 | goto neg_err_exit; | 434 | goto neg_err_exit; |
435 | } | 435 | } |
@@ -462,9 +462,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
462 | utc = CURRENT_TIME; | 462 | utc = CURRENT_TIME; |
463 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, | 463 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
464 | rsp->SrvTime.Time, 0); | 464 | rsp->SrvTime.Time, 0); |
465 | cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d", | 465 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
466 | (int)ts.tv_sec, (int)utc.tv_sec, | 466 | (int)ts.tv_sec, (int)utc.tv_sec, |
467 | (int)(utc.tv_sec - ts.tv_sec))); | 467 | (int)(utc.tv_sec - ts.tv_sec)); |
468 | val = (int)(utc.tv_sec - ts.tv_sec); | 468 | val = (int)(utc.tv_sec - ts.tv_sec); |
469 | seconds = abs(val); | 469 | seconds = abs(val); |
470 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; | 470 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
@@ -478,7 +478,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
478 | server->timeAdj = (int)tmp; | 478 | server->timeAdj = (int)tmp; |
479 | server->timeAdj *= 60; /* also in seconds */ | 479 | server->timeAdj *= 60; /* also in seconds */ |
480 | } | 480 | } |
481 | cFYI(1, ("server->timeAdj: %d seconds", server->timeAdj)); | 481 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
482 | 482 | ||
483 | 483 | ||
484 | /* BB get server time for time conversions and add | 484 | /* BB get server time for time conversions and add |
@@ -493,14 +493,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
493 | goto neg_err_exit; | 493 | goto neg_err_exit; |
494 | } | 494 | } |
495 | 495 | ||
496 | cFYI(1, ("LANMAN negotiated")); | 496 | cFYI(1, "LANMAN negotiated"); |
497 | /* we will not end up setting signing flags - as no signing | 497 | /* we will not end up setting signing flags - as no signing |
498 | was in LANMAN and server did not return the flags on */ | 498 | was in LANMAN and server did not return the flags on */ |
499 | goto signing_check; | 499 | goto signing_check; |
500 | #else /* weak security disabled */ | 500 | #else /* weak security disabled */ |
501 | } else if (pSMBr->hdr.WordCount == 13) { | 501 | } else if (pSMBr->hdr.WordCount == 13) { |
502 | cERROR(1, ("mount failed, cifs module not built " | 502 | cERROR(1, "mount failed, cifs module not built " |
503 | "with CIFS_WEAK_PW_HASH support")); | 503 | "with CIFS_WEAK_PW_HASH support"); |
504 | rc = -EOPNOTSUPP; | 504 | rc = -EOPNOTSUPP; |
505 | #endif /* WEAK_PW_HASH */ | 505 | #endif /* WEAK_PW_HASH */ |
506 | goto neg_err_exit; | 506 | goto neg_err_exit; |
@@ -512,14 +512,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
512 | /* else wct == 17 NTLM */ | 512 | /* else wct == 17 NTLM */ |
513 | server->secMode = pSMBr->SecurityMode; | 513 | server->secMode = pSMBr->SecurityMode; |
514 | if ((server->secMode & SECMODE_USER) == 0) | 514 | if ((server->secMode & SECMODE_USER) == 0) |
515 | cFYI(1, ("share mode security")); | 515 | cFYI(1, "share mode security"); |
516 | 516 | ||
517 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) | 517 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
518 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 518 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
519 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) | 519 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
520 | #endif /* CIFS_WEAK_PW_HASH */ | 520 | #endif /* CIFS_WEAK_PW_HASH */ |
521 | cERROR(1, ("Server requests plain text password" | 521 | cERROR(1, "Server requests plain text password" |
522 | " but client support disabled")); | 522 | " but client support disabled"); |
523 | 523 | ||
524 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) | 524 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
525 | server->secType = NTLMv2; | 525 | server->secType = NTLMv2; |
@@ -539,7 +539,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
539 | #endif */ | 539 | #endif */ |
540 | else { | 540 | else { |
541 | rc = -EOPNOTSUPP; | 541 | rc = -EOPNOTSUPP; |
542 | cERROR(1, ("Invalid security type")); | 542 | cERROR(1, "Invalid security type"); |
543 | goto neg_err_exit; | 543 | goto neg_err_exit; |
544 | } | 544 | } |
545 | /* else ... any others ...? */ | 545 | /* else ... any others ...? */ |
@@ -551,7 +551,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
551 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), | 551 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), |
552 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); | 552 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
553 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); | 553 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
554 | cFYI(DBG2, ("Max buf = %d", ses->server->maxBuf)); | 554 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
555 | GETU32(ses->server->sessid) = le32_to_cpu(pSMBr->SessionKey); | 555 | GETU32(ses->server->sessid) = le32_to_cpu(pSMBr->SessionKey); |
556 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); | 556 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
557 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); | 557 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
@@ -582,7 +582,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
582 | if (memcmp(server->server_GUID, | 582 | if (memcmp(server->server_GUID, |
583 | pSMBr->u.extended_response. | 583 | pSMBr->u.extended_response. |
584 | GUID, 16) != 0) { | 584 | GUID, 16) != 0) { |
585 | cFYI(1, ("server UID changed")); | 585 | cFYI(1, "server UID changed"); |
586 | memcpy(server->server_GUID, | 586 | memcpy(server->server_GUID, |
587 | pSMBr->u.extended_response.GUID, | 587 | pSMBr->u.extended_response.GUID, |
588 | 16); | 588 | 16); |
@@ -597,13 +597,19 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
597 | server->secType = RawNTLMSSP; | 597 | server->secType = RawNTLMSSP; |
598 | } else { | 598 | } else { |
599 | rc = decode_negTokenInit(pSMBr->u.extended_response. | 599 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
600 | SecurityBlob, | 600 | SecurityBlob, count - 16, |
601 | count - 16, | 601 | server); |
602 | &server->secType); | ||
603 | if (rc == 1) | 602 | if (rc == 1) |
604 | rc = 0; | 603 | rc = 0; |
605 | else | 604 | else |
606 | rc = -EINVAL; | 605 | rc = -EINVAL; |
606 | |||
607 | if (server->sec_kerberos || server->sec_mskerberos) | ||
608 | server->secType = Kerberos; | ||
609 | else if (server->sec_ntlmssp) | ||
610 | server->secType = RawNTLMSSP; | ||
611 | else | ||
612 | rc = -EOPNOTSUPP; | ||
607 | } | 613 | } |
608 | } else | 614 | } else |
609 | server->capabilities &= ~CAP_EXTENDED_SECURITY; | 615 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
@@ -614,22 +620,21 @@ signing_check: | |||
614 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { | 620 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
615 | /* MUST_SIGN already includes the MAY_SIGN FLAG | 621 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
616 | so if this is zero it means that signing is disabled */ | 622 | so if this is zero it means that signing is disabled */ |
617 | cFYI(1, ("Signing disabled")); | 623 | cFYI(1, "Signing disabled"); |
618 | if (server->secMode & SECMODE_SIGN_REQUIRED) { | 624 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
619 | cERROR(1, ("Server requires " | 625 | cERROR(1, "Server requires " |
620 | "packet signing to be enabled in " | 626 | "packet signing to be enabled in " |
621 | "/proc/fs/cifs/SecurityFlags.")); | 627 | "/proc/fs/cifs/SecurityFlags."); |
622 | rc = -EOPNOTSUPP; | 628 | rc = -EOPNOTSUPP; |
623 | } | 629 | } |
624 | server->secMode &= | 630 | server->secMode &= |
625 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | 631 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
626 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { | 632 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
627 | /* signing required */ | 633 | /* signing required */ |
628 | cFYI(1, ("Must sign - secFlags 0x%x", secFlags)); | 634 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
629 | if ((server->secMode & | 635 | if ((server->secMode & |
630 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { | 636 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
631 | cERROR(1, | 637 | cERROR(1, "signing required but server lacks support"); |
632 | ("signing required but server lacks support")); | ||
633 | rc = -EOPNOTSUPP; | 638 | rc = -EOPNOTSUPP; |
634 | } else | 639 | } else |
635 | server->secMode |= SECMODE_SIGN_REQUIRED; | 640 | server->secMode |= SECMODE_SIGN_REQUIRED; |
@@ -643,7 +648,7 @@ signing_check: | |||
643 | neg_err_exit: | 648 | neg_err_exit: |
644 | cifs_buf_release(pSMB); | 649 | cifs_buf_release(pSMB); |
645 | 650 | ||
646 | cFYI(1, ("negprot rc %d", rc)); | 651 | cFYI(1, "negprot rc %d", rc); |
647 | return rc; | 652 | return rc; |
648 | } | 653 | } |
649 | 654 | ||
@@ -653,7 +658,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
653 | struct smb_hdr *smb_buffer; | 658 | struct smb_hdr *smb_buffer; |
654 | int rc = 0; | 659 | int rc = 0; |
655 | 660 | ||
656 | cFYI(1, ("In tree disconnect")); | 661 | cFYI(1, "In tree disconnect"); |
657 | 662 | ||
658 | /* BB: do we need to check this? These should never be NULL. */ | 663 | /* BB: do we need to check this? These should never be NULL. */ |
659 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) | 664 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
@@ -675,7 +680,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
675 | 680 | ||
676 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); | 681 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
677 | if (rc) | 682 | if (rc) |
678 | cFYI(1, ("Tree disconnect failed %d", rc)); | 683 | cFYI(1, "Tree disconnect failed %d", rc); |
679 | 684 | ||
680 | /* No need to return error on this operation if tid invalidated and | 685 | /* No need to return error on this operation if tid invalidated and |
681 | closed on server already e.g. due to tcp session crashing */ | 686 | closed on server already e.g. due to tcp session crashing */ |
@@ -691,7 +696,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
691 | LOGOFF_ANDX_REQ *pSMB; | 696 | LOGOFF_ANDX_REQ *pSMB; |
692 | int rc = 0; | 697 | int rc = 0; |
693 | 698 | ||
694 | cFYI(1, ("In SMBLogoff for session disconnect")); | 699 | cFYI(1, "In SMBLogoff for session disconnect"); |
695 | 700 | ||
696 | /* | 701 | /* |
697 | * BB: do we need to check validity of ses and server? They should | 702 | * BB: do we need to check validity of ses and server? They should |
@@ -744,7 +749,7 @@ CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, | |||
744 | int bytes_returned = 0; | 749 | int bytes_returned = 0; |
745 | __u16 params, param_offset, offset, byte_count; | 750 | __u16 params, param_offset, offset, byte_count; |
746 | 751 | ||
747 | cFYI(1, ("In POSIX delete")); | 752 | cFYI(1, "In POSIX delete"); |
748 | PsxDelete: | 753 | PsxDelete: |
749 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 754 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
750 | (void **) &pSMBr); | 755 | (void **) &pSMBr); |
@@ -796,7 +801,7 @@ PsxDelete: | |||
796 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 801 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
797 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 802 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
798 | if (rc) | 803 | if (rc) |
799 | cFYI(1, ("Posix delete returned %d", rc)); | 804 | cFYI(1, "Posix delete returned %d", rc); |
800 | cifs_buf_release(pSMB); | 805 | cifs_buf_release(pSMB); |
801 | 806 | ||
802 | cifs_stats_inc(&tcon->num_deletes); | 807 | cifs_stats_inc(&tcon->num_deletes); |
@@ -843,7 +848,7 @@ DelFileRetry: | |||
843 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 848 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
844 | cifs_stats_inc(&tcon->num_deletes); | 849 | cifs_stats_inc(&tcon->num_deletes); |
845 | if (rc) | 850 | if (rc) |
846 | cFYI(1, ("Error in RMFile = %d", rc)); | 851 | cFYI(1, "Error in RMFile = %d", rc); |
847 | 852 | ||
848 | cifs_buf_release(pSMB); | 853 | cifs_buf_release(pSMB); |
849 | if (rc == -EAGAIN) | 854 | if (rc == -EAGAIN) |
@@ -862,7 +867,7 @@ CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, | |||
862 | int bytes_returned; | 867 | int bytes_returned; |
863 | int name_len; | 868 | int name_len; |
864 | 869 | ||
865 | cFYI(1, ("In CIFSSMBRmDir")); | 870 | cFYI(1, "In CIFSSMBRmDir"); |
866 | RmDirRetry: | 871 | RmDirRetry: |
867 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, | 872 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
868 | (void **) &pSMBr); | 873 | (void **) &pSMBr); |
@@ -887,7 +892,7 @@ RmDirRetry: | |||
887 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 892 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
888 | cifs_stats_inc(&tcon->num_rmdirs); | 893 | cifs_stats_inc(&tcon->num_rmdirs); |
889 | if (rc) | 894 | if (rc) |
890 | cFYI(1, ("Error in RMDir = %d", rc)); | 895 | cFYI(1, "Error in RMDir = %d", rc); |
891 | 896 | ||
892 | cifs_buf_release(pSMB); | 897 | cifs_buf_release(pSMB); |
893 | if (rc == -EAGAIN) | 898 | if (rc == -EAGAIN) |
@@ -905,7 +910,7 @@ CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, | |||
905 | int bytes_returned; | 910 | int bytes_returned; |
906 | int name_len; | 911 | int name_len; |
907 | 912 | ||
908 | cFYI(1, ("In CIFSSMBMkDir")); | 913 | cFYI(1, "In CIFSSMBMkDir"); |
909 | MkDirRetry: | 914 | MkDirRetry: |
910 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, | 915 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
911 | (void **) &pSMBr); | 916 | (void **) &pSMBr); |
@@ -930,7 +935,7 @@ MkDirRetry: | |||
930 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 935 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
931 | cifs_stats_inc(&tcon->num_mkdirs); | 936 | cifs_stats_inc(&tcon->num_mkdirs); |
932 | if (rc) | 937 | if (rc) |
933 | cFYI(1, ("Error in Mkdir = %d", rc)); | 938 | cFYI(1, "Error in Mkdir = %d", rc); |
934 | 939 | ||
935 | cifs_buf_release(pSMB); | 940 | cifs_buf_release(pSMB); |
936 | if (rc == -EAGAIN) | 941 | if (rc == -EAGAIN) |
@@ -953,7 +958,7 @@ CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, | |||
953 | OPEN_PSX_REQ *pdata; | 958 | OPEN_PSX_REQ *pdata; |
954 | OPEN_PSX_RSP *psx_rsp; | 959 | OPEN_PSX_RSP *psx_rsp; |
955 | 960 | ||
956 | cFYI(1, ("In POSIX Create")); | 961 | cFYI(1, "In POSIX Create"); |
957 | PsxCreat: | 962 | PsxCreat: |
958 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 963 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
959 | (void **) &pSMBr); | 964 | (void **) &pSMBr); |
@@ -1007,11 +1012,11 @@ PsxCreat: | |||
1007 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 1012 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
1008 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 1013 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
1009 | if (rc) { | 1014 | if (rc) { |
1010 | cFYI(1, ("Posix create returned %d", rc)); | 1015 | cFYI(1, "Posix create returned %d", rc); |
1011 | goto psx_create_err; | 1016 | goto psx_create_err; |
1012 | } | 1017 | } |
1013 | 1018 | ||
1014 | cFYI(1, ("copying inode info")); | 1019 | cFYI(1, "copying inode info"); |
1015 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 1020 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
1016 | 1021 | ||
1017 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { | 1022 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { |
@@ -1033,11 +1038,11 @@ PsxCreat: | |||
1033 | /* check to make sure response data is there */ | 1038 | /* check to make sure response data is there */ |
1034 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { | 1039 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
1035 | pRetData->Type = cpu_to_le32(-1); /* unknown */ | 1040 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
1036 | cFYI(DBG2, ("unknown type")); | 1041 | cFYI(DBG2, "unknown type"); |
1037 | } else { | 1042 | } else { |
1038 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) | 1043 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) |
1039 | + sizeof(FILE_UNIX_BASIC_INFO)) { | 1044 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
1040 | cERROR(1, ("Open response data too small")); | 1045 | cERROR(1, "Open response data too small"); |
1041 | pRetData->Type = cpu_to_le32(-1); | 1046 | pRetData->Type = cpu_to_le32(-1); |
1042 | goto psx_create_err; | 1047 | goto psx_create_err; |
1043 | } | 1048 | } |
@@ -1084,7 +1089,7 @@ static __u16 convert_disposition(int disposition) | |||
1084 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; | 1089 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
1085 | break; | 1090 | break; |
1086 | default: | 1091 | default: |
1087 | cFYI(1, ("unknown disposition %d", disposition)); | 1092 | cFYI(1, "unknown disposition %d", disposition); |
1088 | ofun = SMBOPEN_OAPPEND; /* regular open */ | 1093 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
1089 | } | 1094 | } |
1090 | return ofun; | 1095 | return ofun; |
@@ -1175,7 +1180,7 @@ OldOpenRetry: | |||
1175 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); | 1180 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
1176 | cifs_stats_inc(&tcon->num_opens); | 1181 | cifs_stats_inc(&tcon->num_opens); |
1177 | if (rc) { | 1182 | if (rc) { |
1178 | cFYI(1, ("Error in Open = %d", rc)); | 1183 | cFYI(1, "Error in Open = %d", rc); |
1179 | } else { | 1184 | } else { |
1180 | /* BB verify if wct == 15 */ | 1185 | /* BB verify if wct == 15 */ |
1181 | 1186 | ||
@@ -1288,7 +1293,7 @@ openRetry: | |||
1288 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); | 1293 | (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); |
1289 | cifs_stats_inc(&tcon->num_opens); | 1294 | cifs_stats_inc(&tcon->num_opens); |
1290 | if (rc) { | 1295 | if (rc) { |
1291 | cFYI(1, ("Error in Open = %d", rc)); | 1296 | cFYI(1, "Error in Open = %d", rc); |
1292 | } else { | 1297 | } else { |
1293 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ | 1298 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
1294 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ | 1299 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
@@ -1326,7 +1331,7 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, | |||
1326 | int resp_buf_type = 0; | 1331 | int resp_buf_type = 0; |
1327 | struct kvec iov[1]; | 1332 | struct kvec iov[1]; |
1328 | 1333 | ||
1329 | cFYI(1, ("Reading %d bytes on fid %d", count, netfid)); | 1334 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
1330 | if (tcon->ses->capabilities & CAP_LARGE_FILES) | 1335 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
1331 | wct = 12; | 1336 | wct = 12; |
1332 | else { | 1337 | else { |
@@ -1371,7 +1376,7 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, | |||
1371 | cifs_stats_inc(&tcon->num_reads); | 1376 | cifs_stats_inc(&tcon->num_reads); |
1372 | pSMBr = (READ_RSP *)iov[0].iov_base; | 1377 | pSMBr = (READ_RSP *)iov[0].iov_base; |
1373 | if (rc) { | 1378 | if (rc) { |
1374 | cERROR(1, ("Send error in read = %d", rc)); | 1379 | cERROR(1, "Send error in read = %d", rc); |
1375 | } else { | 1380 | } else { |
1376 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); | 1381 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
1377 | data_length = data_length << 16; | 1382 | data_length = data_length << 16; |
@@ -1381,15 +1386,15 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, | |||
1381 | /*check that DataLength would not go beyond end of SMB */ | 1386 | /*check that DataLength would not go beyond end of SMB */ |
1382 | if ((data_length > CIFSMaxBufSize) | 1387 | if ((data_length > CIFSMaxBufSize) |
1383 | || (data_length > count)) { | 1388 | || (data_length > count)) { |
1384 | cFYI(1, ("bad length %d for count %d", | 1389 | cFYI(1, "bad length %d for count %d", |
1385 | data_length, count)); | 1390 | data_length, count); |
1386 | rc = -EIO; | 1391 | rc = -EIO; |
1387 | *nbytes = 0; | 1392 | *nbytes = 0; |
1388 | } else { | 1393 | } else { |
1389 | pReadData = (char *) (&pSMBr->hdr.Protocol) + | 1394 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
1390 | le16_to_cpu(pSMBr->DataOffset); | 1395 | le16_to_cpu(pSMBr->DataOffset); |
1391 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { | 1396 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
1392 | cERROR(1,("Faulting on read rc = %d",rc)); | 1397 | cERROR(1, "Faulting on read rc = %d",rc); |
1393 | rc = -EFAULT; | 1398 | rc = -EFAULT; |
1394 | }*/ /* can not use copy_to_user when using page cache*/ | 1399 | }*/ /* can not use copy_to_user when using page cache*/ |
1395 | if (*buf) | 1400 | if (*buf) |
@@ -1433,7 +1438,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1433 | 1438 | ||
1434 | *nbytes = 0; | 1439 | *nbytes = 0; |
1435 | 1440 | ||
1436 | /* cFYI(1, ("write at %lld %d bytes", offset, count));*/ | 1441 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
1437 | if (tcon->ses == NULL) | 1442 | if (tcon->ses == NULL) |
1438 | return -ECONNABORTED; | 1443 | return -ECONNABORTED; |
1439 | 1444 | ||
@@ -1514,7 +1519,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1514 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); | 1519 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
1515 | cifs_stats_inc(&tcon->num_writes); | 1520 | cifs_stats_inc(&tcon->num_writes); |
1516 | if (rc) { | 1521 | if (rc) { |
1517 | cFYI(1, ("Send error in write = %d", rc)); | 1522 | cFYI(1, "Send error in write = %d", rc); |
1518 | } else { | 1523 | } else { |
1519 | *nbytes = le16_to_cpu(pSMBr->CountHigh); | 1524 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
1520 | *nbytes = (*nbytes) << 16; | 1525 | *nbytes = (*nbytes) << 16; |
@@ -1551,7 +1556,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1551 | 1556 | ||
1552 | *nbytes = 0; | 1557 | *nbytes = 0; |
1553 | 1558 | ||
1554 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); | 1559 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
1555 | 1560 | ||
1556 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { | 1561 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
1557 | wct = 14; | 1562 | wct = 14; |
@@ -1606,7 +1611,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1606 | long_op); | 1611 | long_op); |
1607 | cifs_stats_inc(&tcon->num_writes); | 1612 | cifs_stats_inc(&tcon->num_writes); |
1608 | if (rc) { | 1613 | if (rc) { |
1609 | cFYI(1, ("Send error Write2 = %d", rc)); | 1614 | cFYI(1, "Send error Write2 = %d", rc); |
1610 | } else if (resp_buf_type == 0) { | 1615 | } else if (resp_buf_type == 0) { |
1611 | /* presumably this can not happen, but best to be safe */ | 1616 | /* presumably this can not happen, but best to be safe */ |
1612 | rc = -EIO; | 1617 | rc = -EIO; |
@@ -1651,7 +1656,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1651 | int timeout = 0; | 1656 | int timeout = 0; |
1652 | __u16 count; | 1657 | __u16 count; |
1653 | 1658 | ||
1654 | cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock)); | 1659 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
1655 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); | 1660 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
1656 | 1661 | ||
1657 | if (rc) | 1662 | if (rc) |
@@ -1699,7 +1704,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1699 | } | 1704 | } |
1700 | cifs_stats_inc(&tcon->num_locks); | 1705 | cifs_stats_inc(&tcon->num_locks); |
1701 | if (rc) | 1706 | if (rc) |
1702 | cFYI(1, ("Send error in Lock = %d", rc)); | 1707 | cFYI(1, "Send error in Lock = %d", rc); |
1703 | 1708 | ||
1704 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 1709 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
1705 | since file handle passed in no longer valid */ | 1710 | since file handle passed in no longer valid */ |
@@ -1722,7 +1727,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1722 | __u16 params, param_offset, offset, byte_count, count; | 1727 | __u16 params, param_offset, offset, byte_count, count; |
1723 | struct kvec iov[1]; | 1728 | struct kvec iov[1]; |
1724 | 1729 | ||
1725 | cFYI(1, ("Posix Lock")); | 1730 | cFYI(1, "Posix Lock"); |
1726 | 1731 | ||
1727 | if (pLockData == NULL) | 1732 | if (pLockData == NULL) |
1728 | return -EINVAL; | 1733 | return -EINVAL; |
@@ -1792,7 +1797,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1792 | } | 1797 | } |
1793 | 1798 | ||
1794 | if (rc) { | 1799 | if (rc) { |
1795 | cFYI(1, ("Send error in Posix Lock = %d", rc)); | 1800 | cFYI(1, "Send error in Posix Lock = %d", rc); |
1796 | } else if (get_flag) { | 1801 | } else if (get_flag) { |
1797 | /* lock structure can be returned on get */ | 1802 | /* lock structure can be returned on get */ |
1798 | __u16 data_offset; | 1803 | __u16 data_offset; |
@@ -1849,7 +1854,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1849 | { | 1854 | { |
1850 | int rc = 0; | 1855 | int rc = 0; |
1851 | CLOSE_REQ *pSMB = NULL; | 1856 | CLOSE_REQ *pSMB = NULL; |
1852 | cFYI(1, ("In CIFSSMBClose")); | 1857 | cFYI(1, "In CIFSSMBClose"); |
1853 | 1858 | ||
1854 | /* do not retry on dead session on close */ | 1859 | /* do not retry on dead session on close */ |
1855 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); | 1860 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
@@ -1866,7 +1871,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1866 | if (rc) { | 1871 | if (rc) { |
1867 | if (rc != -EINTR) { | 1872 | if (rc != -EINTR) { |
1868 | /* EINTR is expected when user ctl-c to kill app */ | 1873 | /* EINTR is expected when user ctl-c to kill app */ |
1869 | cERROR(1, ("Send error in Close = %d", rc)); | 1874 | cERROR(1, "Send error in Close = %d", rc); |
1870 | } | 1875 | } |
1871 | } | 1876 | } |
1872 | 1877 | ||
@@ -1882,7 +1887,7 @@ CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1882 | { | 1887 | { |
1883 | int rc = 0; | 1888 | int rc = 0; |
1884 | FLUSH_REQ *pSMB = NULL; | 1889 | FLUSH_REQ *pSMB = NULL; |
1885 | cFYI(1, ("In CIFSSMBFlush")); | 1890 | cFYI(1, "In CIFSSMBFlush"); |
1886 | 1891 | ||
1887 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); | 1892 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
1888 | if (rc) | 1893 | if (rc) |
@@ -1893,7 +1898,7 @@ CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1893 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 1898 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
1894 | cifs_stats_inc(&tcon->num_flushes); | 1899 | cifs_stats_inc(&tcon->num_flushes); |
1895 | if (rc) | 1900 | if (rc) |
1896 | cERROR(1, ("Send error in Flush = %d", rc)); | 1901 | cERROR(1, "Send error in Flush = %d", rc); |
1897 | 1902 | ||
1898 | return rc; | 1903 | return rc; |
1899 | } | 1904 | } |
@@ -1910,7 +1915,7 @@ CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, | |||
1910 | int name_len, name_len2; | 1915 | int name_len, name_len2; |
1911 | __u16 count; | 1916 | __u16 count; |
1912 | 1917 | ||
1913 | cFYI(1, ("In CIFSSMBRename")); | 1918 | cFYI(1, "In CIFSSMBRename"); |
1914 | renameRetry: | 1919 | renameRetry: |
1915 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, | 1920 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
1916 | (void **) &pSMBr); | 1921 | (void **) &pSMBr); |
@@ -1956,7 +1961,7 @@ renameRetry: | |||
1956 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 1961 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
1957 | cifs_stats_inc(&tcon->num_renames); | 1962 | cifs_stats_inc(&tcon->num_renames); |
1958 | if (rc) | 1963 | if (rc) |
1959 | cFYI(1, ("Send error in rename = %d", rc)); | 1964 | cFYI(1, "Send error in rename = %d", rc); |
1960 | 1965 | ||
1961 | cifs_buf_release(pSMB); | 1966 | cifs_buf_release(pSMB); |
1962 | 1967 | ||
@@ -1980,7 +1985,7 @@ int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, | |||
1980 | int len_of_str; | 1985 | int len_of_str; |
1981 | __u16 params, param_offset, offset, count, byte_count; | 1986 | __u16 params, param_offset, offset, count, byte_count; |
1982 | 1987 | ||
1983 | cFYI(1, ("Rename to File by handle")); | 1988 | cFYI(1, "Rename to File by handle"); |
1984 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, | 1989 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
1985 | (void **) &pSMBr); | 1990 | (void **) &pSMBr); |
1986 | if (rc) | 1991 | if (rc) |
@@ -2035,7 +2040,7 @@ int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, | |||
2035 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2040 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2036 | cifs_stats_inc(&pTcon->num_t2renames); | 2041 | cifs_stats_inc(&pTcon->num_t2renames); |
2037 | if (rc) | 2042 | if (rc) |
2038 | cFYI(1, ("Send error in Rename (by file handle) = %d", rc)); | 2043 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
2039 | 2044 | ||
2040 | cifs_buf_release(pSMB); | 2045 | cifs_buf_release(pSMB); |
2041 | 2046 | ||
@@ -2057,7 +2062,7 @@ CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, | |||
2057 | int name_len, name_len2; | 2062 | int name_len, name_len2; |
2058 | __u16 count; | 2063 | __u16 count; |
2059 | 2064 | ||
2060 | cFYI(1, ("In CIFSSMBCopy")); | 2065 | cFYI(1, "In CIFSSMBCopy"); |
2061 | copyRetry: | 2066 | copyRetry: |
2062 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, | 2067 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
2063 | (void **) &pSMBr); | 2068 | (void **) &pSMBr); |
@@ -2102,8 +2107,8 @@ copyRetry: | |||
2102 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 2107 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2103 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2108 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2104 | if (rc) { | 2109 | if (rc) { |
2105 | cFYI(1, ("Send error in copy = %d with %d files copied", | 2110 | cFYI(1, "Send error in copy = %d with %d files copied", |
2106 | rc, le16_to_cpu(pSMBr->CopyCount))); | 2111 | rc, le16_to_cpu(pSMBr->CopyCount)); |
2107 | } | 2112 | } |
2108 | cifs_buf_release(pSMB); | 2113 | cifs_buf_release(pSMB); |
2109 | 2114 | ||
@@ -2127,7 +2132,7 @@ CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, | |||
2127 | int bytes_returned = 0; | 2132 | int bytes_returned = 0; |
2128 | __u16 params, param_offset, offset, byte_count; | 2133 | __u16 params, param_offset, offset, byte_count; |
2129 | 2134 | ||
2130 | cFYI(1, ("In Symlink Unix style")); | 2135 | cFYI(1, "In Symlink Unix style"); |
2131 | createSymLinkRetry: | 2136 | createSymLinkRetry: |
2132 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2137 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
2133 | (void **) &pSMBr); | 2138 | (void **) &pSMBr); |
@@ -2192,7 +2197,7 @@ createSymLinkRetry: | |||
2192 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2197 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2193 | cifs_stats_inc(&tcon->num_symlinks); | 2198 | cifs_stats_inc(&tcon->num_symlinks); |
2194 | if (rc) | 2199 | if (rc) |
2195 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); | 2200 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
2196 | 2201 | ||
2197 | cifs_buf_release(pSMB); | 2202 | cifs_buf_release(pSMB); |
2198 | 2203 | ||
@@ -2216,7 +2221,7 @@ CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, | |||
2216 | int bytes_returned = 0; | 2221 | int bytes_returned = 0; |
2217 | __u16 params, param_offset, offset, byte_count; | 2222 | __u16 params, param_offset, offset, byte_count; |
2218 | 2223 | ||
2219 | cFYI(1, ("In Create Hard link Unix style")); | 2224 | cFYI(1, "In Create Hard link Unix style"); |
2220 | createHardLinkRetry: | 2225 | createHardLinkRetry: |
2221 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2226 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
2222 | (void **) &pSMBr); | 2227 | (void **) &pSMBr); |
@@ -2278,7 +2283,7 @@ createHardLinkRetry: | |||
2278 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2283 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2279 | cifs_stats_inc(&tcon->num_hardlinks); | 2284 | cifs_stats_inc(&tcon->num_hardlinks); |
2280 | if (rc) | 2285 | if (rc) |
2281 | cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc)); | 2286 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
2282 | 2287 | ||
2283 | cifs_buf_release(pSMB); | 2288 | cifs_buf_release(pSMB); |
2284 | if (rc == -EAGAIN) | 2289 | if (rc == -EAGAIN) |
@@ -2299,7 +2304,7 @@ CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, | |||
2299 | int name_len, name_len2; | 2304 | int name_len, name_len2; |
2300 | __u16 count; | 2305 | __u16 count; |
2301 | 2306 | ||
2302 | cFYI(1, ("In CIFSCreateHardLink")); | 2307 | cFYI(1, "In CIFSCreateHardLink"); |
2303 | winCreateHardLinkRetry: | 2308 | winCreateHardLinkRetry: |
2304 | 2309 | ||
2305 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, | 2310 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
@@ -2350,7 +2355,7 @@ winCreateHardLinkRetry: | |||
2350 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2355 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2351 | cifs_stats_inc(&tcon->num_hardlinks); | 2356 | cifs_stats_inc(&tcon->num_hardlinks); |
2352 | if (rc) | 2357 | if (rc) |
2353 | cFYI(1, ("Send error in hard link (NT rename) = %d", rc)); | 2358 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
2354 | 2359 | ||
2355 | cifs_buf_release(pSMB); | 2360 | cifs_buf_release(pSMB); |
2356 | if (rc == -EAGAIN) | 2361 | if (rc == -EAGAIN) |
@@ -2373,7 +2378,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, | |||
2373 | __u16 params, byte_count; | 2378 | __u16 params, byte_count; |
2374 | char *data_start; | 2379 | char *data_start; |
2375 | 2380 | ||
2376 | cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName)); | 2381 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
2377 | 2382 | ||
2378 | querySymLinkRetry: | 2383 | querySymLinkRetry: |
2379 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2384 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -2420,7 +2425,7 @@ querySymLinkRetry: | |||
2420 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 2425 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2421 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2426 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2422 | if (rc) { | 2427 | if (rc) { |
2423 | cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc)); | 2428 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
2424 | } else { | 2429 | } else { |
2425 | /* decode response */ | 2430 | /* decode response */ |
2426 | 2431 | ||
@@ -2521,21 +2526,21 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata, | |||
2521 | 2526 | ||
2522 | /* should we also check that parm and data areas do not overlap? */ | 2527 | /* should we also check that parm and data areas do not overlap? */ |
2523 | if (*ppparm > end_of_smb) { | 2528 | if (*ppparm > end_of_smb) { |
2524 | cFYI(1, ("parms start after end of smb")); | 2529 | cFYI(1, "parms start after end of smb"); |
2525 | return -EINVAL; | 2530 | return -EINVAL; |
2526 | } else if (parm_count + *ppparm > end_of_smb) { | 2531 | } else if (parm_count + *ppparm > end_of_smb) { |
2527 | cFYI(1, ("parm end after end of smb")); | 2532 | cFYI(1, "parm end after end of smb"); |
2528 | return -EINVAL; | 2533 | return -EINVAL; |
2529 | } else if (*ppdata > end_of_smb) { | 2534 | } else if (*ppdata > end_of_smb) { |
2530 | cFYI(1, ("data starts after end of smb")); | 2535 | cFYI(1, "data starts after end of smb"); |
2531 | return -EINVAL; | 2536 | return -EINVAL; |
2532 | } else if (data_count + *ppdata > end_of_smb) { | 2537 | } else if (data_count + *ppdata > end_of_smb) { |
2533 | cFYI(1, ("data %p + count %d (%p) ends after end of smb %p start %p", | 2538 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
2534 | *ppdata, data_count, (data_count + *ppdata), | 2539 | *ppdata, data_count, (data_count + *ppdata), |
2535 | end_of_smb, pSMBr)); | 2540 | end_of_smb, pSMBr); |
2536 | return -EINVAL; | 2541 | return -EINVAL; |
2537 | } else if (parm_count + data_count > pSMBr->ByteCount) { | 2542 | } else if (parm_count + data_count > pSMBr->ByteCount) { |
2538 | cFYI(1, ("parm count and data count larger than SMB")); | 2543 | cFYI(1, "parm count and data count larger than SMB"); |
2539 | return -EINVAL; | 2544 | return -EINVAL; |
2540 | } | 2545 | } |
2541 | *pdatalen = data_count; | 2546 | *pdatalen = data_count; |
@@ -2554,7 +2559,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | |||
2554 | struct smb_com_transaction_ioctl_req *pSMB; | 2559 | struct smb_com_transaction_ioctl_req *pSMB; |
2555 | struct smb_com_transaction_ioctl_rsp *pSMBr; | 2560 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
2556 | 2561 | ||
2557 | cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); | 2562 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
2558 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, | 2563 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
2559 | (void **) &pSMBr); | 2564 | (void **) &pSMBr); |
2560 | if (rc) | 2565 | if (rc) |
@@ -2583,7 +2588,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | |||
2583 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 2588 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2584 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2589 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2585 | if (rc) { | 2590 | if (rc) { |
2586 | cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc)); | 2591 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
2587 | } else { /* decode response */ | 2592 | } else { /* decode response */ |
2588 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); | 2593 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
2589 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); | 2594 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
@@ -2607,7 +2612,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | |||
2607 | if ((reparse_buf->LinkNamesBuf + | 2612 | if ((reparse_buf->LinkNamesBuf + |
2608 | reparse_buf->TargetNameOffset + | 2613 | reparse_buf->TargetNameOffset + |
2609 | reparse_buf->TargetNameLen) > end_of_smb) { | 2614 | reparse_buf->TargetNameLen) > end_of_smb) { |
2610 | cFYI(1, ("reparse buf beyond SMB")); | 2615 | cFYI(1, "reparse buf beyond SMB"); |
2611 | rc = -EIO; | 2616 | rc = -EIO; |
2612 | goto qreparse_out; | 2617 | goto qreparse_out; |
2613 | } | 2618 | } |
@@ -2628,12 +2633,12 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | |||
2628 | } | 2633 | } |
2629 | } else { | 2634 | } else { |
2630 | rc = -EIO; | 2635 | rc = -EIO; |
2631 | cFYI(1, ("Invalid return data count on " | 2636 | cFYI(1, "Invalid return data count on " |
2632 | "get reparse info ioctl")); | 2637 | "get reparse info ioctl"); |
2633 | } | 2638 | } |
2634 | symlinkinfo[buflen] = 0; /* just in case so the caller | 2639 | symlinkinfo[buflen] = 0; /* just in case so the caller |
2635 | does not go off the end of the buffer */ | 2640 | does not go off the end of the buffer */ |
2636 | cFYI(1, ("readlink result - %s", symlinkinfo)); | 2641 | cFYI(1, "readlink result - %s", symlinkinfo); |
2637 | } | 2642 | } |
2638 | 2643 | ||
2639 | qreparse_out: | 2644 | qreparse_out: |
@@ -2656,7 +2661,7 @@ static void cifs_convert_ace(posix_acl_xattr_entry *ace, | |||
2656 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); | 2661 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
2657 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); | 2662 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
2658 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); | 2663 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
2659 | /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */ | 2664 | /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */ |
2660 | 2665 | ||
2661 | return; | 2666 | return; |
2662 | } | 2667 | } |
@@ -2682,8 +2687,8 @@ static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, | |||
2682 | size += sizeof(struct cifs_posix_ace) * count; | 2687 | size += sizeof(struct cifs_posix_ace) * count; |
2683 | /* check if we would go beyond end of SMB */ | 2688 | /* check if we would go beyond end of SMB */ |
2684 | if (size_of_data_area < size) { | 2689 | if (size_of_data_area < size) { |
2685 | cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d", | 2690 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
2686 | size_of_data_area, size)); | 2691 | size_of_data_area, size); |
2687 | return -EINVAL; | 2692 | return -EINVAL; |
2688 | } | 2693 | } |
2689 | } else if (acl_type & ACL_TYPE_DEFAULT) { | 2694 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
@@ -2730,7 +2735,7 @@ static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, | |||
2730 | cifs_ace->cifs_uid = cpu_to_le64(-1); | 2735 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
2731 | } else | 2736 | } else |
2732 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); | 2737 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
2733 | /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/ | 2738 | /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/ |
2734 | return rc; | 2739 | return rc; |
2735 | } | 2740 | } |
2736 | 2741 | ||
@@ -2748,12 +2753,12 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, | |||
2748 | return 0; | 2753 | return 0; |
2749 | 2754 | ||
2750 | count = posix_acl_xattr_count((size_t)buflen); | 2755 | count = posix_acl_xattr_count((size_t)buflen); |
2751 | cFYI(1, ("setting acl with %d entries from buf of length %d and " | 2756 | cFYI(1, "setting acl with %d entries from buf of length %d and " |
2752 | "version of %d", | 2757 | "version of %d", |
2753 | count, buflen, le32_to_cpu(local_acl->a_version))); | 2758 | count, buflen, le32_to_cpu(local_acl->a_version)); |
2754 | if (le32_to_cpu(local_acl->a_version) != 2) { | 2759 | if (le32_to_cpu(local_acl->a_version) != 2) { |
2755 | cFYI(1, ("unknown POSIX ACL version %d", | 2760 | cFYI(1, "unknown POSIX ACL version %d", |
2756 | le32_to_cpu(local_acl->a_version))); | 2761 | le32_to_cpu(local_acl->a_version)); |
2757 | return 0; | 2762 | return 0; |
2758 | } | 2763 | } |
2759 | cifs_acl->version = cpu_to_le16(1); | 2764 | cifs_acl->version = cpu_to_le16(1); |
@@ -2762,7 +2767,7 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, | |||
2762 | else if (acl_type == ACL_TYPE_DEFAULT) | 2767 | else if (acl_type == ACL_TYPE_DEFAULT) |
2763 | cifs_acl->default_entry_count = cpu_to_le16(count); | 2768 | cifs_acl->default_entry_count = cpu_to_le16(count); |
2764 | else { | 2769 | else { |
2765 | cFYI(1, ("unknown ACL type %d", acl_type)); | 2770 | cFYI(1, "unknown ACL type %d", acl_type); |
2766 | return 0; | 2771 | return 0; |
2767 | } | 2772 | } |
2768 | for (i = 0; i < count; i++) { | 2773 | for (i = 0; i < count; i++) { |
@@ -2795,7 +2800,7 @@ CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, | |||
2795 | int name_len; | 2800 | int name_len; |
2796 | __u16 params, byte_count; | 2801 | __u16 params, byte_count; |
2797 | 2802 | ||
2798 | cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); | 2803 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
2799 | 2804 | ||
2800 | queryAclRetry: | 2805 | queryAclRetry: |
2801 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2806 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -2847,7 +2852,7 @@ queryAclRetry: | |||
2847 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2852 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2848 | cifs_stats_inc(&tcon->num_acl_get); | 2853 | cifs_stats_inc(&tcon->num_acl_get); |
2849 | if (rc) { | 2854 | if (rc) { |
2850 | cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); | 2855 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
2851 | } else { | 2856 | } else { |
2852 | /* decode response */ | 2857 | /* decode response */ |
2853 | 2858 | ||
@@ -2884,7 +2889,7 @@ CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, | |||
2884 | int bytes_returned = 0; | 2889 | int bytes_returned = 0; |
2885 | __u16 params, byte_count, data_count, param_offset, offset; | 2890 | __u16 params, byte_count, data_count, param_offset, offset; |
2886 | 2891 | ||
2887 | cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); | 2892 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
2888 | setAclRetry: | 2893 | setAclRetry: |
2889 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2894 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
2890 | (void **) &pSMBr); | 2895 | (void **) &pSMBr); |
@@ -2939,7 +2944,7 @@ setAclRetry: | |||
2939 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 2944 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2940 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2945 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2941 | if (rc) | 2946 | if (rc) |
2942 | cFYI(1, ("Set POSIX ACL returned %d", rc)); | 2947 | cFYI(1, "Set POSIX ACL returned %d", rc); |
2943 | 2948 | ||
2944 | setACLerrorExit: | 2949 | setACLerrorExit: |
2945 | cifs_buf_release(pSMB); | 2950 | cifs_buf_release(pSMB); |
@@ -2959,7 +2964,7 @@ CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, | |||
2959 | int bytes_returned; | 2964 | int bytes_returned; |
2960 | __u16 params, byte_count; | 2965 | __u16 params, byte_count; |
2961 | 2966 | ||
2962 | cFYI(1, ("In GetExtAttr")); | 2967 | cFYI(1, "In GetExtAttr"); |
2963 | if (tcon == NULL) | 2968 | if (tcon == NULL) |
2964 | return -ENODEV; | 2969 | return -ENODEV; |
2965 | 2970 | ||
@@ -2998,7 +3003,7 @@ GetExtAttrRetry: | |||
2998 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3003 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2999 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3004 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3000 | if (rc) { | 3005 | if (rc) { |
3001 | cFYI(1, ("error %d in GetExtAttr", rc)); | 3006 | cFYI(1, "error %d in GetExtAttr", rc); |
3002 | } else { | 3007 | } else { |
3003 | /* decode response */ | 3008 | /* decode response */ |
3004 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3009 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
@@ -3013,7 +3018,7 @@ GetExtAttrRetry: | |||
3013 | struct file_chattr_info *pfinfo; | 3018 | struct file_chattr_info *pfinfo; |
3014 | /* BB Do we need a cast or hash here ? */ | 3019 | /* BB Do we need a cast or hash here ? */ |
3015 | if (count != 16) { | 3020 | if (count != 16) { |
3016 | cFYI(1, ("Illegal size ret in GetExtAttr")); | 3021 | cFYI(1, "Illegal size ret in GetExtAttr"); |
3017 | rc = -EIO; | 3022 | rc = -EIO; |
3018 | goto GetExtAttrOut; | 3023 | goto GetExtAttrOut; |
3019 | } | 3024 | } |
@@ -3043,7 +3048,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3043 | QUERY_SEC_DESC_REQ *pSMB; | 3048 | QUERY_SEC_DESC_REQ *pSMB; |
3044 | struct kvec iov[1]; | 3049 | struct kvec iov[1]; |
3045 | 3050 | ||
3046 | cFYI(1, ("GetCifsACL")); | 3051 | cFYI(1, "GetCifsACL"); |
3047 | 3052 | ||
3048 | *pbuflen = 0; | 3053 | *pbuflen = 0; |
3049 | *acl_inf = NULL; | 3054 | *acl_inf = NULL; |
@@ -3068,7 +3073,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3068 | CIFS_STD_OP); | 3073 | CIFS_STD_OP); |
3069 | cifs_stats_inc(&tcon->num_acl_get); | 3074 | cifs_stats_inc(&tcon->num_acl_get); |
3070 | if (rc) { | 3075 | if (rc) { |
3071 | cFYI(1, ("Send error in QuerySecDesc = %d", rc)); | 3076 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
3072 | } else { /* decode response */ | 3077 | } else { /* decode response */ |
3073 | __le32 *parm; | 3078 | __le32 *parm; |
3074 | __u32 parm_len; | 3079 | __u32 parm_len; |
@@ -3083,7 +3088,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3083 | goto qsec_out; | 3088 | goto qsec_out; |
3084 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; | 3089 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
3085 | 3090 | ||
3086 | cFYI(1, ("smb %p parm %p data %p", pSMBr, parm, *acl_inf)); | 3091 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
3087 | 3092 | ||
3088 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { | 3093 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
3089 | rc = -EIO; /* bad smb */ | 3094 | rc = -EIO; /* bad smb */ |
@@ -3095,8 +3100,8 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3095 | 3100 | ||
3096 | acl_len = le32_to_cpu(*parm); | 3101 | acl_len = le32_to_cpu(*parm); |
3097 | if (acl_len != *pbuflen) { | 3102 | if (acl_len != *pbuflen) { |
3098 | cERROR(1, ("acl length %d does not match %d", | 3103 | cERROR(1, "acl length %d does not match %d", |
3099 | acl_len, *pbuflen)); | 3104 | acl_len, *pbuflen); |
3100 | if (*pbuflen > acl_len) | 3105 | if (*pbuflen > acl_len) |
3101 | *pbuflen = acl_len; | 3106 | *pbuflen = acl_len; |
3102 | } | 3107 | } |
@@ -3105,7 +3110,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3105 | header followed by the smallest SID */ | 3110 | header followed by the smallest SID */ |
3106 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || | 3111 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
3107 | (*pbuflen >= 64 * 1024)) { | 3112 | (*pbuflen >= 64 * 1024)) { |
3108 | cERROR(1, ("bad acl length %d", *pbuflen)); | 3113 | cERROR(1, "bad acl length %d", *pbuflen); |
3109 | rc = -EINVAL; | 3114 | rc = -EINVAL; |
3110 | *pbuflen = 0; | 3115 | *pbuflen = 0; |
3111 | } else { | 3116 | } else { |
@@ -3179,9 +3184,9 @@ setCifsAclRetry: | |||
3179 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3184 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3180 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3185 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3181 | 3186 | ||
3182 | cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc)); | 3187 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
3183 | if (rc) | 3188 | if (rc) |
3184 | cFYI(1, ("Set CIFS ACL returned %d", rc)); | 3189 | cFYI(1, "Set CIFS ACL returned %d", rc); |
3185 | cifs_buf_release(pSMB); | 3190 | cifs_buf_release(pSMB); |
3186 | 3191 | ||
3187 | if (rc == -EAGAIN) | 3192 | if (rc == -EAGAIN) |
@@ -3205,7 +3210,7 @@ int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, | |||
3205 | int bytes_returned; | 3210 | int bytes_returned; |
3206 | int name_len; | 3211 | int name_len; |
3207 | 3212 | ||
3208 | cFYI(1, ("In SMBQPath path %s", searchName)); | 3213 | cFYI(1, "In SMBQPath path %s", searchName); |
3209 | QInfRetry: | 3214 | QInfRetry: |
3210 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, | 3215 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
3211 | (void **) &pSMBr); | 3216 | (void **) &pSMBr); |
@@ -3231,7 +3236,7 @@ QInfRetry: | |||
3231 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3236 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3232 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3237 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3233 | if (rc) { | 3238 | if (rc) { |
3234 | cFYI(1, ("Send error in QueryInfo = %d", rc)); | 3239 | cFYI(1, "Send error in QueryInfo = %d", rc); |
3235 | } else if (pFinfo) { | 3240 | } else if (pFinfo) { |
3236 | struct timespec ts; | 3241 | struct timespec ts; |
3237 | __u32 time = le32_to_cpu(pSMBr->last_write_time); | 3242 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
@@ -3305,7 +3310,7 @@ QFileInfoRetry: | |||
3305 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3310 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3306 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3311 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3307 | if (rc) { | 3312 | if (rc) { |
3308 | cFYI(1, ("Send error in QPathInfo = %d", rc)); | 3313 | cFYI(1, "Send error in QPathInfo = %d", rc); |
3309 | } else { /* decode response */ | 3314 | } else { /* decode response */ |
3310 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3315 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3311 | 3316 | ||
@@ -3343,7 +3348,7 @@ CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, | |||
3343 | int name_len; | 3348 | int name_len; |
3344 | __u16 params, byte_count; | 3349 | __u16 params, byte_count; |
3345 | 3350 | ||
3346 | /* cFYI(1, ("In QPathInfo path %s", searchName)); */ | 3351 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
3347 | QPathInfoRetry: | 3352 | QPathInfoRetry: |
3348 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3353 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
3349 | (void **) &pSMBr); | 3354 | (void **) &pSMBr); |
@@ -3393,7 +3398,7 @@ QPathInfoRetry: | |||
3393 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3398 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3394 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3399 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3395 | if (rc) { | 3400 | if (rc) { |
3396 | cFYI(1, ("Send error in QPathInfo = %d", rc)); | 3401 | cFYI(1, "Send error in QPathInfo = %d", rc); |
3397 | } else { /* decode response */ | 3402 | } else { /* decode response */ |
3398 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3403 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3399 | 3404 | ||
@@ -3473,14 +3478,14 @@ UnixQFileInfoRetry: | |||
3473 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3478 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3474 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3479 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3475 | if (rc) { | 3480 | if (rc) { |
3476 | cFYI(1, ("Send error in QPathInfo = %d", rc)); | 3481 | cFYI(1, "Send error in QPathInfo = %d", rc); |
3477 | } else { /* decode response */ | 3482 | } else { /* decode response */ |
3478 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3483 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3479 | 3484 | ||
3480 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { | 3485 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
3481 | cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n" | 3486 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
3482 | "Unix Extensions can be disabled on mount " | 3487 | "Unix Extensions can be disabled on mount " |
3483 | "by specifying the nosfu mount option.")); | 3488 | "by specifying the nosfu mount option."); |
3484 | rc = -EIO; /* bad smb */ | 3489 | rc = -EIO; /* bad smb */ |
3485 | } else { | 3490 | } else { |
3486 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3491 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
@@ -3512,7 +3517,7 @@ CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, | |||
3512 | int name_len; | 3517 | int name_len; |
3513 | __u16 params, byte_count; | 3518 | __u16 params, byte_count; |
3514 | 3519 | ||
3515 | cFYI(1, ("In QPathInfo (Unix) the path %s", searchName)); | 3520 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
3516 | UnixQPathInfoRetry: | 3521 | UnixQPathInfoRetry: |
3517 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3522 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
3518 | (void **) &pSMBr); | 3523 | (void **) &pSMBr); |
@@ -3559,14 +3564,14 @@ UnixQPathInfoRetry: | |||
3559 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3564 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3560 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3565 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3561 | if (rc) { | 3566 | if (rc) { |
3562 | cFYI(1, ("Send error in QPathInfo = %d", rc)); | 3567 | cFYI(1, "Send error in QPathInfo = %d", rc); |
3563 | } else { /* decode response */ | 3568 | } else { /* decode response */ |
3564 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3569 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3565 | 3570 | ||
3566 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { | 3571 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
3567 | cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n" | 3572 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
3568 | "Unix Extensions can be disabled on mount " | 3573 | "Unix Extensions can be disabled on mount " |
3569 | "by specifying the nosfu mount option.")); | 3574 | "by specifying the nosfu mount option."); |
3570 | rc = -EIO; /* bad smb */ | 3575 | rc = -EIO; /* bad smb */ |
3571 | } else { | 3576 | } else { |
3572 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3577 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
@@ -3600,7 +3605,7 @@ CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, | |||
3600 | int name_len; | 3605 | int name_len; |
3601 | __u16 params, byte_count; | 3606 | __u16 params, byte_count; |
3602 | 3607 | ||
3603 | cFYI(1, ("In FindFirst for %s", searchName)); | 3608 | cFYI(1, "In FindFirst for %s", searchName); |
3604 | 3609 | ||
3605 | findFirstRetry: | 3610 | findFirstRetry: |
3606 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3611 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -3677,7 +3682,7 @@ findFirstRetry: | |||
3677 | if (rc) {/* BB add logic to retry regular search if Unix search | 3682 | if (rc) {/* BB add logic to retry regular search if Unix search |
3678 | rejected unexpectedly by server */ | 3683 | rejected unexpectedly by server */ |
3679 | /* BB Add code to handle unsupported level rc */ | 3684 | /* BB Add code to handle unsupported level rc */ |
3680 | cFYI(1, ("Error in FindFirst = %d", rc)); | 3685 | cFYI(1, "Error in FindFirst = %d", rc); |
3681 | 3686 | ||
3682 | cifs_buf_release(pSMB); | 3687 | cifs_buf_release(pSMB); |
3683 | 3688 | ||
@@ -3716,7 +3721,7 @@ findFirstRetry: | |||
3716 | lnoff = le16_to_cpu(parms->LastNameOffset); | 3721 | lnoff = le16_to_cpu(parms->LastNameOffset); |
3717 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < | 3722 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
3718 | lnoff) { | 3723 | lnoff) { |
3719 | cERROR(1, ("ignoring corrupt resume name")); | 3724 | cERROR(1, "ignoring corrupt resume name"); |
3720 | psrch_inf->last_entry = NULL; | 3725 | psrch_inf->last_entry = NULL; |
3721 | return rc; | 3726 | return rc; |
3722 | } | 3727 | } |
@@ -3744,7 +3749,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3744 | int bytes_returned, name_len; | 3749 | int bytes_returned, name_len; |
3745 | __u16 params, byte_count; | 3750 | __u16 params, byte_count; |
3746 | 3751 | ||
3747 | cFYI(1, ("In FindNext")); | 3752 | cFYI(1, "In FindNext"); |
3748 | 3753 | ||
3749 | if (psrch_inf->endOfSearch) | 3754 | if (psrch_inf->endOfSearch) |
3750 | return -ENOENT; | 3755 | return -ENOENT; |
@@ -3808,7 +3813,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3808 | cifs_buf_release(pSMB); | 3813 | cifs_buf_release(pSMB); |
3809 | rc = 0; /* search probably was closed at end of search*/ | 3814 | rc = 0; /* search probably was closed at end of search*/ |
3810 | } else | 3815 | } else |
3811 | cFYI(1, ("FindNext returned = %d", rc)); | 3816 | cFYI(1, "FindNext returned = %d", rc); |
3812 | } else { /* decode response */ | 3817 | } else { /* decode response */ |
3813 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3818 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3814 | 3819 | ||
@@ -3844,15 +3849,15 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3844 | lnoff = le16_to_cpu(parms->LastNameOffset); | 3849 | lnoff = le16_to_cpu(parms->LastNameOffset); |
3845 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < | 3850 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
3846 | lnoff) { | 3851 | lnoff) { |
3847 | cERROR(1, ("ignoring corrupt resume name")); | 3852 | cERROR(1, "ignoring corrupt resume name"); |
3848 | psrch_inf->last_entry = NULL; | 3853 | psrch_inf->last_entry = NULL; |
3849 | return rc; | 3854 | return rc; |
3850 | } else | 3855 | } else |
3851 | psrch_inf->last_entry = | 3856 | psrch_inf->last_entry = |
3852 | psrch_inf->srch_entries_start + lnoff; | 3857 | psrch_inf->srch_entries_start + lnoff; |
3853 | 3858 | ||
3854 | /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d", | 3859 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
3855 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */ | 3860 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
3856 | 3861 | ||
3857 | /* BB fixme add unlock here */ | 3862 | /* BB fixme add unlock here */ |
3858 | } | 3863 | } |
@@ -3877,7 +3882,7 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon, | |||
3877 | int rc = 0; | 3882 | int rc = 0; |
3878 | FINDCLOSE_REQ *pSMB = NULL; | 3883 | FINDCLOSE_REQ *pSMB = NULL; |
3879 | 3884 | ||
3880 | cFYI(1, ("In CIFSSMBFindClose")); | 3885 | cFYI(1, "In CIFSSMBFindClose"); |
3881 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); | 3886 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
3882 | 3887 | ||
3883 | /* no sense returning error if session restarted | 3888 | /* no sense returning error if session restarted |
@@ -3891,7 +3896,7 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon, | |||
3891 | pSMB->ByteCount = 0; | 3896 | pSMB->ByteCount = 0; |
3892 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 3897 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
3893 | if (rc) | 3898 | if (rc) |
3894 | cERROR(1, ("Send error in FindClose = %d", rc)); | 3899 | cERROR(1, "Send error in FindClose = %d", rc); |
3895 | 3900 | ||
3896 | cifs_stats_inc(&tcon->num_fclose); | 3901 | cifs_stats_inc(&tcon->num_fclose); |
3897 | 3902 | ||
@@ -3914,7 +3919,7 @@ CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, | |||
3914 | int name_len, bytes_returned; | 3919 | int name_len, bytes_returned; |
3915 | __u16 params, byte_count; | 3920 | __u16 params, byte_count; |
3916 | 3921 | ||
3917 | cFYI(1, ("In GetSrvInodeNum for %s", searchName)); | 3922 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
3918 | if (tcon == NULL) | 3923 | if (tcon == NULL) |
3919 | return -ENODEV; | 3924 | return -ENODEV; |
3920 | 3925 | ||
@@ -3964,7 +3969,7 @@ GetInodeNumberRetry: | |||
3964 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3969 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3965 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3970 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3966 | if (rc) { | 3971 | if (rc) { |
3967 | cFYI(1, ("error %d in QueryInternalInfo", rc)); | 3972 | cFYI(1, "error %d in QueryInternalInfo", rc); |
3968 | } else { | 3973 | } else { |
3969 | /* decode response */ | 3974 | /* decode response */ |
3970 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3975 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
@@ -3979,7 +3984,7 @@ GetInodeNumberRetry: | |||
3979 | struct file_internal_info *pfinfo; | 3984 | struct file_internal_info *pfinfo; |
3980 | /* BB Do we need a cast or hash here ? */ | 3985 | /* BB Do we need a cast or hash here ? */ |
3981 | if (count < 8) { | 3986 | if (count < 8) { |
3982 | cFYI(1, ("Illegal size ret in QryIntrnlInf")); | 3987 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
3983 | rc = -EIO; | 3988 | rc = -EIO; |
3984 | goto GetInodeNumOut; | 3989 | goto GetInodeNumOut; |
3985 | } | 3990 | } |
@@ -4020,16 +4025,16 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, | |||
4020 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); | 4025 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
4021 | 4026 | ||
4022 | if (*num_of_nodes < 1) { | 4027 | if (*num_of_nodes < 1) { |
4023 | cERROR(1, ("num_referrals: must be at least > 0," | 4028 | cERROR(1, "num_referrals: must be at least > 0," |
4024 | "but we get num_referrals = %d\n", *num_of_nodes)); | 4029 | "but we get num_referrals = %d\n", *num_of_nodes); |
4025 | rc = -EINVAL; | 4030 | rc = -EINVAL; |
4026 | goto parse_DFS_referrals_exit; | 4031 | goto parse_DFS_referrals_exit; |
4027 | } | 4032 | } |
4028 | 4033 | ||
4029 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); | 4034 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
4030 | if (ref->VersionNumber != cpu_to_le16(3)) { | 4035 | if (ref->VersionNumber != cpu_to_le16(3)) { |
4031 | cERROR(1, ("Referrals of V%d version are not supported," | 4036 | cERROR(1, "Referrals of V%d version are not supported," |
4032 | "should be V3", le16_to_cpu(ref->VersionNumber))); | 4037 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
4033 | rc = -EINVAL; | 4038 | rc = -EINVAL; |
4034 | goto parse_DFS_referrals_exit; | 4039 | goto parse_DFS_referrals_exit; |
4035 | } | 4040 | } |
@@ -4038,14 +4043,14 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, | |||
4038 | data_end = (char *)(&(pSMBr->PathConsumed)) + | 4043 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
4039 | le16_to_cpu(pSMBr->t2.DataCount); | 4044 | le16_to_cpu(pSMBr->t2.DataCount); |
4040 | 4045 | ||
4041 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n", | 4046 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
4042 | *num_of_nodes, | 4047 | *num_of_nodes, |
4043 | le32_to_cpu(pSMBr->DFSFlags))); | 4048 | le32_to_cpu(pSMBr->DFSFlags)); |
4044 | 4049 | ||
4045 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * | 4050 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
4046 | *num_of_nodes, GFP_KERNEL); | 4051 | *num_of_nodes, GFP_KERNEL); |
4047 | if (*target_nodes == NULL) { | 4052 | if (*target_nodes == NULL) { |
4048 | cERROR(1, ("Failed to allocate buffer for target_nodes\n")); | 4053 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
4049 | rc = -ENOMEM; | 4054 | rc = -ENOMEM; |
4050 | goto parse_DFS_referrals_exit; | 4055 | goto parse_DFS_referrals_exit; |
4051 | } | 4056 | } |
@@ -4121,7 +4126,7 @@ CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, | |||
4121 | *num_of_nodes = 0; | 4126 | *num_of_nodes = 0; |
4122 | *target_nodes = NULL; | 4127 | *target_nodes = NULL; |
4123 | 4128 | ||
4124 | cFYI(1, ("In GetDFSRefer the path %s", searchName)); | 4129 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
4125 | if (ses == NULL) | 4130 | if (ses == NULL) |
4126 | return -ENODEV; | 4131 | return -ENODEV; |
4127 | getDFSRetry: | 4132 | getDFSRetry: |
@@ -4188,7 +4193,7 @@ getDFSRetry: | |||
4188 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, | 4193 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
4189 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4194 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4190 | if (rc) { | 4195 | if (rc) { |
4191 | cFYI(1, ("Send error in GetDFSRefer = %d", rc)); | 4196 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
4192 | goto GetDFSRefExit; | 4197 | goto GetDFSRefExit; |
4193 | } | 4198 | } |
4194 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4199 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
@@ -4199,9 +4204,9 @@ getDFSRetry: | |||
4199 | goto GetDFSRefExit; | 4204 | goto GetDFSRefExit; |
4200 | } | 4205 | } |
4201 | 4206 | ||
4202 | cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d", | 4207 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
4203 | pSMBr->ByteCount, | 4208 | pSMBr->ByteCount, |
4204 | le16_to_cpu(pSMBr->t2.DataOffset))); | 4209 | le16_to_cpu(pSMBr->t2.DataOffset)); |
4205 | 4210 | ||
4206 | /* parse returned result into more usable form */ | 4211 | /* parse returned result into more usable form */ |
4207 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, | 4212 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
@@ -4229,7 +4234,7 @@ SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) | |||
4229 | int bytes_returned = 0; | 4234 | int bytes_returned = 0; |
4230 | __u16 params, byte_count; | 4235 | __u16 params, byte_count; |
4231 | 4236 | ||
4232 | cFYI(1, ("OldQFSInfo")); | 4237 | cFYI(1, "OldQFSInfo"); |
4233 | oldQFSInfoRetry: | 4238 | oldQFSInfoRetry: |
4234 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4239 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4235 | (void **) &pSMBr); | 4240 | (void **) &pSMBr); |
@@ -4262,7 +4267,7 @@ oldQFSInfoRetry: | |||
4262 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4267 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4263 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4268 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4264 | if (rc) { | 4269 | if (rc) { |
4265 | cFYI(1, ("Send error in QFSInfo = %d", rc)); | 4270 | cFYI(1, "Send error in QFSInfo = %d", rc); |
4266 | } else { /* decode response */ | 4271 | } else { /* decode response */ |
4267 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4272 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4268 | 4273 | ||
@@ -4270,8 +4275,8 @@ oldQFSInfoRetry: | |||
4270 | rc = -EIO; /* bad smb */ | 4275 | rc = -EIO; /* bad smb */ |
4271 | else { | 4276 | else { |
4272 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 4277 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
4273 | cFYI(1, ("qfsinf resp BCC: %d Offset %d", | 4278 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
4274 | pSMBr->ByteCount, data_offset)); | 4279 | pSMBr->ByteCount, data_offset); |
4275 | 4280 | ||
4276 | response_data = (FILE_SYSTEM_ALLOC_INFO *) | 4281 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
4277 | (((char *) &pSMBr->hdr.Protocol) + data_offset); | 4282 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
@@ -4283,11 +4288,10 @@ oldQFSInfoRetry: | |||
4283 | le32_to_cpu(response_data->TotalAllocationUnits); | 4288 | le32_to_cpu(response_data->TotalAllocationUnits); |
4284 | FSData->f_bfree = FSData->f_bavail = | 4289 | FSData->f_bfree = FSData->f_bavail = |
4285 | le32_to_cpu(response_data->FreeAllocationUnits); | 4290 | le32_to_cpu(response_data->FreeAllocationUnits); |
4286 | cFYI(1, | 4291 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
4287 | ("Blocks: %lld Free: %lld Block size %ld", | 4292 | (unsigned long long)FSData->f_blocks, |
4288 | (unsigned long long)FSData->f_blocks, | 4293 | (unsigned long long)FSData->f_bfree, |
4289 | (unsigned long long)FSData->f_bfree, | 4294 | FSData->f_bsize); |
4290 | FSData->f_bsize)); | ||
4291 | } | 4295 | } |
4292 | } | 4296 | } |
4293 | cifs_buf_release(pSMB); | 4297 | cifs_buf_release(pSMB); |
@@ -4309,7 +4313,7 @@ CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) | |||
4309 | int bytes_returned = 0; | 4313 | int bytes_returned = 0; |
4310 | __u16 params, byte_count; | 4314 | __u16 params, byte_count; |
4311 | 4315 | ||
4312 | cFYI(1, ("In QFSInfo")); | 4316 | cFYI(1, "In QFSInfo"); |
4313 | QFSInfoRetry: | 4317 | QFSInfoRetry: |
4314 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4318 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4315 | (void **) &pSMBr); | 4319 | (void **) &pSMBr); |
@@ -4342,7 +4346,7 @@ QFSInfoRetry: | |||
4342 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4346 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4343 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4347 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4344 | if (rc) { | 4348 | if (rc) { |
4345 | cFYI(1, ("Send error in QFSInfo = %d", rc)); | 4349 | cFYI(1, "Send error in QFSInfo = %d", rc); |
4346 | } else { /* decode response */ | 4350 | } else { /* decode response */ |
4347 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4351 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4348 | 4352 | ||
@@ -4363,11 +4367,10 @@ QFSInfoRetry: | |||
4363 | le64_to_cpu(response_data->TotalAllocationUnits); | 4367 | le64_to_cpu(response_data->TotalAllocationUnits); |
4364 | FSData->f_bfree = FSData->f_bavail = | 4368 | FSData->f_bfree = FSData->f_bavail = |
4365 | le64_to_cpu(response_data->FreeAllocationUnits); | 4369 | le64_to_cpu(response_data->FreeAllocationUnits); |
4366 | cFYI(1, | 4370 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
4367 | ("Blocks: %lld Free: %lld Block size %ld", | 4371 | (unsigned long long)FSData->f_blocks, |
4368 | (unsigned long long)FSData->f_blocks, | 4372 | (unsigned long long)FSData->f_bfree, |
4369 | (unsigned long long)FSData->f_bfree, | 4373 | FSData->f_bsize); |
4370 | FSData->f_bsize)); | ||
4371 | } | 4374 | } |
4372 | } | 4375 | } |
4373 | cifs_buf_release(pSMB); | 4376 | cifs_buf_release(pSMB); |
@@ -4389,7 +4392,7 @@ CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) | |||
4389 | int bytes_returned = 0; | 4392 | int bytes_returned = 0; |
4390 | __u16 params, byte_count; | 4393 | __u16 params, byte_count; |
4391 | 4394 | ||
4392 | cFYI(1, ("In QFSAttributeInfo")); | 4395 | cFYI(1, "In QFSAttributeInfo"); |
4393 | QFSAttributeRetry: | 4396 | QFSAttributeRetry: |
4394 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4397 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4395 | (void **) &pSMBr); | 4398 | (void **) &pSMBr); |
@@ -4423,7 +4426,7 @@ QFSAttributeRetry: | |||
4423 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4426 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4424 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4427 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4425 | if (rc) { | 4428 | if (rc) { |
4426 | cERROR(1, ("Send error in QFSAttributeInfo = %d", rc)); | 4429 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
4427 | } else { /* decode response */ | 4430 | } else { /* decode response */ |
4428 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4431 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4429 | 4432 | ||
@@ -4459,7 +4462,7 @@ CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) | |||
4459 | int bytes_returned = 0; | 4462 | int bytes_returned = 0; |
4460 | __u16 params, byte_count; | 4463 | __u16 params, byte_count; |
4461 | 4464 | ||
4462 | cFYI(1, ("In QFSDeviceInfo")); | 4465 | cFYI(1, "In QFSDeviceInfo"); |
4463 | QFSDeviceRetry: | 4466 | QFSDeviceRetry: |
4464 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4467 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4465 | (void **) &pSMBr); | 4468 | (void **) &pSMBr); |
@@ -4494,7 +4497,7 @@ QFSDeviceRetry: | |||
4494 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4497 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4495 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4498 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4496 | if (rc) { | 4499 | if (rc) { |
4497 | cFYI(1, ("Send error in QFSDeviceInfo = %d", rc)); | 4500 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
4498 | } else { /* decode response */ | 4501 | } else { /* decode response */ |
4499 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4502 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4500 | 4503 | ||
@@ -4529,7 +4532,7 @@ CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) | |||
4529 | int bytes_returned = 0; | 4532 | int bytes_returned = 0; |
4530 | __u16 params, byte_count; | 4533 | __u16 params, byte_count; |
4531 | 4534 | ||
4532 | cFYI(1, ("In QFSUnixInfo")); | 4535 | cFYI(1, "In QFSUnixInfo"); |
4533 | QFSUnixRetry: | 4536 | QFSUnixRetry: |
4534 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4537 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4535 | (void **) &pSMBr); | 4538 | (void **) &pSMBr); |
@@ -4563,7 +4566,7 @@ QFSUnixRetry: | |||
4563 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4566 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4564 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4567 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4565 | if (rc) { | 4568 | if (rc) { |
4566 | cERROR(1, ("Send error in QFSUnixInfo = %d", rc)); | 4569 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
4567 | } else { /* decode response */ | 4570 | } else { /* decode response */ |
4568 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4571 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4569 | 4572 | ||
@@ -4598,7 +4601,7 @@ CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) | |||
4598 | int bytes_returned = 0; | 4601 | int bytes_returned = 0; |
4599 | __u16 params, param_offset, offset, byte_count; | 4602 | __u16 params, param_offset, offset, byte_count; |
4600 | 4603 | ||
4601 | cFYI(1, ("In SETFSUnixInfo")); | 4604 | cFYI(1, "In SETFSUnixInfo"); |
4602 | SETFSUnixRetry: | 4605 | SETFSUnixRetry: |
4603 | /* BB switch to small buf init to save memory */ | 4606 | /* BB switch to small buf init to save memory */ |
4604 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4607 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -4646,7 +4649,7 @@ SETFSUnixRetry: | |||
4646 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4649 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4647 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4650 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4648 | if (rc) { | 4651 | if (rc) { |
4649 | cERROR(1, ("Send error in SETFSUnixInfo = %d", rc)); | 4652 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
4650 | } else { /* decode response */ | 4653 | } else { /* decode response */ |
4651 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4654 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4652 | if (rc) | 4655 | if (rc) |
@@ -4674,7 +4677,7 @@ CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, | |||
4674 | int bytes_returned = 0; | 4677 | int bytes_returned = 0; |
4675 | __u16 params, byte_count; | 4678 | __u16 params, byte_count; |
4676 | 4679 | ||
4677 | cFYI(1, ("In QFSPosixInfo")); | 4680 | cFYI(1, "In QFSPosixInfo"); |
4678 | QFSPosixRetry: | 4681 | QFSPosixRetry: |
4679 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4682 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4680 | (void **) &pSMBr); | 4683 | (void **) &pSMBr); |
@@ -4708,7 +4711,7 @@ QFSPosixRetry: | |||
4708 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4711 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4709 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4712 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4710 | if (rc) { | 4713 | if (rc) { |
4711 | cFYI(1, ("Send error in QFSUnixInfo = %d", rc)); | 4714 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
4712 | } else { /* decode response */ | 4715 | } else { /* decode response */ |
4713 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4716 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4714 | 4717 | ||
@@ -4768,7 +4771,7 @@ CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, | |||
4768 | int bytes_returned = 0; | 4771 | int bytes_returned = 0; |
4769 | __u16 params, byte_count, data_count, param_offset, offset; | 4772 | __u16 params, byte_count, data_count, param_offset, offset; |
4770 | 4773 | ||
4771 | cFYI(1, ("In SetEOF")); | 4774 | cFYI(1, "In SetEOF"); |
4772 | SetEOFRetry: | 4775 | SetEOFRetry: |
4773 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 4776 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
4774 | (void **) &pSMBr); | 4777 | (void **) &pSMBr); |
@@ -4834,7 +4837,7 @@ SetEOFRetry: | |||
4834 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4837 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4835 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4838 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4836 | if (rc) | 4839 | if (rc) |
4837 | cFYI(1, ("SetPathInfo (file size) returned %d", rc)); | 4840 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
4838 | 4841 | ||
4839 | cifs_buf_release(pSMB); | 4842 | cifs_buf_release(pSMB); |
4840 | 4843 | ||
@@ -4854,8 +4857,8 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4854 | int rc = 0; | 4857 | int rc = 0; |
4855 | __u16 params, param_offset, offset, byte_count, count; | 4858 | __u16 params, param_offset, offset, byte_count, count; |
4856 | 4859 | ||
4857 | cFYI(1, ("SetFileSize (via SetFileInfo) %lld", | 4860 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
4858 | (long long)size)); | 4861 | (long long)size); |
4859 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 4862 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
4860 | 4863 | ||
4861 | if (rc) | 4864 | if (rc) |
@@ -4914,9 +4917,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4914 | pSMB->ByteCount = cpu_to_le16(byte_count); | 4917 | pSMB->ByteCount = cpu_to_le16(byte_count); |
4915 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 4918 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
4916 | if (rc) { | 4919 | if (rc) { |
4917 | cFYI(1, | 4920 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
4918 | ("Send error in SetFileInfo (SetFileSize) = %d", | ||
4919 | rc)); | ||
4920 | } | 4921 | } |
4921 | 4922 | ||
4922 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 4923 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
@@ -4940,7 +4941,7 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, | |||
4940 | int rc = 0; | 4941 | int rc = 0; |
4941 | __u16 params, param_offset, offset, byte_count, count; | 4942 | __u16 params, param_offset, offset, byte_count, count; |
4942 | 4943 | ||
4943 | cFYI(1, ("Set Times (via SetFileInfo)")); | 4944 | cFYI(1, "Set Times (via SetFileInfo)"); |
4944 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 4945 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
4945 | 4946 | ||
4946 | if (rc) | 4947 | if (rc) |
@@ -4985,7 +4986,7 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, | |||
4985 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); | 4986 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
4986 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 4987 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
4987 | if (rc) | 4988 | if (rc) |
4988 | cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc)); | 4989 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
4989 | 4990 | ||
4990 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 4991 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
4991 | since file handle passed in no longer valid */ | 4992 | since file handle passed in no longer valid */ |
@@ -5002,7 +5003,7 @@ CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, | |||
5002 | int rc = 0; | 5003 | int rc = 0; |
5003 | __u16 params, param_offset, offset, byte_count, count; | 5004 | __u16 params, param_offset, offset, byte_count, count; |
5004 | 5005 | ||
5005 | cFYI(1, ("Set File Disposition (via SetFileInfo)")); | 5006 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
5006 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 5007 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
5007 | 5008 | ||
5008 | if (rc) | 5009 | if (rc) |
@@ -5044,7 +5045,7 @@ CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, | |||
5044 | *data_offset = delete_file ? 1 : 0; | 5045 | *data_offset = delete_file ? 1 : 0; |
5045 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 5046 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
5046 | if (rc) | 5047 | if (rc) |
5047 | cFYI(1, ("Send error in SetFileDisposition = %d", rc)); | 5048 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
5048 | 5049 | ||
5049 | return rc; | 5050 | return rc; |
5050 | } | 5051 | } |
@@ -5062,7 +5063,7 @@ CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, | |||
5062 | char *data_offset; | 5063 | char *data_offset; |
5063 | __u16 params, param_offset, offset, byte_count, count; | 5064 | __u16 params, param_offset, offset, byte_count, count; |
5064 | 5065 | ||
5065 | cFYI(1, ("In SetTimes")); | 5066 | cFYI(1, "In SetTimes"); |
5066 | 5067 | ||
5067 | SetTimesRetry: | 5068 | SetTimesRetry: |
5068 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 5069 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -5118,7 +5119,7 @@ SetTimesRetry: | |||
5118 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5119 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
5119 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5120 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5120 | if (rc) | 5121 | if (rc) |
5121 | cFYI(1, ("SetPathInfo (times) returned %d", rc)); | 5122 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
5122 | 5123 | ||
5123 | cifs_buf_release(pSMB); | 5124 | cifs_buf_release(pSMB); |
5124 | 5125 | ||
@@ -5143,7 +5144,7 @@ CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, | |||
5143 | int bytes_returned; | 5144 | int bytes_returned; |
5144 | int name_len; | 5145 | int name_len; |
5145 | 5146 | ||
5146 | cFYI(1, ("In SetAttrLegacy")); | 5147 | cFYI(1, "In SetAttrLegacy"); |
5147 | 5148 | ||
5148 | SetAttrLgcyRetry: | 5149 | SetAttrLgcyRetry: |
5149 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, | 5150 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
@@ -5169,7 +5170,7 @@ SetAttrLgcyRetry: | |||
5169 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5170 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
5170 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5171 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5171 | if (rc) | 5172 | if (rc) |
5172 | cFYI(1, ("Error in LegacySetAttr = %d", rc)); | 5173 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
5173 | 5174 | ||
5174 | cifs_buf_release(pSMB); | 5175 | cifs_buf_release(pSMB); |
5175 | 5176 | ||
@@ -5231,7 +5232,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon, | |||
5231 | int rc = 0; | 5232 | int rc = 0; |
5232 | u16 params, param_offset, offset, byte_count, count; | 5233 | u16 params, param_offset, offset, byte_count, count; |
5233 | 5234 | ||
5234 | cFYI(1, ("Set Unix Info (via SetFileInfo)")); | 5235 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
5235 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 5236 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
5236 | 5237 | ||
5237 | if (rc) | 5238 | if (rc) |
@@ -5276,7 +5277,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon, | |||
5276 | 5277 | ||
5277 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); | 5278 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
5278 | if (rc) | 5279 | if (rc) |
5279 | cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc)); | 5280 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
5280 | 5281 | ||
5281 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 5282 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
5282 | since file handle passed in no longer valid */ | 5283 | since file handle passed in no longer valid */ |
@@ -5297,7 +5298,7 @@ CIFSSMBUnixSetPathInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, | |||
5297 | FILE_UNIX_BASIC_INFO *data_offset; | 5298 | FILE_UNIX_BASIC_INFO *data_offset; |
5298 | __u16 params, param_offset, offset, count, byte_count; | 5299 | __u16 params, param_offset, offset, count, byte_count; |
5299 | 5300 | ||
5300 | cFYI(1, ("In SetUID/GID/Mode")); | 5301 | cFYI(1, "In SetUID/GID/Mode"); |
5301 | setPermsRetry: | 5302 | setPermsRetry: |
5302 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 5303 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
5303 | (void **) &pSMBr); | 5304 | (void **) &pSMBr); |
@@ -5353,7 +5354,7 @@ setPermsRetry: | |||
5353 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5354 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
5354 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5355 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5355 | if (rc) | 5356 | if (rc) |
5356 | cFYI(1, ("SetPathInfo (perms) returned %d", rc)); | 5357 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
5357 | 5358 | ||
5358 | cifs_buf_release(pSMB); | 5359 | cifs_buf_release(pSMB); |
5359 | if (rc == -EAGAIN) | 5360 | if (rc == -EAGAIN) |
@@ -5372,7 +5373,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5372 | struct dir_notify_req *dnotify_req; | 5373 | struct dir_notify_req *dnotify_req; |
5373 | int bytes_returned; | 5374 | int bytes_returned; |
5374 | 5375 | ||
5375 | cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid)); | 5376 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
5376 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, | 5377 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
5377 | (void **) &pSMBr); | 5378 | (void **) &pSMBr); |
5378 | if (rc) | 5379 | if (rc) |
@@ -5406,7 +5407,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5406 | (struct smb_hdr *)pSMBr, &bytes_returned, | 5407 | (struct smb_hdr *)pSMBr, &bytes_returned, |
5407 | CIFS_ASYNC_OP); | 5408 | CIFS_ASYNC_OP); |
5408 | if (rc) { | 5409 | if (rc) { |
5409 | cFYI(1, ("Error in Notify = %d", rc)); | 5410 | cFYI(1, "Error in Notify = %d", rc); |
5410 | } else { | 5411 | } else { |
5411 | /* Add file to outstanding requests */ | 5412 | /* Add file to outstanding requests */ |
5412 | /* BB change to kmem cache alloc */ | 5413 | /* BB change to kmem cache alloc */ |
@@ -5462,7 +5463,7 @@ CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, | |||
5462 | char *end_of_smb; | 5463 | char *end_of_smb; |
5463 | __u16 params, byte_count, data_offset; | 5464 | __u16 params, byte_count, data_offset; |
5464 | 5465 | ||
5465 | cFYI(1, ("In Query All EAs path %s", searchName)); | 5466 | cFYI(1, "In Query All EAs path %s", searchName); |
5466 | QAllEAsRetry: | 5467 | QAllEAsRetry: |
5467 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 5468 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
5468 | (void **) &pSMBr); | 5469 | (void **) &pSMBr); |
@@ -5509,7 +5510,7 @@ QAllEAsRetry: | |||
5509 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5510 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
5510 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5511 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5511 | if (rc) { | 5512 | if (rc) { |
5512 | cFYI(1, ("Send error in QueryAllEAs = %d", rc)); | 5513 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
5513 | goto QAllEAsOut; | 5514 | goto QAllEAsOut; |
5514 | } | 5515 | } |
5515 | 5516 | ||
@@ -5537,16 +5538,16 @@ QAllEAsRetry: | |||
5537 | (((char *) &pSMBr->hdr.Protocol) + data_offset); | 5538 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
5538 | 5539 | ||
5539 | list_len = le32_to_cpu(ea_response_data->list_len); | 5540 | list_len = le32_to_cpu(ea_response_data->list_len); |
5540 | cFYI(1, ("ea length %d", list_len)); | 5541 | cFYI(1, "ea length %d", list_len); |
5541 | if (list_len <= 8) { | 5542 | if (list_len <= 8) { |
5542 | cFYI(1, ("empty EA list returned from server")); | 5543 | cFYI(1, "empty EA list returned from server"); |
5543 | goto QAllEAsOut; | 5544 | goto QAllEAsOut; |
5544 | } | 5545 | } |
5545 | 5546 | ||
5546 | /* make sure list_len doesn't go past end of SMB */ | 5547 | /* make sure list_len doesn't go past end of SMB */ |
5547 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + BCC(&pSMBr->hdr); | 5548 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + BCC(&pSMBr->hdr); |
5548 | if ((char *)ea_response_data + list_len > end_of_smb) { | 5549 | if ((char *)ea_response_data + list_len > end_of_smb) { |
5549 | cFYI(1, ("EA list appears to go beyond SMB")); | 5550 | cFYI(1, "EA list appears to go beyond SMB"); |
5550 | rc = -EIO; | 5551 | rc = -EIO; |
5551 | goto QAllEAsOut; | 5552 | goto QAllEAsOut; |
5552 | } | 5553 | } |
@@ -5563,7 +5564,7 @@ QAllEAsRetry: | |||
5563 | temp_ptr += 4; | 5564 | temp_ptr += 4; |
5564 | /* make sure we can read name_len and value_len */ | 5565 | /* make sure we can read name_len and value_len */ |
5565 | if (list_len < 0) { | 5566 | if (list_len < 0) { |
5566 | cFYI(1, ("EA entry goes beyond length of list")); | 5567 | cFYI(1, "EA entry goes beyond length of list"); |
5567 | rc = -EIO; | 5568 | rc = -EIO; |
5568 | goto QAllEAsOut; | 5569 | goto QAllEAsOut; |
5569 | } | 5570 | } |
@@ -5572,7 +5573,7 @@ QAllEAsRetry: | |||
5572 | value_len = le16_to_cpu(temp_fea->value_len); | 5573 | value_len = le16_to_cpu(temp_fea->value_len); |
5573 | list_len -= name_len + 1 + value_len; | 5574 | list_len -= name_len + 1 + value_len; |
5574 | if (list_len < 0) { | 5575 | if (list_len < 0) { |
5575 | cFYI(1, ("EA entry goes beyond length of list")); | 5576 | cFYI(1, "EA entry goes beyond length of list"); |
5576 | rc = -EIO; | 5577 | rc = -EIO; |
5577 | goto QAllEAsOut; | 5578 | goto QAllEAsOut; |
5578 | } | 5579 | } |
@@ -5639,7 +5640,7 @@ CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, | |||
5639 | int bytes_returned = 0; | 5640 | int bytes_returned = 0; |
5640 | __u16 params, param_offset, byte_count, offset, count; | 5641 | __u16 params, param_offset, byte_count, offset, count; |
5641 | 5642 | ||
5642 | cFYI(1, ("In SetEA")); | 5643 | cFYI(1, "In SetEA"); |
5643 | SetEARetry: | 5644 | SetEARetry: |
5644 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 5645 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
5645 | (void **) &pSMBr); | 5646 | (void **) &pSMBr); |
@@ -5721,7 +5722,7 @@ SetEARetry: | |||
5721 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 5722 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
5722 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 5723 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
5723 | if (rc) | 5724 | if (rc) |
5724 | cFYI(1, ("SetPathInfo (EA) returned %d", rc)); | 5725 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
5725 | 5726 | ||
5726 | cifs_buf_release(pSMB); | 5727 | cifs_buf_release(pSMB); |
5727 | 5728 | ||
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index d9566bf8f917..2208f06e4c45 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -102,6 +102,7 @@ struct smb_vol { | |||
102 | bool sockopt_tcp_nodelay:1; | 102 | bool sockopt_tcp_nodelay:1; |
103 | unsigned short int port; | 103 | unsigned short int port; |
104 | char *prepath; | 104 | char *prepath; |
105 | struct nls_table *local_nls; | ||
105 | }; | 106 | }; |
106 | 107 | ||
107 | static int ipv4_connect(struct TCP_Server_Info *server); | 108 | static int ipv4_connect(struct TCP_Server_Info *server); |
@@ -135,7 +136,7 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
135 | spin_unlock(&GlobalMid_Lock); | 136 | spin_unlock(&GlobalMid_Lock); |
136 | server->maxBuf = 0; | 137 | server->maxBuf = 0; |
137 | 138 | ||
138 | cFYI(1, ("Reconnecting tcp session")); | 139 | cFYI(1, "Reconnecting tcp session"); |
139 | 140 | ||
140 | /* before reconnecting the tcp session, mark the smb session (uid) | 141 | /* before reconnecting the tcp session, mark the smb session (uid) |
141 | and the tid bad so they are not used until reconnected */ | 142 | and the tid bad so they are not used until reconnected */ |
@@ -153,12 +154,12 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
153 | /* do not want to be sending data on a socket we are freeing */ | 154 | /* do not want to be sending data on a socket we are freeing */ |
154 | mutex_lock(&server->srv_mutex); | 155 | mutex_lock(&server->srv_mutex); |
155 | if (server->ssocket) { | 156 | if (server->ssocket) { |
156 | cFYI(1, ("State: 0x%x Flags: 0x%lx", server->ssocket->state, | 157 | cFYI(1, "State: 0x%x Flags: 0x%lx", server->ssocket->state, |
157 | server->ssocket->flags)); | 158 | server->ssocket->flags); |
158 | kernel_sock_shutdown(server->ssocket, SHUT_WR); | 159 | kernel_sock_shutdown(server->ssocket, SHUT_WR); |
159 | cFYI(1, ("Post shutdown state: 0x%x Flags: 0x%lx", | 160 | cFYI(1, "Post shutdown state: 0x%x Flags: 0x%lx", |
160 | server->ssocket->state, | 161 | server->ssocket->state, |
161 | server->ssocket->flags)); | 162 | server->ssocket->flags); |
162 | sock_release(server->ssocket); | 163 | sock_release(server->ssocket); |
163 | server->ssocket = NULL; | 164 | server->ssocket = NULL; |
164 | } | 165 | } |
@@ -187,7 +188,7 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
187 | else | 188 | else |
188 | rc = ipv4_connect(server); | 189 | rc = ipv4_connect(server); |
189 | if (rc) { | 190 | if (rc) { |
190 | cFYI(1, ("reconnect error %d", rc)); | 191 | cFYI(1, "reconnect error %d", rc); |
191 | msleep(3000); | 192 | msleep(3000); |
192 | } else { | 193 | } else { |
193 | atomic_inc(&tcpSesReconnectCount); | 194 | atomic_inc(&tcpSesReconnectCount); |
@@ -223,7 +224,7 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) | |||
223 | /* check for plausible wct, bcc and t2 data and parm sizes */ | 224 | /* check for plausible wct, bcc and t2 data and parm sizes */ |
224 | /* check for parm and data offset going beyond end of smb */ | 225 | /* check for parm and data offset going beyond end of smb */ |
225 | if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */ | 226 | if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */ |
226 | cFYI(1, ("invalid transact2 word count")); | 227 | cFYI(1, "invalid transact2 word count"); |
227 | return -EINVAL; | 228 | return -EINVAL; |
228 | } | 229 | } |
229 | 230 | ||
@@ -237,15 +238,15 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) | |||
237 | if (remaining == 0) | 238 | if (remaining == 0) |
238 | return 0; | 239 | return 0; |
239 | else if (remaining < 0) { | 240 | else if (remaining < 0) { |
240 | cFYI(1, ("total data %d smaller than data in frame %d", | 241 | cFYI(1, "total data %d smaller than data in frame %d", |
241 | total_data_size, data_in_this_rsp)); | 242 | total_data_size, data_in_this_rsp); |
242 | return -EINVAL; | 243 | return -EINVAL; |
243 | } else { | 244 | } else { |
244 | cFYI(1, ("missing %d bytes from transact2, check next response", | 245 | cFYI(1, "missing %d bytes from transact2, check next response", |
245 | remaining)); | 246 | remaining); |
246 | if (total_data_size > maxBufSize) { | 247 | if (total_data_size > maxBufSize) { |
247 | cERROR(1, ("TotalDataSize %d is over maximum buffer %d", | 248 | cERROR(1, "TotalDataSize %d is over maximum buffer %d", |
248 | total_data_size, maxBufSize)); | 249 | total_data_size, maxBufSize); |
249 | return -EINVAL; | 250 | return -EINVAL; |
250 | } | 251 | } |
251 | return remaining; | 252 | return remaining; |
@@ -267,7 +268,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) | |||
267 | total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); | 268 | total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); |
268 | 269 | ||
269 | if (total_data_size != le16_to_cpu(pSMB2->t2_rsp.TotalDataCount)) { | 270 | if (total_data_size != le16_to_cpu(pSMB2->t2_rsp.TotalDataCount)) { |
270 | cFYI(1, ("total data size of primary and secondary t2 differ")); | 271 | cFYI(1, "total data size of primary and secondary t2 differ"); |
271 | } | 272 | } |
272 | 273 | ||
273 | total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount); | 274 | total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount); |
@@ -282,7 +283,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) | |||
282 | 283 | ||
283 | total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount); | 284 | total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount); |
284 | if (remaining < total_in_buf2) { | 285 | if (remaining < total_in_buf2) { |
285 | cFYI(1, ("transact2 2nd response contains too much data")); | 286 | cFYI(1, "transact2 2nd response contains too much data"); |
286 | } | 287 | } |
287 | 288 | ||
288 | /* find end of first SMB data area */ | 289 | /* find end of first SMB data area */ |
@@ -311,7 +312,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) | |||
311 | pTargetSMB->smb_buf_length = byte_count; | 312 | pTargetSMB->smb_buf_length = byte_count; |
312 | 313 | ||
313 | if (remaining == total_in_buf2) { | 314 | if (remaining == total_in_buf2) { |
314 | cFYI(1, ("found the last secondary response")); | 315 | cFYI(1, "found the last secondary response"); |
315 | return 0; /* we are done */ | 316 | return 0; /* we are done */ |
316 | } else /* more responses to go */ | 317 | } else /* more responses to go */ |
317 | return 1; | 318 | return 1; |
@@ -339,7 +340,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) | |||
339 | int reconnect; | 340 | int reconnect; |
340 | 341 | ||
341 | current->flags |= PF_MEMALLOC; | 342 | current->flags |= PF_MEMALLOC; |
342 | cFYI(1, ("Demultiplex PID: %d", task_pid_nr(current))); | 343 | cFYI(1, "Demultiplex PID: %d", task_pid_nr(current)); |
343 | 344 | ||
344 | length = atomic_inc_return(&tcpSesAllocCount); | 345 | length = atomic_inc_return(&tcpSesAllocCount); |
345 | if (length > 1) | 346 | if (length > 1) |
@@ -353,7 +354,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) | |||
353 | if (bigbuf == NULL) { | 354 | if (bigbuf == NULL) { |
354 | bigbuf = cifs_buf_get(); | 355 | bigbuf = cifs_buf_get(); |
355 | if (!bigbuf) { | 356 | if (!bigbuf) { |
356 | cERROR(1, ("No memory for large SMB response")); | 357 | cERROR(1, "No memory for large SMB response"); |
357 | msleep(3000); | 358 | msleep(3000); |
358 | /* retry will check if exiting */ | 359 | /* retry will check if exiting */ |
359 | continue; | 360 | continue; |
@@ -366,7 +367,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) | |||
366 | if (smallbuf == NULL) { | 367 | if (smallbuf == NULL) { |
367 | smallbuf = cifs_small_buf_get(); | 368 | smallbuf = cifs_small_buf_get(); |
368 | if (!smallbuf) { | 369 | if (!smallbuf) { |
369 | cERROR(1, ("No memory for SMB response")); | 370 | cERROR(1, "No memory for SMB response"); |
370 | msleep(1000); | 371 | msleep(1000); |
371 | /* retry will check if exiting */ | 372 | /* retry will check if exiting */ |
372 | continue; | 373 | continue; |
@@ -391,9 +392,9 @@ incomplete_rcv: | |||
391 | if (server->tcpStatus == CifsExiting) { | 392 | if (server->tcpStatus == CifsExiting) { |
392 | break; | 393 | break; |
393 | } else if (server->tcpStatus == CifsNeedReconnect) { | 394 | } else if (server->tcpStatus == CifsNeedReconnect) { |
394 | cFYI(1, ("Reconnect after server stopped responding")); | 395 | cFYI(1, "Reconnect after server stopped responding"); |
395 | cifs_reconnect(server); | 396 | cifs_reconnect(server); |
396 | cFYI(1, ("call to reconnect done")); | 397 | cFYI(1, "call to reconnect done"); |
397 | csocket = server->ssocket; | 398 | csocket = server->ssocket; |
398 | continue; | 399 | continue; |
399 | } else if ((length == -ERESTARTSYS) || (length == -EAGAIN)) { | 400 | } else if ((length == -ERESTARTSYS) || (length == -EAGAIN)) { |
@@ -411,7 +412,7 @@ incomplete_rcv: | |||
411 | continue; | 412 | continue; |
412 | } else if (length <= 0) { | 413 | } else if (length <= 0) { |
413 | if (server->tcpStatus == CifsNew) { | 414 | if (server->tcpStatus == CifsNew) { |
414 | cFYI(1, ("tcp session abend after SMBnegprot")); | 415 | cFYI(1, "tcp session abend after SMBnegprot"); |
415 | /* some servers kill the TCP session rather than | 416 | /* some servers kill the TCP session rather than |
416 | returning an SMB negprot error, in which | 417 | returning an SMB negprot error, in which |
417 | case reconnecting here is not going to help, | 418 | case reconnecting here is not going to help, |
@@ -419,18 +420,18 @@ incomplete_rcv: | |||
419 | break; | 420 | break; |
420 | } | 421 | } |
421 | if (!try_to_freeze() && (length == -EINTR)) { | 422 | if (!try_to_freeze() && (length == -EINTR)) { |
422 | cFYI(1, ("cifsd thread killed")); | 423 | cFYI(1, "cifsd thread killed"); |
423 | break; | 424 | break; |
424 | } | 425 | } |
425 | cFYI(1, ("Reconnect after unexpected peek error %d", | 426 | cFYI(1, "Reconnect after unexpected peek error %d", |
426 | length)); | 427 | length); |
427 | cifs_reconnect(server); | 428 | cifs_reconnect(server); |
428 | csocket = server->ssocket; | 429 | csocket = server->ssocket; |
429 | wake_up(&server->response_q); | 430 | wake_up(&server->response_q); |
430 | continue; | 431 | continue; |
431 | } else if (length < pdu_length) { | 432 | } else if (length < pdu_length) { |
432 | cFYI(1, ("requested %d bytes but only got %d bytes", | 433 | cFYI(1, "requested %d bytes but only got %d bytes", |
433 | pdu_length, length)); | 434 | pdu_length, length); |
434 | pdu_length -= length; | 435 | pdu_length -= length; |
435 | msleep(1); | 436 | msleep(1); |
436 | goto incomplete_rcv; | 437 | goto incomplete_rcv; |
@@ -450,18 +451,18 @@ incomplete_rcv: | |||
450 | pdu_length = be32_to_cpu((__force __be32)smb_buffer->smb_buf_length); | 451 | pdu_length = be32_to_cpu((__force __be32)smb_buffer->smb_buf_length); |
451 | smb_buffer->smb_buf_length = pdu_length; | 452 | smb_buffer->smb_buf_length = pdu_length; |
452 | 453 | ||
453 | cFYI(1, ("rfc1002 length 0x%x", pdu_length+4)); | 454 | cFYI(1, "rfc1002 length 0x%x", pdu_length+4); |
454 | 455 | ||
455 | if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) { | 456 | if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) { |
456 | continue; | 457 | continue; |
457 | } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) { | 458 | } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) { |
458 | cFYI(1, ("Good RFC 1002 session rsp")); | 459 | cFYI(1, "Good RFC 1002 session rsp"); |
459 | continue; | 460 | continue; |
460 | } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) { | 461 | } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) { |
461 | /* we get this from Windows 98 instead of | 462 | /* we get this from Windows 98 instead of |
462 | an error on SMB negprot response */ | 463 | an error on SMB negprot response */ |
463 | cFYI(1, ("Negative RFC1002 Session Response Error 0x%x)", | 464 | cFYI(1, "Negative RFC1002 Session Response Error 0x%x)", |
464 | pdu_length)); | 465 | pdu_length); |
465 | if (server->tcpStatus == CifsNew) { | 466 | if (server->tcpStatus == CifsNew) { |
466 | /* if nack on negprot (rather than | 467 | /* if nack on negprot (rather than |
467 | ret of smb negprot error) reconnecting | 468 | ret of smb negprot error) reconnecting |
@@ -484,7 +485,7 @@ incomplete_rcv: | |||
484 | continue; | 485 | continue; |
485 | } | 486 | } |
486 | } else if (temp != (char) 0) { | 487 | } else if (temp != (char) 0) { |
487 | cERROR(1, ("Unknown RFC 1002 frame")); | 488 | cERROR(1, "Unknown RFC 1002 frame"); |
488 | cifs_dump_mem(" Received Data: ", (char *)smb_buffer, | 489 | cifs_dump_mem(" Received Data: ", (char *)smb_buffer, |
489 | length); | 490 | length); |
490 | cifs_reconnect(server); | 491 | cifs_reconnect(server); |
@@ -495,8 +496,8 @@ incomplete_rcv: | |||
495 | /* else we have an SMB response */ | 496 | /* else we have an SMB response */ |
496 | if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) || | 497 | if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) || |
497 | (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) { | 498 | (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) { |
498 | cERROR(1, ("Invalid size SMB length %d pdu_length %d", | 499 | cERROR(1, "Invalid size SMB length %d pdu_length %d", |
499 | length, pdu_length+4)); | 500 | length, pdu_length+4); |
500 | cifs_reconnect(server); | 501 | cifs_reconnect(server); |
501 | csocket = server->ssocket; | 502 | csocket = server->ssocket; |
502 | wake_up(&server->response_q); | 503 | wake_up(&server->response_q); |
@@ -539,8 +540,8 @@ incomplete_rcv: | |||
539 | length = 0; | 540 | length = 0; |
540 | continue; | 541 | continue; |
541 | } else if (length <= 0) { | 542 | } else if (length <= 0) { |
542 | cERROR(1, ("Received no data, expecting %d", | 543 | cERROR(1, "Received no data, expecting %d", |
543 | pdu_length - total_read)); | 544 | pdu_length - total_read); |
544 | cifs_reconnect(server); | 545 | cifs_reconnect(server); |
545 | csocket = server->ssocket; | 546 | csocket = server->ssocket; |
546 | reconnect = 1; | 547 | reconnect = 1; |
@@ -588,7 +589,7 @@ incomplete_rcv: | |||
588 | } | 589 | } |
589 | } else { | 590 | } else { |
590 | if (!isLargeBuf) { | 591 | if (!isLargeBuf) { |
591 | cERROR(1,("1st trans2 resp needs bigbuf")); | 592 | cERROR(1, "1st trans2 resp needs bigbuf"); |
592 | /* BB maybe we can fix this up, switch | 593 | /* BB maybe we can fix this up, switch |
593 | to already allocated large buffer? */ | 594 | to already allocated large buffer? */ |
594 | } else { | 595 | } else { |
@@ -630,8 +631,8 @@ multi_t2_fnd: | |||
630 | wake_up_process(task_to_wake); | 631 | wake_up_process(task_to_wake); |
631 | } else if (!is_valid_oplock_break(smb_buffer, server) && | 632 | } else if (!is_valid_oplock_break(smb_buffer, server) && |
632 | !isMultiRsp) { | 633 | !isMultiRsp) { |
633 | cERROR(1, ("No task to wake, unknown frame received! " | 634 | cERROR(1, "No task to wake, unknown frame received! " |
634 | "NumMids %d", midCount.counter)); | 635 | "NumMids %d", midCount.counter); |
635 | cifs_dump_mem("Received Data is: ", (char *)smb_buffer, | 636 | cifs_dump_mem("Received Data is: ", (char *)smb_buffer, |
636 | sizeof(struct smb_hdr)); | 637 | sizeof(struct smb_hdr)); |
637 | #ifdef CONFIG_CIFS_DEBUG2 | 638 | #ifdef CONFIG_CIFS_DEBUG2 |
@@ -708,8 +709,8 @@ multi_t2_fnd: | |||
708 | list_for_each(tmp, &server->pending_mid_q) { | 709 | list_for_each(tmp, &server->pending_mid_q) { |
709 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); | 710 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
710 | if (mid_entry->midState == MID_REQUEST_SUBMITTED) { | 711 | if (mid_entry->midState == MID_REQUEST_SUBMITTED) { |
711 | cFYI(1, ("Clearing Mid 0x%x - waking up ", | 712 | cFYI(1, "Clearing Mid 0x%x - waking up ", |
712 | mid_entry->mid)); | 713 | mid_entry->mid); |
713 | task_to_wake = mid_entry->tsk; | 714 | task_to_wake = mid_entry->tsk; |
714 | if (task_to_wake) | 715 | if (task_to_wake) |
715 | wake_up_process(task_to_wake); | 716 | wake_up_process(task_to_wake); |
@@ -728,7 +729,7 @@ multi_t2_fnd: | |||
728 | to wait at least 45 seconds before giving up | 729 | to wait at least 45 seconds before giving up |
729 | on a request getting a response and going ahead | 730 | on a request getting a response and going ahead |
730 | and killing cifsd */ | 731 | and killing cifsd */ |
731 | cFYI(1, ("Wait for exit from demultiplex thread")); | 732 | cFYI(1, "Wait for exit from demultiplex thread"); |
732 | msleep(46000); | 733 | msleep(46000); |
733 | /* if threads still have not exited they are probably never | 734 | /* if threads still have not exited they are probably never |
734 | coming home not much else we can do but free the memory */ | 735 | coming home not much else we can do but free the memory */ |
@@ -849,7 +850,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
849 | separator[0] = options[4]; | 850 | separator[0] = options[4]; |
850 | options += 5; | 851 | options += 5; |
851 | } else { | 852 | } else { |
852 | cFYI(1, ("Null separator not allowed")); | 853 | cFYI(1, "Null separator not allowed"); |
853 | } | 854 | } |
854 | } | 855 | } |
855 | 856 | ||
@@ -974,7 +975,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
974 | } | 975 | } |
975 | } else if (strnicmp(data, "sec", 3) == 0) { | 976 | } else if (strnicmp(data, "sec", 3) == 0) { |
976 | if (!value || !*value) { | 977 | if (!value || !*value) { |
977 | cERROR(1, ("no security value specified")); | 978 | cERROR(1, "no security value specified"); |
978 | continue; | 979 | continue; |
979 | } else if (strnicmp(value, "krb5i", 5) == 0) { | 980 | } else if (strnicmp(value, "krb5i", 5) == 0) { |
980 | vol->secFlg |= CIFSSEC_MAY_KRB5 | | 981 | vol->secFlg |= CIFSSEC_MAY_KRB5 | |
@@ -982,7 +983,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
982 | } else if (strnicmp(value, "krb5p", 5) == 0) { | 983 | } else if (strnicmp(value, "krb5p", 5) == 0) { |
983 | /* vol->secFlg |= CIFSSEC_MUST_SEAL | | 984 | /* vol->secFlg |= CIFSSEC_MUST_SEAL | |
984 | CIFSSEC_MAY_KRB5; */ | 985 | CIFSSEC_MAY_KRB5; */ |
985 | cERROR(1, ("Krb5 cifs privacy not supported")); | 986 | cERROR(1, "Krb5 cifs privacy not supported"); |
986 | return 1; | 987 | return 1; |
987 | } else if (strnicmp(value, "krb5", 4) == 0) { | 988 | } else if (strnicmp(value, "krb5", 4) == 0) { |
988 | vol->secFlg |= CIFSSEC_MAY_KRB5; | 989 | vol->secFlg |= CIFSSEC_MAY_KRB5; |
@@ -1014,7 +1015,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1014 | } else if (strnicmp(value, "none", 4) == 0) { | 1015 | } else if (strnicmp(value, "none", 4) == 0) { |
1015 | vol->nullauth = 1; | 1016 | vol->nullauth = 1; |
1016 | } else { | 1017 | } else { |
1017 | cERROR(1, ("bad security option: %s", value)); | 1018 | cERROR(1, "bad security option: %s", value); |
1018 | return 1; | 1019 | return 1; |
1019 | } | 1020 | } |
1020 | } else if ((strnicmp(data, "unc", 3) == 0) | 1021 | } else if ((strnicmp(data, "unc", 3) == 0) |
@@ -1053,7 +1054,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1053 | a domain name and need special handling? */ | 1054 | a domain name and need special handling? */ |
1054 | if (strnlen(value, 256) < 256) { | 1055 | if (strnlen(value, 256) < 256) { |
1055 | vol->domainname = value; | 1056 | vol->domainname = value; |
1056 | cFYI(1, ("Domain name set")); | 1057 | cFYI(1, "Domain name set"); |
1057 | } else { | 1058 | } else { |
1058 | printk(KERN_WARNING "CIFS: domain name too " | 1059 | printk(KERN_WARNING "CIFS: domain name too " |
1059 | "long\n"); | 1060 | "long\n"); |
@@ -1076,7 +1077,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1076 | strcpy(vol->prepath+1, value); | 1077 | strcpy(vol->prepath+1, value); |
1077 | } else | 1078 | } else |
1078 | strcpy(vol->prepath, value); | 1079 | strcpy(vol->prepath, value); |
1079 | cFYI(1, ("prefix path %s", vol->prepath)); | 1080 | cFYI(1, "prefix path %s", vol->prepath); |
1080 | } else { | 1081 | } else { |
1081 | printk(KERN_WARNING "CIFS: prefix too long\n"); | 1082 | printk(KERN_WARNING "CIFS: prefix too long\n"); |
1082 | return 1; | 1083 | return 1; |
@@ -1092,7 +1093,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1092 | vol->iocharset = value; | 1093 | vol->iocharset = value; |
1093 | /* if iocharset not set then load_nls_default | 1094 | /* if iocharset not set then load_nls_default |
1094 | is used by caller */ | 1095 | is used by caller */ |
1095 | cFYI(1, ("iocharset set to %s", value)); | 1096 | cFYI(1, "iocharset set to %s", value); |
1096 | } else { | 1097 | } else { |
1097 | printk(KERN_WARNING "CIFS: iocharset name " | 1098 | printk(KERN_WARNING "CIFS: iocharset name " |
1098 | "too long.\n"); | 1099 | "too long.\n"); |
@@ -1144,14 +1145,14 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1144 | } | 1145 | } |
1145 | } else if (strnicmp(data, "sockopt", 5) == 0) { | 1146 | } else if (strnicmp(data, "sockopt", 5) == 0) { |
1146 | if (!value || !*value) { | 1147 | if (!value || !*value) { |
1147 | cERROR(1, ("no socket option specified")); | 1148 | cERROR(1, "no socket option specified"); |
1148 | continue; | 1149 | continue; |
1149 | } else if (strnicmp(value, "TCP_NODELAY", 11) == 0) { | 1150 | } else if (strnicmp(value, "TCP_NODELAY", 11) == 0) { |
1150 | vol->sockopt_tcp_nodelay = 1; | 1151 | vol->sockopt_tcp_nodelay = 1; |
1151 | } | 1152 | } |
1152 | } else if (strnicmp(data, "netbiosname", 4) == 0) { | 1153 | } else if (strnicmp(data, "netbiosname", 4) == 0) { |
1153 | if (!value || !*value || (*value == ' ')) { | 1154 | if (!value || !*value || (*value == ' ')) { |
1154 | cFYI(1, ("invalid (empty) netbiosname")); | 1155 | cFYI(1, "invalid (empty) netbiosname"); |
1155 | } else { | 1156 | } else { |
1156 | memset(vol->source_rfc1001_name, 0x20, 15); | 1157 | memset(vol->source_rfc1001_name, 0x20, 15); |
1157 | for (i = 0; i < 15; i++) { | 1158 | for (i = 0; i < 15; i++) { |
@@ -1175,7 +1176,7 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1175 | } else if (strnicmp(data, "servern", 7) == 0) { | 1176 | } else if (strnicmp(data, "servern", 7) == 0) { |
1176 | /* servernetbiosname specified override *SMBSERVER */ | 1177 | /* servernetbiosname specified override *SMBSERVER */ |
1177 | if (!value || !*value || (*value == ' ')) { | 1178 | if (!value || !*value || (*value == ' ')) { |
1178 | cFYI(1, ("empty server netbiosname specified")); | 1179 | cFYI(1, "empty server netbiosname specified"); |
1179 | } else { | 1180 | } else { |
1180 | /* last byte, type, is 0x20 for servr type */ | 1181 | /* last byte, type, is 0x20 for servr type */ |
1181 | memset(vol->target_rfc1001_name, 0x20, 16); | 1182 | memset(vol->target_rfc1001_name, 0x20, 16); |
@@ -1434,7 +1435,7 @@ cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port) | |||
1434 | 1435 | ||
1435 | ++server->srv_count; | 1436 | ++server->srv_count; |
1436 | write_unlock(&cifs_tcp_ses_lock); | 1437 | write_unlock(&cifs_tcp_ses_lock); |
1437 | cFYI(1, ("Existing tcp session with server found")); | 1438 | cFYI(1, "Existing tcp session with server found"); |
1438 | return server; | 1439 | return server; |
1439 | } | 1440 | } |
1440 | write_unlock(&cifs_tcp_ses_lock); | 1441 | write_unlock(&cifs_tcp_ses_lock); |
@@ -1475,7 +1476,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1475 | 1476 | ||
1476 | memset(&addr, 0, sizeof(struct sockaddr_storage)); | 1477 | memset(&addr, 0, sizeof(struct sockaddr_storage)); |
1477 | 1478 | ||
1478 | cFYI(1, ("UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip)); | 1479 | cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip); |
1479 | 1480 | ||
1480 | if (volume_info->UNCip && volume_info->UNC) { | 1481 | if (volume_info->UNCip && volume_info->UNC) { |
1481 | rc = cifs_convert_address(volume_info->UNCip, &addr); | 1482 | rc = cifs_convert_address(volume_info->UNCip, &addr); |
@@ -1487,13 +1488,12 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1487 | } else if (volume_info->UNCip) { | 1488 | } else if (volume_info->UNCip) { |
1488 | /* BB using ip addr as tcp_ses name to connect to the | 1489 | /* BB using ip addr as tcp_ses name to connect to the |
1489 | DFS root below */ | 1490 | DFS root below */ |
1490 | cERROR(1, ("Connecting to DFS root not implemented yet")); | 1491 | cERROR(1, "Connecting to DFS root not implemented yet"); |
1491 | rc = -EINVAL; | 1492 | rc = -EINVAL; |
1492 | goto out_err; | 1493 | goto out_err; |
1493 | } else /* which tcp_sess DFS root would we conect to */ { | 1494 | } else /* which tcp_sess DFS root would we conect to */ { |
1494 | cERROR(1, | 1495 | cERROR(1, "CIFS mount error: No UNC path (e.g. -o " |
1495 | ("CIFS mount error: No UNC path (e.g. -o " | 1496 | "unc=//192.168.1.100/public) specified"); |
1496 | "unc=//192.168.1.100/public) specified")); | ||
1497 | rc = -EINVAL; | 1497 | rc = -EINVAL; |
1498 | goto out_err; | 1498 | goto out_err; |
1499 | } | 1499 | } |
@@ -1540,7 +1540,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1540 | ++tcp_ses->srv_count; | 1540 | ++tcp_ses->srv_count; |
1541 | 1541 | ||
1542 | if (addr.ss_family == AF_INET6) { | 1542 | if (addr.ss_family == AF_INET6) { |
1543 | cFYI(1, ("attempting ipv6 connect")); | 1543 | cFYI(1, "attempting ipv6 connect"); |
1544 | /* BB should we allow ipv6 on port 139? */ | 1544 | /* BB should we allow ipv6 on port 139? */ |
1545 | /* other OS never observed in Wild doing 139 with v6 */ | 1545 | /* other OS never observed in Wild doing 139 with v6 */ |
1546 | sin_server6->sin6_port = htons(volume_info->port); | 1546 | sin_server6->sin6_port = htons(volume_info->port); |
@@ -1554,7 +1554,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1554 | rc = ipv4_connect(tcp_ses); | 1554 | rc = ipv4_connect(tcp_ses); |
1555 | } | 1555 | } |
1556 | if (rc < 0) { | 1556 | if (rc < 0) { |
1557 | cERROR(1, ("Error connecting to socket. Aborting operation")); | 1557 | cERROR(1, "Error connecting to socket. Aborting operation"); |
1558 | goto out_err; | 1558 | goto out_err; |
1559 | } | 1559 | } |
1560 | 1560 | ||
@@ -1567,7 +1567,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1567 | tcp_ses, "cifsd"); | 1567 | tcp_ses, "cifsd"); |
1568 | if (IS_ERR(tcp_ses->tsk)) { | 1568 | if (IS_ERR(tcp_ses->tsk)) { |
1569 | rc = PTR_ERR(tcp_ses->tsk); | 1569 | rc = PTR_ERR(tcp_ses->tsk); |
1570 | cERROR(1, ("error %d create cifsd thread", rc)); | 1570 | cERROR(1, "error %d create cifsd thread", rc); |
1571 | module_put(THIS_MODULE); | 1571 | module_put(THIS_MODULE); |
1572 | goto out_err; | 1572 | goto out_err; |
1573 | } | 1573 | } |
@@ -1616,6 +1616,7 @@ cifs_put_smb_ses(struct cifsSesInfo *ses) | |||
1616 | int xid; | 1616 | int xid; |
1617 | struct TCP_Server_Info *server = ses->server; | 1617 | struct TCP_Server_Info *server = ses->server; |
1618 | 1618 | ||
1619 | cFYI(1, "%s: ses_count=%d\n", __func__, ses->ses_count); | ||
1619 | write_lock(&cifs_tcp_ses_lock); | 1620 | write_lock(&cifs_tcp_ses_lock); |
1620 | if (--ses->ses_count > 0) { | 1621 | if (--ses->ses_count > 0) { |
1621 | write_unlock(&cifs_tcp_ses_lock); | 1622 | write_unlock(&cifs_tcp_ses_lock); |
@@ -1634,6 +1635,102 @@ cifs_put_smb_ses(struct cifsSesInfo *ses) | |||
1634 | cifs_put_tcp_session(server); | 1635 | cifs_put_tcp_session(server); |
1635 | } | 1636 | } |
1636 | 1637 | ||
1638 | static struct cifsSesInfo * | ||
1639 | cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) | ||
1640 | { | ||
1641 | int rc = -ENOMEM, xid; | ||
1642 | struct cifsSesInfo *ses; | ||
1643 | |||
1644 | xid = GetXid(); | ||
1645 | |||
1646 | ses = cifs_find_smb_ses(server, volume_info->username); | ||
1647 | if (ses) { | ||
1648 | cFYI(1, "Existing smb sess found (status=%d)", ses->status); | ||
1649 | |||
1650 | /* existing SMB ses has a server reference already */ | ||
1651 | cifs_put_tcp_session(server); | ||
1652 | |||
1653 | mutex_lock(&ses->session_mutex); | ||
1654 | rc = cifs_negotiate_protocol(xid, ses); | ||
1655 | if (rc) { | ||
1656 | mutex_unlock(&ses->session_mutex); | ||
1657 | /* problem -- put our ses reference */ | ||
1658 | cifs_put_smb_ses(ses); | ||
1659 | FreeXid(xid); | ||
1660 | return ERR_PTR(rc); | ||
1661 | } | ||
1662 | if (ses->need_reconnect) { | ||
1663 | cFYI(1, "Session needs reconnect"); | ||
1664 | rc = cifs_setup_session(xid, ses, | ||
1665 | volume_info->local_nls); | ||
1666 | if (rc) { | ||
1667 | mutex_unlock(&ses->session_mutex); | ||
1668 | /* problem -- put our reference */ | ||
1669 | cifs_put_smb_ses(ses); | ||
1670 | FreeXid(xid); | ||
1671 | return ERR_PTR(rc); | ||
1672 | } | ||
1673 | } | ||
1674 | mutex_unlock(&ses->session_mutex); | ||
1675 | FreeXid(xid); | ||
1676 | return ses; | ||
1677 | } | ||
1678 | |||
1679 | cFYI(1, "Existing smb sess not found"); | ||
1680 | ses = sesInfoAlloc(); | ||
1681 | if (ses == NULL) | ||
1682 | goto get_ses_fail; | ||
1683 | |||
1684 | /* new SMB session uses our server ref */ | ||
1685 | ses->server = server; | ||
1686 | if (server->addr.sockAddr6.sin6_family == AF_INET6) | ||
1687 | sprintf(ses->serverName, "%pI6", | ||
1688 | &server->addr.sockAddr6.sin6_addr); | ||
1689 | else | ||
1690 | sprintf(ses->serverName, "%pI4", | ||
1691 | &server->addr.sockAddr.sin_addr.s_addr); | ||
1692 | |||
1693 | if (volume_info->username) | ||
1694 | strncpy(ses->userName, volume_info->username, | ||
1695 | MAX_USERNAME_SIZE); | ||
1696 | |||
1697 | /* volume_info->password freed at unmount */ | ||
1698 | if (volume_info->password) { | ||
1699 | ses->password = kstrdup(volume_info->password, GFP_KERNEL); | ||
1700 | if (!ses->password) | ||
1701 | goto get_ses_fail; | ||
1702 | } | ||
1703 | if (volume_info->domainname) { | ||
1704 | int len = strlen(volume_info->domainname); | ||
1705 | ses->domainName = kmalloc(len + 1, GFP_KERNEL); | ||
1706 | if (ses->domainName) | ||
1707 | strcpy(ses->domainName, volume_info->domainname); | ||
1708 | } | ||
1709 | ses->linux_uid = volume_info->linux_uid; | ||
1710 | ses->overrideSecFlg = volume_info->secFlg; | ||
1711 | |||
1712 | mutex_lock(&ses->session_mutex); | ||
1713 | rc = cifs_negotiate_protocol(xid, ses); | ||
1714 | if (!rc) | ||
1715 | rc = cifs_setup_session(xid, ses, volume_info->local_nls); | ||
1716 | mutex_unlock(&ses->session_mutex); | ||
1717 | if (rc) | ||
1718 | goto get_ses_fail; | ||
1719 | |||
1720 | /* success, put it on the list */ | ||
1721 | write_lock(&cifs_tcp_ses_lock); | ||
1722 | list_add(&ses->smb_ses_list, &server->smb_ses_list); | ||
1723 | write_unlock(&cifs_tcp_ses_lock); | ||
1724 | |||
1725 | FreeXid(xid); | ||
1726 | return ses; | ||
1727 | |||
1728 | get_ses_fail: | ||
1729 | sesInfoFree(ses); | ||
1730 | FreeXid(xid); | ||
1731 | return ERR_PTR(rc); | ||
1732 | } | ||
1733 | |||
1637 | static struct cifsTconInfo * | 1734 | static struct cifsTconInfo * |
1638 | cifs_find_tcon(struct cifsSesInfo *ses, const char *unc) | 1735 | cifs_find_tcon(struct cifsSesInfo *ses, const char *unc) |
1639 | { | 1736 | { |
@@ -1662,6 +1759,7 @@ cifs_put_tcon(struct cifsTconInfo *tcon) | |||
1662 | int xid; | 1759 | int xid; |
1663 | struct cifsSesInfo *ses = tcon->ses; | 1760 | struct cifsSesInfo *ses = tcon->ses; |
1664 | 1761 | ||
1762 | cFYI(1, "%s: tc_count=%d\n", __func__, tcon->tc_count); | ||
1665 | write_lock(&cifs_tcp_ses_lock); | 1763 | write_lock(&cifs_tcp_ses_lock); |
1666 | if (--tcon->tc_count > 0) { | 1764 | if (--tcon->tc_count > 0) { |
1667 | write_unlock(&cifs_tcp_ses_lock); | 1765 | write_unlock(&cifs_tcp_ses_lock); |
@@ -1679,6 +1777,80 @@ cifs_put_tcon(struct cifsTconInfo *tcon) | |||
1679 | cifs_put_smb_ses(ses); | 1777 | cifs_put_smb_ses(ses); |
1680 | } | 1778 | } |
1681 | 1779 | ||
1780 | static struct cifsTconInfo * | ||
1781 | cifs_get_tcon(struct cifsSesInfo *ses, struct smb_vol *volume_info) | ||
1782 | { | ||
1783 | int rc, xid; | ||
1784 | struct cifsTconInfo *tcon; | ||
1785 | |||
1786 | tcon = cifs_find_tcon(ses, volume_info->UNC); | ||
1787 | if (tcon) { | ||
1788 | cFYI(1, "Found match on UNC path"); | ||
1789 | /* existing tcon already has a reference */ | ||
1790 | cifs_put_smb_ses(ses); | ||
1791 | if (tcon->seal != volume_info->seal) | ||
1792 | cERROR(1, "transport encryption setting " | ||
1793 | "conflicts with existing tid"); | ||
1794 | return tcon; | ||
1795 | } | ||
1796 | |||
1797 | tcon = tconInfoAlloc(); | ||
1798 | if (tcon == NULL) { | ||
1799 | rc = -ENOMEM; | ||
1800 | goto out_fail; | ||
1801 | } | ||
1802 | |||
1803 | tcon->ses = ses; | ||
1804 | if (volume_info->password) { | ||
1805 | tcon->password = kstrdup(volume_info->password, GFP_KERNEL); | ||
1806 | if (!tcon->password) { | ||
1807 | rc = -ENOMEM; | ||
1808 | goto out_fail; | ||
1809 | } | ||
1810 | } | ||
1811 | |||
1812 | if (strchr(volume_info->UNC + 3, '\\') == NULL | ||
1813 | && strchr(volume_info->UNC + 3, '/') == NULL) { | ||
1814 | cERROR(1, "Missing share name"); | ||
1815 | rc = -ENODEV; | ||
1816 | goto out_fail; | ||
1817 | } | ||
1818 | |||
1819 | /* BB Do we need to wrap session_mutex around | ||
1820 | * this TCon call and Unix SetFS as | ||
1821 | * we do on SessSetup and reconnect? */ | ||
1822 | xid = GetXid(); | ||
1823 | rc = CIFSTCon(xid, ses, volume_info->UNC, tcon, volume_info->local_nls); | ||
1824 | FreeXid(xid); | ||
1825 | cFYI(1, "CIFS Tcon rc = %d", rc); | ||
1826 | if (rc) | ||
1827 | goto out_fail; | ||
1828 | |||
1829 | if (volume_info->nodfs) { | ||
1830 | tcon->Flags &= ~SMB_SHARE_IS_IN_DFS; | ||
1831 | cFYI(1, "DFS disabled (%d)", tcon->Flags); | ||
1832 | } | ||
1833 | tcon->seal = volume_info->seal; | ||
1834 | /* we can have only one retry value for a connection | ||
1835 | to a share so for resources mounted more than once | ||
1836 | to the same server share the last value passed in | ||
1837 | for the retry flag is used */ | ||
1838 | tcon->retry = volume_info->retry; | ||
1839 | tcon->nocase = volume_info->nocase; | ||
1840 | tcon->local_lease = volume_info->local_lease; | ||
1841 | |||
1842 | write_lock(&cifs_tcp_ses_lock); | ||
1843 | list_add(&tcon->tcon_list, &ses->tcon_list); | ||
1844 | write_unlock(&cifs_tcp_ses_lock); | ||
1845 | |||
1846 | return tcon; | ||
1847 | |||
1848 | out_fail: | ||
1849 | tconInfoFree(tcon); | ||
1850 | return ERR_PTR(rc); | ||
1851 | } | ||
1852 | |||
1853 | |||
1682 | int | 1854 | int |
1683 | get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path, | 1855 | get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path, |
1684 | const struct nls_table *nls_codepage, unsigned int *pnum_referrals, | 1856 | const struct nls_table *nls_codepage, unsigned int *pnum_referrals, |
@@ -1703,8 +1875,7 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path, | |||
1703 | strcpy(temp_unc + 2, pSesInfo->serverName); | 1875 | strcpy(temp_unc + 2, pSesInfo->serverName); |
1704 | strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$"); | 1876 | strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$"); |
1705 | rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage); | 1877 | rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage); |
1706 | cFYI(1, | 1878 | cFYI(1, "CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid); |
1707 | ("CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid)); | ||
1708 | kfree(temp_unc); | 1879 | kfree(temp_unc); |
1709 | } | 1880 | } |
1710 | if (rc == 0) | 1881 | if (rc == 0) |
@@ -1777,12 +1948,12 @@ ipv4_connect(struct TCP_Server_Info *server) | |||
1777 | rc = sock_create_kern(PF_INET, SOCK_STREAM, | 1948 | rc = sock_create_kern(PF_INET, SOCK_STREAM, |
1778 | IPPROTO_TCP, &socket); | 1949 | IPPROTO_TCP, &socket); |
1779 | if (rc < 0) { | 1950 | if (rc < 0) { |
1780 | cERROR(1, ("Error %d creating socket", rc)); | 1951 | cERROR(1, "Error %d creating socket", rc); |
1781 | return rc; | 1952 | return rc; |
1782 | } | 1953 | } |
1783 | 1954 | ||
1784 | /* BB other socket options to set KEEPALIVE, NODELAY? */ | 1955 | /* BB other socket options to set KEEPALIVE, NODELAY? */ |
1785 | cFYI(1, ("Socket created")); | 1956 | cFYI(1, "Socket created"); |
1786 | server->ssocket = socket; | 1957 | server->ssocket = socket; |
1787 | socket->sk->sk_allocation = GFP_NOFS; | 1958 | socket->sk->sk_allocation = GFP_NOFS; |
1788 | cifs_reclassify_socket4(socket); | 1959 | cifs_reclassify_socket4(socket); |
@@ -1827,7 +1998,7 @@ ipv4_connect(struct TCP_Server_Info *server) | |||
1827 | if (!connected) { | 1998 | if (!connected) { |
1828 | if (orig_port) | 1999 | if (orig_port) |
1829 | server->addr.sockAddr.sin_port = orig_port; | 2000 | server->addr.sockAddr.sin_port = orig_port; |
1830 | cFYI(1, ("Error %d connecting to server via ipv4", rc)); | 2001 | cFYI(1, "Error %d connecting to server via ipv4", rc); |
1831 | sock_release(socket); | 2002 | sock_release(socket); |
1832 | server->ssocket = NULL; | 2003 | server->ssocket = NULL; |
1833 | return rc; | 2004 | return rc; |
@@ -1855,12 +2026,12 @@ ipv4_connect(struct TCP_Server_Info *server) | |||
1855 | rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, | 2026 | rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, |
1856 | (char *)&val, sizeof(val)); | 2027 | (char *)&val, sizeof(val)); |
1857 | if (rc) | 2028 | if (rc) |
1858 | cFYI(1, ("set TCP_NODELAY socket option error %d", rc)); | 2029 | cFYI(1, "set TCP_NODELAY socket option error %d", rc); |
1859 | } | 2030 | } |
1860 | 2031 | ||
1861 | cFYI(1, ("sndbuf %d rcvbuf %d rcvtimeo 0x%lx", | 2032 | cFYI(1, "sndbuf %d rcvbuf %d rcvtimeo 0x%lx", |
1862 | socket->sk->sk_sndbuf, | 2033 | socket->sk->sk_sndbuf, |
1863 | socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo)); | 2034 | socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo); |
1864 | 2035 | ||
1865 | /* send RFC1001 sessinit */ | 2036 | /* send RFC1001 sessinit */ |
1866 | if (server->addr.sockAddr.sin_port == htons(RFC1001_PORT)) { | 2037 | if (server->addr.sockAddr.sin_port == htons(RFC1001_PORT)) { |
@@ -1938,13 +2109,13 @@ ipv6_connect(struct TCP_Server_Info *server) | |||
1938 | rc = sock_create_kern(PF_INET6, SOCK_STREAM, | 2109 | rc = sock_create_kern(PF_INET6, SOCK_STREAM, |
1939 | IPPROTO_TCP, &socket); | 2110 | IPPROTO_TCP, &socket); |
1940 | if (rc < 0) { | 2111 | if (rc < 0) { |
1941 | cERROR(1, ("Error %d creating ipv6 socket", rc)); | 2112 | cERROR(1, "Error %d creating ipv6 socket", rc); |
1942 | socket = NULL; | 2113 | socket = NULL; |
1943 | return rc; | 2114 | return rc; |
1944 | } | 2115 | } |
1945 | 2116 | ||
1946 | /* BB other socket options to set KEEPALIVE, NODELAY? */ | 2117 | /* BB other socket options to set KEEPALIVE, NODELAY? */ |
1947 | cFYI(1, ("ipv6 Socket created")); | 2118 | cFYI(1, "ipv6 Socket created"); |
1948 | server->ssocket = socket; | 2119 | server->ssocket = socket; |
1949 | socket->sk->sk_allocation = GFP_NOFS; | 2120 | socket->sk->sk_allocation = GFP_NOFS; |
1950 | cifs_reclassify_socket6(socket); | 2121 | cifs_reclassify_socket6(socket); |
@@ -1988,7 +2159,7 @@ ipv6_connect(struct TCP_Server_Info *server) | |||
1988 | if (!connected) { | 2159 | if (!connected) { |
1989 | if (orig_port) | 2160 | if (orig_port) |
1990 | server->addr.sockAddr6.sin6_port = orig_port; | 2161 | server->addr.sockAddr6.sin6_port = orig_port; |
1991 | cFYI(1, ("Error %d connecting to server via ipv6", rc)); | 2162 | cFYI(1, "Error %d connecting to server via ipv6", rc); |
1992 | sock_release(socket); | 2163 | sock_release(socket); |
1993 | server->ssocket = NULL; | 2164 | server->ssocket = NULL; |
1994 | return rc; | 2165 | return rc; |
@@ -2007,7 +2178,7 @@ ipv6_connect(struct TCP_Server_Info *server) | |||
2007 | rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, | 2178 | rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY, |
2008 | (char *)&val, sizeof(val)); | 2179 | (char *)&val, sizeof(val)); |
2009 | if (rc) | 2180 | if (rc) |
2010 | cFYI(1, ("set TCP_NODELAY socket option error %d", rc)); | 2181 | cFYI(1, "set TCP_NODELAY socket option error %d", rc); |
2011 | } | 2182 | } |
2012 | 2183 | ||
2013 | server->ssocket = socket; | 2184 | server->ssocket = socket; |
@@ -2032,13 +2203,13 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, | |||
2032 | if (vol_info && vol_info->no_linux_ext) { | 2203 | if (vol_info && vol_info->no_linux_ext) { |
2033 | tcon->fsUnixInfo.Capability = 0; | 2204 | tcon->fsUnixInfo.Capability = 0; |
2034 | tcon->unix_ext = 0; /* Unix Extensions disabled */ | 2205 | tcon->unix_ext = 0; /* Unix Extensions disabled */ |
2035 | cFYI(1, ("Linux protocol extensions disabled")); | 2206 | cFYI(1, "Linux protocol extensions disabled"); |
2036 | return; | 2207 | return; |
2037 | } else if (vol_info) | 2208 | } else if (vol_info) |
2038 | tcon->unix_ext = 1; /* Unix Extensions supported */ | 2209 | tcon->unix_ext = 1; /* Unix Extensions supported */ |
2039 | 2210 | ||
2040 | if (tcon->unix_ext == 0) { | 2211 | if (tcon->unix_ext == 0) { |
2041 | cFYI(1, ("Unix extensions disabled so not set on reconnect")); | 2212 | cFYI(1, "Unix extensions disabled so not set on reconnect"); |
2042 | return; | 2213 | return; |
2043 | } | 2214 | } |
2044 | 2215 | ||
@@ -2054,12 +2225,11 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, | |||
2054 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; | 2225 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
2055 | if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { | 2226 | if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { |
2056 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) | 2227 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) |
2057 | cERROR(1, ("POSIXPATH support change")); | 2228 | cERROR(1, "POSIXPATH support change"); |
2058 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; | 2229 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
2059 | } else if ((cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { | 2230 | } else if ((cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) { |
2060 | cERROR(1, ("possible reconnect error")); | 2231 | cERROR(1, "possible reconnect error"); |
2061 | cERROR(1, | 2232 | cERROR(1, "server disabled POSIX path support"); |
2062 | ("server disabled POSIX path support")); | ||
2063 | } | 2233 | } |
2064 | } | 2234 | } |
2065 | 2235 | ||
@@ -2067,7 +2237,7 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, | |||
2067 | if (vol_info && vol_info->no_psx_acl) | 2237 | if (vol_info && vol_info->no_psx_acl) |
2068 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; | 2238 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
2069 | else if (CIFS_UNIX_POSIX_ACL_CAP & cap) { | 2239 | else if (CIFS_UNIX_POSIX_ACL_CAP & cap) { |
2070 | cFYI(1, ("negotiated posix acl support")); | 2240 | cFYI(1, "negotiated posix acl support"); |
2071 | if (sb) | 2241 | if (sb) |
2072 | sb->s_flags |= MS_POSIXACL; | 2242 | sb->s_flags |= MS_POSIXACL; |
2073 | } | 2243 | } |
@@ -2075,7 +2245,7 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, | |||
2075 | if (vol_info && vol_info->posix_paths == 0) | 2245 | if (vol_info && vol_info->posix_paths == 0) |
2076 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; | 2246 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
2077 | else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) { | 2247 | else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) { |
2078 | cFYI(1, ("negotiate posix pathnames")); | 2248 | cFYI(1, "negotiate posix pathnames"); |
2079 | if (sb) | 2249 | if (sb) |
2080 | CIFS_SB(sb)->mnt_cifs_flags |= | 2250 | CIFS_SB(sb)->mnt_cifs_flags |= |
2081 | CIFS_MOUNT_POSIX_PATHS; | 2251 | CIFS_MOUNT_POSIX_PATHS; |
@@ -2090,39 +2260,38 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, | |||
2090 | if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) { | 2260 | if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) { |
2091 | if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) { | 2261 | if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) { |
2092 | CIFS_SB(sb)->rsize = 127 * 1024; | 2262 | CIFS_SB(sb)->rsize = 127 * 1024; |
2093 | cFYI(DBG2, | 2263 | cFYI(DBG2, "larger reads not supported by srv"); |
2094 | ("larger reads not supported by srv")); | ||
2095 | } | 2264 | } |
2096 | } | 2265 | } |
2097 | 2266 | ||
2098 | 2267 | ||
2099 | cFYI(1, ("Negotiate caps 0x%x", (int)cap)); | 2268 | cFYI(1, "Negotiate caps 0x%x", (int)cap); |
2100 | #ifdef CONFIG_CIFS_DEBUG2 | 2269 | #ifdef CONFIG_CIFS_DEBUG2 |
2101 | if (cap & CIFS_UNIX_FCNTL_CAP) | 2270 | if (cap & CIFS_UNIX_FCNTL_CAP) |
2102 | cFYI(1, ("FCNTL cap")); | 2271 | cFYI(1, "FCNTL cap"); |
2103 | if (cap & CIFS_UNIX_EXTATTR_CAP) | 2272 | if (cap & CIFS_UNIX_EXTATTR_CAP) |
2104 | cFYI(1, ("EXTATTR cap")); | 2273 | cFYI(1, "EXTATTR cap"); |
2105 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) | 2274 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) |
2106 | cFYI(1, ("POSIX path cap")); | 2275 | cFYI(1, "POSIX path cap"); |
2107 | if (cap & CIFS_UNIX_XATTR_CAP) | 2276 | if (cap & CIFS_UNIX_XATTR_CAP) |
2108 | cFYI(1, ("XATTR cap")); | 2277 | cFYI(1, "XATTR cap"); |
2109 | if (cap & CIFS_UNIX_POSIX_ACL_CAP) | 2278 | if (cap & CIFS_UNIX_POSIX_ACL_CAP) |
2110 | cFYI(1, ("POSIX ACL cap")); | 2279 | cFYI(1, "POSIX ACL cap"); |
2111 | if (cap & CIFS_UNIX_LARGE_READ_CAP) | 2280 | if (cap & CIFS_UNIX_LARGE_READ_CAP) |
2112 | cFYI(1, ("very large read cap")); | 2281 | cFYI(1, "very large read cap"); |
2113 | if (cap & CIFS_UNIX_LARGE_WRITE_CAP) | 2282 | if (cap & CIFS_UNIX_LARGE_WRITE_CAP) |
2114 | cFYI(1, ("very large write cap")); | 2283 | cFYI(1, "very large write cap"); |
2115 | #endif /* CIFS_DEBUG2 */ | 2284 | #endif /* CIFS_DEBUG2 */ |
2116 | if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { | 2285 | if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { |
2117 | if (vol_info == NULL) { | 2286 | if (vol_info == NULL) { |
2118 | cFYI(1, ("resetting capabilities failed")); | 2287 | cFYI(1, "resetting capabilities failed"); |
2119 | } else | 2288 | } else |
2120 | cERROR(1, ("Negotiating Unix capabilities " | 2289 | cERROR(1, "Negotiating Unix capabilities " |
2121 | "with the server failed. Consider " | 2290 | "with the server failed. Consider " |
2122 | "mounting with the Unix Extensions\n" | 2291 | "mounting with the Unix Extensions\n" |
2123 | "disabled, if problems are found, " | 2292 | "disabled, if problems are found, " |
2124 | "by specifying the nounix mount " | 2293 | "by specifying the nounix mount " |
2125 | "option.")); | 2294 | "option."); |
2126 | 2295 | ||
2127 | } | 2296 | } |
2128 | } | 2297 | } |
@@ -2152,8 +2321,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2152 | struct cifs_sb_info *cifs_sb) | 2321 | struct cifs_sb_info *cifs_sb) |
2153 | { | 2322 | { |
2154 | if (pvolume_info->rsize > CIFSMaxBufSize) { | 2323 | if (pvolume_info->rsize > CIFSMaxBufSize) { |
2155 | cERROR(1, ("rsize %d too large, using MaxBufSize", | 2324 | cERROR(1, "rsize %d too large, using MaxBufSize", |
2156 | pvolume_info->rsize)); | 2325 | pvolume_info->rsize); |
2157 | cifs_sb->rsize = CIFSMaxBufSize; | 2326 | cifs_sb->rsize = CIFSMaxBufSize; |
2158 | } else if ((pvolume_info->rsize) && | 2327 | } else if ((pvolume_info->rsize) && |
2159 | (pvolume_info->rsize <= CIFSMaxBufSize)) | 2328 | (pvolume_info->rsize <= CIFSMaxBufSize)) |
@@ -2162,8 +2331,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2162 | cifs_sb->rsize = CIFSMaxBufSize; | 2331 | cifs_sb->rsize = CIFSMaxBufSize; |
2163 | 2332 | ||
2164 | if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) { | 2333 | if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) { |
2165 | cERROR(1, ("wsize %d too large, using 4096 instead", | 2334 | cERROR(1, "wsize %d too large, using 4096 instead", |
2166 | pvolume_info->wsize)); | 2335 | pvolume_info->wsize); |
2167 | cifs_sb->wsize = 4096; | 2336 | cifs_sb->wsize = 4096; |
2168 | } else if (pvolume_info->wsize) | 2337 | } else if (pvolume_info->wsize) |
2169 | cifs_sb->wsize = pvolume_info->wsize; | 2338 | cifs_sb->wsize = pvolume_info->wsize; |
@@ -2181,7 +2350,7 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2181 | if (cifs_sb->rsize < 2048) { | 2350 | if (cifs_sb->rsize < 2048) { |
2182 | cifs_sb->rsize = 2048; | 2351 | cifs_sb->rsize = 2048; |
2183 | /* Windows ME may prefer this */ | 2352 | /* Windows ME may prefer this */ |
2184 | cFYI(1, ("readsize set to minimum: 2048")); | 2353 | cFYI(1, "readsize set to minimum: 2048"); |
2185 | } | 2354 | } |
2186 | /* calculate prepath */ | 2355 | /* calculate prepath */ |
2187 | cifs_sb->prepath = pvolume_info->prepath; | 2356 | cifs_sb->prepath = pvolume_info->prepath; |
@@ -2199,8 +2368,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2199 | cifs_sb->mnt_gid = pvolume_info->linux_gid; | 2368 | cifs_sb->mnt_gid = pvolume_info->linux_gid; |
2200 | cifs_sb->mnt_file_mode = pvolume_info->file_mode; | 2369 | cifs_sb->mnt_file_mode = pvolume_info->file_mode; |
2201 | cifs_sb->mnt_dir_mode = pvolume_info->dir_mode; | 2370 | cifs_sb->mnt_dir_mode = pvolume_info->dir_mode; |
2202 | cFYI(1, ("file mode: 0x%x dir mode: 0x%x", | 2371 | cFYI(1, "file mode: 0x%x dir mode: 0x%x", |
2203 | cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode)); | 2372 | cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode); |
2204 | 2373 | ||
2205 | if (pvolume_info->noperm) | 2374 | if (pvolume_info->noperm) |
2206 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM; | 2375 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM; |
@@ -2229,13 +2398,13 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2229 | if (pvolume_info->dynperm) | 2398 | if (pvolume_info->dynperm) |
2230 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM; | 2399 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM; |
2231 | if (pvolume_info->direct_io) { | 2400 | if (pvolume_info->direct_io) { |
2232 | cFYI(1, ("mounting share using direct i/o")); | 2401 | cFYI(1, "mounting share using direct i/o"); |
2233 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; | 2402 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; |
2234 | } | 2403 | } |
2235 | 2404 | ||
2236 | if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm)) | 2405 | if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm)) |
2237 | cERROR(1, ("mount option dynperm ignored if cifsacl " | 2406 | cERROR(1, "mount option dynperm ignored if cifsacl " |
2238 | "mount option supported")); | 2407 | "mount option supported"); |
2239 | } | 2408 | } |
2240 | 2409 | ||
2241 | static int | 2410 | static int |
@@ -2262,7 +2431,7 @@ cleanup_volume_info(struct smb_vol **pvolume_info) | |||
2262 | { | 2431 | { |
2263 | struct smb_vol *volume_info; | 2432 | struct smb_vol *volume_info; |
2264 | 2433 | ||
2265 | if (!pvolume_info && !*pvolume_info) | 2434 | if (!pvolume_info || !*pvolume_info) |
2266 | return; | 2435 | return; |
2267 | 2436 | ||
2268 | volume_info = *pvolume_info; | 2437 | volume_info = *pvolume_info; |
@@ -2344,11 +2513,11 @@ try_mount_again: | |||
2344 | } | 2513 | } |
2345 | 2514 | ||
2346 | if (volume_info->nullauth) { | 2515 | if (volume_info->nullauth) { |
2347 | cFYI(1, ("null user")); | 2516 | cFYI(1, "null user"); |
2348 | volume_info->username = ""; | 2517 | volume_info->username = ""; |
2349 | } else if (volume_info->username) { | 2518 | } else if (volume_info->username) { |
2350 | /* BB fixme parse for domain name here */ | 2519 | /* BB fixme parse for domain name here */ |
2351 | cFYI(1, ("Username: %s", volume_info->username)); | 2520 | cFYI(1, "Username: %s", volume_info->username); |
2352 | } else { | 2521 | } else { |
2353 | cifserror("No username specified"); | 2522 | cifserror("No username specified"); |
2354 | /* In userspace mount helper we can get user name from alternate | 2523 | /* In userspace mount helper we can get user name from alternate |
@@ -2357,20 +2526,20 @@ try_mount_again: | |||
2357 | goto out; | 2526 | goto out; |
2358 | } | 2527 | } |
2359 | 2528 | ||
2360 | |||
2361 | /* this is needed for ASCII cp to Unicode converts */ | 2529 | /* this is needed for ASCII cp to Unicode converts */ |
2362 | if (volume_info->iocharset == NULL) { | 2530 | if (volume_info->iocharset == NULL) { |
2363 | cifs_sb->local_nls = load_nls_default(); | 2531 | /* load_nls_default cannot return null */ |
2364 | /* load_nls_default can not return null */ | 2532 | volume_info->local_nls = load_nls_default(); |
2365 | } else { | 2533 | } else { |
2366 | cifs_sb->local_nls = load_nls(volume_info->iocharset); | 2534 | volume_info->local_nls = load_nls(volume_info->iocharset); |
2367 | if (cifs_sb->local_nls == NULL) { | 2535 | if (volume_info->local_nls == NULL) { |
2368 | cERROR(1, ("CIFS mount error: iocharset %s not found", | 2536 | cERROR(1, "CIFS mount error: iocharset %s not found", |
2369 | volume_info->iocharset)); | 2537 | volume_info->iocharset); |
2370 | rc = -ELIBACC; | 2538 | rc = -ELIBACC; |
2371 | goto out; | 2539 | goto out; |
2372 | } | 2540 | } |
2373 | } | 2541 | } |
2542 | cifs_sb->local_nls = volume_info->local_nls; | ||
2374 | 2543 | ||
2375 | /* get a reference to a tcp session */ | 2544 | /* get a reference to a tcp session */ |
2376 | srvTcp = cifs_get_tcp_session(volume_info); | 2545 | srvTcp = cifs_get_tcp_session(volume_info); |
@@ -2379,148 +2548,30 @@ try_mount_again: | |||
2379 | goto out; | 2548 | goto out; |
2380 | } | 2549 | } |
2381 | 2550 | ||
2382 | pSesInfo = cifs_find_smb_ses(srvTcp, volume_info->username); | 2551 | /* get a reference to a SMB session */ |
2383 | if (pSesInfo) { | 2552 | pSesInfo = cifs_get_smb_ses(srvTcp, volume_info); |
2384 | cFYI(1, ("Existing smb sess found (status=%d)", | 2553 | if (IS_ERR(pSesInfo)) { |
2385 | pSesInfo->status)); | 2554 | rc = PTR_ERR(pSesInfo); |
2386 | /* | 2555 | pSesInfo = NULL; |
2387 | * The existing SMB session already has a reference to srvTcp, | 2556 | goto mount_fail_check; |
2388 | * so we can put back the extra one we got before | ||
2389 | */ | ||
2390 | cifs_put_tcp_session(srvTcp); | ||
2391 | |||
2392 | mutex_lock(&pSesInfo->session_mutex); | ||
2393 | if (pSesInfo->need_reconnect) { | ||
2394 | cFYI(1, ("Session needs reconnect")); | ||
2395 | rc = cifs_setup_session(xid, pSesInfo, | ||
2396 | cifs_sb->local_nls); | ||
2397 | } | ||
2398 | mutex_unlock(&pSesInfo->session_mutex); | ||
2399 | } else if (!rc) { | ||
2400 | cFYI(1, ("Existing smb sess not found")); | ||
2401 | pSesInfo = sesInfoAlloc(); | ||
2402 | if (pSesInfo == NULL) { | ||
2403 | rc = -ENOMEM; | ||
2404 | goto mount_fail_check; | ||
2405 | } | ||
2406 | |||
2407 | /* new SMB session uses our srvTcp ref */ | ||
2408 | pSesInfo->server = srvTcp; | ||
2409 | if (srvTcp->addr.sockAddr6.sin6_family == AF_INET6) | ||
2410 | sprintf(pSesInfo->serverName, "%pI6", | ||
2411 | &srvTcp->addr.sockAddr6.sin6_addr); | ||
2412 | else | ||
2413 | sprintf(pSesInfo->serverName, "%pI4", | ||
2414 | &srvTcp->addr.sockAddr.sin_addr.s_addr); | ||
2415 | |||
2416 | write_lock(&cifs_tcp_ses_lock); | ||
2417 | list_add(&pSesInfo->smb_ses_list, &srvTcp->smb_ses_list); | ||
2418 | write_unlock(&cifs_tcp_ses_lock); | ||
2419 | |||
2420 | /* volume_info->password freed at unmount */ | ||
2421 | if (volume_info->password) { | ||
2422 | pSesInfo->password = kstrdup(volume_info->password, | ||
2423 | GFP_KERNEL); | ||
2424 | if (!pSesInfo->password) { | ||
2425 | rc = -ENOMEM; | ||
2426 | goto mount_fail_check; | ||
2427 | } | ||
2428 | } | ||
2429 | if (volume_info->username) | ||
2430 | strncpy(pSesInfo->userName, volume_info->username, | ||
2431 | MAX_USERNAME_SIZE); | ||
2432 | if (volume_info->domainname) { | ||
2433 | int len = strlen(volume_info->domainname); | ||
2434 | pSesInfo->domainName = kmalloc(len + 1, GFP_KERNEL); | ||
2435 | if (pSesInfo->domainName) | ||
2436 | strcpy(pSesInfo->domainName, | ||
2437 | volume_info->domainname); | ||
2438 | } | ||
2439 | pSesInfo->linux_uid = volume_info->linux_uid; | ||
2440 | pSesInfo->overrideSecFlg = volume_info->secFlg; | ||
2441 | mutex_lock(&pSesInfo->session_mutex); | ||
2442 | |||
2443 | /* BB FIXME need to pass vol->secFlgs BB */ | ||
2444 | rc = cifs_setup_session(xid, pSesInfo, | ||
2445 | cifs_sb->local_nls); | ||
2446 | mutex_unlock(&pSesInfo->session_mutex); | ||
2447 | } | 2557 | } |
2448 | 2558 | ||
2449 | /* search for existing tcon to this server share */ | 2559 | setup_cifs_sb(volume_info, cifs_sb); |
2450 | if (!rc) { | 2560 | if (pSesInfo->capabilities & CAP_LARGE_FILES) |
2451 | setup_cifs_sb(volume_info, cifs_sb); | 2561 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
2452 | 2562 | else | |
2453 | tcon = cifs_find_tcon(pSesInfo, volume_info->UNC); | 2563 | sb->s_maxbytes = MAX_NON_LFS; |
2454 | if (tcon) { | ||
2455 | cFYI(1, ("Found match on UNC path")); | ||
2456 | /* existing tcon already has a reference */ | ||
2457 | cifs_put_smb_ses(pSesInfo); | ||
2458 | if (tcon->seal != volume_info->seal) | ||
2459 | cERROR(1, ("transport encryption setting " | ||
2460 | "conflicts with existing tid")); | ||
2461 | } else { | ||
2462 | tcon = tconInfoAlloc(); | ||
2463 | if (tcon == NULL) { | ||
2464 | rc = -ENOMEM; | ||
2465 | goto mount_fail_check; | ||
2466 | } | ||
2467 | |||
2468 | tcon->ses = pSesInfo; | ||
2469 | if (volume_info->password) { | ||
2470 | tcon->password = kstrdup(volume_info->password, | ||
2471 | GFP_KERNEL); | ||
2472 | if (!tcon->password) { | ||
2473 | rc = -ENOMEM; | ||
2474 | goto mount_fail_check; | ||
2475 | } | ||
2476 | } | ||
2477 | |||
2478 | if ((strchr(volume_info->UNC + 3, '\\') == NULL) | ||
2479 | && (strchr(volume_info->UNC + 3, '/') == NULL)) { | ||
2480 | cERROR(1, ("Missing share name")); | ||
2481 | rc = -ENODEV; | ||
2482 | goto mount_fail_check; | ||
2483 | } else { | ||
2484 | /* BB Do we need to wrap sesSem around | ||
2485 | * this TCon call and Unix SetFS as | ||
2486 | * we do on SessSetup and reconnect? */ | ||
2487 | rc = CIFSTCon(xid, pSesInfo, volume_info->UNC, | ||
2488 | tcon, cifs_sb->local_nls); | ||
2489 | cFYI(1, ("CIFS Tcon rc = %d", rc)); | ||
2490 | if (volume_info->nodfs) { | ||
2491 | tcon->Flags &= ~SMB_SHARE_IS_IN_DFS; | ||
2492 | cFYI(1, ("DFS disabled (%d)", | ||
2493 | tcon->Flags)); | ||
2494 | } | ||
2495 | } | ||
2496 | if (rc) | ||
2497 | goto remote_path_check; | ||
2498 | tcon->seal = volume_info->seal; | ||
2499 | write_lock(&cifs_tcp_ses_lock); | ||
2500 | list_add(&tcon->tcon_list, &pSesInfo->tcon_list); | ||
2501 | write_unlock(&cifs_tcp_ses_lock); | ||
2502 | } | ||
2503 | |||
2504 | /* we can have only one retry value for a connection | ||
2505 | to a share so for resources mounted more than once | ||
2506 | to the same server share the last value passed in | ||
2507 | for the retry flag is used */ | ||
2508 | tcon->retry = volume_info->retry; | ||
2509 | tcon->nocase = volume_info->nocase; | ||
2510 | tcon->local_lease = volume_info->local_lease; | ||
2511 | } | ||
2512 | if (pSesInfo) { | ||
2513 | if (pSesInfo->capabilities & CAP_LARGE_FILES) | ||
2514 | sb->s_maxbytes = MAX_LFS_FILESIZE; | ||
2515 | else | ||
2516 | sb->s_maxbytes = MAX_NON_LFS; | ||
2517 | } | ||
2518 | 2564 | ||
2519 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ | 2565 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ |
2520 | sb->s_time_gran = 100; | 2566 | sb->s_time_gran = 100; |
2521 | 2567 | ||
2522 | if (rc) | 2568 | /* search for existing tcon to this server share */ |
2569 | tcon = cifs_get_tcon(pSesInfo, volume_info); | ||
2570 | if (IS_ERR(tcon)) { | ||
2571 | rc = PTR_ERR(tcon); | ||
2572 | tcon = NULL; | ||
2523 | goto remote_path_check; | 2573 | goto remote_path_check; |
2574 | } | ||
2524 | 2575 | ||
2525 | cifs_sb->tcon = tcon; | 2576 | cifs_sb->tcon = tcon; |
2526 | 2577 | ||
@@ -2544,7 +2595,7 @@ try_mount_again: | |||
2544 | 2595 | ||
2545 | if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) { | 2596 | if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) { |
2546 | cifs_sb->rsize = 1024 * 127; | 2597 | cifs_sb->rsize = 1024 * 127; |
2547 | cFYI(DBG2, ("no very large read support, rsize now 127K")); | 2598 | cFYI(DBG2, "no very large read support, rsize now 127K"); |
2548 | } | 2599 | } |
2549 | if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X)) | 2600 | if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X)) |
2550 | cifs_sb->wsize = min(cifs_sb->wsize, | 2601 | cifs_sb->wsize = min(cifs_sb->wsize, |
@@ -2593,7 +2644,7 @@ remote_path_check: | |||
2593 | goto mount_fail_check; | 2644 | goto mount_fail_check; |
2594 | } | 2645 | } |
2595 | 2646 | ||
2596 | cFYI(1, ("Getting referral for: %s", full_path)); | 2647 | cFYI(1, "Getting referral for: %s", full_path); |
2597 | rc = get_dfs_path(xid, pSesInfo , full_path + 1, | 2648 | rc = get_dfs_path(xid, pSesInfo , full_path + 1, |
2598 | cifs_sb->local_nls, &num_referrals, &referrals, | 2649 | cifs_sb->local_nls, &num_referrals, &referrals, |
2599 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 2650 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
@@ -2707,7 +2758,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
2707 | by Samba (not sure whether other servers allow | 2758 | by Samba (not sure whether other servers allow |
2708 | NTLMv2 password here) */ | 2759 | NTLMv2 password here) */ |
2709 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 2760 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
2710 | if ((extended_security & CIFSSEC_MAY_LANMAN) && | 2761 | if ((global_secflags & CIFSSEC_MAY_LANMAN) && |
2711 | (ses->server->secType == LANMAN)) | 2762 | (ses->server->secType == LANMAN)) |
2712 | calc_lanman_hash(tcon->password, ses->server->cryptKey, | 2763 | calc_lanman_hash(tcon->password, ses->server->cryptKey, |
2713 | ses->server->secMode & | 2764 | ses->server->secMode & |
@@ -2778,13 +2829,13 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
2778 | if (length == 3) { | 2829 | if (length == 3) { |
2779 | if ((bcc_ptr[0] == 'I') && (bcc_ptr[1] == 'P') && | 2830 | if ((bcc_ptr[0] == 'I') && (bcc_ptr[1] == 'P') && |
2780 | (bcc_ptr[2] == 'C')) { | 2831 | (bcc_ptr[2] == 'C')) { |
2781 | cFYI(1, ("IPC connection")); | 2832 | cFYI(1, "IPC connection"); |
2782 | tcon->ipc = 1; | 2833 | tcon->ipc = 1; |
2783 | } | 2834 | } |
2784 | } else if (length == 2) { | 2835 | } else if (length == 2) { |
2785 | if ((bcc_ptr[0] == 'A') && (bcc_ptr[1] == ':')) { | 2836 | if ((bcc_ptr[0] == 'A') && (bcc_ptr[1] == ':')) { |
2786 | /* the most common case */ | 2837 | /* the most common case */ |
2787 | cFYI(1, ("disk share connection")); | 2838 | cFYI(1, "disk share connection"); |
2788 | } | 2839 | } |
2789 | } | 2840 | } |
2790 | bcc_ptr += length + 1; | 2841 | bcc_ptr += length + 1; |
@@ -2797,7 +2848,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
2797 | bytes_left, is_unicode, | 2848 | bytes_left, is_unicode, |
2798 | nls_codepage); | 2849 | nls_codepage); |
2799 | 2850 | ||
2800 | cFYI(1, ("nativeFileSystem=%s", tcon->nativeFileSystem)); | 2851 | cFYI(1, "nativeFileSystem=%s", tcon->nativeFileSystem); |
2801 | 2852 | ||
2802 | if ((smb_buffer_response->WordCount == 3) || | 2853 | if ((smb_buffer_response->WordCount == 3) || |
2803 | (smb_buffer_response->WordCount == 7)) | 2854 | (smb_buffer_response->WordCount == 7)) |
@@ -2805,7 +2856,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
2805 | tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); | 2856 | tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); |
2806 | else | 2857 | else |
2807 | tcon->Flags = 0; | 2858 | tcon->Flags = 0; |
2808 | cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags)); | 2859 | cFYI(1, "Tcon flags: 0x%x ", tcon->Flags); |
2809 | } else if ((rc == 0) && tcon == NULL) { | 2860 | } else if ((rc == 0) && tcon == NULL) { |
2810 | /* all we need to save for IPC$ connection */ | 2861 | /* all we need to save for IPC$ connection */ |
2811 | ses->ipc_tid = smb_buffer_response->Tid; | 2862 | ses->ipc_tid = smb_buffer_response->Tid; |
@@ -2833,57 +2884,61 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) | |||
2833 | return rc; | 2884 | return rc; |
2834 | } | 2885 | } |
2835 | 2886 | ||
2836 | int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo, | 2887 | int cifs_negotiate_protocol(unsigned int xid, struct cifsSesInfo *ses) |
2837 | struct nls_table *nls_info) | ||
2838 | { | 2888 | { |
2839 | int rc = 0; | 2889 | int rc = 0; |
2840 | int first_time = 0; | 2890 | struct TCP_Server_Info *server = ses->server; |
2841 | struct TCP_Server_Info *server = pSesInfo->server; | 2891 | |
2842 | 2892 | /* only send once per connect */ | |
2843 | /* what if server changes its buffer size after dropping the session? */ | 2893 | if (server->maxBuf != 0) |
2844 | if (server->maxBuf == 0) /* no need to send on reconnect */ { | 2894 | return 0; |
2845 | rc = CIFSSMBNegotiate(xid, pSesInfo); | 2895 | |
2846 | if (rc == -EAGAIN) { | 2896 | rc = CIFSSMBNegotiate(xid, ses); |
2847 | /* retry only once on 1st time connection */ | 2897 | if (rc == -EAGAIN) { |
2848 | rc = CIFSSMBNegotiate(xid, pSesInfo); | 2898 | /* retry only once on 1st time connection */ |
2849 | if (rc == -EAGAIN) | 2899 | rc = CIFSSMBNegotiate(xid, ses); |
2850 | rc = -EHOSTDOWN; | 2900 | if (rc == -EAGAIN) |
2851 | } | 2901 | rc = -EHOSTDOWN; |
2852 | if (rc == 0) { | 2902 | } |
2853 | spin_lock(&GlobalMid_Lock); | 2903 | if (rc == 0) { |
2854 | if (server->tcpStatus != CifsExiting) | 2904 | spin_lock(&GlobalMid_Lock); |
2855 | server->tcpStatus = CifsGood; | 2905 | if (server->tcpStatus != CifsExiting) |
2856 | else | 2906 | server->tcpStatus = CifsGood; |
2857 | rc = -EHOSTDOWN; | 2907 | else |
2858 | spin_unlock(&GlobalMid_Lock); | 2908 | rc = -EHOSTDOWN; |
2909 | spin_unlock(&GlobalMid_Lock); | ||
2859 | 2910 | ||
2860 | } | ||
2861 | first_time = 1; | ||
2862 | } | 2911 | } |
2863 | 2912 | ||
2864 | if (rc) | 2913 | return rc; |
2865 | goto ss_err_exit; | 2914 | } |
2915 | |||
2916 | |||
2917 | int cifs_setup_session(unsigned int xid, struct cifsSesInfo *ses, | ||
2918 | struct nls_table *nls_info) | ||
2919 | { | ||
2920 | int rc = 0; | ||
2921 | struct TCP_Server_Info *server = ses->server; | ||
2866 | 2922 | ||
2867 | pSesInfo->flags = 0; | 2923 | ses->flags = 0; |
2868 | pSesInfo->capabilities = server->capabilities; | 2924 | ses->capabilities = server->capabilities; |
2869 | if (linuxExtEnabled == 0) | 2925 | if (linuxExtEnabled == 0) |
2870 | pSesInfo->capabilities &= (~CAP_UNIX); | 2926 | ses->capabilities &= (~CAP_UNIX); |
2871 | 2927 | ||
2872 | cFYI(1, ("Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d", | 2928 | cFYI(1, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d", |
2873 | server->secMode, server->capabilities, server->timeAdj)); | 2929 | server->secMode, server->capabilities, server->timeAdj); |
2874 | 2930 | ||
2875 | rc = CIFS_SessSetup(xid, pSesInfo, first_time, nls_info); | 2931 | rc = CIFS_SessSetup(xid, ses, nls_info); |
2876 | if (rc) { | 2932 | if (rc) { |
2877 | cERROR(1, ("Send error in SessSetup = %d", rc)); | 2933 | cERROR(1, "Send error in SessSetup = %d", rc); |
2878 | } else { | 2934 | } else { |
2879 | cFYI(1, ("CIFS Session Established successfully")); | 2935 | cFYI(1, "CIFS Session Established successfully"); |
2880 | spin_lock(&GlobalMid_Lock); | 2936 | spin_lock(&GlobalMid_Lock); |
2881 | pSesInfo->status = CifsGood; | 2937 | ses->status = CifsGood; |
2882 | pSesInfo->need_reconnect = false; | 2938 | ses->need_reconnect = false; |
2883 | spin_unlock(&GlobalMid_Lock); | 2939 | spin_unlock(&GlobalMid_Lock); |
2884 | } | 2940 | } |
2885 | 2941 | ||
2886 | ss_err_exit: | ||
2887 | return rc; | 2942 | return rc; |
2888 | } | 2943 | } |
2889 | 2944 | ||
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index e9f7ecc2714b..391816b461ca 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -73,7 +73,7 @@ cifs_bp_rename_retry: | |||
73 | namelen += (1 + temp->d_name.len); | 73 | namelen += (1 + temp->d_name.len); |
74 | temp = temp->d_parent; | 74 | temp = temp->d_parent; |
75 | if (temp == NULL) { | 75 | if (temp == NULL) { |
76 | cERROR(1, ("corrupt dentry")); | 76 | cERROR(1, "corrupt dentry"); |
77 | return NULL; | 77 | return NULL; |
78 | } | 78 | } |
79 | } | 79 | } |
@@ -90,19 +90,18 @@ cifs_bp_rename_retry: | |||
90 | full_path[namelen] = dirsep; | 90 | full_path[namelen] = dirsep; |
91 | strncpy(full_path + namelen + 1, temp->d_name.name, | 91 | strncpy(full_path + namelen + 1, temp->d_name.name, |
92 | temp->d_name.len); | 92 | temp->d_name.len); |
93 | cFYI(0, ("name: %s", full_path + namelen)); | 93 | cFYI(0, "name: %s", full_path + namelen); |
94 | } | 94 | } |
95 | temp = temp->d_parent; | 95 | temp = temp->d_parent; |
96 | if (temp == NULL) { | 96 | if (temp == NULL) { |
97 | cERROR(1, ("corrupt dentry")); | 97 | cERROR(1, "corrupt dentry"); |
98 | kfree(full_path); | 98 | kfree(full_path); |
99 | return NULL; | 99 | return NULL; |
100 | } | 100 | } |
101 | } | 101 | } |
102 | if (namelen != pplen + dfsplen) { | 102 | if (namelen != pplen + dfsplen) { |
103 | cERROR(1, | 103 | cERROR(1, "did not end path lookup where expected namelen is %d", |
104 | ("did not end path lookup where expected namelen is %d", | 104 | namelen); |
105 | namelen)); | ||
106 | /* presumably this is only possible if racing with a rename | 105 | /* presumably this is only possible if racing with a rename |
107 | of one of the parent directories (we can not lock the dentries | 106 | of one of the parent directories (we can not lock the dentries |
108 | above us to prevent this, but retrying should be harmless) */ | 107 | above us to prevent this, but retrying should be harmless) */ |
@@ -130,6 +129,12 @@ cifs_bp_rename_retry: | |||
130 | return full_path; | 129 | return full_path; |
131 | } | 130 | } |
132 | 131 | ||
132 | /* | ||
133 | * When called with struct file pointer set to NULL, there is no way we could | ||
134 | * update file->private_data, but getting it stuck on openFileList provides a | ||
135 | * way to access it from cifs_fill_filedata and thereby set file->private_data | ||
136 | * from cifs_open. | ||
137 | */ | ||
133 | struct cifsFileInfo * | 138 | struct cifsFileInfo * |
134 | cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle, | 139 | cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle, |
135 | struct file *file, struct vfsmount *mnt, unsigned int oflags) | 140 | struct file *file, struct vfsmount *mnt, unsigned int oflags) |
@@ -173,7 +178,7 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle, | |||
173 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | 178 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { |
174 | pCifsInode->clientCanCacheAll = true; | 179 | pCifsInode->clientCanCacheAll = true; |
175 | pCifsInode->clientCanCacheRead = true; | 180 | pCifsInode->clientCanCacheRead = true; |
176 | cFYI(1, ("Exclusive Oplock inode %p", newinode)); | 181 | cFYI(1, "Exclusive Oplock inode %p", newinode); |
177 | } else if ((oplock & 0xF) == OPLOCK_READ) | 182 | } else if ((oplock & 0xF) == OPLOCK_READ) |
178 | pCifsInode->clientCanCacheRead = true; | 183 | pCifsInode->clientCanCacheRead = true; |
179 | } | 184 | } |
@@ -183,16 +188,17 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle, | |||
183 | } | 188 | } |
184 | 189 | ||
185 | int cifs_posix_open(char *full_path, struct inode **pinode, | 190 | int cifs_posix_open(char *full_path, struct inode **pinode, |
186 | struct vfsmount *mnt, int mode, int oflags, | 191 | struct vfsmount *mnt, struct super_block *sb, |
187 | __u32 *poplock, __u16 *pnetfid, int xid) | 192 | int mode, int oflags, |
193 | __u32 *poplock, __u16 *pnetfid, int xid) | ||
188 | { | 194 | { |
189 | int rc; | 195 | int rc; |
190 | FILE_UNIX_BASIC_INFO *presp_data; | 196 | FILE_UNIX_BASIC_INFO *presp_data; |
191 | __u32 posix_flags = 0; | 197 | __u32 posix_flags = 0; |
192 | struct cifs_sb_info *cifs_sb = CIFS_SB(mnt->mnt_sb); | 198 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
193 | struct cifs_fattr fattr; | 199 | struct cifs_fattr fattr; |
194 | 200 | ||
195 | cFYI(1, ("posix open %s", full_path)); | 201 | cFYI(1, "posix open %s", full_path); |
196 | 202 | ||
197 | presp_data = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL); | 203 | presp_data = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL); |
198 | if (presp_data == NULL) | 204 | if (presp_data == NULL) |
@@ -242,7 +248,8 @@ int cifs_posix_open(char *full_path, struct inode **pinode, | |||
242 | 248 | ||
243 | /* get new inode and set it up */ | 249 | /* get new inode and set it up */ |
244 | if (*pinode == NULL) { | 250 | if (*pinode == NULL) { |
245 | *pinode = cifs_iget(mnt->mnt_sb, &fattr); | 251 | cifs_fill_uniqueid(sb, &fattr); |
252 | *pinode = cifs_iget(sb, &fattr); | ||
246 | if (!*pinode) { | 253 | if (!*pinode) { |
247 | rc = -ENOMEM; | 254 | rc = -ENOMEM; |
248 | goto posix_open_ret; | 255 | goto posix_open_ret; |
@@ -251,7 +258,18 @@ int cifs_posix_open(char *full_path, struct inode **pinode, | |||
251 | cifs_fattr_to_inode(*pinode, &fattr); | 258 | cifs_fattr_to_inode(*pinode, &fattr); |
252 | } | 259 | } |
253 | 260 | ||
254 | cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt, oflags); | 261 | /* |
262 | * cifs_fill_filedata() takes care of setting cifsFileInfo pointer to | ||
263 | * file->private_data. | ||
264 | */ | ||
265 | if (mnt) { | ||
266 | struct cifsFileInfo *pfile_info; | ||
267 | |||
268 | pfile_info = cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt, | ||
269 | oflags); | ||
270 | if (pfile_info == NULL) | ||
271 | rc = -ENOMEM; | ||
272 | } | ||
255 | 273 | ||
256 | posix_open_ret: | 274 | posix_open_ret: |
257 | kfree(presp_data); | 275 | kfree(presp_data); |
@@ -315,13 +333,14 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
315 | if (nd && (nd->flags & LOOKUP_OPEN)) | 333 | if (nd && (nd->flags & LOOKUP_OPEN)) |
316 | oflags = nd->intent.open.flags; | 334 | oflags = nd->intent.open.flags; |
317 | else | 335 | else |
318 | oflags = FMODE_READ; | 336 | oflags = FMODE_READ | SMB_O_CREAT; |
319 | 337 | ||
320 | if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) && | 338 | if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) && |
321 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & | 339 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
322 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { | 340 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
323 | rc = cifs_posix_open(full_path, &newinode, nd->path.mnt, | 341 | rc = cifs_posix_open(full_path, &newinode, |
324 | mode, oflags, &oplock, &fileHandle, xid); | 342 | nd ? nd->path.mnt : NULL, |
343 | inode->i_sb, mode, oflags, &oplock, &fileHandle, xid); | ||
325 | /* EIO could indicate that (posix open) operation is not | 344 | /* EIO could indicate that (posix open) operation is not |
326 | supported, despite what server claimed in capability | 345 | supported, despite what server claimed in capability |
327 | negotation. EREMOTE indicates DFS junction, which is not | 346 | negotation. EREMOTE indicates DFS junction, which is not |
@@ -358,7 +377,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
358 | else if ((oflags & O_CREAT) == O_CREAT) | 377 | else if ((oflags & O_CREAT) == O_CREAT) |
359 | disposition = FILE_OPEN_IF; | 378 | disposition = FILE_OPEN_IF; |
360 | else | 379 | else |
361 | cFYI(1, ("Create flag not set in create function")); | 380 | cFYI(1, "Create flag not set in create function"); |
362 | } | 381 | } |
363 | 382 | ||
364 | /* BB add processing to set equivalent of mode - e.g. via CreateX with | 383 | /* BB add processing to set equivalent of mode - e.g. via CreateX with |
@@ -394,7 +413,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
394 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 413 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
395 | } | 414 | } |
396 | if (rc) { | 415 | if (rc) { |
397 | cFYI(1, ("cifs_create returned 0x%x", rc)); | 416 | cFYI(1, "cifs_create returned 0x%x", rc); |
398 | goto cifs_create_out; | 417 | goto cifs_create_out; |
399 | } | 418 | } |
400 | 419 | ||
@@ -457,15 +476,22 @@ cifs_create_set_dentry: | |||
457 | if (rc == 0) | 476 | if (rc == 0) |
458 | setup_cifs_dentry(tcon, direntry, newinode); | 477 | setup_cifs_dentry(tcon, direntry, newinode); |
459 | else | 478 | else |
460 | cFYI(1, ("Create worked, get_inode_info failed rc = %d", rc)); | 479 | cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); |
461 | 480 | ||
462 | /* nfsd case - nfs srv does not set nd */ | 481 | /* nfsd case - nfs srv does not set nd */ |
463 | if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) { | 482 | if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) { |
464 | /* mknod case - do not leave file open */ | 483 | /* mknod case - do not leave file open */ |
465 | CIFSSMBClose(xid, tcon, fileHandle); | 484 | CIFSSMBClose(xid, tcon, fileHandle); |
466 | } else if (!(posix_create) && (newinode)) { | 485 | } else if (!(posix_create) && (newinode)) { |
467 | cifs_new_fileinfo(newinode, fileHandle, NULL, | 486 | struct cifsFileInfo *pfile_info; |
468 | nd->path.mnt, oflags); | 487 | /* |
488 | * cifs_fill_filedata() takes care of setting cifsFileInfo | ||
489 | * pointer to file->private_data. | ||
490 | */ | ||
491 | pfile_info = cifs_new_fileinfo(newinode, fileHandle, NULL, | ||
492 | nd->path.mnt, oflags); | ||
493 | if (pfile_info == NULL) | ||
494 | rc = -ENOMEM; | ||
469 | } | 495 | } |
470 | cifs_create_out: | 496 | cifs_create_out: |
471 | kfree(buf); | 497 | kfree(buf); |
@@ -531,7 +557,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, | |||
531 | u16 fileHandle; | 557 | u16 fileHandle; |
532 | FILE_ALL_INFO *buf; | 558 | FILE_ALL_INFO *buf; |
533 | 559 | ||
534 | cFYI(1, ("sfu compat create special file")); | 560 | cFYI(1, "sfu compat create special file"); |
535 | 561 | ||
536 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 562 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
537 | if (buf == NULL) { | 563 | if (buf == NULL) { |
@@ -616,8 +642,8 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
616 | 642 | ||
617 | xid = GetXid(); | 643 | xid = GetXid(); |
618 | 644 | ||
619 | cFYI(1, ("parent inode = 0x%p name is: %s and dentry = 0x%p", | 645 | cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p", |
620 | parent_dir_inode, direntry->d_name.name, direntry)); | 646 | parent_dir_inode, direntry->d_name.name, direntry); |
621 | 647 | ||
622 | /* check whether path exists */ | 648 | /* check whether path exists */ |
623 | 649 | ||
@@ -632,7 +658,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
632 | int i; | 658 | int i; |
633 | for (i = 0; i < direntry->d_name.len; i++) | 659 | for (i = 0; i < direntry->d_name.len; i++) |
634 | if (direntry->d_name.name[i] == '\\') { | 660 | if (direntry->d_name.name[i] == '\\') { |
635 | cFYI(1, ("Invalid file name")); | 661 | cFYI(1, "Invalid file name"); |
636 | FreeXid(xid); | 662 | FreeXid(xid); |
637 | return ERR_PTR(-EINVAL); | 663 | return ERR_PTR(-EINVAL); |
638 | } | 664 | } |
@@ -657,11 +683,11 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
657 | } | 683 | } |
658 | 684 | ||
659 | if (direntry->d_inode != NULL) { | 685 | if (direntry->d_inode != NULL) { |
660 | cFYI(1, ("non-NULL inode in lookup")); | 686 | cFYI(1, "non-NULL inode in lookup"); |
661 | } else { | 687 | } else { |
662 | cFYI(1, ("NULL inode in lookup")); | 688 | cFYI(1, "NULL inode in lookup"); |
663 | } | 689 | } |
664 | cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode)); | 690 | cFYI(1, "Full path: %s inode = 0x%p", full_path, direntry->d_inode); |
665 | 691 | ||
666 | /* Posix open is only called (at lookup time) for file create now. | 692 | /* Posix open is only called (at lookup time) for file create now. |
667 | * For opens (rather than creates), because we do not know if it | 693 | * For opens (rather than creates), because we do not know if it |
@@ -678,6 +704,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
678 | (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open && | 704 | (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open && |
679 | (nd->intent.open.flags & O_CREAT)) { | 705 | (nd->intent.open.flags & O_CREAT)) { |
680 | rc = cifs_posix_open(full_path, &newInode, nd->path.mnt, | 706 | rc = cifs_posix_open(full_path, &newInode, nd->path.mnt, |
707 | parent_dir_inode->i_sb, | ||
681 | nd->intent.open.create_mode, | 708 | nd->intent.open.create_mode, |
682 | nd->intent.open.flags, &oplock, | 709 | nd->intent.open.flags, &oplock, |
683 | &fileHandle, xid); | 710 | &fileHandle, xid); |
@@ -723,7 +750,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, | |||
723 | /* if it was once a directory (but how can we tell?) we could do | 750 | /* if it was once a directory (but how can we tell?) we could do |
724 | shrink_dcache_parent(direntry); */ | 751 | shrink_dcache_parent(direntry); */ |
725 | } else if (rc != -EACCES) { | 752 | } else if (rc != -EACCES) { |
726 | cERROR(1, ("Unexpected lookup error %d", rc)); | 753 | cERROR(1, "Unexpected lookup error %d", rc); |
727 | /* We special case check for Access Denied - since that | 754 | /* We special case check for Access Denied - since that |
728 | is a common return code */ | 755 | is a common return code */ |
729 | } | 756 | } |
@@ -742,8 +769,8 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd) | |||
742 | if (cifs_revalidate_dentry(direntry)) | 769 | if (cifs_revalidate_dentry(direntry)) |
743 | return 0; | 770 | return 0; |
744 | } else { | 771 | } else { |
745 | cFYI(1, ("neg dentry 0x%p name = %s", | 772 | cFYI(1, "neg dentry 0x%p name = %s", |
746 | direntry, direntry->d_name.name)); | 773 | direntry, direntry->d_name.name); |
747 | if (time_after(jiffies, direntry->d_time + HZ) || | 774 | if (time_after(jiffies, direntry->d_time + HZ) || |
748 | !lookupCacheEnabled) { | 775 | !lookupCacheEnabled) { |
749 | d_drop(direntry); | 776 | d_drop(direntry); |
@@ -758,7 +785,7 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd) | |||
758 | { | 785 | { |
759 | int rc = 0; | 786 | int rc = 0; |
760 | 787 | ||
761 | cFYI(1, ("In cifs d_delete, name = %s", direntry->d_name.name)); | 788 | cFYI(1, "In cifs d_delete, name = %s", direntry->d_name.name); |
762 | 789 | ||
763 | return rc; | 790 | return rc; |
764 | } */ | 791 | } */ |
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c index 6f8a0e3fb25b..4db2c5e7283f 100644 --- a/fs/cifs/dns_resolve.c +++ b/fs/cifs/dns_resolve.c | |||
@@ -106,14 +106,14 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) | |||
106 | /* search for server name delimiter */ | 106 | /* search for server name delimiter */ |
107 | len = strlen(unc); | 107 | len = strlen(unc); |
108 | if (len < 3) { | 108 | if (len < 3) { |
109 | cFYI(1, ("%s: unc is too short: %s", __func__, unc)); | 109 | cFYI(1, "%s: unc is too short: %s", __func__, unc); |
110 | return -EINVAL; | 110 | return -EINVAL; |
111 | } | 111 | } |
112 | len -= 2; | 112 | len -= 2; |
113 | name = memchr(unc+2, '\\', len); | 113 | name = memchr(unc+2, '\\', len); |
114 | if (!name) { | 114 | if (!name) { |
115 | cFYI(1, ("%s: probably server name is whole unc: %s", | 115 | cFYI(1, "%s: probably server name is whole unc: %s", |
116 | __func__, unc)); | 116 | __func__, unc); |
117 | } else { | 117 | } else { |
118 | len = (name - unc) - 2/* leading // */; | 118 | len = (name - unc) - 2/* leading // */; |
119 | } | 119 | } |
@@ -127,8 +127,8 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) | |||
127 | name[len] = 0; | 127 | name[len] = 0; |
128 | 128 | ||
129 | if (is_ip(name)) { | 129 | if (is_ip(name)) { |
130 | cFYI(1, ("%s: it is IP, skipping dns upcall: %s", | 130 | cFYI(1, "%s: it is IP, skipping dns upcall: %s", |
131 | __func__, name)); | 131 | __func__, name); |
132 | data = name; | 132 | data = name; |
133 | goto skip_upcall; | 133 | goto skip_upcall; |
134 | } | 134 | } |
@@ -138,7 +138,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) | |||
138 | len = rkey->type_data.x[0]; | 138 | len = rkey->type_data.x[0]; |
139 | data = rkey->payload.data; | 139 | data = rkey->payload.data; |
140 | } else { | 140 | } else { |
141 | cERROR(1, ("%s: unable to resolve: %s", __func__, name)); | 141 | cERROR(1, "%s: unable to resolve: %s", __func__, name); |
142 | goto out; | 142 | goto out; |
143 | } | 143 | } |
144 | 144 | ||
@@ -148,10 +148,10 @@ skip_upcall: | |||
148 | if (*ip_addr) { | 148 | if (*ip_addr) { |
149 | memcpy(*ip_addr, data, len + 1); | 149 | memcpy(*ip_addr, data, len + 1); |
150 | if (!IS_ERR(rkey)) | 150 | if (!IS_ERR(rkey)) |
151 | cFYI(1, ("%s: resolved: %s to %s", __func__, | 151 | cFYI(1, "%s: resolved: %s to %s", __func__, |
152 | name, | 152 | name, |
153 | *ip_addr | 153 | *ip_addr |
154 | )); | 154 | ); |
155 | rc = 0; | 155 | rc = 0; |
156 | } else { | 156 | } else { |
157 | rc = -ENOMEM; | 157 | rc = -ENOMEM; |
diff --git a/fs/cifs/export.c b/fs/cifs/export.c index 6177f7cca16a..993f82045bf6 100644 --- a/fs/cifs/export.c +++ b/fs/cifs/export.c | |||
@@ -49,7 +49,7 @@ | |||
49 | static struct dentry *cifs_get_parent(struct dentry *dentry) | 49 | static struct dentry *cifs_get_parent(struct dentry *dentry) |
50 | { | 50 | { |
51 | /* BB need to add code here eventually to enable export via NFSD */ | 51 | /* BB need to add code here eventually to enable export via NFSD */ |
52 | cFYI(1, ("get parent for %p", dentry)); | 52 | cFYI(1, "get parent for %p", dentry); |
53 | return ERR_PTR(-EACCES); | 53 | return ERR_PTR(-EACCES); |
54 | } | 54 | } |
55 | 55 | ||
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 9b11a8f56f3a..a83541ec9713 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * vfs operations that deal with files | 4 | * vfs operations that deal with files |
5 | * | 5 | * |
6 | * Copyright (C) International Business Machines Corp., 2002,2007 | 6 | * Copyright (C) International Business Machines Corp., 2002,2010 |
7 | * Author(s): Steve French (sfrench@us.ibm.com) | 7 | * Author(s): Steve French (sfrench@us.ibm.com) |
8 | * Jeremy Allison (jra@samba.org) | 8 | * Jeremy Allison (jra@samba.org) |
9 | * | 9 | * |
@@ -108,8 +108,7 @@ static inline int cifs_get_disposition(unsigned int flags) | |||
108 | /* all arguments to this function must be checked for validity in caller */ | 108 | /* all arguments to this function must be checked for validity in caller */ |
109 | static inline int | 109 | static inline int |
110 | cifs_posix_open_inode_helper(struct inode *inode, struct file *file, | 110 | cifs_posix_open_inode_helper(struct inode *inode, struct file *file, |
111 | struct cifsInodeInfo *pCifsInode, | 111 | struct cifsInodeInfo *pCifsInode, __u32 oplock, |
112 | struct cifsFileInfo *pCifsFile, __u32 oplock, | ||
113 | u16 netfid) | 112 | u16 netfid) |
114 | { | 113 | { |
115 | 114 | ||
@@ -136,15 +135,15 @@ cifs_posix_open_inode_helper(struct inode *inode, struct file *file, | |||
136 | if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) && | 135 | if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) && |
137 | (file->f_path.dentry->d_inode->i_size == | 136 | (file->f_path.dentry->d_inode->i_size == |
138 | (loff_t)le64_to_cpu(buf->EndOfFile))) { | 137 | (loff_t)le64_to_cpu(buf->EndOfFile))) { |
139 | cFYI(1, ("inode unchanged on server")); | 138 | cFYI(1, "inode unchanged on server"); |
140 | } else { | 139 | } else { |
141 | if (file->f_path.dentry->d_inode->i_mapping) { | 140 | if (file->f_path.dentry->d_inode->i_mapping) { |
142 | rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping); | 141 | rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping); |
143 | if (rc != 0) | 142 | if (rc != 0) |
144 | CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc; | 143 | CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc; |
145 | } | 144 | } |
146 | cFYI(1, ("invalidating remote inode since open detected it " | 145 | cFYI(1, "invalidating remote inode since open detected it " |
147 | "changed")); | 146 | "changed"); |
148 | invalidate_remote_inode(file->f_path.dentry->d_inode); | 147 | invalidate_remote_inode(file->f_path.dentry->d_inode); |
149 | } */ | 148 | } */ |
150 | 149 | ||
@@ -152,8 +151,8 @@ psx_client_can_cache: | |||
152 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | 151 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { |
153 | pCifsInode->clientCanCacheAll = true; | 152 | pCifsInode->clientCanCacheAll = true; |
154 | pCifsInode->clientCanCacheRead = true; | 153 | pCifsInode->clientCanCacheRead = true; |
155 | cFYI(1, ("Exclusive Oplock granted on inode %p", | 154 | cFYI(1, "Exclusive Oplock granted on inode %p", |
156 | file->f_path.dentry->d_inode)); | 155 | file->f_path.dentry->d_inode); |
157 | } else if ((oplock & 0xF) == OPLOCK_READ) | 156 | } else if ((oplock & 0xF) == OPLOCK_READ) |
158 | pCifsInode->clientCanCacheRead = true; | 157 | pCifsInode->clientCanCacheRead = true; |
159 | 158 | ||
@@ -190,8 +189,8 @@ cifs_fill_filedata(struct file *file) | |||
190 | if (file->private_data != NULL) { | 189 | if (file->private_data != NULL) { |
191 | return pCifsFile; | 190 | return pCifsFile; |
192 | } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL)) | 191 | } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL)) |
193 | cERROR(1, ("could not find file instance for " | 192 | cERROR(1, "could not find file instance for " |
194 | "new file %p", file)); | 193 | "new file %p", file); |
195 | return NULL; | 194 | return NULL; |
196 | } | 195 | } |
197 | 196 | ||
@@ -217,7 +216,7 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file, | |||
217 | if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) && | 216 | if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) && |
218 | (file->f_path.dentry->d_inode->i_size == | 217 | (file->f_path.dentry->d_inode->i_size == |
219 | (loff_t)le64_to_cpu(buf->EndOfFile))) { | 218 | (loff_t)le64_to_cpu(buf->EndOfFile))) { |
220 | cFYI(1, ("inode unchanged on server")); | 219 | cFYI(1, "inode unchanged on server"); |
221 | } else { | 220 | } else { |
222 | if (file->f_path.dentry->d_inode->i_mapping) { | 221 | if (file->f_path.dentry->d_inode->i_mapping) { |
223 | /* BB no need to lock inode until after invalidate | 222 | /* BB no need to lock inode until after invalidate |
@@ -226,8 +225,8 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file, | |||
226 | if (rc != 0) | 225 | if (rc != 0) |
227 | CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc; | 226 | CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc; |
228 | } | 227 | } |
229 | cFYI(1, ("invalidating remote inode since open detected it " | 228 | cFYI(1, "invalidating remote inode since open detected it " |
230 | "changed")); | 229 | "changed"); |
231 | invalidate_remote_inode(file->f_path.dentry->d_inode); | 230 | invalidate_remote_inode(file->f_path.dentry->d_inode); |
232 | } | 231 | } |
233 | 232 | ||
@@ -242,8 +241,8 @@ client_can_cache: | |||
242 | if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) { | 241 | if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) { |
243 | pCifsInode->clientCanCacheAll = true; | 242 | pCifsInode->clientCanCacheAll = true; |
244 | pCifsInode->clientCanCacheRead = true; | 243 | pCifsInode->clientCanCacheRead = true; |
245 | cFYI(1, ("Exclusive Oplock granted on inode %p", | 244 | cFYI(1, "Exclusive Oplock granted on inode %p", |
246 | file->f_path.dentry->d_inode)); | 245 | file->f_path.dentry->d_inode); |
247 | } else if ((*oplock & 0xF) == OPLOCK_READ) | 246 | } else if ((*oplock & 0xF) == OPLOCK_READ) |
248 | pCifsInode->clientCanCacheRead = true; | 247 | pCifsInode->clientCanCacheRead = true; |
249 | 248 | ||
@@ -285,8 +284,8 @@ int cifs_open(struct inode *inode, struct file *file) | |||
285 | return rc; | 284 | return rc; |
286 | } | 285 | } |
287 | 286 | ||
288 | cFYI(1, ("inode = 0x%p file flags are 0x%x for %s", | 287 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", |
289 | inode, file->f_flags, full_path)); | 288 | inode, file->f_flags, full_path); |
290 | 289 | ||
291 | if (oplockEnabled) | 290 | if (oplockEnabled) |
292 | oplock = REQ_OPLOCK; | 291 | oplock = REQ_OPLOCK; |
@@ -298,27 +297,29 @@ int cifs_open(struct inode *inode, struct file *file) | |||
298 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & | 297 | (CIFS_UNIX_POSIX_PATH_OPS_CAP & |
299 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { | 298 | le64_to_cpu(tcon->fsUnixInfo.Capability))) { |
300 | int oflags = (int) cifs_posix_convert_flags(file->f_flags); | 299 | int oflags = (int) cifs_posix_convert_flags(file->f_flags); |
300 | oflags |= SMB_O_CREAT; | ||
301 | /* can not refresh inode info since size could be stale */ | 301 | /* can not refresh inode info since size could be stale */ |
302 | rc = cifs_posix_open(full_path, &inode, file->f_path.mnt, | 302 | rc = cifs_posix_open(full_path, &inode, file->f_path.mnt, |
303 | cifs_sb->mnt_file_mode /* ignored */, | 303 | inode->i_sb, |
304 | oflags, &oplock, &netfid, xid); | 304 | cifs_sb->mnt_file_mode /* ignored */, |
305 | oflags, &oplock, &netfid, xid); | ||
305 | if (rc == 0) { | 306 | if (rc == 0) { |
306 | cFYI(1, ("posix open succeeded")); | 307 | cFYI(1, "posix open succeeded"); |
307 | /* no need for special case handling of setting mode | 308 | /* no need for special case handling of setting mode |
308 | on read only files needed here */ | 309 | on read only files needed here */ |
309 | 310 | ||
310 | pCifsFile = cifs_fill_filedata(file); | 311 | pCifsFile = cifs_fill_filedata(file); |
311 | cifs_posix_open_inode_helper(inode, file, pCifsInode, | 312 | cifs_posix_open_inode_helper(inode, file, pCifsInode, |
312 | pCifsFile, oplock, netfid); | 313 | oplock, netfid); |
313 | goto out; | 314 | goto out; |
314 | } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 315 | } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
315 | if (tcon->ses->serverNOS) | 316 | if (tcon->ses->serverNOS) |
316 | cERROR(1, ("server %s of type %s returned" | 317 | cERROR(1, "server %s of type %s returned" |
317 | " unexpected error on SMB posix open" | 318 | " unexpected error on SMB posix open" |
318 | ", disabling posix open support." | 319 | ", disabling posix open support." |
319 | " Check if server update available.", | 320 | " Check if server update available.", |
320 | tcon->ses->serverName, | 321 | tcon->ses->serverName, |
321 | tcon->ses->serverNOS)); | 322 | tcon->ses->serverNOS); |
322 | tcon->broken_posix_open = true; | 323 | tcon->broken_posix_open = true; |
323 | } else if ((rc != -EIO) && (rc != -EREMOTE) && | 324 | } else if ((rc != -EIO) && (rc != -EREMOTE) && |
324 | (rc != -EOPNOTSUPP)) /* path not found or net err */ | 325 | (rc != -EOPNOTSUPP)) /* path not found or net err */ |
@@ -386,7 +387,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
386 | & CIFS_MOUNT_MAP_SPECIAL_CHR); | 387 | & CIFS_MOUNT_MAP_SPECIAL_CHR); |
387 | } | 388 | } |
388 | if (rc) { | 389 | if (rc) { |
389 | cFYI(1, ("cifs_open returned 0x%x", rc)); | 390 | cFYI(1, "cifs_open returned 0x%x", rc); |
390 | goto out; | 391 | goto out; |
391 | } | 392 | } |
392 | 393 | ||
@@ -469,7 +470,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
469 | } | 470 | } |
470 | 471 | ||
471 | if (file->f_path.dentry == NULL) { | 472 | if (file->f_path.dentry == NULL) { |
472 | cERROR(1, ("no valid name if dentry freed")); | 473 | cERROR(1, "no valid name if dentry freed"); |
473 | dump_stack(); | 474 | dump_stack(); |
474 | rc = -EBADF; | 475 | rc = -EBADF; |
475 | goto reopen_error_exit; | 476 | goto reopen_error_exit; |
@@ -477,7 +478,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush) | |||
477 | 478 | ||
478 | inode = file->f_path.dentry->d_inode; | 479 | inode = file->f_path.dentry->d_inode; |
479 | if (inode == NULL) { | 480 | if (inode == NULL) { |
480 | cERROR(1, ("inode not valid")); | 481 | cERROR(1, "inode not valid"); |
481 | dump_stack(); | 482 | dump_stack(); |
482 | rc = -EBADF; | 483 | rc = -EBADF; |
483 | goto reopen_error_exit; | 484 | goto reopen_error_exit; |
@@ -499,8 +500,8 @@ reopen_error_exit: | |||
499 | return rc; | 500 | return rc; |
500 | } | 501 | } |
501 | 502 | ||
502 | cFYI(1, ("inode = 0x%p file flags 0x%x for %s", | 503 | cFYI(1, "inode = 0x%p file flags 0x%x for %s", |
503 | inode, file->f_flags, full_path)); | 504 | inode, file->f_flags, full_path); |
504 | 505 | ||
505 | if (oplockEnabled) | 506 | if (oplockEnabled) |
506 | oplock = REQ_OPLOCK; | 507 | oplock = REQ_OPLOCK; |
@@ -513,10 +514,11 @@ reopen_error_exit: | |||
513 | int oflags = (int) cifs_posix_convert_flags(file->f_flags); | 514 | int oflags = (int) cifs_posix_convert_flags(file->f_flags); |
514 | /* can not refresh inode info since size could be stale */ | 515 | /* can not refresh inode info since size could be stale */ |
515 | rc = cifs_posix_open(full_path, NULL, file->f_path.mnt, | 516 | rc = cifs_posix_open(full_path, NULL, file->f_path.mnt, |
516 | cifs_sb->mnt_file_mode /* ignored */, | 517 | inode->i_sb, |
517 | oflags, &oplock, &netfid, xid); | 518 | cifs_sb->mnt_file_mode /* ignored */, |
519 | oflags, &oplock, &netfid, xid); | ||
518 | if (rc == 0) { | 520 | if (rc == 0) { |
519 | cFYI(1, ("posix reopen succeeded")); | 521 | cFYI(1, "posix reopen succeeded"); |
520 | goto reopen_success; | 522 | goto reopen_success; |
521 | } | 523 | } |
522 | /* fallthrough to retry open the old way on errors, especially | 524 | /* fallthrough to retry open the old way on errors, especially |
@@ -537,8 +539,8 @@ reopen_error_exit: | |||
537 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 539 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
538 | if (rc) { | 540 | if (rc) { |
539 | mutex_unlock(&pCifsFile->fh_mutex); | 541 | mutex_unlock(&pCifsFile->fh_mutex); |
540 | cFYI(1, ("cifs_open returned 0x%x", rc)); | 542 | cFYI(1, "cifs_open returned 0x%x", rc); |
541 | cFYI(1, ("oplock: %d", oplock)); | 543 | cFYI(1, "oplock: %d", oplock); |
542 | } else { | 544 | } else { |
543 | reopen_success: | 545 | reopen_success: |
544 | pCifsFile->netfid = netfid; | 546 | pCifsFile->netfid = netfid; |
@@ -570,8 +572,8 @@ reopen_success: | |||
570 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { | 572 | if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) { |
571 | pCifsInode->clientCanCacheAll = true; | 573 | pCifsInode->clientCanCacheAll = true; |
572 | pCifsInode->clientCanCacheRead = true; | 574 | pCifsInode->clientCanCacheRead = true; |
573 | cFYI(1, ("Exclusive Oplock granted on inode %p", | 575 | cFYI(1, "Exclusive Oplock granted on inode %p", |
574 | file->f_path.dentry->d_inode)); | 576 | file->f_path.dentry->d_inode); |
575 | } else if ((oplock & 0xF) == OPLOCK_READ) { | 577 | } else if ((oplock & 0xF) == OPLOCK_READ) { |
576 | pCifsInode->clientCanCacheRead = true; | 578 | pCifsInode->clientCanCacheRead = true; |
577 | pCifsInode->clientCanCacheAll = false; | 579 | pCifsInode->clientCanCacheAll = false; |
@@ -619,8 +621,7 @@ int cifs_close(struct inode *inode, struct file *file) | |||
619 | the struct would be in each open file, | 621 | the struct would be in each open file, |
620 | but this should give enough time to | 622 | but this should give enough time to |
621 | clear the socket */ | 623 | clear the socket */ |
622 | cFYI(DBG2, | 624 | cFYI(DBG2, "close delay, write pending"); |
623 | ("close delay, write pending")); | ||
624 | msleep(timeout); | 625 | msleep(timeout); |
625 | timeout *= 4; | 626 | timeout *= 4; |
626 | } | 627 | } |
@@ -653,7 +654,7 @@ int cifs_close(struct inode *inode, struct file *file) | |||
653 | 654 | ||
654 | read_lock(&GlobalSMBSeslock); | 655 | read_lock(&GlobalSMBSeslock); |
655 | if (list_empty(&(CIFS_I(inode)->openFileList))) { | 656 | if (list_empty(&(CIFS_I(inode)->openFileList))) { |
656 | cFYI(1, ("closing last open instance for inode %p", inode)); | 657 | cFYI(1, "closing last open instance for inode %p", inode); |
657 | /* if the file is not open we do not know if we can cache info | 658 | /* if the file is not open we do not know if we can cache info |
658 | on this inode, much less write behind and read ahead */ | 659 | on this inode, much less write behind and read ahead */ |
659 | CIFS_I(inode)->clientCanCacheRead = false; | 660 | CIFS_I(inode)->clientCanCacheRead = false; |
@@ -674,7 +675,7 @@ int cifs_closedir(struct inode *inode, struct file *file) | |||
674 | (struct cifsFileInfo *)file->private_data; | 675 | (struct cifsFileInfo *)file->private_data; |
675 | char *ptmp; | 676 | char *ptmp; |
676 | 677 | ||
677 | cFYI(1, ("Closedir inode = 0x%p", inode)); | 678 | cFYI(1, "Closedir inode = 0x%p", inode); |
678 | 679 | ||
679 | xid = GetXid(); | 680 | xid = GetXid(); |
680 | 681 | ||
@@ -685,22 +686,22 @@ int cifs_closedir(struct inode *inode, struct file *file) | |||
685 | 686 | ||
686 | pTcon = cifs_sb->tcon; | 687 | pTcon = cifs_sb->tcon; |
687 | 688 | ||
688 | cFYI(1, ("Freeing private data in close dir")); | 689 | cFYI(1, "Freeing private data in close dir"); |
689 | write_lock(&GlobalSMBSeslock); | 690 | write_lock(&GlobalSMBSeslock); |
690 | if (!pCFileStruct->srch_inf.endOfSearch && | 691 | if (!pCFileStruct->srch_inf.endOfSearch && |
691 | !pCFileStruct->invalidHandle) { | 692 | !pCFileStruct->invalidHandle) { |
692 | pCFileStruct->invalidHandle = true; | 693 | pCFileStruct->invalidHandle = true; |
693 | write_unlock(&GlobalSMBSeslock); | 694 | write_unlock(&GlobalSMBSeslock); |
694 | rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid); | 695 | rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid); |
695 | cFYI(1, ("Closing uncompleted readdir with rc %d", | 696 | cFYI(1, "Closing uncompleted readdir with rc %d", |
696 | rc)); | 697 | rc); |
697 | /* not much we can do if it fails anyway, ignore rc */ | 698 | /* not much we can do if it fails anyway, ignore rc */ |
698 | rc = 0; | 699 | rc = 0; |
699 | } else | 700 | } else |
700 | write_unlock(&GlobalSMBSeslock); | 701 | write_unlock(&GlobalSMBSeslock); |
701 | ptmp = pCFileStruct->srch_inf.ntwrk_buf_start; | 702 | ptmp = pCFileStruct->srch_inf.ntwrk_buf_start; |
702 | if (ptmp) { | 703 | if (ptmp) { |
703 | cFYI(1, ("closedir free smb buf in srch struct")); | 704 | cFYI(1, "closedir free smb buf in srch struct"); |
704 | pCFileStruct->srch_inf.ntwrk_buf_start = NULL; | 705 | pCFileStruct->srch_inf.ntwrk_buf_start = NULL; |
705 | if (pCFileStruct->srch_inf.smallBuf) | 706 | if (pCFileStruct->srch_inf.smallBuf) |
706 | cifs_small_buf_release(ptmp); | 707 | cifs_small_buf_release(ptmp); |
@@ -748,49 +749,49 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
748 | rc = -EACCES; | 749 | rc = -EACCES; |
749 | xid = GetXid(); | 750 | xid = GetXid(); |
750 | 751 | ||
751 | cFYI(1, ("Lock parm: 0x%x flockflags: " | 752 | cFYI(1, "Lock parm: 0x%x flockflags: " |
752 | "0x%x flocktype: 0x%x start: %lld end: %lld", | 753 | "0x%x flocktype: 0x%x start: %lld end: %lld", |
753 | cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start, | 754 | cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start, |
754 | pfLock->fl_end)); | 755 | pfLock->fl_end); |
755 | 756 | ||
756 | if (pfLock->fl_flags & FL_POSIX) | 757 | if (pfLock->fl_flags & FL_POSIX) |
757 | cFYI(1, ("Posix")); | 758 | cFYI(1, "Posix"); |
758 | if (pfLock->fl_flags & FL_FLOCK) | 759 | if (pfLock->fl_flags & FL_FLOCK) |
759 | cFYI(1, ("Flock")); | 760 | cFYI(1, "Flock"); |
760 | if (pfLock->fl_flags & FL_SLEEP) { | 761 | if (pfLock->fl_flags & FL_SLEEP) { |
761 | cFYI(1, ("Blocking lock")); | 762 | cFYI(1, "Blocking lock"); |
762 | wait_flag = true; | 763 | wait_flag = true; |
763 | } | 764 | } |
764 | if (pfLock->fl_flags & FL_ACCESS) | 765 | if (pfLock->fl_flags & FL_ACCESS) |
765 | cFYI(1, ("Process suspended by mandatory locking - " | 766 | cFYI(1, "Process suspended by mandatory locking - " |
766 | "not implemented yet")); | 767 | "not implemented yet"); |
767 | if (pfLock->fl_flags & FL_LEASE) | 768 | if (pfLock->fl_flags & FL_LEASE) |
768 | cFYI(1, ("Lease on file - not implemented yet")); | 769 | cFYI(1, "Lease on file - not implemented yet"); |
769 | if (pfLock->fl_flags & | 770 | if (pfLock->fl_flags & |
770 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE))) | 771 | (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE))) |
771 | cFYI(1, ("Unknown lock flags 0x%x", pfLock->fl_flags)); | 772 | cFYI(1, "Unknown lock flags 0x%x", pfLock->fl_flags); |
772 | 773 | ||
773 | if (pfLock->fl_type == F_WRLCK) { | 774 | if (pfLock->fl_type == F_WRLCK) { |
774 | cFYI(1, ("F_WRLCK ")); | 775 | cFYI(1, "F_WRLCK "); |
775 | numLock = 1; | 776 | numLock = 1; |
776 | } else if (pfLock->fl_type == F_UNLCK) { | 777 | } else if (pfLock->fl_type == F_UNLCK) { |
777 | cFYI(1, ("F_UNLCK")); | 778 | cFYI(1, "F_UNLCK"); |
778 | numUnlock = 1; | 779 | numUnlock = 1; |
779 | /* Check if unlock includes more than | 780 | /* Check if unlock includes more than |
780 | one lock range */ | 781 | one lock range */ |
781 | } else if (pfLock->fl_type == F_RDLCK) { | 782 | } else if (pfLock->fl_type == F_RDLCK) { |
782 | cFYI(1, ("F_RDLCK")); | 783 | cFYI(1, "F_RDLCK"); |
783 | lockType |= LOCKING_ANDX_SHARED_LOCK; | 784 | lockType |= LOCKING_ANDX_SHARED_LOCK; |
784 | numLock = 1; | 785 | numLock = 1; |
785 | } else if (pfLock->fl_type == F_EXLCK) { | 786 | } else if (pfLock->fl_type == F_EXLCK) { |
786 | cFYI(1, ("F_EXLCK")); | 787 | cFYI(1, "F_EXLCK"); |
787 | numLock = 1; | 788 | numLock = 1; |
788 | } else if (pfLock->fl_type == F_SHLCK) { | 789 | } else if (pfLock->fl_type == F_SHLCK) { |
789 | cFYI(1, ("F_SHLCK")); | 790 | cFYI(1, "F_SHLCK"); |
790 | lockType |= LOCKING_ANDX_SHARED_LOCK; | 791 | lockType |= LOCKING_ANDX_SHARED_LOCK; |
791 | numLock = 1; | 792 | numLock = 1; |
792 | } else | 793 | } else |
793 | cFYI(1, ("Unknown type of lock")); | 794 | cFYI(1, "Unknown type of lock"); |
794 | 795 | ||
795 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 796 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
796 | tcon = cifs_sb->tcon; | 797 | tcon = cifs_sb->tcon; |
@@ -833,8 +834,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
833 | 0 /* wait flag */ ); | 834 | 0 /* wait flag */ ); |
834 | pfLock->fl_type = F_UNLCK; | 835 | pfLock->fl_type = F_UNLCK; |
835 | if (rc != 0) | 836 | if (rc != 0) |
836 | cERROR(1, ("Error unlocking previously locked " | 837 | cERROR(1, "Error unlocking previously locked " |
837 | "range %d during test of lock", rc)); | 838 | "range %d during test of lock", rc); |
838 | rc = 0; | 839 | rc = 0; |
839 | 840 | ||
840 | } else { | 841 | } else { |
@@ -856,9 +857,9 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
856 | 0 /* wait flag */); | 857 | 0 /* wait flag */); |
857 | pfLock->fl_type = F_RDLCK; | 858 | pfLock->fl_type = F_RDLCK; |
858 | if (rc != 0) | 859 | if (rc != 0) |
859 | cERROR(1, ("Error unlocking " | 860 | cERROR(1, "Error unlocking " |
860 | "previously locked range %d " | 861 | "previously locked range %d " |
861 | "during test of lock", rc)); | 862 | "during test of lock", rc); |
862 | rc = 0; | 863 | rc = 0; |
863 | } else { | 864 | } else { |
864 | pfLock->fl_type = F_WRLCK; | 865 | pfLock->fl_type = F_WRLCK; |
@@ -923,9 +924,10 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
923 | 1, 0, li->type, false); | 924 | 1, 0, li->type, false); |
924 | if (stored_rc) | 925 | if (stored_rc) |
925 | rc = stored_rc; | 926 | rc = stored_rc; |
926 | 927 | else { | |
927 | list_del(&li->llist); | 928 | list_del(&li->llist); |
928 | kfree(li); | 929 | kfree(li); |
930 | } | ||
929 | } | 931 | } |
930 | } | 932 | } |
931 | mutex_unlock(&fid->lock_mutex); | 933 | mutex_unlock(&fid->lock_mutex); |
@@ -988,9 +990,8 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data, | |||
988 | 990 | ||
989 | pTcon = cifs_sb->tcon; | 991 | pTcon = cifs_sb->tcon; |
990 | 992 | ||
991 | /* cFYI(1, | 993 | /* cFYI(1, " write %d bytes to offset %lld of %s", write_size, |
992 | (" write %d bytes to offset %lld of %s", write_size, | 994 | *poffset, file->f_path.dentry->d_name.name); */ |
993 | *poffset, file->f_path.dentry->d_name.name)); */ | ||
994 | 995 | ||
995 | if (file->private_data == NULL) | 996 | if (file->private_data == NULL) |
996 | return -EBADF; | 997 | return -EBADF; |
@@ -1091,8 +1092,8 @@ static ssize_t cifs_write(struct file *file, const char *write_data, | |||
1091 | 1092 | ||
1092 | pTcon = cifs_sb->tcon; | 1093 | pTcon = cifs_sb->tcon; |
1093 | 1094 | ||
1094 | cFYI(1, ("write %zd bytes to offset %lld of %s", write_size, | 1095 | cFYI(1, "write %zd bytes to offset %lld of %s", write_size, |
1095 | *poffset, file->f_path.dentry->d_name.name)); | 1096 | *poffset, file->f_path.dentry->d_name.name); |
1096 | 1097 | ||
1097 | if (file->private_data == NULL) | 1098 | if (file->private_data == NULL) |
1098 | return -EBADF; | 1099 | return -EBADF; |
@@ -1233,7 +1234,7 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode) | |||
1233 | it being zero) during stress testcases so we need to check for it */ | 1234 | it being zero) during stress testcases so we need to check for it */ |
1234 | 1235 | ||
1235 | if (cifs_inode == NULL) { | 1236 | if (cifs_inode == NULL) { |
1236 | cERROR(1, ("Null inode passed to cifs_writeable_file")); | 1237 | cERROR(1, "Null inode passed to cifs_writeable_file"); |
1237 | dump_stack(); | 1238 | dump_stack(); |
1238 | return NULL; | 1239 | return NULL; |
1239 | } | 1240 | } |
@@ -1277,7 +1278,7 @@ refind_writable: | |||
1277 | again. Note that it would be bad | 1278 | again. Note that it would be bad |
1278 | to hold up writepages here (rather than | 1279 | to hold up writepages here (rather than |
1279 | in caller) with continuous retries */ | 1280 | in caller) with continuous retries */ |
1280 | cFYI(1, ("wp failed on reopen file")); | 1281 | cFYI(1, "wp failed on reopen file"); |
1281 | read_lock(&GlobalSMBSeslock); | 1282 | read_lock(&GlobalSMBSeslock); |
1282 | /* can not use this handle, no write | 1283 | /* can not use this handle, no write |
1283 | pending on this one after all */ | 1284 | pending on this one after all */ |
@@ -1353,7 +1354,7 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) | |||
1353 | else if (bytes_written < 0) | 1354 | else if (bytes_written < 0) |
1354 | rc = bytes_written; | 1355 | rc = bytes_written; |
1355 | } else { | 1356 | } else { |
1356 | cFYI(1, ("No writeable filehandles for inode")); | 1357 | cFYI(1, "No writeable filehandles for inode"); |
1357 | rc = -EIO; | 1358 | rc = -EIO; |
1358 | } | 1359 | } |
1359 | 1360 | ||
@@ -1525,7 +1526,7 @@ retry: | |||
1525 | */ | 1526 | */ |
1526 | open_file = find_writable_file(CIFS_I(mapping->host)); | 1527 | open_file = find_writable_file(CIFS_I(mapping->host)); |
1527 | if (!open_file) { | 1528 | if (!open_file) { |
1528 | cERROR(1, ("No writable handles for inode")); | 1529 | cERROR(1, "No writable handles for inode"); |
1529 | rc = -EBADF; | 1530 | rc = -EBADF; |
1530 | } else { | 1531 | } else { |
1531 | long_op = cifs_write_timeout(cifsi, offset); | 1532 | long_op = cifs_write_timeout(cifsi, offset); |
@@ -1538,8 +1539,8 @@ retry: | |||
1538 | cifs_update_eof(cifsi, offset, bytes_written); | 1539 | cifs_update_eof(cifsi, offset, bytes_written); |
1539 | 1540 | ||
1540 | if (rc || bytes_written < bytes_to_write) { | 1541 | if (rc || bytes_written < bytes_to_write) { |
1541 | cERROR(1, ("Write2 ret %d, wrote %d", | 1542 | cERROR(1, "Write2 ret %d, wrote %d", |
1542 | rc, bytes_written)); | 1543 | rc, bytes_written); |
1543 | /* BB what if continued retry is | 1544 | /* BB what if continued retry is |
1544 | requested via mount flags? */ | 1545 | requested via mount flags? */ |
1545 | if (rc == -ENOSPC) | 1546 | if (rc == -ENOSPC) |
@@ -1600,7 +1601,7 @@ static int cifs_writepage(struct page *page, struct writeback_control *wbc) | |||
1600 | /* BB add check for wbc flags */ | 1601 | /* BB add check for wbc flags */ |
1601 | page_cache_get(page); | 1602 | page_cache_get(page); |
1602 | if (!PageUptodate(page)) | 1603 | if (!PageUptodate(page)) |
1603 | cFYI(1, ("ppw - page not up to date")); | 1604 | cFYI(1, "ppw - page not up to date"); |
1604 | 1605 | ||
1605 | /* | 1606 | /* |
1606 | * Set the "writeback" flag, and clear "dirty" in the radix tree. | 1607 | * Set the "writeback" flag, and clear "dirty" in the radix tree. |
@@ -1629,8 +1630,8 @@ static int cifs_write_end(struct file *file, struct address_space *mapping, | |||
1629 | int rc; | 1630 | int rc; |
1630 | struct inode *inode = mapping->host; | 1631 | struct inode *inode = mapping->host; |
1631 | 1632 | ||
1632 | cFYI(1, ("write_end for page %p from pos %lld with %d bytes", | 1633 | cFYI(1, "write_end for page %p from pos %lld with %d bytes", |
1633 | page, pos, copied)); | 1634 | page, pos, copied); |
1634 | 1635 | ||
1635 | if (PageChecked(page)) { | 1636 | if (PageChecked(page)) { |
1636 | if (copied == len) | 1637 | if (copied == len) |
@@ -1686,8 +1687,8 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
1686 | 1687 | ||
1687 | xid = GetXid(); | 1688 | xid = GetXid(); |
1688 | 1689 | ||
1689 | cFYI(1, ("Sync file - name: %s datasync: 0x%x", | 1690 | cFYI(1, "Sync file - name: %s datasync: 0x%x", |
1690 | dentry->d_name.name, datasync)); | 1691 | dentry->d_name.name, datasync); |
1691 | 1692 | ||
1692 | rc = filemap_write_and_wait(inode->i_mapping); | 1693 | rc = filemap_write_and_wait(inode->i_mapping); |
1693 | if (rc == 0) { | 1694 | if (rc == 0) { |
@@ -1711,7 +1712,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
1711 | unsigned int rpages = 0; | 1712 | unsigned int rpages = 0; |
1712 | int rc = 0; | 1713 | int rc = 0; |
1713 | 1714 | ||
1714 | cFYI(1, ("sync page %p",page)); | 1715 | cFYI(1, "sync page %p", page); |
1715 | mapping = page->mapping; | 1716 | mapping = page->mapping; |
1716 | if (!mapping) | 1717 | if (!mapping) |
1717 | return 0; | 1718 | return 0; |
@@ -1722,7 +1723,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
1722 | /* fill in rpages then | 1723 | /* fill in rpages then |
1723 | result = cifs_pagein_inode(inode, index, rpages); */ /* BB finish */ | 1724 | result = cifs_pagein_inode(inode, index, rpages); */ /* BB finish */ |
1724 | 1725 | ||
1725 | /* cFYI(1, ("rpages is %d for sync page of Index %ld", rpages, index)); | 1726 | /* cFYI(1, "rpages is %d for sync page of Index %ld", rpages, index); |
1726 | 1727 | ||
1727 | #if 0 | 1728 | #if 0 |
1728 | if (rc < 0) | 1729 | if (rc < 0) |
@@ -1756,7 +1757,7 @@ int cifs_flush(struct file *file, fl_owner_t id) | |||
1756 | CIFS_I(inode)->write_behind_rc = 0; | 1757 | CIFS_I(inode)->write_behind_rc = 0; |
1757 | } | 1758 | } |
1758 | 1759 | ||
1759 | cFYI(1, ("Flush inode %p file %p rc %d", inode, file, rc)); | 1760 | cFYI(1, "Flush inode %p file %p rc %d", inode, file, rc); |
1760 | 1761 | ||
1761 | return rc; | 1762 | return rc; |
1762 | } | 1763 | } |
@@ -1788,7 +1789,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data, | |||
1788 | open_file = (struct cifsFileInfo *)file->private_data; | 1789 | open_file = (struct cifsFileInfo *)file->private_data; |
1789 | 1790 | ||
1790 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) | 1791 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
1791 | cFYI(1, ("attempting read on write only file instance")); | 1792 | cFYI(1, "attempting read on write only file instance"); |
1792 | 1793 | ||
1793 | for (total_read = 0, current_offset = read_data; | 1794 | for (total_read = 0, current_offset = read_data; |
1794 | read_size > total_read; | 1795 | read_size > total_read; |
@@ -1869,7 +1870,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, | |||
1869 | open_file = (struct cifsFileInfo *)file->private_data; | 1870 | open_file = (struct cifsFileInfo *)file->private_data; |
1870 | 1871 | ||
1871 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) | 1872 | if ((file->f_flags & O_ACCMODE) == O_WRONLY) |
1872 | cFYI(1, ("attempting read on write only file instance")); | 1873 | cFYI(1, "attempting read on write only file instance"); |
1873 | 1874 | ||
1874 | for (total_read = 0, current_offset = read_data; | 1875 | for (total_read = 0, current_offset = read_data; |
1875 | read_size > total_read; | 1876 | read_size > total_read; |
@@ -1920,7 +1921,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
1920 | xid = GetXid(); | 1921 | xid = GetXid(); |
1921 | rc = cifs_revalidate_file(file); | 1922 | rc = cifs_revalidate_file(file); |
1922 | if (rc) { | 1923 | if (rc) { |
1923 | cFYI(1, ("Validation prior to mmap failed, error=%d", rc)); | 1924 | cFYI(1, "Validation prior to mmap failed, error=%d", rc); |
1924 | FreeXid(xid); | 1925 | FreeXid(xid); |
1925 | return rc; | 1926 | return rc; |
1926 | } | 1927 | } |
@@ -1931,8 +1932,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) | |||
1931 | 1932 | ||
1932 | 1933 | ||
1933 | static void cifs_copy_cache_pages(struct address_space *mapping, | 1934 | static void cifs_copy_cache_pages(struct address_space *mapping, |
1934 | struct list_head *pages, int bytes_read, char *data, | 1935 | struct list_head *pages, int bytes_read, char *data) |
1935 | struct pagevec *plru_pvec) | ||
1936 | { | 1936 | { |
1937 | struct page *page; | 1937 | struct page *page; |
1938 | char *target; | 1938 | char *target; |
@@ -1944,10 +1944,10 @@ static void cifs_copy_cache_pages(struct address_space *mapping, | |||
1944 | page = list_entry(pages->prev, struct page, lru); | 1944 | page = list_entry(pages->prev, struct page, lru); |
1945 | list_del(&page->lru); | 1945 | list_del(&page->lru); |
1946 | 1946 | ||
1947 | if (add_to_page_cache(page, mapping, page->index, | 1947 | if (add_to_page_cache_lru(page, mapping, page->index, |
1948 | GFP_KERNEL)) { | 1948 | GFP_KERNEL)) { |
1949 | page_cache_release(page); | 1949 | page_cache_release(page); |
1950 | cFYI(1, ("Add page cache failed")); | 1950 | cFYI(1, "Add page cache failed"); |
1951 | data += PAGE_CACHE_SIZE; | 1951 | data += PAGE_CACHE_SIZE; |
1952 | bytes_read -= PAGE_CACHE_SIZE; | 1952 | bytes_read -= PAGE_CACHE_SIZE; |
1953 | continue; | 1953 | continue; |
@@ -1970,8 +1970,6 @@ static void cifs_copy_cache_pages(struct address_space *mapping, | |||
1970 | flush_dcache_page(page); | 1970 | flush_dcache_page(page); |
1971 | SetPageUptodate(page); | 1971 | SetPageUptodate(page); |
1972 | unlock_page(page); | 1972 | unlock_page(page); |
1973 | if (!pagevec_add(plru_pvec, page)) | ||
1974 | __pagevec_lru_add_file(plru_pvec); | ||
1975 | data += PAGE_CACHE_SIZE; | 1973 | data += PAGE_CACHE_SIZE; |
1976 | } | 1974 | } |
1977 | return; | 1975 | return; |
@@ -1990,7 +1988,6 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
1990 | unsigned int read_size, i; | 1988 | unsigned int read_size, i; |
1991 | char *smb_read_data = NULL; | 1989 | char *smb_read_data = NULL; |
1992 | struct smb_com_read_rsp *pSMBr; | 1990 | struct smb_com_read_rsp *pSMBr; |
1993 | struct pagevec lru_pvec; | ||
1994 | struct cifsFileInfo *open_file; | 1991 | struct cifsFileInfo *open_file; |
1995 | int buf_type = CIFS_NO_BUFFER; | 1992 | int buf_type = CIFS_NO_BUFFER; |
1996 | 1993 | ||
@@ -2004,8 +2001,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2004 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | 2001 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); |
2005 | pTcon = cifs_sb->tcon; | 2002 | pTcon = cifs_sb->tcon; |
2006 | 2003 | ||
2007 | pagevec_init(&lru_pvec, 0); | 2004 | cFYI(DBG2, "rpages: num pages %d", num_pages); |
2008 | cFYI(DBG2, ("rpages: num pages %d", num_pages)); | ||
2009 | for (i = 0; i < num_pages; ) { | 2005 | for (i = 0; i < num_pages; ) { |
2010 | unsigned contig_pages; | 2006 | unsigned contig_pages; |
2011 | struct page *tmp_page; | 2007 | struct page *tmp_page; |
@@ -2038,8 +2034,8 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2038 | /* Read size needs to be in multiples of one page */ | 2034 | /* Read size needs to be in multiples of one page */ |
2039 | read_size = min_t(const unsigned int, read_size, | 2035 | read_size = min_t(const unsigned int, read_size, |
2040 | cifs_sb->rsize & PAGE_CACHE_MASK); | 2036 | cifs_sb->rsize & PAGE_CACHE_MASK); |
2041 | cFYI(DBG2, ("rpages: read size 0x%x contiguous pages %d", | 2037 | cFYI(DBG2, "rpages: read size 0x%x contiguous pages %d", |
2042 | read_size, contig_pages)); | 2038 | read_size, contig_pages); |
2043 | rc = -EAGAIN; | 2039 | rc = -EAGAIN; |
2044 | while (rc == -EAGAIN) { | 2040 | while (rc == -EAGAIN) { |
2045 | if ((open_file->invalidHandle) && | 2041 | if ((open_file->invalidHandle) && |
@@ -2066,14 +2062,14 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2066 | } | 2062 | } |
2067 | } | 2063 | } |
2068 | if ((rc < 0) || (smb_read_data == NULL)) { | 2064 | if ((rc < 0) || (smb_read_data == NULL)) { |
2069 | cFYI(1, ("Read error in readpages: %d", rc)); | 2065 | cFYI(1, "Read error in readpages: %d", rc); |
2070 | break; | 2066 | break; |
2071 | } else if (bytes_read > 0) { | 2067 | } else if (bytes_read > 0) { |
2072 | task_io_account_read(bytes_read); | 2068 | task_io_account_read(bytes_read); |
2073 | pSMBr = (struct smb_com_read_rsp *)smb_read_data; | 2069 | pSMBr = (struct smb_com_read_rsp *)smb_read_data; |
2074 | cifs_copy_cache_pages(mapping, page_list, bytes_read, | 2070 | cifs_copy_cache_pages(mapping, page_list, bytes_read, |
2075 | smb_read_data + 4 /* RFC1001 hdr */ + | 2071 | smb_read_data + 4 /* RFC1001 hdr */ + |
2076 | le16_to_cpu(pSMBr->DataOffset), &lru_pvec); | 2072 | le16_to_cpu(pSMBr->DataOffset)); |
2077 | 2073 | ||
2078 | i += bytes_read >> PAGE_CACHE_SHIFT; | 2074 | i += bytes_read >> PAGE_CACHE_SHIFT; |
2079 | cifs_stats_bytes_read(pTcon, bytes_read); | 2075 | cifs_stats_bytes_read(pTcon, bytes_read); |
@@ -2089,9 +2085,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2089 | /* break; */ | 2085 | /* break; */ |
2090 | } | 2086 | } |
2091 | } else { | 2087 | } else { |
2092 | cFYI(1, ("No bytes read (%d) at offset %lld . " | 2088 | cFYI(1, "No bytes read (%d) at offset %lld . " |
2093 | "Cleaning remaining pages from readahead list", | 2089 | "Cleaning remaining pages from readahead list", |
2094 | bytes_read, offset)); | 2090 | bytes_read, offset); |
2095 | /* BB turn off caching and do new lookup on | 2091 | /* BB turn off caching and do new lookup on |
2096 | file size at server? */ | 2092 | file size at server? */ |
2097 | break; | 2093 | break; |
@@ -2106,8 +2102,6 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
2106 | bytes_read = 0; | 2102 | bytes_read = 0; |
2107 | } | 2103 | } |
2108 | 2104 | ||
2109 | pagevec_lru_add_file(&lru_pvec); | ||
2110 | |||
2111 | /* need to free smb_read_data buf before exit */ | 2105 | /* need to free smb_read_data buf before exit */ |
2112 | if (smb_read_data) { | 2106 | if (smb_read_data) { |
2113 | if (buf_type == CIFS_SMALL_BUFFER) | 2107 | if (buf_type == CIFS_SMALL_BUFFER) |
@@ -2136,7 +2130,7 @@ static int cifs_readpage_worker(struct file *file, struct page *page, | |||
2136 | if (rc < 0) | 2130 | if (rc < 0) |
2137 | goto io_error; | 2131 | goto io_error; |
2138 | else | 2132 | else |
2139 | cFYI(1, ("Bytes read %d", rc)); | 2133 | cFYI(1, "Bytes read %d", rc); |
2140 | 2134 | ||
2141 | file->f_path.dentry->d_inode->i_atime = | 2135 | file->f_path.dentry->d_inode->i_atime = |
2142 | current_fs_time(file->f_path.dentry->d_inode->i_sb); | 2136 | current_fs_time(file->f_path.dentry->d_inode->i_sb); |
@@ -2168,8 +2162,8 @@ static int cifs_readpage(struct file *file, struct page *page) | |||
2168 | return rc; | 2162 | return rc; |
2169 | } | 2163 | } |
2170 | 2164 | ||
2171 | cFYI(1, ("readpage %p at offset %d 0x%x\n", | 2165 | cFYI(1, "readpage %p at offset %d 0x%x\n", |
2172 | page, (int)offset, (int)offset)); | 2166 | page, (int)offset, (int)offset); |
2173 | 2167 | ||
2174 | rc = cifs_readpage_worker(file, page, &offset); | 2168 | rc = cifs_readpage_worker(file, page, &offset); |
2175 | 2169 | ||
@@ -2239,7 +2233,7 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping, | |||
2239 | struct page *page; | 2233 | struct page *page; |
2240 | int rc = 0; | 2234 | int rc = 0; |
2241 | 2235 | ||
2242 | cFYI(1, ("write_begin from %lld len %d", (long long)pos, len)); | 2236 | cFYI(1, "write_begin from %lld len %d", (long long)pos, len); |
2243 | 2237 | ||
2244 | page = grab_cache_page_write_begin(mapping, index, flags); | 2238 | page = grab_cache_page_write_begin(mapping, index, flags); |
2245 | if (!page) { | 2239 | if (!page) { |
@@ -2311,12 +2305,10 @@ cifs_oplock_break(struct slow_work *work) | |||
2311 | int rc, waitrc = 0; | 2305 | int rc, waitrc = 0; |
2312 | 2306 | ||
2313 | if (inode && S_ISREG(inode->i_mode)) { | 2307 | if (inode && S_ISREG(inode->i_mode)) { |
2314 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 2308 | if (cinode->clientCanCacheRead) |
2315 | if (cinode->clientCanCacheAll == 0) | ||
2316 | break_lease(inode, O_RDONLY); | 2309 | break_lease(inode, O_RDONLY); |
2317 | else if (cinode->clientCanCacheRead == 0) | 2310 | else |
2318 | break_lease(inode, O_WRONLY); | 2311 | break_lease(inode, O_WRONLY); |
2319 | #endif | ||
2320 | rc = filemap_fdatawrite(inode->i_mapping); | 2312 | rc = filemap_fdatawrite(inode->i_mapping); |
2321 | if (cinode->clientCanCacheRead == 0) { | 2313 | if (cinode->clientCanCacheRead == 0) { |
2322 | waitrc = filemap_fdatawait(inode->i_mapping); | 2314 | waitrc = filemap_fdatawait(inode->i_mapping); |
@@ -2326,7 +2318,7 @@ cifs_oplock_break(struct slow_work *work) | |||
2326 | rc = waitrc; | 2318 | rc = waitrc; |
2327 | if (rc) | 2319 | if (rc) |
2328 | cinode->write_behind_rc = rc; | 2320 | cinode->write_behind_rc = rc; |
2329 | cFYI(1, ("Oplock flush inode %p rc %d", inode, rc)); | 2321 | cFYI(1, "Oplock flush inode %p rc %d", inode, rc); |
2330 | } | 2322 | } |
2331 | 2323 | ||
2332 | /* | 2324 | /* |
@@ -2338,7 +2330,7 @@ cifs_oplock_break(struct slow_work *work) | |||
2338 | if (!cfile->closePend && !cfile->oplock_break_cancelled) { | 2330 | if (!cfile->closePend && !cfile->oplock_break_cancelled) { |
2339 | rc = CIFSSMBLock(0, cifs_sb->tcon, cfile->netfid, 0, 0, 0, 0, | 2331 | rc = CIFSSMBLock(0, cifs_sb->tcon, cfile->netfid, 0, 0, 0, 0, |
2340 | LOCKING_ANDX_OPLOCK_RELEASE, false); | 2332 | LOCKING_ANDX_OPLOCK_RELEASE, false); |
2341 | cFYI(1, ("Oplock release rc = %d", rc)); | 2333 | cFYI(1, "Oplock release rc = %d", rc); |
2342 | } | 2334 | } |
2343 | } | 2335 | } |
2344 | 2336 | ||
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 35ec11716213..62b324f26a56 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * fs/cifs/inode.c | 2 | * fs/cifs/inode.c |
3 | * | 3 | * |
4 | * Copyright (C) International Business Machines Corp., 2002,2008 | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
5 | * Author(s): Steve French (sfrench@us.ibm.com) | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
6 | * | 6 | * |
7 | * This library is free software; you can redistribute it and/or modify | 7 | * This library is free software; you can redistribute it and/or modify |
@@ -86,30 +86,30 @@ cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr) | |||
86 | { | 86 | { |
87 | struct cifsInodeInfo *cifs_i = CIFS_I(inode); | 87 | struct cifsInodeInfo *cifs_i = CIFS_I(inode); |
88 | 88 | ||
89 | cFYI(1, ("%s: revalidating inode %llu", __func__, cifs_i->uniqueid)); | 89 | cFYI(1, "%s: revalidating inode %llu", __func__, cifs_i->uniqueid); |
90 | 90 | ||
91 | if (inode->i_state & I_NEW) { | 91 | if (inode->i_state & I_NEW) { |
92 | cFYI(1, ("%s: inode %llu is new", __func__, cifs_i->uniqueid)); | 92 | cFYI(1, "%s: inode %llu is new", __func__, cifs_i->uniqueid); |
93 | return; | 93 | return; |
94 | } | 94 | } |
95 | 95 | ||
96 | /* don't bother with revalidation if we have an oplock */ | 96 | /* don't bother with revalidation if we have an oplock */ |
97 | if (cifs_i->clientCanCacheRead) { | 97 | if (cifs_i->clientCanCacheRead) { |
98 | cFYI(1, ("%s: inode %llu is oplocked", __func__, | 98 | cFYI(1, "%s: inode %llu is oplocked", __func__, |
99 | cifs_i->uniqueid)); | 99 | cifs_i->uniqueid); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | 102 | ||
103 | /* revalidate if mtime or size have changed */ | 103 | /* revalidate if mtime or size have changed */ |
104 | if (timespec_equal(&inode->i_mtime, &fattr->cf_mtime) && | 104 | if (timespec_equal(&inode->i_mtime, &fattr->cf_mtime) && |
105 | cifs_i->server_eof == fattr->cf_eof) { | 105 | cifs_i->server_eof == fattr->cf_eof) { |
106 | cFYI(1, ("%s: inode %llu is unchanged", __func__, | 106 | cFYI(1, "%s: inode %llu is unchanged", __func__, |
107 | cifs_i->uniqueid)); | 107 | cifs_i->uniqueid); |
108 | return; | 108 | return; |
109 | } | 109 | } |
110 | 110 | ||
111 | cFYI(1, ("%s: invalidating inode %llu mapping", __func__, | 111 | cFYI(1, "%s: invalidating inode %llu mapping", __func__, |
112 | cifs_i->uniqueid)); | 112 | cifs_i->uniqueid); |
113 | cifs_i->invalid_mapping = true; | 113 | cifs_i->invalid_mapping = true; |
114 | } | 114 | } |
115 | 115 | ||
@@ -137,15 +137,14 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) | |||
137 | inode->i_mode = fattr->cf_mode; | 137 | inode->i_mode = fattr->cf_mode; |
138 | 138 | ||
139 | cifs_i->cifsAttrs = fattr->cf_cifsattrs; | 139 | cifs_i->cifsAttrs = fattr->cf_cifsattrs; |
140 | cifs_i->uniqueid = fattr->cf_uniqueid; | ||
141 | 140 | ||
142 | if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL) | 141 | if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL) |
143 | cifs_i->time = 0; | 142 | cifs_i->time = 0; |
144 | else | 143 | else |
145 | cifs_i->time = jiffies; | 144 | cifs_i->time = jiffies; |
146 | 145 | ||
147 | cFYI(1, ("inode 0x%p old_time=%ld new_time=%ld", inode, | 146 | cFYI(1, "inode 0x%p old_time=%ld new_time=%ld", inode, |
148 | oldtime, cifs_i->time)); | 147 | oldtime, cifs_i->time); |
149 | 148 | ||
150 | cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING; | 149 | cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING; |
151 | 150 | ||
@@ -170,6 +169,17 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) | |||
170 | cifs_set_ops(inode, fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL); | 169 | cifs_set_ops(inode, fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL); |
171 | } | 170 | } |
172 | 171 | ||
172 | void | ||
173 | cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr) | ||
174 | { | ||
175 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | ||
176 | |||
177 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) | ||
178 | return; | ||
179 | |||
180 | fattr->cf_uniqueid = iunique(sb, ROOT_I); | ||
181 | } | ||
182 | |||
173 | /* Fill a cifs_fattr struct with info from FILE_UNIX_BASIC_INFO. */ | 183 | /* Fill a cifs_fattr struct with info from FILE_UNIX_BASIC_INFO. */ |
174 | void | 184 | void |
175 | cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info, | 185 | cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info, |
@@ -227,7 +237,7 @@ cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info, | |||
227 | /* safest to call it a file if we do not know */ | 237 | /* safest to call it a file if we do not know */ |
228 | fattr->cf_mode |= S_IFREG; | 238 | fattr->cf_mode |= S_IFREG; |
229 | fattr->cf_dtype = DT_REG; | 239 | fattr->cf_dtype = DT_REG; |
230 | cFYI(1, ("unknown type %d", le32_to_cpu(info->Type))); | 240 | cFYI(1, "unknown type %d", le32_to_cpu(info->Type)); |
231 | break; | 241 | break; |
232 | } | 242 | } |
233 | 243 | ||
@@ -256,7 +266,7 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb) | |||
256 | { | 266 | { |
257 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 267 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
258 | 268 | ||
259 | cFYI(1, ("creating fake fattr for DFS referral")); | 269 | cFYI(1, "creating fake fattr for DFS referral"); |
260 | 270 | ||
261 | memset(fattr, 0, sizeof(*fattr)); | 271 | memset(fattr, 0, sizeof(*fattr)); |
262 | fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU; | 272 | fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU; |
@@ -305,7 +315,7 @@ int cifs_get_inode_info_unix(struct inode **pinode, | |||
305 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); | 315 | struct cifs_sb_info *cifs_sb = CIFS_SB(sb); |
306 | 316 | ||
307 | tcon = cifs_sb->tcon; | 317 | tcon = cifs_sb->tcon; |
308 | cFYI(1, ("Getting info on %s", full_path)); | 318 | cFYI(1, "Getting info on %s", full_path); |
309 | 319 | ||
310 | /* could have done a find first instead but this returns more info */ | 320 | /* could have done a find first instead but this returns more info */ |
311 | rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data, | 321 | rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data, |
@@ -323,6 +333,7 @@ int cifs_get_inode_info_unix(struct inode **pinode, | |||
323 | 333 | ||
324 | if (*pinode == NULL) { | 334 | if (*pinode == NULL) { |
325 | /* get new inode */ | 335 | /* get new inode */ |
336 | cifs_fill_uniqueid(sb, &fattr); | ||
326 | *pinode = cifs_iget(sb, &fattr); | 337 | *pinode = cifs_iget(sb, &fattr); |
327 | if (!*pinode) | 338 | if (!*pinode) |
328 | rc = -ENOMEM; | 339 | rc = -ENOMEM; |
@@ -373,7 +384,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path, | |||
373 | &bytes_read, &pbuf, &buf_type); | 384 | &bytes_read, &pbuf, &buf_type); |
374 | if ((rc == 0) && (bytes_read >= 8)) { | 385 | if ((rc == 0) && (bytes_read >= 8)) { |
375 | if (memcmp("IntxBLK", pbuf, 8) == 0) { | 386 | if (memcmp("IntxBLK", pbuf, 8) == 0) { |
376 | cFYI(1, ("Block device")); | 387 | cFYI(1, "Block device"); |
377 | fattr->cf_mode |= S_IFBLK; | 388 | fattr->cf_mode |= S_IFBLK; |
378 | fattr->cf_dtype = DT_BLK; | 389 | fattr->cf_dtype = DT_BLK; |
379 | if (bytes_read == 24) { | 390 | if (bytes_read == 24) { |
@@ -385,7 +396,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path, | |||
385 | fattr->cf_rdev = MKDEV(mjr, mnr); | 396 | fattr->cf_rdev = MKDEV(mjr, mnr); |
386 | } | 397 | } |
387 | } else if (memcmp("IntxCHR", pbuf, 8) == 0) { | 398 | } else if (memcmp("IntxCHR", pbuf, 8) == 0) { |
388 | cFYI(1, ("Char device")); | 399 | cFYI(1, "Char device"); |
389 | fattr->cf_mode |= S_IFCHR; | 400 | fattr->cf_mode |= S_IFCHR; |
390 | fattr->cf_dtype = DT_CHR; | 401 | fattr->cf_dtype = DT_CHR; |
391 | if (bytes_read == 24) { | 402 | if (bytes_read == 24) { |
@@ -397,7 +408,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path, | |||
397 | fattr->cf_rdev = MKDEV(mjr, mnr); | 408 | fattr->cf_rdev = MKDEV(mjr, mnr); |
398 | } | 409 | } |
399 | } else if (memcmp("IntxLNK", pbuf, 7) == 0) { | 410 | } else if (memcmp("IntxLNK", pbuf, 7) == 0) { |
400 | cFYI(1, ("Symlink")); | 411 | cFYI(1, "Symlink"); |
401 | fattr->cf_mode |= S_IFLNK; | 412 | fattr->cf_mode |= S_IFLNK; |
402 | fattr->cf_dtype = DT_LNK; | 413 | fattr->cf_dtype = DT_LNK; |
403 | } else { | 414 | } else { |
@@ -439,10 +450,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path, | |||
439 | else if (rc > 3) { | 450 | else if (rc > 3) { |
440 | mode = le32_to_cpu(*((__le32 *)ea_value)); | 451 | mode = le32_to_cpu(*((__le32 *)ea_value)); |
441 | fattr->cf_mode &= ~SFBITS_MASK; | 452 | fattr->cf_mode &= ~SFBITS_MASK; |
442 | cFYI(1, ("special bits 0%o org mode 0%o", mode, | 453 | cFYI(1, "special bits 0%o org mode 0%o", mode, |
443 | fattr->cf_mode)); | 454 | fattr->cf_mode); |
444 | fattr->cf_mode = (mode & SFBITS_MASK) | fattr->cf_mode; | 455 | fattr->cf_mode = (mode & SFBITS_MASK) | fattr->cf_mode; |
445 | cFYI(1, ("special mode bits 0%o", mode)); | 456 | cFYI(1, "special mode bits 0%o", mode); |
446 | } | 457 | } |
447 | 458 | ||
448 | return 0; | 459 | return 0; |
@@ -548,11 +559,11 @@ int cifs_get_inode_info(struct inode **pinode, | |||
548 | struct cifs_fattr fattr; | 559 | struct cifs_fattr fattr; |
549 | 560 | ||
550 | pTcon = cifs_sb->tcon; | 561 | pTcon = cifs_sb->tcon; |
551 | cFYI(1, ("Getting info on %s", full_path)); | 562 | cFYI(1, "Getting info on %s", full_path); |
552 | 563 | ||
553 | if ((pfindData == NULL) && (*pinode != NULL)) { | 564 | if ((pfindData == NULL) && (*pinode != NULL)) { |
554 | if (CIFS_I(*pinode)->clientCanCacheRead) { | 565 | if (CIFS_I(*pinode)->clientCanCacheRead) { |
555 | cFYI(1, ("No need to revalidate cached inode sizes")); | 566 | cFYI(1, "No need to revalidate cached inode sizes"); |
556 | return rc; | 567 | return rc; |
557 | } | 568 | } |
558 | } | 569 | } |
@@ -618,7 +629,7 @@ int cifs_get_inode_info(struct inode **pinode, | |||
618 | cifs_sb->mnt_cifs_flags & | 629 | cifs_sb->mnt_cifs_flags & |
619 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 630 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
620 | if (rc1 || !fattr.cf_uniqueid) { | 631 | if (rc1 || !fattr.cf_uniqueid) { |
621 | cFYI(1, ("GetSrvInodeNum rc %d", rc1)); | 632 | cFYI(1, "GetSrvInodeNum rc %d", rc1); |
622 | fattr.cf_uniqueid = iunique(sb, ROOT_I); | 633 | fattr.cf_uniqueid = iunique(sb, ROOT_I); |
623 | cifs_autodisable_serverino(cifs_sb); | 634 | cifs_autodisable_serverino(cifs_sb); |
624 | } | 635 | } |
@@ -634,13 +645,13 @@ int cifs_get_inode_info(struct inode **pinode, | |||
634 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { | 645 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { |
635 | tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid); | 646 | tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid); |
636 | if (tmprc) | 647 | if (tmprc) |
637 | cFYI(1, ("cifs_sfu_type failed: %d", tmprc)); | 648 | cFYI(1, "cifs_sfu_type failed: %d", tmprc); |
638 | } | 649 | } |
639 | 650 | ||
640 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 651 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
641 | /* fill in 0777 bits from ACL */ | 652 | /* fill in 0777 bits from ACL */ |
642 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { | 653 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { |
643 | cFYI(1, ("Getting mode bits from ACL")); | 654 | cFYI(1, "Getting mode bits from ACL"); |
644 | cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path, pfid); | 655 | cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path, pfid); |
645 | } | 656 | } |
646 | #endif | 657 | #endif |
@@ -715,6 +726,16 @@ cifs_find_inode(struct inode *inode, void *opaque) | |||
715 | if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid) | 726 | if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid) |
716 | return 0; | 727 | return 0; |
717 | 728 | ||
729 | /* | ||
730 | * uh oh -- it's a directory. We can't use it since hardlinked dirs are | ||
731 | * verboten. Disable serverino and return it as if it were found, the | ||
732 | * caller can discard it, generate a uniqueid and retry the find | ||
733 | */ | ||
734 | if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry)) { | ||
735 | fattr->cf_flags |= CIFS_FATTR_INO_COLLISION; | ||
736 | cifs_autodisable_serverino(CIFS_SB(inode->i_sb)); | ||
737 | } | ||
738 | |||
718 | return 1; | 739 | return 1; |
719 | } | 740 | } |
720 | 741 | ||
@@ -734,15 +755,22 @@ cifs_iget(struct super_block *sb, struct cifs_fattr *fattr) | |||
734 | unsigned long hash; | 755 | unsigned long hash; |
735 | struct inode *inode; | 756 | struct inode *inode; |
736 | 757 | ||
737 | cFYI(1, ("looking for uniqueid=%llu", fattr->cf_uniqueid)); | 758 | retry_iget5_locked: |
759 | cFYI(1, "looking for uniqueid=%llu", fattr->cf_uniqueid); | ||
738 | 760 | ||
739 | /* hash down to 32-bits on 32-bit arch */ | 761 | /* hash down to 32-bits on 32-bit arch */ |
740 | hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid); | 762 | hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid); |
741 | 763 | ||
742 | inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr); | 764 | inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr); |
743 | |||
744 | /* we have fattrs in hand, update the inode */ | ||
745 | if (inode) { | 765 | if (inode) { |
766 | /* was there a problematic inode number collision? */ | ||
767 | if (fattr->cf_flags & CIFS_FATTR_INO_COLLISION) { | ||
768 | iput(inode); | ||
769 | fattr->cf_uniqueid = iunique(sb, ROOT_I); | ||
770 | fattr->cf_flags &= ~CIFS_FATTR_INO_COLLISION; | ||
771 | goto retry_iget5_locked; | ||
772 | } | ||
773 | |||
746 | cifs_fattr_to_inode(inode, fattr); | 774 | cifs_fattr_to_inode(inode, fattr); |
747 | if (sb->s_flags & MS_NOATIME) | 775 | if (sb->s_flags & MS_NOATIME) |
748 | inode->i_flags |= S_NOATIME | S_NOCMTIME; | 776 | inode->i_flags |= S_NOATIME | S_NOCMTIME; |
@@ -780,7 +808,7 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino) | |||
780 | return ERR_PTR(-ENOMEM); | 808 | return ERR_PTR(-ENOMEM); |
781 | 809 | ||
782 | if (rc && cifs_sb->tcon->ipc) { | 810 | if (rc && cifs_sb->tcon->ipc) { |
783 | cFYI(1, ("ipc connection - fake read inode")); | 811 | cFYI(1, "ipc connection - fake read inode"); |
784 | inode->i_mode |= S_IFDIR; | 812 | inode->i_mode |= S_IFDIR; |
785 | inode->i_nlink = 2; | 813 | inode->i_nlink = 2; |
786 | inode->i_op = &cifs_ipc_inode_ops; | 814 | inode->i_op = &cifs_ipc_inode_ops; |
@@ -842,7 +870,7 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid, | |||
842 | * server times. | 870 | * server times. |
843 | */ | 871 | */ |
844 | if (set_time && (attrs->ia_valid & ATTR_CTIME)) { | 872 | if (set_time && (attrs->ia_valid & ATTR_CTIME)) { |
845 | cFYI(1, ("CIFS - CTIME changed")); | 873 | cFYI(1, "CIFS - CTIME changed"); |
846 | info_buf.ChangeTime = | 874 | info_buf.ChangeTime = |
847 | cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime)); | 875 | cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime)); |
848 | } else | 876 | } else |
@@ -877,8 +905,8 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid, | |||
877 | goto out; | 905 | goto out; |
878 | } | 906 | } |
879 | 907 | ||
880 | cFYI(1, ("calling SetFileInfo since SetPathInfo for " | 908 | cFYI(1, "calling SetFileInfo since SetPathInfo for " |
881 | "times not supported by this server")); | 909 | "times not supported by this server"); |
882 | rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, | 910 | rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, |
883 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, | 911 | SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, |
884 | CREATE_NOT_DIR, &netfid, &oplock, | 912 | CREATE_NOT_DIR, &netfid, &oplock, |
@@ -1036,7 +1064,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1036 | struct iattr *attrs = NULL; | 1064 | struct iattr *attrs = NULL; |
1037 | __u32 dosattr = 0, origattr = 0; | 1065 | __u32 dosattr = 0, origattr = 0; |
1038 | 1066 | ||
1039 | cFYI(1, ("cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry)); | 1067 | cFYI(1, "cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry); |
1040 | 1068 | ||
1041 | xid = GetXid(); | 1069 | xid = GetXid(); |
1042 | 1070 | ||
@@ -1055,7 +1083,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry) | |||
1055 | rc = CIFSPOSIXDelFile(xid, tcon, full_path, | 1083 | rc = CIFSPOSIXDelFile(xid, tcon, full_path, |
1056 | SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls, | 1084 | SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls, |
1057 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 1085 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
1058 | cFYI(1, ("posix del rc %d", rc)); | 1086 | cFYI(1, "posix del rc %d", rc); |
1059 | if ((rc == 0) || (rc == -ENOENT)) | 1087 | if ((rc == 0) || (rc == -ENOENT)) |
1060 | goto psx_del_no_retry; | 1088 | goto psx_del_no_retry; |
1061 | } | 1089 | } |
@@ -1129,7 +1157,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1129 | struct inode *newinode = NULL; | 1157 | struct inode *newinode = NULL; |
1130 | struct cifs_fattr fattr; | 1158 | struct cifs_fattr fattr; |
1131 | 1159 | ||
1132 | cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode)); | 1160 | cFYI(1, "In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode); |
1133 | 1161 | ||
1134 | xid = GetXid(); | 1162 | xid = GetXid(); |
1135 | 1163 | ||
@@ -1164,7 +1192,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1164 | kfree(pInfo); | 1192 | kfree(pInfo); |
1165 | goto mkdir_retry_old; | 1193 | goto mkdir_retry_old; |
1166 | } else if (rc) { | 1194 | } else if (rc) { |
1167 | cFYI(1, ("posix mkdir returned 0x%x", rc)); | 1195 | cFYI(1, "posix mkdir returned 0x%x", rc); |
1168 | d_drop(direntry); | 1196 | d_drop(direntry); |
1169 | } else { | 1197 | } else { |
1170 | if (pInfo->Type == cpu_to_le32(-1)) { | 1198 | if (pInfo->Type == cpu_to_le32(-1)) { |
@@ -1181,6 +1209,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1181 | direntry->d_op = &cifs_dentry_ops; | 1209 | direntry->d_op = &cifs_dentry_ops; |
1182 | 1210 | ||
1183 | cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb); | 1211 | cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb); |
1212 | cifs_fill_uniqueid(inode->i_sb, &fattr); | ||
1184 | newinode = cifs_iget(inode->i_sb, &fattr); | 1213 | newinode = cifs_iget(inode->i_sb, &fattr); |
1185 | if (!newinode) { | 1214 | if (!newinode) { |
1186 | kfree(pInfo); | 1215 | kfree(pInfo); |
@@ -1190,12 +1219,12 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode) | |||
1190 | d_instantiate(direntry, newinode); | 1219 | d_instantiate(direntry, newinode); |
1191 | 1220 | ||
1192 | #ifdef CONFIG_CIFS_DEBUG2 | 1221 | #ifdef CONFIG_CIFS_DEBUG2 |
1193 | cFYI(1, ("instantiated dentry %p %s to inode %p", | 1222 | cFYI(1, "instantiated dentry %p %s to inode %p", |
1194 | direntry, direntry->d_name.name, newinode)); | 1223 | direntry, direntry->d_name.name, newinode); |
1195 | 1224 | ||
1196 | if (newinode->i_nlink != 2) | 1225 | if (newinode->i_nlink != 2) |
1197 | cFYI(1, ("unexpected number of links %d", | 1226 | cFYI(1, "unexpected number of links %d", |
1198 | newinode->i_nlink)); | 1227 | newinode->i_nlink); |
1199 | #endif | 1228 | #endif |
1200 | } | 1229 | } |
1201 | kfree(pInfo); | 1230 | kfree(pInfo); |
@@ -1206,7 +1235,7 @@ mkdir_retry_old: | |||
1206 | rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls, | 1235 | rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls, |
1207 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | 1236 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); |
1208 | if (rc) { | 1237 | if (rc) { |
1209 | cFYI(1, ("cifs_mkdir returned 0x%x", rc)); | 1238 | cFYI(1, "cifs_mkdir returned 0x%x", rc); |
1210 | d_drop(direntry); | 1239 | d_drop(direntry); |
1211 | } else { | 1240 | } else { |
1212 | mkdir_get_info: | 1241 | mkdir_get_info: |
@@ -1309,7 +1338,7 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry) | |||
1309 | char *full_path = NULL; | 1338 | char *full_path = NULL; |
1310 | struct cifsInodeInfo *cifsInode; | 1339 | struct cifsInodeInfo *cifsInode; |
1311 | 1340 | ||
1312 | cFYI(1, ("cifs_rmdir, inode = 0x%p", inode)); | 1341 | cFYI(1, "cifs_rmdir, inode = 0x%p", inode); |
1313 | 1342 | ||
1314 | xid = GetXid(); | 1343 | xid = GetXid(); |
1315 | 1344 | ||
@@ -1511,6 +1540,11 @@ cifs_inode_needs_reval(struct inode *inode) | |||
1511 | if (time_after_eq(jiffies, cifs_i->time + HZ)) | 1540 | if (time_after_eq(jiffies, cifs_i->time + HZ)) |
1512 | return true; | 1541 | return true; |
1513 | 1542 | ||
1543 | /* hardlinked files w/ noserverino get "special" treatment */ | ||
1544 | if (!(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) && | ||
1545 | S_ISREG(inode->i_mode) && inode->i_nlink != 1) | ||
1546 | return true; | ||
1547 | |||
1514 | return false; | 1548 | return false; |
1515 | } | 1549 | } |
1516 | 1550 | ||
@@ -1577,9 +1611,9 @@ int cifs_revalidate_dentry(struct dentry *dentry) | |||
1577 | goto check_inval; | 1611 | goto check_inval; |
1578 | } | 1612 | } |
1579 | 1613 | ||
1580 | cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " | 1614 | cFYI(1, "Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld " |
1581 | "jiffies %ld", full_path, inode, inode->i_count.counter, | 1615 | "jiffies %ld", full_path, inode, inode->i_count.counter, |
1582 | dentry, dentry->d_time, jiffies)); | 1616 | dentry, dentry->d_time, jiffies); |
1583 | 1617 | ||
1584 | if (CIFS_SB(sb)->tcon->unix_ext) | 1618 | if (CIFS_SB(sb)->tcon->unix_ext) |
1585 | rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid); | 1619 | rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid); |
@@ -1673,12 +1707,12 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1673 | rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid, | 1707 | rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid, |
1674 | npid, false); | 1708 | npid, false); |
1675 | cifsFileInfo_put(open_file); | 1709 | cifsFileInfo_put(open_file); |
1676 | cFYI(1, ("SetFSize for attrs rc = %d", rc)); | 1710 | cFYI(1, "SetFSize for attrs rc = %d", rc); |
1677 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1711 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
1678 | unsigned int bytes_written; | 1712 | unsigned int bytes_written; |
1679 | rc = CIFSSMBWrite(xid, pTcon, nfid, 0, attrs->ia_size, | 1713 | rc = CIFSSMBWrite(xid, pTcon, nfid, 0, attrs->ia_size, |
1680 | &bytes_written, NULL, NULL, 1); | 1714 | &bytes_written, NULL, NULL, 1); |
1681 | cFYI(1, ("Wrt seteof rc %d", rc)); | 1715 | cFYI(1, "Wrt seteof rc %d", rc); |
1682 | } | 1716 | } |
1683 | } else | 1717 | } else |
1684 | rc = -EINVAL; | 1718 | rc = -EINVAL; |
@@ -1692,7 +1726,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1692 | false, cifs_sb->local_nls, | 1726 | false, cifs_sb->local_nls, |
1693 | cifs_sb->mnt_cifs_flags & | 1727 | cifs_sb->mnt_cifs_flags & |
1694 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 1728 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
1695 | cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc)); | 1729 | cFYI(1, "SetEOF by path (setattrs) rc = %d", rc); |
1696 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { | 1730 | if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { |
1697 | __u16 netfid; | 1731 | __u16 netfid; |
1698 | int oplock = 0; | 1732 | int oplock = 0; |
@@ -1709,7 +1743,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, | |||
1709 | attrs->ia_size, | 1743 | attrs->ia_size, |
1710 | &bytes_written, NULL, | 1744 | &bytes_written, NULL, |
1711 | NULL, 1); | 1745 | NULL, 1); |
1712 | cFYI(1, ("wrt seteof rc %d", rc)); | 1746 | cFYI(1, "wrt seteof rc %d", rc); |
1713 | CIFSSMBClose(xid, pTcon, netfid); | 1747 | CIFSSMBClose(xid, pTcon, netfid); |
1714 | } | 1748 | } |
1715 | } | 1749 | } |
@@ -1737,8 +1771,8 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) | |||
1737 | struct cifs_unix_set_info_args *args = NULL; | 1771 | struct cifs_unix_set_info_args *args = NULL; |
1738 | struct cifsFileInfo *open_file; | 1772 | struct cifsFileInfo *open_file; |
1739 | 1773 | ||
1740 | cFYI(1, ("setattr_unix on file %s attrs->ia_valid=0x%x", | 1774 | cFYI(1, "setattr_unix on file %s attrs->ia_valid=0x%x", |
1741 | direntry->d_name.name, attrs->ia_valid)); | 1775 | direntry->d_name.name, attrs->ia_valid); |
1742 | 1776 | ||
1743 | xid = GetXid(); | 1777 | xid = GetXid(); |
1744 | 1778 | ||
@@ -1868,8 +1902,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) | |||
1868 | 1902 | ||
1869 | xid = GetXid(); | 1903 | xid = GetXid(); |
1870 | 1904 | ||
1871 | cFYI(1, ("setattr on file %s attrs->iavalid 0x%x", | 1905 | cFYI(1, "setattr on file %s attrs->iavalid 0x%x", |
1872 | direntry->d_name.name, attrs->ia_valid)); | 1906 | direntry->d_name.name, attrs->ia_valid); |
1873 | 1907 | ||
1874 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) { | 1908 | if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) { |
1875 | /* check if we have permission to change attrs */ | 1909 | /* check if we have permission to change attrs */ |
@@ -1926,7 +1960,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) | |||
1926 | attrs->ia_valid &= ~ATTR_MODE; | 1960 | attrs->ia_valid &= ~ATTR_MODE; |
1927 | 1961 | ||
1928 | if (attrs->ia_valid & ATTR_MODE) { | 1962 | if (attrs->ia_valid & ATTR_MODE) { |
1929 | cFYI(1, ("Mode changed to 0%o", attrs->ia_mode)); | 1963 | cFYI(1, "Mode changed to 0%o", attrs->ia_mode); |
1930 | mode = attrs->ia_mode; | 1964 | mode = attrs->ia_mode; |
1931 | } | 1965 | } |
1932 | 1966 | ||
@@ -2012,7 +2046,7 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs) | |||
2012 | #if 0 | 2046 | #if 0 |
2013 | void cifs_delete_inode(struct inode *inode) | 2047 | void cifs_delete_inode(struct inode *inode) |
2014 | { | 2048 | { |
2015 | cFYI(1, ("In cifs_delete_inode, inode = 0x%p", inode)); | 2049 | cFYI(1, "In cifs_delete_inode, inode = 0x%p", inode); |
2016 | /* may have to add back in if and when safe distributed caching of | 2050 | /* may have to add back in if and when safe distributed caching of |
2017 | directories added e.g. via FindNotify */ | 2051 | directories added e.g. via FindNotify */ |
2018 | } | 2052 | } |
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c index f94650683a00..505926f1ee6b 100644 --- a/fs/cifs/ioctl.c +++ b/fs/cifs/ioctl.c | |||
@@ -47,7 +47,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
47 | 47 | ||
48 | xid = GetXid(); | 48 | xid = GetXid(); |
49 | 49 | ||
50 | cFYI(1, ("ioctl file %p cmd %u arg %lu", filep, command, arg)); | 50 | cFYI(1, "ioctl file %p cmd %u arg %lu", filep, command, arg); |
51 | 51 | ||
52 | cifs_sb = CIFS_SB(inode->i_sb); | 52 | cifs_sb = CIFS_SB(inode->i_sb); |
53 | 53 | ||
@@ -64,12 +64,12 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
64 | 64 | ||
65 | switch (command) { | 65 | switch (command) { |
66 | case CIFS_IOC_CHECKUMOUNT: | 66 | case CIFS_IOC_CHECKUMOUNT: |
67 | cFYI(1, ("User unmount attempted")); | 67 | cFYI(1, "User unmount attempted"); |
68 | if (cifs_sb->mnt_uid == current_uid()) | 68 | if (cifs_sb->mnt_uid == current_uid()) |
69 | rc = 0; | 69 | rc = 0; |
70 | else { | 70 | else { |
71 | rc = -EACCES; | 71 | rc = -EACCES; |
72 | cFYI(1, ("uids do not match")); | 72 | cFYI(1, "uids do not match"); |
73 | } | 73 | } |
74 | break; | 74 | break; |
75 | #ifdef CONFIG_CIFS_POSIX | 75 | #ifdef CONFIG_CIFS_POSIX |
@@ -97,11 +97,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) | |||
97 | /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, | 97 | /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid, |
98 | extAttrBits, &ExtAttrMask);*/ | 98 | extAttrBits, &ExtAttrMask);*/ |
99 | } | 99 | } |
100 | cFYI(1, ("set flags not implemented yet")); | 100 | cFYI(1, "set flags not implemented yet"); |
101 | break; | 101 | break; |
102 | #endif /* CONFIG_CIFS_POSIX */ | 102 | #endif /* CONFIG_CIFS_POSIX */ |
103 | default: | 103 | default: |
104 | cFYI(1, ("unsupported ioctl")); | 104 | cFYI(1, "unsupported ioctl"); |
105 | break; | 105 | break; |
106 | } | 106 | } |
107 | 107 | ||
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index c1a9d4236a8c..473ca8033656 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -139,7 +139,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) | |||
139 | if (!full_path) | 139 | if (!full_path) |
140 | goto out; | 140 | goto out; |
141 | 141 | ||
142 | cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode)); | 142 | cFYI(1, "Full path: %s inode = 0x%p", full_path, inode); |
143 | 143 | ||
144 | rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path, | 144 | rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path, |
145 | cifs_sb->local_nls); | 145 | cifs_sb->local_nls); |
@@ -178,8 +178,8 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname) | |||
178 | return rc; | 178 | return rc; |
179 | } | 179 | } |
180 | 180 | ||
181 | cFYI(1, ("Full path: %s", full_path)); | 181 | cFYI(1, "Full path: %s", full_path); |
182 | cFYI(1, ("symname is %s", symname)); | 182 | cFYI(1, "symname is %s", symname); |
183 | 183 | ||
184 | /* BB what if DFS and this volume is on different share? BB */ | 184 | /* BB what if DFS and this volume is on different share? BB */ |
185 | if (pTcon->unix_ext) | 185 | if (pTcon->unix_ext) |
@@ -198,8 +198,8 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname) | |||
198 | inode->i_sb, xid, NULL); | 198 | inode->i_sb, xid, NULL); |
199 | 199 | ||
200 | if (rc != 0) { | 200 | if (rc != 0) { |
201 | cFYI(1, ("Create symlink ok, getinodeinfo fail rc = %d", | 201 | cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d", |
202 | rc)); | 202 | rc); |
203 | } else { | 203 | } else { |
204 | if (pTcon->nocase) | 204 | if (pTcon->nocase) |
205 | direntry->d_op = &cifs_ci_dentry_ops; | 205 | direntry->d_op = &cifs_ci_dentry_ops; |
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index d1474996a812..1394aa37f26c 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -51,7 +51,7 @@ _GetXid(void) | |||
51 | if (GlobalTotalActiveXid > GlobalMaxActiveXid) | 51 | if (GlobalTotalActiveXid > GlobalMaxActiveXid) |
52 | GlobalMaxActiveXid = GlobalTotalActiveXid; | 52 | GlobalMaxActiveXid = GlobalTotalActiveXid; |
53 | if (GlobalTotalActiveXid > 65000) | 53 | if (GlobalTotalActiveXid > 65000) |
54 | cFYI(1, ("warning: more than 65000 requests active")); | 54 | cFYI(1, "warning: more than 65000 requests active"); |
55 | xid = GlobalCurrentXid++; | 55 | xid = GlobalCurrentXid++; |
56 | spin_unlock(&GlobalMid_Lock); | 56 | spin_unlock(&GlobalMid_Lock); |
57 | return xid; | 57 | return xid; |
@@ -88,7 +88,7 @@ void | |||
88 | sesInfoFree(struct cifsSesInfo *buf_to_free) | 88 | sesInfoFree(struct cifsSesInfo *buf_to_free) |
89 | { | 89 | { |
90 | if (buf_to_free == NULL) { | 90 | if (buf_to_free == NULL) { |
91 | cFYI(1, ("Null buffer passed to sesInfoFree")); | 91 | cFYI(1, "Null buffer passed to sesInfoFree"); |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | 94 | ||
@@ -126,7 +126,7 @@ void | |||
126 | tconInfoFree(struct cifsTconInfo *buf_to_free) | 126 | tconInfoFree(struct cifsTconInfo *buf_to_free) |
127 | { | 127 | { |
128 | if (buf_to_free == NULL) { | 128 | if (buf_to_free == NULL) { |
129 | cFYI(1, ("Null buffer passed to tconInfoFree")); | 129 | cFYI(1, "Null buffer passed to tconInfoFree"); |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | atomic_dec(&tconInfoAllocCount); | 132 | atomic_dec(&tconInfoAllocCount); |
@@ -166,7 +166,7 @@ void | |||
166 | cifs_buf_release(void *buf_to_free) | 166 | cifs_buf_release(void *buf_to_free) |
167 | { | 167 | { |
168 | if (buf_to_free == NULL) { | 168 | if (buf_to_free == NULL) { |
169 | /* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/ | 169 | /* cFYI(1, "Null buffer passed to cifs_buf_release");*/ |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | mempool_free(buf_to_free, cifs_req_poolp); | 172 | mempool_free(buf_to_free, cifs_req_poolp); |
@@ -202,7 +202,7 @@ cifs_small_buf_release(void *buf_to_free) | |||
202 | { | 202 | { |
203 | 203 | ||
204 | if (buf_to_free == NULL) { | 204 | if (buf_to_free == NULL) { |
205 | cFYI(1, ("Null buffer passed to cifs_small_buf_release")); | 205 | cFYI(1, "Null buffer passed to cifs_small_buf_release"); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | mempool_free(buf_to_free, cifs_sm_req_poolp); | 208 | mempool_free(buf_to_free, cifs_sm_req_poolp); |
@@ -345,19 +345,19 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
345 | /* with userid/password pairs found on the smb session */ | 345 | /* with userid/password pairs found on the smb session */ |
346 | /* for other target tcp/ip addresses BB */ | 346 | /* for other target tcp/ip addresses BB */ |
347 | if (current_fsuid() != treeCon->ses->linux_uid) { | 347 | if (current_fsuid() != treeCon->ses->linux_uid) { |
348 | cFYI(1, ("Multiuser mode and UID " | 348 | cFYI(1, "Multiuser mode and UID " |
349 | "did not match tcon uid")); | 349 | "did not match tcon uid"); |
350 | read_lock(&cifs_tcp_ses_lock); | 350 | read_lock(&cifs_tcp_ses_lock); |
351 | list_for_each(temp_item, &treeCon->ses->server->smb_ses_list) { | 351 | list_for_each(temp_item, &treeCon->ses->server->smb_ses_list) { |
352 | ses = list_entry(temp_item, struct cifsSesInfo, smb_ses_list); | 352 | ses = list_entry(temp_item, struct cifsSesInfo, smb_ses_list); |
353 | if (ses->linux_uid == current_fsuid()) { | 353 | if (ses->linux_uid == current_fsuid()) { |
354 | if (ses->server == treeCon->ses->server) { | 354 | if (ses->server == treeCon->ses->server) { |
355 | cFYI(1, ("found matching uid substitute right smb_uid")); | 355 | cFYI(1, "found matching uid substitute right smb_uid"); |
356 | buffer->Uid = ses->Suid; | 356 | buffer->Uid = ses->Suid; |
357 | break; | 357 | break; |
358 | } else { | 358 | } else { |
359 | /* BB eventually call cifs_setup_session here */ | 359 | /* BB eventually call cifs_setup_session here */ |
360 | cFYI(1, ("local UID found but no smb sess with this server exists")); | 360 | cFYI(1, "local UID found but no smb sess with this server exists"); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | } | 363 | } |
@@ -394,17 +394,16 @@ checkSMBhdr(struct smb_hdr *smb, __u16 mid) | |||
394 | if (smb->Command == SMB_COM_LOCKING_ANDX) | 394 | if (smb->Command == SMB_COM_LOCKING_ANDX) |
395 | return 0; | 395 | return 0; |
396 | else | 396 | else |
397 | cERROR(1, ("Received Request not response")); | 397 | cERROR(1, "Received Request not response"); |
398 | } | 398 | } |
399 | } else { /* bad signature or mid */ | 399 | } else { /* bad signature or mid */ |
400 | if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) | 400 | if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) |
401 | cERROR(1, | 401 | cERROR(1, "Bad protocol string signature header %x", |
402 | ("Bad protocol string signature header %x", | 402 | *(unsigned int *) smb->Protocol); |
403 | *(unsigned int *) smb->Protocol)); | ||
404 | if (mid != smb->Mid) | 403 | if (mid != smb->Mid) |
405 | cERROR(1, ("Mids do not match")); | 404 | cERROR(1, "Mids do not match"); |
406 | } | 405 | } |
407 | cERROR(1, ("bad smb detected. The Mid=%d", smb->Mid)); | 406 | cERROR(1, "bad smb detected. The Mid=%d", smb->Mid); |
408 | return 1; | 407 | return 1; |
409 | } | 408 | } |
410 | 409 | ||
@@ -413,7 +412,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
413 | { | 412 | { |
414 | __u32 len = smb->smb_buf_length; | 413 | __u32 len = smb->smb_buf_length; |
415 | __u32 clc_len; /* calculated length */ | 414 | __u32 clc_len; /* calculated length */ |
416 | cFYI(0, ("checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len)); | 415 | cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len); |
417 | 416 | ||
418 | if (length < 2 + sizeof(struct smb_hdr)) { | 417 | if (length < 2 + sizeof(struct smb_hdr)) { |
419 | if ((length >= sizeof(struct smb_hdr) - 1) | 418 | if ((length >= sizeof(struct smb_hdr) - 1) |
@@ -437,15 +436,15 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
437 | tmp[sizeof(struct smb_hdr)+1] = 0; | 436 | tmp[sizeof(struct smb_hdr)+1] = 0; |
438 | return 0; | 437 | return 0; |
439 | } | 438 | } |
440 | cERROR(1, ("rcvd invalid byte count (bcc)")); | 439 | cERROR(1, "rcvd invalid byte count (bcc)"); |
441 | } else { | 440 | } else { |
442 | cERROR(1, ("Length less than smb header size")); | 441 | cERROR(1, "Length less than smb header size"); |
443 | } | 442 | } |
444 | return 1; | 443 | return 1; |
445 | } | 444 | } |
446 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { | 445 | if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
447 | cERROR(1, ("smb length greater than MaxBufSize, mid=%d", | 446 | cERROR(1, "smb length greater than MaxBufSize, mid=%d", |
448 | smb->Mid)); | 447 | smb->Mid); |
449 | return 1; | 448 | return 1; |
450 | } | 449 | } |
451 | 450 | ||
@@ -454,8 +453,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
454 | clc_len = smbCalcSize_LE(smb); | 453 | clc_len = smbCalcSize_LE(smb); |
455 | 454 | ||
456 | if (4 + len != length) { | 455 | if (4 + len != length) { |
457 | cERROR(1, ("Length read does not match RFC1001 length %d", | 456 | cERROR(1, "Length read does not match RFC1001 length %d", |
458 | len)); | 457 | len); |
459 | return 1; | 458 | return 1; |
460 | } | 459 | } |
461 | 460 | ||
@@ -466,8 +465,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
466 | if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) | 465 | if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) |
467 | return 0; /* bcc wrapped */ | 466 | return 0; /* bcc wrapped */ |
468 | } | 467 | } |
469 | cFYI(1, ("Calculated size %d vs length %d mismatch for mid %d", | 468 | cFYI(1, "Calculated size %d vs length %d mismatch for mid %d", |
470 | clc_len, 4 + len, smb->Mid)); | 469 | clc_len, 4 + len, smb->Mid); |
471 | /* Windows XP can return a few bytes too much, presumably | 470 | /* Windows XP can return a few bytes too much, presumably |
472 | an illegal pad, at the end of byte range lock responses | 471 | an illegal pad, at the end of byte range lock responses |
473 | so we allow for that three byte pad, as long as actual | 472 | so we allow for that three byte pad, as long as actual |
@@ -482,8 +481,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
482 | if ((4+len > clc_len) && (len <= clc_len + 512)) | 481 | if ((4+len > clc_len) && (len <= clc_len + 512)) |
483 | return 0; | 482 | return 0; |
484 | else { | 483 | else { |
485 | cERROR(1, ("RFC1001 size %d bigger than SMB for Mid=%d", | 484 | cERROR(1, "RFC1001 size %d bigger than SMB for Mid=%d", |
486 | len, smb->Mid)); | 485 | len, smb->Mid); |
487 | return 1; | 486 | return 1; |
488 | } | 487 | } |
489 | } | 488 | } |
@@ -501,7 +500,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
501 | struct cifsFileInfo *netfile; | 500 | struct cifsFileInfo *netfile; |
502 | int rc; | 501 | int rc; |
503 | 502 | ||
504 | cFYI(1, ("Checking for oplock break or dnotify response")); | 503 | cFYI(1, "Checking for oplock break or dnotify response"); |
505 | if ((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) && | 504 | if ((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) && |
506 | (pSMB->hdr.Flags & SMBFLG_RESPONSE)) { | 505 | (pSMB->hdr.Flags & SMBFLG_RESPONSE)) { |
507 | struct smb_com_transaction_change_notify_rsp *pSMBr = | 506 | struct smb_com_transaction_change_notify_rsp *pSMBr = |
@@ -513,15 +512,15 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
513 | 512 | ||
514 | pnotify = (struct file_notify_information *) | 513 | pnotify = (struct file_notify_information *) |
515 | ((char *)&pSMBr->hdr.Protocol + data_offset); | 514 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
516 | cFYI(1, ("dnotify on %s Action: 0x%x", | 515 | cFYI(1, "dnotify on %s Action: 0x%x", |
517 | pnotify->FileName, pnotify->Action)); | 516 | pnotify->FileName, pnotify->Action); |
518 | /* cifs_dump_mem("Rcvd notify Data: ",buf, | 517 | /* cifs_dump_mem("Rcvd notify Data: ",buf, |
519 | sizeof(struct smb_hdr)+60); */ | 518 | sizeof(struct smb_hdr)+60); */ |
520 | return true; | 519 | return true; |
521 | } | 520 | } |
522 | if (pSMBr->hdr.Status.CifsError) { | 521 | if (pSMBr->hdr.Status.CifsError) { |
523 | cFYI(1, ("notify err 0x%d", | 522 | cFYI(1, "notify err 0x%d", |
524 | pSMBr->hdr.Status.CifsError)); | 523 | pSMBr->hdr.Status.CifsError); |
525 | return true; | 524 | return true; |
526 | } | 525 | } |
527 | return false; | 526 | return false; |
@@ -535,7 +534,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
535 | large dirty files cached on the client */ | 534 | large dirty files cached on the client */ |
536 | if ((NT_STATUS_INVALID_HANDLE) == | 535 | if ((NT_STATUS_INVALID_HANDLE) == |
537 | le32_to_cpu(pSMB->hdr.Status.CifsError)) { | 536 | le32_to_cpu(pSMB->hdr.Status.CifsError)) { |
538 | cFYI(1, ("invalid handle on oplock break")); | 537 | cFYI(1, "invalid handle on oplock break"); |
539 | return true; | 538 | return true; |
540 | } else if (ERRbadfid == | 539 | } else if (ERRbadfid == |
541 | le16_to_cpu(pSMB->hdr.Status.DosError.Error)) { | 540 | le16_to_cpu(pSMB->hdr.Status.DosError.Error)) { |
@@ -547,8 +546,8 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
547 | if (pSMB->hdr.WordCount != 8) | 546 | if (pSMB->hdr.WordCount != 8) |
548 | return false; | 547 | return false; |
549 | 548 | ||
550 | cFYI(1, ("oplock type 0x%d level 0x%d", | 549 | cFYI(1, "oplock type 0x%d level 0x%d", |
551 | pSMB->LockType, pSMB->OplockLevel)); | 550 | pSMB->LockType, pSMB->OplockLevel); |
552 | if (!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)) | 551 | if (!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)) |
553 | return false; | 552 | return false; |
554 | 553 | ||
@@ -579,15 +578,15 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
579 | return true; | 578 | return true; |
580 | } | 579 | } |
581 | 580 | ||
582 | cFYI(1, ("file id match, oplock break")); | 581 | cFYI(1, "file id match, oplock break"); |
583 | pCifsInode = CIFS_I(netfile->pInode); | 582 | pCifsInode = CIFS_I(netfile->pInode); |
584 | pCifsInode->clientCanCacheAll = false; | 583 | pCifsInode->clientCanCacheAll = false; |
585 | if (pSMB->OplockLevel == 0) | 584 | if (pSMB->OplockLevel == 0) |
586 | pCifsInode->clientCanCacheRead = false; | 585 | pCifsInode->clientCanCacheRead = false; |
587 | rc = slow_work_enqueue(&netfile->oplock_break); | 586 | rc = slow_work_enqueue(&netfile->oplock_break); |
588 | if (rc) { | 587 | if (rc) { |
589 | cERROR(1, ("failed to enqueue oplock " | 588 | cERROR(1, "failed to enqueue oplock " |
590 | "break: %d\n", rc)); | 589 | "break: %d\n", rc); |
591 | } else { | 590 | } else { |
592 | netfile->oplock_break_cancelled = false; | 591 | netfile->oplock_break_cancelled = false; |
593 | } | 592 | } |
@@ -597,12 +596,12 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) | |||
597 | } | 596 | } |
598 | read_unlock(&GlobalSMBSeslock); | 597 | read_unlock(&GlobalSMBSeslock); |
599 | read_unlock(&cifs_tcp_ses_lock); | 598 | read_unlock(&cifs_tcp_ses_lock); |
600 | cFYI(1, ("No matching file for oplock break")); | 599 | cFYI(1, "No matching file for oplock break"); |
601 | return true; | 600 | return true; |
602 | } | 601 | } |
603 | } | 602 | } |
604 | read_unlock(&cifs_tcp_ses_lock); | 603 | read_unlock(&cifs_tcp_ses_lock); |
605 | cFYI(1, ("Can not process oplock break for non-existent connection")); | 604 | cFYI(1, "Can not process oplock break for non-existent connection"); |
606 | return true; | 605 | return true; |
607 | } | 606 | } |
608 | 607 | ||
@@ -721,11 +720,11 @@ cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb) | |||
721 | { | 720 | { |
722 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { | 721 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { |
723 | cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM; | 722 | cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM; |
724 | cERROR(1, ("Autodisabling the use of server inode numbers on " | 723 | cERROR(1, "Autodisabling the use of server inode numbers on " |
725 | "%s. This server doesn't seem to support them " | 724 | "%s. This server doesn't seem to support them " |
726 | "properly. Hardlinks will not be recognized on this " | 725 | "properly. Hardlinks will not be recognized on this " |
727 | "mount. Consider mounting with the \"noserverino\" " | 726 | "mount. Consider mounting with the \"noserverino\" " |
728 | "option to silence this message.", | 727 | "option to silence this message.", |
729 | cifs_sb->tcon->treeName)); | 728 | cifs_sb->tcon->treeName); |
730 | } | 729 | } |
731 | } | 730 | } |
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index bd6d6895730d..d35d52889cb5 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -149,7 +149,7 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst) | |||
149 | else if (address_family == AF_INET6) | 149 | else if (address_family == AF_INET6) |
150 | ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL); | 150 | ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL); |
151 | 151 | ||
152 | cFYI(DBG2, ("address conversion returned %d for %s", ret, cp)); | 152 | cFYI(DBG2, "address conversion returned %d for %s", ret, cp); |
153 | if (ret > 0) | 153 | if (ret > 0) |
154 | ret = 1; | 154 | ret = 1; |
155 | return ret; | 155 | return ret; |
@@ -870,8 +870,8 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr) | |||
870 | } | 870 | } |
871 | /* else ERRHRD class errors or junk - return EIO */ | 871 | /* else ERRHRD class errors or junk - return EIO */ |
872 | 872 | ||
873 | cFYI(1, ("Mapping smb error code %d to POSIX err %d", | 873 | cFYI(1, "Mapping smb error code %d to POSIX err %d", |
874 | smberrcode, rc)); | 874 | smberrcode, rc); |
875 | 875 | ||
876 | /* generic corrective action e.g. reconnect SMB session on | 876 | /* generic corrective action e.g. reconnect SMB session on |
877 | * ERRbaduid could be added */ | 877 | * ERRbaduid could be added */ |
@@ -940,20 +940,20 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset) | |||
940 | SMB_TIME *st = (SMB_TIME *)&time; | 940 | SMB_TIME *st = (SMB_TIME *)&time; |
941 | SMB_DATE *sd = (SMB_DATE *)&date; | 941 | SMB_DATE *sd = (SMB_DATE *)&date; |
942 | 942 | ||
943 | cFYI(1, ("date %d time %d", date, time)); | 943 | cFYI(1, "date %d time %d", date, time); |
944 | 944 | ||
945 | sec = 2 * st->TwoSeconds; | 945 | sec = 2 * st->TwoSeconds; |
946 | min = st->Minutes; | 946 | min = st->Minutes; |
947 | if ((sec > 59) || (min > 59)) | 947 | if ((sec > 59) || (min > 59)) |
948 | cERROR(1, ("illegal time min %d sec %d", min, sec)); | 948 | cERROR(1, "illegal time min %d sec %d", min, sec); |
949 | sec += (min * 60); | 949 | sec += (min * 60); |
950 | sec += 60 * 60 * st->Hours; | 950 | sec += 60 * 60 * st->Hours; |
951 | if (st->Hours > 24) | 951 | if (st->Hours > 24) |
952 | cERROR(1, ("illegal hours %d", st->Hours)); | 952 | cERROR(1, "illegal hours %d", st->Hours); |
953 | days = sd->Day; | 953 | days = sd->Day; |
954 | month = sd->Month; | 954 | month = sd->Month; |
955 | if ((days > 31) || (month > 12)) { | 955 | if ((days > 31) || (month > 12)) { |
956 | cERROR(1, ("illegal date, month %d day: %d", month, days)); | 956 | cERROR(1, "illegal date, month %d day: %d", month, days); |
957 | if (month > 12) | 957 | if (month > 12) |
958 | month = 12; | 958 | month = 12; |
959 | } | 959 | } |
@@ -979,7 +979,7 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset) | |||
979 | 979 | ||
980 | ts.tv_sec = sec + offset; | 980 | ts.tv_sec = sec + offset; |
981 | 981 | ||
982 | /* cFYI(1,("sec after cnvrt dos to unix time %d",sec)); */ | 982 | /* cFYI(1, "sec after cnvrt dos to unix time %d",sec); */ |
983 | 983 | ||
984 | ts.tv_nsec = 0; | 984 | ts.tv_nsec = 0; |
985 | return ts; | 985 | return ts; |
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index 18e0bc1fb593..daf1753af674 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -47,15 +47,15 @@ static void dump_cifs_file_struct(struct file *file, char *label) | |||
47 | if (file) { | 47 | if (file) { |
48 | cf = file->private_data; | 48 | cf = file->private_data; |
49 | if (cf == NULL) { | 49 | if (cf == NULL) { |
50 | cFYI(1, ("empty cifs private file data")); | 50 | cFYI(1, "empty cifs private file data"); |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | if (cf->invalidHandle) | 53 | if (cf->invalidHandle) |
54 | cFYI(1, ("invalid handle")); | 54 | cFYI(1, "invalid handle"); |
55 | if (cf->srch_inf.endOfSearch) | 55 | if (cf->srch_inf.endOfSearch) |
56 | cFYI(1, ("end of search")); | 56 | cFYI(1, "end of search"); |
57 | if (cf->srch_inf.emptyDir) | 57 | if (cf->srch_inf.emptyDir) |
58 | cFYI(1, ("empty dir")); | 58 | cFYI(1, "empty dir"); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | #else | 61 | #else |
@@ -76,7 +76,7 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name, | |||
76 | struct inode *inode; | 76 | struct inode *inode; |
77 | struct super_block *sb = parent->d_inode->i_sb; | 77 | struct super_block *sb = parent->d_inode->i_sb; |
78 | 78 | ||
79 | cFYI(1, ("For %s", name->name)); | 79 | cFYI(1, "For %s", name->name); |
80 | 80 | ||
81 | if (parent->d_op && parent->d_op->d_hash) | 81 | if (parent->d_op && parent->d_op->d_hash) |
82 | parent->d_op->d_hash(parent, name); | 82 | parent->d_op->d_hash(parent, name); |
@@ -214,7 +214,7 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb, | |||
214 | fid, | 214 | fid, |
215 | cifs_sb->local_nls); | 215 | cifs_sb->local_nls); |
216 | if (CIFSSMBClose(xid, ptcon, fid)) { | 216 | if (CIFSSMBClose(xid, ptcon, fid)) { |
217 | cFYI(1, ("Error closing temporary reparsepoint open)")); | 217 | cFYI(1, "Error closing temporary reparsepoint open"); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | } | 220 | } |
@@ -252,7 +252,7 @@ static int initiate_cifs_search(const int xid, struct file *file) | |||
252 | if (full_path == NULL) | 252 | if (full_path == NULL) |
253 | return -ENOMEM; | 253 | return -ENOMEM; |
254 | 254 | ||
255 | cFYI(1, ("Full path: %s start at: %lld", full_path, file->f_pos)); | 255 | cFYI(1, "Full path: %s start at: %lld", full_path, file->f_pos); |
256 | 256 | ||
257 | ffirst_retry: | 257 | ffirst_retry: |
258 | /* test for Unix extensions */ | 258 | /* test for Unix extensions */ |
@@ -297,7 +297,7 @@ static int cifs_unicode_bytelen(char *str) | |||
297 | if (ustr[len] == 0) | 297 | if (ustr[len] == 0) |
298 | return len << 1; | 298 | return len << 1; |
299 | } | 299 | } |
300 | cFYI(1, ("Unicode string longer than PATH_MAX found")); | 300 | cFYI(1, "Unicode string longer than PATH_MAX found"); |
301 | return len << 1; | 301 | return len << 1; |
302 | } | 302 | } |
303 | 303 | ||
@@ -314,19 +314,18 @@ static char *nxt_dir_entry(char *old_entry, char *end_of_smb, int level) | |||
314 | pfData->FileNameLength; | 314 | pfData->FileNameLength; |
315 | } else | 315 | } else |
316 | new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset); | 316 | new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset); |
317 | cFYI(1, ("new entry %p old entry %p", new_entry, old_entry)); | 317 | cFYI(1, "new entry %p old entry %p", new_entry, old_entry); |
318 | /* validate that new_entry is not past end of SMB */ | 318 | /* validate that new_entry is not past end of SMB */ |
319 | if (new_entry >= end_of_smb) { | 319 | if (new_entry >= end_of_smb) { |
320 | cERROR(1, | 320 | cERROR(1, "search entry %p began after end of SMB %p old entry %p", |
321 | ("search entry %p began after end of SMB %p old entry %p", | 321 | new_entry, end_of_smb, old_entry); |
322 | new_entry, end_of_smb, old_entry)); | ||
323 | return NULL; | 322 | return NULL; |
324 | } else if (((level == SMB_FIND_FILE_INFO_STANDARD) && | 323 | } else if (((level == SMB_FIND_FILE_INFO_STANDARD) && |
325 | (new_entry + sizeof(FIND_FILE_STANDARD_INFO) > end_of_smb)) | 324 | (new_entry + sizeof(FIND_FILE_STANDARD_INFO) > end_of_smb)) |
326 | || ((level != SMB_FIND_FILE_INFO_STANDARD) && | 325 | || ((level != SMB_FIND_FILE_INFO_STANDARD) && |
327 | (new_entry + sizeof(FILE_DIRECTORY_INFO) > end_of_smb))) { | 326 | (new_entry + sizeof(FILE_DIRECTORY_INFO) > end_of_smb))) { |
328 | cERROR(1, ("search entry %p extends after end of SMB %p", | 327 | cERROR(1, "search entry %p extends after end of SMB %p", |
329 | new_entry, end_of_smb)); | 328 | new_entry, end_of_smb); |
330 | return NULL; | 329 | return NULL; |
331 | } else | 330 | } else |
332 | return new_entry; | 331 | return new_entry; |
@@ -380,8 +379,8 @@ static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile) | |||
380 | filename = &pFindData->FileName[0]; | 379 | filename = &pFindData->FileName[0]; |
381 | len = pFindData->FileNameLength; | 380 | len = pFindData->FileNameLength; |
382 | } else { | 381 | } else { |
383 | cFYI(1, ("Unknown findfirst level %d", | 382 | cFYI(1, "Unknown findfirst level %d", |
384 | cfile->srch_inf.info_level)); | 383 | cfile->srch_inf.info_level); |
385 | } | 384 | } |
386 | 385 | ||
387 | if (filename) { | 386 | if (filename) { |
@@ -481,7 +480,7 @@ static int cifs_save_resume_key(const char *current_entry, | |||
481 | len = (unsigned int)pFindData->FileNameLength; | 480 | len = (unsigned int)pFindData->FileNameLength; |
482 | cifsFile->srch_inf.resume_key = pFindData->ResumeKey; | 481 | cifsFile->srch_inf.resume_key = pFindData->ResumeKey; |
483 | } else { | 482 | } else { |
484 | cFYI(1, ("Unknown findfirst level %d", level)); | 483 | cFYI(1, "Unknown findfirst level %d", level); |
485 | return -EINVAL; | 484 | return -EINVAL; |
486 | } | 485 | } |
487 | cifsFile->srch_inf.resume_name_len = len; | 486 | cifsFile->srch_inf.resume_name_len = len; |
@@ -525,7 +524,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
525 | is_dir_changed(file)) || | 524 | is_dir_changed(file)) || |
526 | (index_to_find < first_entry_in_buffer)) { | 525 | (index_to_find < first_entry_in_buffer)) { |
527 | /* close and restart search */ | 526 | /* close and restart search */ |
528 | cFYI(1, ("search backing up - close and restart search")); | 527 | cFYI(1, "search backing up - close and restart search"); |
529 | write_lock(&GlobalSMBSeslock); | 528 | write_lock(&GlobalSMBSeslock); |
530 | if (!cifsFile->srch_inf.endOfSearch && | 529 | if (!cifsFile->srch_inf.endOfSearch && |
531 | !cifsFile->invalidHandle) { | 530 | !cifsFile->invalidHandle) { |
@@ -535,7 +534,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
535 | } else | 534 | } else |
536 | write_unlock(&GlobalSMBSeslock); | 535 | write_unlock(&GlobalSMBSeslock); |
537 | if (cifsFile->srch_inf.ntwrk_buf_start) { | 536 | if (cifsFile->srch_inf.ntwrk_buf_start) { |
538 | cFYI(1, ("freeing SMB ff cache buf on search rewind")); | 537 | cFYI(1, "freeing SMB ff cache buf on search rewind"); |
539 | if (cifsFile->srch_inf.smallBuf) | 538 | if (cifsFile->srch_inf.smallBuf) |
540 | cifs_small_buf_release(cifsFile->srch_inf. | 539 | cifs_small_buf_release(cifsFile->srch_inf. |
541 | ntwrk_buf_start); | 540 | ntwrk_buf_start); |
@@ -546,8 +545,8 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
546 | } | 545 | } |
547 | rc = initiate_cifs_search(xid, file); | 546 | rc = initiate_cifs_search(xid, file); |
548 | if (rc) { | 547 | if (rc) { |
549 | cFYI(1, ("error %d reinitiating a search on rewind", | 548 | cFYI(1, "error %d reinitiating a search on rewind", |
550 | rc)); | 549 | rc); |
551 | return rc; | 550 | return rc; |
552 | } | 551 | } |
553 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); | 552 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); |
@@ -555,7 +554,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
555 | 554 | ||
556 | while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && | 555 | while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && |
557 | (rc == 0) && !cifsFile->srch_inf.endOfSearch) { | 556 | (rc == 0) && !cifsFile->srch_inf.endOfSearch) { |
558 | cFYI(1, ("calling findnext2")); | 557 | cFYI(1, "calling findnext2"); |
559 | rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, | 558 | rc = CIFSFindNext(xid, pTcon, cifsFile->netfid, |
560 | &cifsFile->srch_inf); | 559 | &cifsFile->srch_inf); |
561 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); | 560 | cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile); |
@@ -575,7 +574,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
575 | first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry | 574 | first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry |
576 | - cifsFile->srch_inf.entries_in_buffer; | 575 | - cifsFile->srch_inf.entries_in_buffer; |
577 | pos_in_buf = index_to_find - first_entry_in_buffer; | 576 | pos_in_buf = index_to_find - first_entry_in_buffer; |
578 | cFYI(1, ("found entry - pos_in_buf %d", pos_in_buf)); | 577 | cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); |
579 | 578 | ||
580 | for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) { | 579 | for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) { |
581 | /* go entry by entry figuring out which is first */ | 580 | /* go entry by entry figuring out which is first */ |
@@ -584,19 +583,19 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon, | |||
584 | } | 583 | } |
585 | if ((current_entry == NULL) && (i < pos_in_buf)) { | 584 | if ((current_entry == NULL) && (i < pos_in_buf)) { |
586 | /* BB fixme - check if we should flag this error */ | 585 | /* BB fixme - check if we should flag this error */ |
587 | cERROR(1, ("reached end of buf searching for pos in buf" | 586 | cERROR(1, "reached end of buf searching for pos in buf" |
588 | " %d index to find %lld rc %d", | 587 | " %d index to find %lld rc %d", |
589 | pos_in_buf, index_to_find, rc)); | 588 | pos_in_buf, index_to_find, rc); |
590 | } | 589 | } |
591 | rc = 0; | 590 | rc = 0; |
592 | *ppCurrentEntry = current_entry; | 591 | *ppCurrentEntry = current_entry; |
593 | } else { | 592 | } else { |
594 | cFYI(1, ("index not in buffer - could not findnext into it")); | 593 | cFYI(1, "index not in buffer - could not findnext into it"); |
595 | return 0; | 594 | return 0; |
596 | } | 595 | } |
597 | 596 | ||
598 | if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) { | 597 | if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) { |
599 | cFYI(1, ("can not return entries pos_in_buf beyond last")); | 598 | cFYI(1, "can not return entries pos_in_buf beyond last"); |
600 | *num_to_ret = 0; | 599 | *num_to_ret = 0; |
601 | } else | 600 | } else |
602 | *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf; | 601 | *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf; |
@@ -656,12 +655,12 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst, | |||
656 | /* one byte length, no name conversion */ | 655 | /* one byte length, no name conversion */ |
657 | len = (unsigned int)pFindData->FileNameLength; | 656 | len = (unsigned int)pFindData->FileNameLength; |
658 | } else { | 657 | } else { |
659 | cFYI(1, ("Unknown findfirst level %d", level)); | 658 | cFYI(1, "Unknown findfirst level %d", level); |
660 | return -EINVAL; | 659 | return -EINVAL; |
661 | } | 660 | } |
662 | 661 | ||
663 | if (len > max_len) { | 662 | if (len > max_len) { |
664 | cERROR(1, ("bad search response length %d past smb end", len)); | 663 | cERROR(1, "bad search response length %d past smb end", len); |
665 | return -EINVAL; | 664 | return -EINVAL; |
666 | } | 665 | } |
667 | 666 | ||
@@ -754,7 +753,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir, | |||
754 | * case already. Why should we be clobbering other errors from it? | 753 | * case already. Why should we be clobbering other errors from it? |
755 | */ | 754 | */ |
756 | if (rc) { | 755 | if (rc) { |
757 | cFYI(1, ("filldir rc = %d", rc)); | 756 | cFYI(1, "filldir rc = %d", rc); |
758 | rc = -EOVERFLOW; | 757 | rc = -EOVERFLOW; |
759 | } | 758 | } |
760 | dput(tmp_dentry); | 759 | dput(tmp_dentry); |
@@ -786,7 +785,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
786 | case 0: | 785 | case 0: |
787 | if (filldir(direntry, ".", 1, file->f_pos, | 786 | if (filldir(direntry, ".", 1, file->f_pos, |
788 | file->f_path.dentry->d_inode->i_ino, DT_DIR) < 0) { | 787 | file->f_path.dentry->d_inode->i_ino, DT_DIR) < 0) { |
789 | cERROR(1, ("Filldir for current dir failed")); | 788 | cERROR(1, "Filldir for current dir failed"); |
790 | rc = -ENOMEM; | 789 | rc = -ENOMEM; |
791 | break; | 790 | break; |
792 | } | 791 | } |
@@ -794,7 +793,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
794 | case 1: | 793 | case 1: |
795 | if (filldir(direntry, "..", 2, file->f_pos, | 794 | if (filldir(direntry, "..", 2, file->f_pos, |
796 | file->f_path.dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) { | 795 | file->f_path.dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) { |
797 | cERROR(1, ("Filldir for parent dir failed")); | 796 | cERROR(1, "Filldir for parent dir failed"); |
798 | rc = -ENOMEM; | 797 | rc = -ENOMEM; |
799 | break; | 798 | break; |
800 | } | 799 | } |
@@ -807,7 +806,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
807 | 806 | ||
808 | if (file->private_data == NULL) { | 807 | if (file->private_data == NULL) { |
809 | rc = initiate_cifs_search(xid, file); | 808 | rc = initiate_cifs_search(xid, file); |
810 | cFYI(1, ("initiate cifs search rc %d", rc)); | 809 | cFYI(1, "initiate cifs search rc %d", rc); |
811 | if (rc) { | 810 | if (rc) { |
812 | FreeXid(xid); | 811 | FreeXid(xid); |
813 | return rc; | 812 | return rc; |
@@ -821,7 +820,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
821 | cifsFile = file->private_data; | 820 | cifsFile = file->private_data; |
822 | if (cifsFile->srch_inf.endOfSearch) { | 821 | if (cifsFile->srch_inf.endOfSearch) { |
823 | if (cifsFile->srch_inf.emptyDir) { | 822 | if (cifsFile->srch_inf.emptyDir) { |
824 | cFYI(1, ("End of search, empty dir")); | 823 | cFYI(1, "End of search, empty dir"); |
825 | rc = 0; | 824 | rc = 0; |
826 | break; | 825 | break; |
827 | } | 826 | } |
@@ -833,16 +832,16 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
833 | rc = find_cifs_entry(xid, pTcon, file, | 832 | rc = find_cifs_entry(xid, pTcon, file, |
834 | ¤t_entry, &num_to_fill); | 833 | ¤t_entry, &num_to_fill); |
835 | if (rc) { | 834 | if (rc) { |
836 | cFYI(1, ("fce error %d", rc)); | 835 | cFYI(1, "fce error %d", rc); |
837 | goto rddir2_exit; | 836 | goto rddir2_exit; |
838 | } else if (current_entry != NULL) { | 837 | } else if (current_entry != NULL) { |
839 | cFYI(1, ("entry %lld found", file->f_pos)); | 838 | cFYI(1, "entry %lld found", file->f_pos); |
840 | } else { | 839 | } else { |
841 | cFYI(1, ("could not find entry")); | 840 | cFYI(1, "could not find entry"); |
842 | goto rddir2_exit; | 841 | goto rddir2_exit; |
843 | } | 842 | } |
844 | cFYI(1, ("loop through %d times filling dir for net buf %p", | 843 | cFYI(1, "loop through %d times filling dir for net buf %p", |
845 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start)); | 844 | num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); |
846 | max_len = smbCalcSize((struct smb_hdr *) | 845 | max_len = smbCalcSize((struct smb_hdr *) |
847 | cifsFile->srch_inf.ntwrk_buf_start); | 846 | cifsFile->srch_inf.ntwrk_buf_start); |
848 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; | 847 | end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; |
@@ -851,8 +850,8 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
851 | for (i = 0; (i < num_to_fill) && (rc == 0); i++) { | 850 | for (i = 0; (i < num_to_fill) && (rc == 0); i++) { |
852 | if (current_entry == NULL) { | 851 | if (current_entry == NULL) { |
853 | /* evaluate whether this case is an error */ | 852 | /* evaluate whether this case is an error */ |
854 | cERROR(1, ("past SMB end, num to fill %d i %d", | 853 | cERROR(1, "past SMB end, num to fill %d i %d", |
855 | num_to_fill, i)); | 854 | num_to_fill, i); |
856 | break; | 855 | break; |
857 | } | 856 | } |
858 | /* if buggy server returns . and .. late do | 857 | /* if buggy server returns . and .. late do |
@@ -867,8 +866,8 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) | |||
867 | file->f_pos++; | 866 | file->f_pos++; |
868 | if (file->f_pos == | 867 | if (file->f_pos == |
869 | cifsFile->srch_inf.index_of_last_entry) { | 868 | cifsFile->srch_inf.index_of_last_entry) { |
870 | cFYI(1, ("last entry in buf at pos %lld %s", | 869 | cFYI(1, "last entry in buf at pos %lld %s", |
871 | file->f_pos, tmp_buf)); | 870 | file->f_pos, tmp_buf); |
872 | cifs_save_resume_key(current_entry, cifsFile); | 871 | cifs_save_resume_key(current_entry, cifsFile); |
873 | break; | 872 | break; |
874 | } else | 873 | } else |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 7c3fd7463f44..7707389bdf2c 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -35,9 +35,11 @@ | |||
35 | extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, | 35 | extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, |
36 | unsigned char *p24); | 36 | unsigned char *p24); |
37 | 37 | ||
38 | /* Checks if this is the first smb session to be reconnected after | 38 | /* |
39 | the socket has been reestablished (so we know whether to use vc 0). | 39 | * Checks if this is the first smb session to be reconnected after |
40 | Called while holding the cifs_tcp_ses_lock, so do not block */ | 40 | * the socket has been reestablished (so we know whether to use vc 0). |
41 | * Called while holding the cifs_tcp_ses_lock, so do not block | ||
42 | */ | ||
41 | static bool is_first_ses_reconnect(struct cifsSesInfo *ses) | 43 | static bool is_first_ses_reconnect(struct cifsSesInfo *ses) |
42 | { | 44 | { |
43 | struct list_head *tmp; | 45 | struct list_head *tmp; |
@@ -284,7 +286,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, | |||
284 | int len; | 286 | int len; |
285 | char *data = *pbcc_area; | 287 | char *data = *pbcc_area; |
286 | 288 | ||
287 | cFYI(1, ("bleft %d", bleft)); | 289 | cFYI(1, "bleft %d", bleft); |
288 | 290 | ||
289 | /* | 291 | /* |
290 | * Windows servers do not always double null terminate their final | 292 | * Windows servers do not always double null terminate their final |
@@ -301,7 +303,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, | |||
301 | 303 | ||
302 | kfree(ses->serverOS); | 304 | kfree(ses->serverOS); |
303 | ses->serverOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp); | 305 | ses->serverOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp); |
304 | cFYI(1, ("serverOS=%s", ses->serverOS)); | 306 | cFYI(1, "serverOS=%s", ses->serverOS); |
305 | len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; | 307 | len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; |
306 | data += len; | 308 | data += len; |
307 | bleft -= len; | 309 | bleft -= len; |
@@ -310,7 +312,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, | |||
310 | 312 | ||
311 | kfree(ses->serverNOS); | 313 | kfree(ses->serverNOS); |
312 | ses->serverNOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp); | 314 | ses->serverNOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp); |
313 | cFYI(1, ("serverNOS=%s", ses->serverNOS)); | 315 | cFYI(1, "serverNOS=%s", ses->serverNOS); |
314 | len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; | 316 | len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; |
315 | data += len; | 317 | data += len; |
316 | bleft -= len; | 318 | bleft -= len; |
@@ -319,7 +321,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, | |||
319 | 321 | ||
320 | kfree(ses->serverDomain); | 322 | kfree(ses->serverDomain); |
321 | ses->serverDomain = cifs_strndup_from_ucs(data, bleft, true, nls_cp); | 323 | ses->serverDomain = cifs_strndup_from_ucs(data, bleft, true, nls_cp); |
322 | cFYI(1, ("serverDomain=%s", ses->serverDomain)); | 324 | cFYI(1, "serverDomain=%s", ses->serverDomain); |
323 | 325 | ||
324 | return; | 326 | return; |
325 | } | 327 | } |
@@ -332,7 +334,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft, | |||
332 | int len; | 334 | int len; |
333 | char *bcc_ptr = *pbcc_area; | 335 | char *bcc_ptr = *pbcc_area; |
334 | 336 | ||
335 | cFYI(1, ("decode sessetup ascii. bleft %d", bleft)); | 337 | cFYI(1, "decode sessetup ascii. bleft %d", bleft); |
336 | 338 | ||
337 | len = strnlen(bcc_ptr, bleft); | 339 | len = strnlen(bcc_ptr, bleft); |
338 | if (len >= bleft) | 340 | if (len >= bleft) |
@@ -344,7 +346,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft, | |||
344 | if (ses->serverOS) | 346 | if (ses->serverOS) |
345 | strncpy(ses->serverOS, bcc_ptr, len); | 347 | strncpy(ses->serverOS, bcc_ptr, len); |
346 | if (strncmp(ses->serverOS, "OS/2", 4) == 0) { | 348 | if (strncmp(ses->serverOS, "OS/2", 4) == 0) { |
347 | cFYI(1, ("OS/2 server")); | 349 | cFYI(1, "OS/2 server"); |
348 | ses->flags |= CIFS_SES_OS2; | 350 | ses->flags |= CIFS_SES_OS2; |
349 | } | 351 | } |
350 | 352 | ||
@@ -373,7 +375,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft, | |||
373 | /* BB For newer servers which do not support Unicode, | 375 | /* BB For newer servers which do not support Unicode, |
374 | but thus do return domain here we could add parsing | 376 | but thus do return domain here we could add parsing |
375 | for it later, but it is not very important */ | 377 | for it later, but it is not very important */ |
376 | cFYI(1, ("ascii: bytes left %d", bleft)); | 378 | cFYI(1, "ascii: bytes left %d", bleft); |
377 | 379 | ||
378 | return rc; | 380 | return rc; |
379 | } | 381 | } |
@@ -384,16 +386,16 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, | |||
384 | CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr; | 386 | CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr; |
385 | 387 | ||
386 | if (blob_len < sizeof(CHALLENGE_MESSAGE)) { | 388 | if (blob_len < sizeof(CHALLENGE_MESSAGE)) { |
387 | cERROR(1, ("challenge blob len %d too small", blob_len)); | 389 | cERROR(1, "challenge blob len %d too small", blob_len); |
388 | return -EINVAL; | 390 | return -EINVAL; |
389 | } | 391 | } |
390 | 392 | ||
391 | if (memcmp(pblob->Signature, "NTLMSSP", 8)) { | 393 | if (memcmp(pblob->Signature, "NTLMSSP", 8)) { |
392 | cERROR(1, ("blob signature incorrect %s", pblob->Signature)); | 394 | cERROR(1, "blob signature incorrect %s", pblob->Signature); |
393 | return -EINVAL; | 395 | return -EINVAL; |
394 | } | 396 | } |
395 | if (pblob->MessageType != NtLmChallenge) { | 397 | if (pblob->MessageType != NtLmChallenge) { |
396 | cERROR(1, ("Incorrect message type %d", pblob->MessageType)); | 398 | cERROR(1, "Incorrect message type %d", pblob->MessageType); |
397 | return -EINVAL; | 399 | return -EINVAL; |
398 | } | 400 | } |
399 | 401 | ||
@@ -447,7 +449,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, | |||
447 | This function returns the length of the data in the blob */ | 449 | This function returns the length of the data in the blob */ |
448 | static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | 450 | static int build_ntlmssp_auth_blob(unsigned char *pbuffer, |
449 | struct cifsSesInfo *ses, | 451 | struct cifsSesInfo *ses, |
450 | const struct nls_table *nls_cp, int first) | 452 | const struct nls_table *nls_cp, bool first) |
451 | { | 453 | { |
452 | AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer; | 454 | AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer; |
453 | __u32 flags; | 455 | __u32 flags; |
@@ -546,7 +548,7 @@ static void setup_ntlmssp_neg_req(SESSION_SETUP_ANDX *pSMB, | |||
546 | 548 | ||
547 | static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB, | 549 | static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB, |
548 | struct cifsSesInfo *ses, | 550 | struct cifsSesInfo *ses, |
549 | const struct nls_table *nls, int first_time) | 551 | const struct nls_table *nls, bool first_time) |
550 | { | 552 | { |
551 | int bloblen; | 553 | int bloblen; |
552 | 554 | ||
@@ -559,8 +561,8 @@ static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB, | |||
559 | #endif | 561 | #endif |
560 | 562 | ||
561 | int | 563 | int |
562 | CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time, | 564 | CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, |
563 | const struct nls_table *nls_cp) | 565 | const struct nls_table *nls_cp) |
564 | { | 566 | { |
565 | int rc = 0; | 567 | int rc = 0; |
566 | int wct; | 568 | int wct; |
@@ -577,13 +579,18 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time, | |||
577 | int bytes_remaining; | 579 | int bytes_remaining; |
578 | struct key *spnego_key = NULL; | 580 | struct key *spnego_key = NULL; |
579 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ | 581 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ |
582 | bool first_time; | ||
580 | 583 | ||
581 | if (ses == NULL) | 584 | if (ses == NULL) |
582 | return -EINVAL; | 585 | return -EINVAL; |
583 | 586 | ||
587 | read_lock(&cifs_tcp_ses_lock); | ||
588 | first_time = is_first_ses_reconnect(ses); | ||
589 | read_unlock(&cifs_tcp_ses_lock); | ||
590 | |||
584 | type = ses->server->secType; | 591 | type = ses->server->secType; |
585 | 592 | ||
586 | cFYI(1, ("sess setup type %d", type)); | 593 | cFYI(1, "sess setup type %d", type); |
587 | ssetup_ntlmssp_authenticate: | 594 | ssetup_ntlmssp_authenticate: |
588 | if (phase == NtLmChallenge) | 595 | if (phase == NtLmChallenge) |
589 | phase = NtLmAuthenticate; /* if ntlmssp, now final phase */ | 596 | phase = NtLmAuthenticate; /* if ntlmssp, now final phase */ |
@@ -664,7 +671,7 @@ ssetup_ntlmssp_authenticate: | |||
664 | changed to do higher than lanman dialect and | 671 | changed to do higher than lanman dialect and |
665 | we reconnected would we ever calc signing_key? */ | 672 | we reconnected would we ever calc signing_key? */ |
666 | 673 | ||
667 | cFYI(1, ("Negotiating LANMAN setting up strings")); | 674 | cFYI(1, "Negotiating LANMAN setting up strings"); |
668 | /* Unicode not allowed for LANMAN dialects */ | 675 | /* Unicode not allowed for LANMAN dialects */ |
669 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 676 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); |
670 | #endif | 677 | #endif |
@@ -744,7 +751,7 @@ ssetup_ntlmssp_authenticate: | |||
744 | unicode_ssetup_strings(&bcc_ptr, ses, nls_cp); | 751 | unicode_ssetup_strings(&bcc_ptr, ses, nls_cp); |
745 | } else | 752 | } else |
746 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 753 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); |
747 | } else if (type == Kerberos || type == MSKerberos) { | 754 | } else if (type == Kerberos) { |
748 | #ifdef CONFIG_CIFS_UPCALL | 755 | #ifdef CONFIG_CIFS_UPCALL |
749 | struct cifs_spnego_msg *msg; | 756 | struct cifs_spnego_msg *msg; |
750 | spnego_key = cifs_get_spnego_key(ses); | 757 | spnego_key = cifs_get_spnego_key(ses); |
@@ -758,17 +765,17 @@ ssetup_ntlmssp_authenticate: | |||
758 | /* check version field to make sure that cifs.upcall is | 765 | /* check version field to make sure that cifs.upcall is |
759 | sending us a response in an expected form */ | 766 | sending us a response in an expected form */ |
760 | if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { | 767 | if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) { |
761 | cERROR(1, ("incorrect version of cifs.upcall (expected" | 768 | cERROR(1, "incorrect version of cifs.upcall (expected" |
762 | " %d but got %d)", | 769 | " %d but got %d)", |
763 | CIFS_SPNEGO_UPCALL_VERSION, msg->version)); | 770 | CIFS_SPNEGO_UPCALL_VERSION, msg->version); |
764 | rc = -EKEYREJECTED; | 771 | rc = -EKEYREJECTED; |
765 | goto ssetup_exit; | 772 | goto ssetup_exit; |
766 | } | 773 | } |
767 | /* bail out if key is too long */ | 774 | /* bail out if key is too long */ |
768 | if (msg->sesskey_len > | 775 | if (msg->sesskey_len > |
769 | sizeof(ses->server->mac_signing_key.data.krb5)) { | 776 | sizeof(ses->server->mac_signing_key.data.krb5)) { |
770 | cERROR(1, ("Kerberos signing key too long (%u bytes)", | 777 | cERROR(1, "Kerberos signing key too long (%u bytes)", |
771 | msg->sesskey_len)); | 778 | msg->sesskey_len); |
772 | rc = -EOVERFLOW; | 779 | rc = -EOVERFLOW; |
773 | goto ssetup_exit; | 780 | goto ssetup_exit; |
774 | } | 781 | } |
@@ -796,7 +803,7 @@ ssetup_ntlmssp_authenticate: | |||
796 | /* BB: is this right? */ | 803 | /* BB: is this right? */ |
797 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 804 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); |
798 | #else /* ! CONFIG_CIFS_UPCALL */ | 805 | #else /* ! CONFIG_CIFS_UPCALL */ |
799 | cERROR(1, ("Kerberos negotiated but upcall support disabled!")); | 806 | cERROR(1, "Kerberos negotiated but upcall support disabled!"); |
800 | rc = -ENOSYS; | 807 | rc = -ENOSYS; |
801 | goto ssetup_exit; | 808 | goto ssetup_exit; |
802 | #endif /* CONFIG_CIFS_UPCALL */ | 809 | #endif /* CONFIG_CIFS_UPCALL */ |
@@ -804,12 +811,12 @@ ssetup_ntlmssp_authenticate: | |||
804 | #ifdef CONFIG_CIFS_EXPERIMENTAL | 811 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
805 | if (type == RawNTLMSSP) { | 812 | if (type == RawNTLMSSP) { |
806 | if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) { | 813 | if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) { |
807 | cERROR(1, ("NTLMSSP requires Unicode support")); | 814 | cERROR(1, "NTLMSSP requires Unicode support"); |
808 | rc = -ENOSYS; | 815 | rc = -ENOSYS; |
809 | goto ssetup_exit; | 816 | goto ssetup_exit; |
810 | } | 817 | } |
811 | 818 | ||
812 | cFYI(1, ("ntlmssp session setup phase %d", phase)); | 819 | cFYI(1, "ntlmssp session setup phase %d", phase); |
813 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; | 820 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; |
814 | capabilities |= CAP_EXTENDED_SECURITY; | 821 | capabilities |= CAP_EXTENDED_SECURITY; |
815 | pSMB->req.Capabilities |= cpu_to_le32(capabilities); | 822 | pSMB->req.Capabilities |= cpu_to_le32(capabilities); |
@@ -827,7 +834,7 @@ ssetup_ntlmssp_authenticate: | |||
827 | on the response (challenge) */ | 834 | on the response (challenge) */ |
828 | smb_buf->Uid = ses->Suid; | 835 | smb_buf->Uid = ses->Suid; |
829 | } else { | 836 | } else { |
830 | cERROR(1, ("invalid phase %d", phase)); | 837 | cERROR(1, "invalid phase %d", phase); |
831 | rc = -ENOSYS; | 838 | rc = -ENOSYS; |
832 | goto ssetup_exit; | 839 | goto ssetup_exit; |
833 | } | 840 | } |
@@ -839,12 +846,12 @@ ssetup_ntlmssp_authenticate: | |||
839 | } | 846 | } |
840 | unicode_oslm_strings(&bcc_ptr, nls_cp); | 847 | unicode_oslm_strings(&bcc_ptr, nls_cp); |
841 | } else { | 848 | } else { |
842 | cERROR(1, ("secType %d not supported!", type)); | 849 | cERROR(1, "secType %d not supported!", type); |
843 | rc = -ENOSYS; | 850 | rc = -ENOSYS; |
844 | goto ssetup_exit; | 851 | goto ssetup_exit; |
845 | } | 852 | } |
846 | #else | 853 | #else |
847 | cERROR(1, ("secType %d not supported!", type)); | 854 | cERROR(1, "secType %d not supported!", type); |
848 | rc = -ENOSYS; | 855 | rc = -ENOSYS; |
849 | goto ssetup_exit; | 856 | goto ssetup_exit; |
850 | #endif | 857 | #endif |
@@ -862,7 +869,7 @@ ssetup_ntlmssp_authenticate: | |||
862 | CIFS_STD_OP /* not long */ | CIFS_LOG_ERROR); | 869 | CIFS_STD_OP /* not long */ | CIFS_LOG_ERROR); |
863 | /* SMB request buf freed in SendReceive2 */ | 870 | /* SMB request buf freed in SendReceive2 */ |
864 | 871 | ||
865 | cFYI(1, ("ssetup rc from sendrecv2 is %d", rc)); | 872 | cFYI(1, "ssetup rc from sendrecv2 is %d", rc); |
866 | 873 | ||
867 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; | 874 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; |
868 | smb_buf = (struct smb_hdr *)iov[0].iov_base; | 875 | smb_buf = (struct smb_hdr *)iov[0].iov_base; |
@@ -870,7 +877,7 @@ ssetup_ntlmssp_authenticate: | |||
870 | if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError == | 877 | if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError == |
871 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { | 878 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { |
872 | if (phase != NtLmNegotiate) { | 879 | if (phase != NtLmNegotiate) { |
873 | cERROR(1, ("Unexpected more processing error")); | 880 | cERROR(1, "Unexpected more processing error"); |
874 | goto ssetup_exit; | 881 | goto ssetup_exit; |
875 | } | 882 | } |
876 | /* NTLMSSP Negotiate sent now processing challenge (response) */ | 883 | /* NTLMSSP Negotiate sent now processing challenge (response) */ |
@@ -882,14 +889,14 @@ ssetup_ntlmssp_authenticate: | |||
882 | 889 | ||
883 | if ((smb_buf->WordCount != 3) && (smb_buf->WordCount != 4)) { | 890 | if ((smb_buf->WordCount != 3) && (smb_buf->WordCount != 4)) { |
884 | rc = -EIO; | 891 | rc = -EIO; |
885 | cERROR(1, ("bad word count %d", smb_buf->WordCount)); | 892 | cERROR(1, "bad word count %d", smb_buf->WordCount); |
886 | goto ssetup_exit; | 893 | goto ssetup_exit; |
887 | } | 894 | } |
888 | action = le16_to_cpu(pSMB->resp.Action); | 895 | action = le16_to_cpu(pSMB->resp.Action); |
889 | if (action & GUEST_LOGIN) | 896 | if (action & GUEST_LOGIN) |
890 | cFYI(1, ("Guest login")); /* BB mark SesInfo struct? */ | 897 | cFYI(1, "Guest login"); /* BB mark SesInfo struct? */ |
891 | ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */ | 898 | ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */ |
892 | cFYI(1, ("UID = %d ", ses->Suid)); | 899 | cFYI(1, "UID = %d ", ses->Suid); |
893 | /* response can have either 3 or 4 word count - Samba sends 3 */ | 900 | /* response can have either 3 or 4 word count - Samba sends 3 */ |
894 | /* and lanman response is 3 */ | 901 | /* and lanman response is 3 */ |
895 | bytes_remaining = BCC(smb_buf); | 902 | bytes_remaining = BCC(smb_buf); |
@@ -899,7 +906,7 @@ ssetup_ntlmssp_authenticate: | |||
899 | __u16 blob_len; | 906 | __u16 blob_len; |
900 | blob_len = le16_to_cpu(pSMB->resp.SecurityBlobLength); | 907 | blob_len = le16_to_cpu(pSMB->resp.SecurityBlobLength); |
901 | if (blob_len > bytes_remaining) { | 908 | if (blob_len > bytes_remaining) { |
902 | cERROR(1, ("bad security blob length %d", blob_len)); | 909 | cERROR(1, "bad security blob length %d", blob_len); |
903 | rc = -EINVAL; | 910 | rc = -EINVAL; |
904 | goto ssetup_exit; | 911 | goto ssetup_exit; |
905 | } | 912 | } |
@@ -933,7 +940,7 @@ ssetup_exit: | |||
933 | } | 940 | } |
934 | kfree(str_area); | 941 | kfree(str_area); |
935 | if (resp_buf_type == CIFS_SMALL_BUFFER) { | 942 | if (resp_buf_type == CIFS_SMALL_BUFFER) { |
936 | cFYI(1, ("ssetup freeing small buf %p", iov[0].iov_base)); | 943 | cFYI(1, "ssetup freeing small buf %p", iov[0].iov_base); |
937 | cifs_small_buf_release(iov[0].iov_base); | 944 | cifs_small_buf_release(iov[0].iov_base); |
938 | } else if (resp_buf_type == CIFS_LARGE_BUFFER) | 945 | } else if (resp_buf_type == CIFS_LARGE_BUFFER) |
939 | cifs_buf_release(iov[0].iov_base); | 946 | cifs_buf_release(iov[0].iov_base); |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index ad081fe7eb18..82f78c4d6978 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include "cifs_debug.h" | 35 | #include "cifs_debug.h" |
36 | 36 | ||
37 | extern mempool_t *cifs_mid_poolp; | 37 | extern mempool_t *cifs_mid_poolp; |
38 | extern struct kmem_cache *cifs_oplock_cachep; | ||
39 | 38 | ||
40 | static struct mid_q_entry * | 39 | static struct mid_q_entry * |
41 | AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) | 40 | AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) |
@@ -43,7 +42,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) | |||
43 | struct mid_q_entry *temp; | 42 | struct mid_q_entry *temp; |
44 | 43 | ||
45 | if (server == NULL) { | 44 | if (server == NULL) { |
46 | cERROR(1, ("Null TCP session in AllocMidQEntry")); | 45 | cERROR(1, "Null TCP session in AllocMidQEntry"); |
47 | return NULL; | 46 | return NULL; |
48 | } | 47 | } |
49 | 48 | ||
@@ -55,7 +54,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) | |||
55 | temp->mid = smb_buffer->Mid; /* always LE */ | 54 | temp->mid = smb_buffer->Mid; /* always LE */ |
56 | temp->pid = current->pid; | 55 | temp->pid = current->pid; |
57 | temp->command = smb_buffer->Command; | 56 | temp->command = smb_buffer->Command; |
58 | cFYI(1, ("For smb_command %d", temp->command)); | 57 | cFYI(1, "For smb_command %d", temp->command); |
59 | /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ | 58 | /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ |
60 | /* when mid allocated can be before when sent */ | 59 | /* when mid allocated can be before when sent */ |
61 | temp->when_alloc = jiffies; | 60 | temp->when_alloc = jiffies; |
@@ -140,7 +139,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
140 | total_len += iov[i].iov_len; | 139 | total_len += iov[i].iov_len; |
141 | 140 | ||
142 | smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length); | 141 | smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length); |
143 | cFYI(1, ("Sending smb: total_len %d", total_len)); | 142 | cFYI(1, "Sending smb: total_len %d", total_len); |
144 | dump_smb(smb_buffer, len); | 143 | dump_smb(smb_buffer, len); |
145 | 144 | ||
146 | i = 0; | 145 | i = 0; |
@@ -168,9 +167,8 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
168 | reconnect which may clear the network problem. | 167 | reconnect which may clear the network problem. |
169 | */ | 168 | */ |
170 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { | 169 | if ((i >= 14) || (!server->noblocksnd && (i > 2))) { |
171 | cERROR(1, | 170 | cERROR(1, "sends on sock %p stuck for 15 seconds", |
172 | ("sends on sock %p stuck for 15 seconds", | 171 | ssocket); |
173 | ssocket)); | ||
174 | rc = -EAGAIN; | 172 | rc = -EAGAIN; |
175 | break; | 173 | break; |
176 | } | 174 | } |
@@ -184,13 +182,13 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
184 | total_len = 0; | 182 | total_len = 0; |
185 | break; | 183 | break; |
186 | } else if (rc > total_len) { | 184 | } else if (rc > total_len) { |
187 | cERROR(1, ("sent %d requested %d", rc, total_len)); | 185 | cERROR(1, "sent %d requested %d", rc, total_len); |
188 | break; | 186 | break; |
189 | } | 187 | } |
190 | if (rc == 0) { | 188 | if (rc == 0) { |
191 | /* should never happen, letting socket clear before | 189 | /* should never happen, letting socket clear before |
192 | retrying is our only obvious option here */ | 190 | retrying is our only obvious option here */ |
193 | cERROR(1, ("tcp sent no data")); | 191 | cERROR(1, "tcp sent no data"); |
194 | msleep(500); | 192 | msleep(500); |
195 | continue; | 193 | continue; |
196 | } | 194 | } |
@@ -213,8 +211,8 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
213 | } | 211 | } |
214 | 212 | ||
215 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { | 213 | if ((total_len > 0) && (total_len != smb_buf_length + 4)) { |
216 | cFYI(1, ("partial send (%d remaining), terminating session", | 214 | cFYI(1, "partial send (%d remaining), terminating session", |
217 | total_len)); | 215 | total_len); |
218 | /* If we have only sent part of an SMB then the next SMB | 216 | /* If we have only sent part of an SMB then the next SMB |
219 | could be taken as the remainder of this one. We need | 217 | could be taken as the remainder of this one. We need |
220 | to kill the socket so the server throws away the partial | 218 | to kill the socket so the server throws away the partial |
@@ -223,7 +221,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
223 | } | 221 | } |
224 | 222 | ||
225 | if (rc < 0) { | 223 | if (rc < 0) { |
226 | cERROR(1, ("Error %d sending data on socket to server", rc)); | 224 | cERROR(1, "Error %d sending data on socket to server", rc); |
227 | } else | 225 | } else |
228 | rc = 0; | 226 | rc = 0; |
229 | 227 | ||
@@ -296,7 +294,7 @@ static int allocate_mid(struct cifsSesInfo *ses, struct smb_hdr *in_buf, | |||
296 | } | 294 | } |
297 | 295 | ||
298 | if (ses->server->tcpStatus == CifsNeedReconnect) { | 296 | if (ses->server->tcpStatus == CifsNeedReconnect) { |
299 | cFYI(1, ("tcp session dead - return to caller to retry")); | 297 | cFYI(1, "tcp session dead - return to caller to retry"); |
300 | return -EAGAIN; | 298 | return -EAGAIN; |
301 | } | 299 | } |
302 | 300 | ||
@@ -348,7 +346,7 @@ static int wait_for_response(struct cifsSesInfo *ses, | |||
348 | lrt += time_to_wait; | 346 | lrt += time_to_wait; |
349 | if (time_after(jiffies, lrt)) { | 347 | if (time_after(jiffies, lrt)) { |
350 | /* No replies for time_to_wait. */ | 348 | /* No replies for time_to_wait. */ |
351 | cERROR(1, ("server not responding")); | 349 | cERROR(1, "server not responding"); |
352 | return -1; | 350 | return -1; |
353 | } | 351 | } |
354 | } else { | 352 | } else { |
@@ -379,7 +377,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifsSesInfo *ses, | |||
379 | iov[0].iov_len = in_buf->smb_buf_length + 4; | 377 | iov[0].iov_len = in_buf->smb_buf_length + 4; |
380 | flags |= CIFS_NO_RESP; | 378 | flags |= CIFS_NO_RESP; |
381 | rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags); | 379 | rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags); |
382 | cFYI(DBG2, ("SendRcvNoRsp flags %d rc %d", flags, rc)); | 380 | cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc); |
383 | 381 | ||
384 | return rc; | 382 | return rc; |
385 | } | 383 | } |
@@ -402,7 +400,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
402 | 400 | ||
403 | if ((ses == NULL) || (ses->server == NULL)) { | 401 | if ((ses == NULL) || (ses->server == NULL)) { |
404 | cifs_small_buf_release(in_buf); | 402 | cifs_small_buf_release(in_buf); |
405 | cERROR(1, ("Null session")); | 403 | cERROR(1, "Null session"); |
406 | return -EIO; | 404 | return -EIO; |
407 | } | 405 | } |
408 | 406 | ||
@@ -471,7 +469,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
471 | else if (long_op == CIFS_BLOCKING_OP) | 469 | else if (long_op == CIFS_BLOCKING_OP) |
472 | timeout = 0x7FFFFFFF; /* large, but not so large as to wrap */ | 470 | timeout = 0x7FFFFFFF; /* large, but not so large as to wrap */ |
473 | else { | 471 | else { |
474 | cERROR(1, ("unknown timeout flag %d", long_op)); | 472 | cERROR(1, "unknown timeout flag %d", long_op); |
475 | rc = -EIO; | 473 | rc = -EIO; |
476 | goto out; | 474 | goto out; |
477 | } | 475 | } |
@@ -490,8 +488,8 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
490 | spin_lock(&GlobalMid_Lock); | 488 | spin_lock(&GlobalMid_Lock); |
491 | 489 | ||
492 | if (midQ->resp_buf == NULL) { | 490 | if (midQ->resp_buf == NULL) { |
493 | cERROR(1, ("No response to cmd %d mid %d", | 491 | cERROR(1, "No response to cmd %d mid %d", |
494 | midQ->command, midQ->mid)); | 492 | midQ->command, midQ->mid); |
495 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | 493 | if (midQ->midState == MID_REQUEST_SUBMITTED) { |
496 | if (ses->server->tcpStatus == CifsExiting) | 494 | if (ses->server->tcpStatus == CifsExiting) |
497 | rc = -EHOSTDOWN; | 495 | rc = -EHOSTDOWN; |
@@ -504,7 +502,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
504 | if (rc != -EHOSTDOWN) { | 502 | if (rc != -EHOSTDOWN) { |
505 | if (midQ->midState == MID_RETRY_NEEDED) { | 503 | if (midQ->midState == MID_RETRY_NEEDED) { |
506 | rc = -EAGAIN; | 504 | rc = -EAGAIN; |
507 | cFYI(1, ("marking request for retry")); | 505 | cFYI(1, "marking request for retry"); |
508 | } else { | 506 | } else { |
509 | rc = -EIO; | 507 | rc = -EIO; |
510 | } | 508 | } |
@@ -521,8 +519,8 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
521 | receive_len = midQ->resp_buf->smb_buf_length; | 519 | receive_len = midQ->resp_buf->smb_buf_length; |
522 | 520 | ||
523 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { | 521 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { |
524 | cERROR(1, ("Frame too large received. Length: %d Xid: %d", | 522 | cERROR(1, "Frame too large received. Length: %d Xid: %d", |
525 | receive_len, xid)); | 523 | receive_len, xid); |
526 | rc = -EIO; | 524 | rc = -EIO; |
527 | goto out; | 525 | goto out; |
528 | } | 526 | } |
@@ -548,7 +546,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
548 | &ses->server->mac_signing_key, | 546 | &ses->server->mac_signing_key, |
549 | midQ->sequence_number+1); | 547 | midQ->sequence_number+1); |
550 | if (rc) { | 548 | if (rc) { |
551 | cERROR(1, ("Unexpected SMB signature")); | 549 | cERROR(1, "Unexpected SMB signature"); |
552 | /* BB FIXME add code to kill session */ | 550 | /* BB FIXME add code to kill session */ |
553 | } | 551 | } |
554 | } | 552 | } |
@@ -569,7 +567,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
569 | DeleteMidQEntry */ | 567 | DeleteMidQEntry */ |
570 | } else { | 568 | } else { |
571 | rc = -EIO; | 569 | rc = -EIO; |
572 | cFYI(1, ("Bad MID state?")); | 570 | cFYI(1, "Bad MID state?"); |
573 | } | 571 | } |
574 | 572 | ||
575 | out: | 573 | out: |
@@ -591,11 +589,11 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
591 | struct mid_q_entry *midQ; | 589 | struct mid_q_entry *midQ; |
592 | 590 | ||
593 | if (ses == NULL) { | 591 | if (ses == NULL) { |
594 | cERROR(1, ("Null smb session")); | 592 | cERROR(1, "Null smb session"); |
595 | return -EIO; | 593 | return -EIO; |
596 | } | 594 | } |
597 | if (ses->server == NULL) { | 595 | if (ses->server == NULL) { |
598 | cERROR(1, ("Null tcp session")); | 596 | cERROR(1, "Null tcp session"); |
599 | return -EIO; | 597 | return -EIO; |
600 | } | 598 | } |
601 | 599 | ||
@@ -607,8 +605,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
607 | use ses->maxReq */ | 605 | use ses->maxReq */ |
608 | 606 | ||
609 | if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { | 607 | if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
610 | cERROR(1, ("Illegal length, greater than maximum frame, %d", | 608 | cERROR(1, "Illegal length, greater than maximum frame, %d", |
611 | in_buf->smb_buf_length)); | 609 | in_buf->smb_buf_length); |
612 | return -EIO; | 610 | return -EIO; |
613 | } | 611 | } |
614 | 612 | ||
@@ -665,7 +663,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
665 | else if (long_op == CIFS_BLOCKING_OP) | 663 | else if (long_op == CIFS_BLOCKING_OP) |
666 | timeout = 0x7FFFFFFF; /* large but no so large as to wrap */ | 664 | timeout = 0x7FFFFFFF; /* large but no so large as to wrap */ |
667 | else { | 665 | else { |
668 | cERROR(1, ("unknown timeout flag %d", long_op)); | 666 | cERROR(1, "unknown timeout flag %d", long_op); |
669 | rc = -EIO; | 667 | rc = -EIO; |
670 | goto out; | 668 | goto out; |
671 | } | 669 | } |
@@ -681,8 +679,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
681 | 679 | ||
682 | spin_lock(&GlobalMid_Lock); | 680 | spin_lock(&GlobalMid_Lock); |
683 | if (midQ->resp_buf == NULL) { | 681 | if (midQ->resp_buf == NULL) { |
684 | cERROR(1, ("No response for cmd %d mid %d", | 682 | cERROR(1, "No response for cmd %d mid %d", |
685 | midQ->command, midQ->mid)); | 683 | midQ->command, midQ->mid); |
686 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | 684 | if (midQ->midState == MID_REQUEST_SUBMITTED) { |
687 | if (ses->server->tcpStatus == CifsExiting) | 685 | if (ses->server->tcpStatus == CifsExiting) |
688 | rc = -EHOSTDOWN; | 686 | rc = -EHOSTDOWN; |
@@ -695,7 +693,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
695 | if (rc != -EHOSTDOWN) { | 693 | if (rc != -EHOSTDOWN) { |
696 | if (midQ->midState == MID_RETRY_NEEDED) { | 694 | if (midQ->midState == MID_RETRY_NEEDED) { |
697 | rc = -EAGAIN; | 695 | rc = -EAGAIN; |
698 | cFYI(1, ("marking request for retry")); | 696 | cFYI(1, "marking request for retry"); |
699 | } else { | 697 | } else { |
700 | rc = -EIO; | 698 | rc = -EIO; |
701 | } | 699 | } |
@@ -712,8 +710,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
712 | receive_len = midQ->resp_buf->smb_buf_length; | 710 | receive_len = midQ->resp_buf->smb_buf_length; |
713 | 711 | ||
714 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { | 712 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { |
715 | cERROR(1, ("Frame too large received. Length: %d Xid: %d", | 713 | cERROR(1, "Frame too large received. Length: %d Xid: %d", |
716 | receive_len, xid)); | 714 | receive_len, xid); |
717 | rc = -EIO; | 715 | rc = -EIO; |
718 | goto out; | 716 | goto out; |
719 | } | 717 | } |
@@ -736,7 +734,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
736 | &ses->server->mac_signing_key, | 734 | &ses->server->mac_signing_key, |
737 | midQ->sequence_number+1); | 735 | midQ->sequence_number+1); |
738 | if (rc) { | 736 | if (rc) { |
739 | cERROR(1, ("Unexpected SMB signature")); | 737 | cERROR(1, "Unexpected SMB signature"); |
740 | /* BB FIXME add code to kill session */ | 738 | /* BB FIXME add code to kill session */ |
741 | } | 739 | } |
742 | } | 740 | } |
@@ -753,7 +751,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
753 | BCC(out_buf) = le16_to_cpu(BCC_LE(out_buf)); | 751 | BCC(out_buf) = le16_to_cpu(BCC_LE(out_buf)); |
754 | } else { | 752 | } else { |
755 | rc = -EIO; | 753 | rc = -EIO; |
756 | cERROR(1, ("Bad MID state?")); | 754 | cERROR(1, "Bad MID state?"); |
757 | } | 755 | } |
758 | 756 | ||
759 | out: | 757 | out: |
@@ -824,13 +822,13 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
824 | struct cifsSesInfo *ses; | 822 | struct cifsSesInfo *ses; |
825 | 823 | ||
826 | if (tcon == NULL || tcon->ses == NULL) { | 824 | if (tcon == NULL || tcon->ses == NULL) { |
827 | cERROR(1, ("Null smb session")); | 825 | cERROR(1, "Null smb session"); |
828 | return -EIO; | 826 | return -EIO; |
829 | } | 827 | } |
830 | ses = tcon->ses; | 828 | ses = tcon->ses; |
831 | 829 | ||
832 | if (ses->server == NULL) { | 830 | if (ses->server == NULL) { |
833 | cERROR(1, ("Null tcp session")); | 831 | cERROR(1, "Null tcp session"); |
834 | return -EIO; | 832 | return -EIO; |
835 | } | 833 | } |
836 | 834 | ||
@@ -842,8 +840,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
842 | use ses->maxReq */ | 840 | use ses->maxReq */ |
843 | 841 | ||
844 | if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { | 842 | if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { |
845 | cERROR(1, ("Illegal length, greater than maximum frame, %d", | 843 | cERROR(1, "Illegal length, greater than maximum frame, %d", |
846 | in_buf->smb_buf_length)); | 844 | in_buf->smb_buf_length); |
847 | return -EIO; | 845 | return -EIO; |
848 | } | 846 | } |
849 | 847 | ||
@@ -933,8 +931,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
933 | spin_unlock(&GlobalMid_Lock); | 931 | spin_unlock(&GlobalMid_Lock); |
934 | receive_len = midQ->resp_buf->smb_buf_length; | 932 | receive_len = midQ->resp_buf->smb_buf_length; |
935 | } else { | 933 | } else { |
936 | cERROR(1, ("No response for cmd %d mid %d", | 934 | cERROR(1, "No response for cmd %d mid %d", |
937 | midQ->command, midQ->mid)); | 935 | midQ->command, midQ->mid); |
938 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | 936 | if (midQ->midState == MID_REQUEST_SUBMITTED) { |
939 | if (ses->server->tcpStatus == CifsExiting) | 937 | if (ses->server->tcpStatus == CifsExiting) |
940 | rc = -EHOSTDOWN; | 938 | rc = -EHOSTDOWN; |
@@ -947,7 +945,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
947 | if (rc != -EHOSTDOWN) { | 945 | if (rc != -EHOSTDOWN) { |
948 | if (midQ->midState == MID_RETRY_NEEDED) { | 946 | if (midQ->midState == MID_RETRY_NEEDED) { |
949 | rc = -EAGAIN; | 947 | rc = -EAGAIN; |
950 | cFYI(1, ("marking request for retry")); | 948 | cFYI(1, "marking request for retry"); |
951 | } else { | 949 | } else { |
952 | rc = -EIO; | 950 | rc = -EIO; |
953 | } | 951 | } |
@@ -958,8 +956,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
958 | } | 956 | } |
959 | 957 | ||
960 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { | 958 | if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { |
961 | cERROR(1, ("Frame too large received. Length: %d Xid: %d", | 959 | cERROR(1, "Frame too large received. Length: %d Xid: %d", |
962 | receive_len, xid)); | 960 | receive_len, xid); |
963 | rc = -EIO; | 961 | rc = -EIO; |
964 | goto out; | 962 | goto out; |
965 | } | 963 | } |
@@ -968,7 +966,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
968 | 966 | ||
969 | if ((out_buf == NULL) || (midQ->midState != MID_RESPONSE_RECEIVED)) { | 967 | if ((out_buf == NULL) || (midQ->midState != MID_RESPONSE_RECEIVED)) { |
970 | rc = -EIO; | 968 | rc = -EIO; |
971 | cERROR(1, ("Bad MID state?")); | 969 | cERROR(1, "Bad MID state?"); |
972 | goto out; | 970 | goto out; |
973 | } | 971 | } |
974 | 972 | ||
@@ -986,7 +984,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
986 | &ses->server->mac_signing_key, | 984 | &ses->server->mac_signing_key, |
987 | midQ->sequence_number+1); | 985 | midQ->sequence_number+1); |
988 | if (rc) { | 986 | if (rc) { |
989 | cERROR(1, ("Unexpected SMB signature")); | 987 | cERROR(1, "Unexpected SMB signature"); |
990 | /* BB FIXME add code to kill session */ | 988 | /* BB FIXME add code to kill session */ |
991 | } | 989 | } |
992 | } | 990 | } |
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c index f555ce077d4f..a1509207bfa6 100644 --- a/fs/cifs/xattr.c +++ b/fs/cifs/xattr.c | |||
@@ -70,12 +70,12 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name) | |||
70 | return rc; | 70 | return rc; |
71 | } | 71 | } |
72 | if (ea_name == NULL) { | 72 | if (ea_name == NULL) { |
73 | cFYI(1, ("Null xattr names not supported")); | 73 | cFYI(1, "Null xattr names not supported"); |
74 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) | 74 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) |
75 | && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) { | 75 | && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) { |
76 | cFYI(1, | 76 | cFYI(1, |
77 | ("illegal xattr request %s (only user namespace supported)", | 77 | "illegal xattr request %s (only user namespace supported)", |
78 | ea_name)); | 78 | ea_name); |
79 | /* BB what if no namespace prefix? */ | 79 | /* BB what if no namespace prefix? */ |
80 | /* Should we just pass them to server, except for | 80 | /* Should we just pass them to server, except for |
81 | system and perhaps security prefixes? */ | 81 | system and perhaps security prefixes? */ |
@@ -131,19 +131,19 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name, | |||
131 | search server for EAs or streams to | 131 | search server for EAs or streams to |
132 | returns as xattrs */ | 132 | returns as xattrs */ |
133 | if (value_size > MAX_EA_VALUE_SIZE) { | 133 | if (value_size > MAX_EA_VALUE_SIZE) { |
134 | cFYI(1, ("size of EA value too large")); | 134 | cFYI(1, "size of EA value too large"); |
135 | kfree(full_path); | 135 | kfree(full_path); |
136 | FreeXid(xid); | 136 | FreeXid(xid); |
137 | return -EOPNOTSUPP; | 137 | return -EOPNOTSUPP; |
138 | } | 138 | } |
139 | 139 | ||
140 | if (ea_name == NULL) { | 140 | if (ea_name == NULL) { |
141 | cFYI(1, ("Null xattr names not supported")); | 141 | cFYI(1, "Null xattr names not supported"); |
142 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { | 142 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { |
143 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) | 143 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
144 | goto set_ea_exit; | 144 | goto set_ea_exit; |
145 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) | 145 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) |
146 | cFYI(1, ("attempt to set cifs inode metadata")); | 146 | cFYI(1, "attempt to set cifs inode metadata"); |
147 | 147 | ||
148 | ea_name += 5; /* skip past user. prefix */ | 148 | ea_name += 5; /* skip past user. prefix */ |
149 | rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, | 149 | rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, |
@@ -169,9 +169,9 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name, | |||
169 | ACL_TYPE_ACCESS, cifs_sb->local_nls, | 169 | ACL_TYPE_ACCESS, cifs_sb->local_nls, |
170 | cifs_sb->mnt_cifs_flags & | 170 | cifs_sb->mnt_cifs_flags & |
171 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 171 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
172 | cFYI(1, ("set POSIX ACL rc %d", rc)); | 172 | cFYI(1, "set POSIX ACL rc %d", rc); |
173 | #else | 173 | #else |
174 | cFYI(1, ("set POSIX ACL not supported")); | 174 | cFYI(1, "set POSIX ACL not supported"); |
175 | #endif | 175 | #endif |
176 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, | 176 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, |
177 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { | 177 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
@@ -182,13 +182,13 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name, | |||
182 | ACL_TYPE_DEFAULT, cifs_sb->local_nls, | 182 | ACL_TYPE_DEFAULT, cifs_sb->local_nls, |
183 | cifs_sb->mnt_cifs_flags & | 183 | cifs_sb->mnt_cifs_flags & |
184 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 184 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
185 | cFYI(1, ("set POSIX default ACL rc %d", rc)); | 185 | cFYI(1, "set POSIX default ACL rc %d", rc); |
186 | #else | 186 | #else |
187 | cFYI(1, ("set default POSIX ACL not supported")); | 187 | cFYI(1, "set default POSIX ACL not supported"); |
188 | #endif | 188 | #endif |
189 | } else { | 189 | } else { |
190 | cFYI(1, ("illegal xattr request %s (only user namespace" | 190 | cFYI(1, "illegal xattr request %s (only user namespace" |
191 | " supported)", ea_name)); | 191 | " supported)", ea_name); |
192 | /* BB what if no namespace prefix? */ | 192 | /* BB what if no namespace prefix? */ |
193 | /* Should we just pass them to server, except for | 193 | /* Should we just pass them to server, except for |
194 | system and perhaps security prefixes? */ | 194 | system and perhaps security prefixes? */ |
@@ -235,13 +235,13 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, | |||
235 | /* return dos attributes as pseudo xattr */ | 235 | /* return dos attributes as pseudo xattr */ |
236 | /* return alt name if available as pseudo attr */ | 236 | /* return alt name if available as pseudo attr */ |
237 | if (ea_name == NULL) { | 237 | if (ea_name == NULL) { |
238 | cFYI(1, ("Null xattr names not supported")); | 238 | cFYI(1, "Null xattr names not supported"); |
239 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { | 239 | } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) { |
240 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) | 240 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) |
241 | goto get_ea_exit; | 241 | goto get_ea_exit; |
242 | 242 | ||
243 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) { | 243 | if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) { |
244 | cFYI(1, ("attempt to query cifs inode metadata")); | 244 | cFYI(1, "attempt to query cifs inode metadata"); |
245 | /* revalidate/getattr then populate from inode */ | 245 | /* revalidate/getattr then populate from inode */ |
246 | } /* BB add else when above is implemented */ | 246 | } /* BB add else when above is implemented */ |
247 | ea_name += 5; /* skip past user. prefix */ | 247 | ea_name += 5; /* skip past user. prefix */ |
@@ -287,7 +287,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, | |||
287 | } | 287 | } |
288 | #endif /* EXPERIMENTAL */ | 288 | #endif /* EXPERIMENTAL */ |
289 | #else | 289 | #else |
290 | cFYI(1, ("query POSIX ACL not supported yet")); | 290 | cFYI(1, "query POSIX ACL not supported yet"); |
291 | #endif /* CONFIG_CIFS_POSIX */ | 291 | #endif /* CONFIG_CIFS_POSIX */ |
292 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, | 292 | } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT, |
293 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { | 293 | strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) { |
@@ -299,18 +299,18 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name, | |||
299 | cifs_sb->mnt_cifs_flags & | 299 | cifs_sb->mnt_cifs_flags & |
300 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 300 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
301 | #else | 301 | #else |
302 | cFYI(1, ("query POSIX default ACL not supported yet")); | 302 | cFYI(1, "query POSIX default ACL not supported yet"); |
303 | #endif | 303 | #endif |
304 | } else if (strncmp(ea_name, | 304 | } else if (strncmp(ea_name, |
305 | CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) { | 305 | CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) { |
306 | cFYI(1, ("Trusted xattr namespace not supported yet")); | 306 | cFYI(1, "Trusted xattr namespace not supported yet"); |
307 | } else if (strncmp(ea_name, | 307 | } else if (strncmp(ea_name, |
308 | CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) { | 308 | CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) { |
309 | cFYI(1, ("Security xattr namespace not supported yet")); | 309 | cFYI(1, "Security xattr namespace not supported yet"); |
310 | } else | 310 | } else |
311 | cFYI(1, | 311 | cFYI(1, |
312 | ("illegal xattr request %s (only user namespace supported)", | 312 | "illegal xattr request %s (only user namespace supported)", |
313 | ea_name)); | 313 | ea_name); |
314 | 314 | ||
315 | /* We could add an additional check for streams ie | 315 | /* We could add an additional check for streams ie |
316 | if proc/fs/cifs/streamstoxattr is set then | 316 | if proc/fs/cifs/streamstoxattr is set then |
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 8e48b52205aa..0b502f80c691 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c | |||
@@ -645,6 +645,7 @@ static void detach_groups(struct config_group *group) | |||
645 | 645 | ||
646 | configfs_detach_group(sd->s_element); | 646 | configfs_detach_group(sd->s_element); |
647 | child->d_inode->i_flags |= S_DEAD; | 647 | child->d_inode->i_flags |= S_DEAD; |
648 | dont_mount(child); | ||
648 | 649 | ||
649 | mutex_unlock(&child->d_inode->i_mutex); | 650 | mutex_unlock(&child->d_inode->i_mutex); |
650 | 651 | ||
@@ -840,6 +841,7 @@ static int configfs_attach_item(struct config_item *parent_item, | |||
840 | mutex_lock(&dentry->d_inode->i_mutex); | 841 | mutex_lock(&dentry->d_inode->i_mutex); |
841 | configfs_remove_dir(item); | 842 | configfs_remove_dir(item); |
842 | dentry->d_inode->i_flags |= S_DEAD; | 843 | dentry->d_inode->i_flags |= S_DEAD; |
844 | dont_mount(dentry); | ||
843 | mutex_unlock(&dentry->d_inode->i_mutex); | 845 | mutex_unlock(&dentry->d_inode->i_mutex); |
844 | d_delete(dentry); | 846 | d_delete(dentry); |
845 | } | 847 | } |
@@ -882,6 +884,7 @@ static int configfs_attach_group(struct config_item *parent_item, | |||
882 | if (ret) { | 884 | if (ret) { |
883 | configfs_detach_item(item); | 885 | configfs_detach_item(item); |
884 | dentry->d_inode->i_flags |= S_DEAD; | 886 | dentry->d_inode->i_flags |= S_DEAD; |
887 | dont_mount(dentry); | ||
885 | } | 888 | } |
886 | configfs_adjust_dir_dirent_depth_after_populate(sd); | 889 | configfs_adjust_dir_dirent_depth_after_populate(sd); |
887 | mutex_unlock(&dentry->d_inode->i_mutex); | 890 | mutex_unlock(&dentry->d_inode->i_mutex); |
@@ -1725,6 +1728,7 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys) | |||
1725 | mutex_unlock(&configfs_symlink_mutex); | 1728 | mutex_unlock(&configfs_symlink_mutex); |
1726 | configfs_detach_group(&group->cg_item); | 1729 | configfs_detach_group(&group->cg_item); |
1727 | dentry->d_inode->i_flags |= S_DEAD; | 1730 | dentry->d_inode->i_flags |= S_DEAD; |
1731 | dont_mount(dentry); | ||
1728 | mutex_unlock(&dentry->d_inode->i_mutex); | 1732 | mutex_unlock(&dentry->d_inode->i_mutex); |
1729 | 1733 | ||
1730 | d_delete(dentry); | 1734 | d_delete(dentry); |
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index bd056a5b4efc..3817149919cb 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -1140,8 +1140,7 @@ retry: | |||
1140 | * ep_poll_callback() when events will become available. | 1140 | * ep_poll_callback() when events will become available. |
1141 | */ | 1141 | */ |
1142 | init_waitqueue_entry(&wait, current); | 1142 | init_waitqueue_entry(&wait, current); |
1143 | wait.flags |= WQ_FLAG_EXCLUSIVE; | 1143 | __add_wait_queue_exclusive(&ep->wq, &wait); |
1144 | __add_wait_queue(&ep->wq, &wait); | ||
1145 | 1144 | ||
1146 | for (;;) { | 1145 | for (;;) { |
1147 | /* | 1146 | /* |
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 157382fa6256..b66832ac33ac 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
@@ -446,10 +446,8 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |||
446 | /* initialize the mount flag and determine the default error handler */ | 446 | /* initialize the mount flag and determine the default error handler */ |
447 | flag = JFS_ERR_REMOUNT_RO; | 447 | flag = JFS_ERR_REMOUNT_RO; |
448 | 448 | ||
449 | if (!parse_options((char *) data, sb, &newLVSize, &flag)) { | 449 | if (!parse_options((char *) data, sb, &newLVSize, &flag)) |
450 | kfree(sbi); | 450 | goto out_kfree; |
451 | return -EINVAL; | ||
452 | } | ||
453 | sbi->flag = flag; | 451 | sbi->flag = flag; |
454 | 452 | ||
455 | #ifdef CONFIG_JFS_POSIX_ACL | 453 | #ifdef CONFIG_JFS_POSIX_ACL |
@@ -458,7 +456,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |||
458 | 456 | ||
459 | if (newLVSize) { | 457 | if (newLVSize) { |
460 | printk(KERN_ERR "resize option for remount only\n"); | 458 | printk(KERN_ERR "resize option for remount only\n"); |
461 | return -EINVAL; | 459 | goto out_kfree; |
462 | } | 460 | } |
463 | 461 | ||
464 | /* | 462 | /* |
@@ -478,7 +476,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |||
478 | inode = new_inode(sb); | 476 | inode = new_inode(sb); |
479 | if (inode == NULL) { | 477 | if (inode == NULL) { |
480 | ret = -ENOMEM; | 478 | ret = -ENOMEM; |
481 | goto out_kfree; | 479 | goto out_unload; |
482 | } | 480 | } |
483 | inode->i_ino = 0; | 481 | inode->i_ino = 0; |
484 | inode->i_nlink = 1; | 482 | inode->i_nlink = 1; |
@@ -550,9 +548,10 @@ out_mount_failed: | |||
550 | make_bad_inode(sbi->direct_inode); | 548 | make_bad_inode(sbi->direct_inode); |
551 | iput(sbi->direct_inode); | 549 | iput(sbi->direct_inode); |
552 | sbi->direct_inode = NULL; | 550 | sbi->direct_inode = NULL; |
553 | out_kfree: | 551 | out_unload: |
554 | if (sbi->nls_tab) | 552 | if (sbi->nls_tab) |
555 | unload_nls(sbi->nls_tab); | 553 | unload_nls(sbi->nls_tab); |
554 | out_kfree: | ||
556 | kfree(sbi); | 555 | kfree(sbi); |
557 | return ret; | 556 | return ret; |
558 | } | 557 | } |
diff --git a/fs/logfs/dev_bdev.c b/fs/logfs/dev_bdev.c index 243c00071f76..9bd2ce2a3040 100644 --- a/fs/logfs/dev_bdev.c +++ b/fs/logfs/dev_bdev.c | |||
@@ -303,6 +303,11 @@ static void bdev_put_device(struct super_block *sb) | |||
303 | close_bdev_exclusive(logfs_super(sb)->s_bdev, FMODE_READ|FMODE_WRITE); | 303 | close_bdev_exclusive(logfs_super(sb)->s_bdev, FMODE_READ|FMODE_WRITE); |
304 | } | 304 | } |
305 | 305 | ||
306 | static int bdev_can_write_buf(struct super_block *sb, u64 ofs) | ||
307 | { | ||
308 | return 0; | ||
309 | } | ||
310 | |||
306 | static const struct logfs_device_ops bd_devops = { | 311 | static const struct logfs_device_ops bd_devops = { |
307 | .find_first_sb = bdev_find_first_sb, | 312 | .find_first_sb = bdev_find_first_sb, |
308 | .find_last_sb = bdev_find_last_sb, | 313 | .find_last_sb = bdev_find_last_sb, |
@@ -310,6 +315,7 @@ static const struct logfs_device_ops bd_devops = { | |||
310 | .readpage = bdev_readpage, | 315 | .readpage = bdev_readpage, |
311 | .writeseg = bdev_writeseg, | 316 | .writeseg = bdev_writeseg, |
312 | .erase = bdev_erase, | 317 | .erase = bdev_erase, |
318 | .can_write_buf = bdev_can_write_buf, | ||
313 | .sync = bdev_sync, | 319 | .sync = bdev_sync, |
314 | .put_device = bdev_put_device, | 320 | .put_device = bdev_put_device, |
315 | }; | 321 | }; |
diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index cafb6ef2e05b..a85d47d13e4b 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/completion.h> | 9 | #include <linux/completion.h> |
10 | #include <linux/mount.h> | 10 | #include <linux/mount.h> |
11 | #include <linux/sched.h> | 11 | #include <linux/sched.h> |
12 | #include <linux/slab.h> | ||
12 | 13 | ||
13 | #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) | 14 | #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1)) |
14 | 15 | ||
@@ -126,7 +127,8 @@ static int mtd_readpage(void *_sb, struct page *page) | |||
126 | 127 | ||
127 | err = mtd_read(sb, page->index << PAGE_SHIFT, PAGE_SIZE, | 128 | err = mtd_read(sb, page->index << PAGE_SHIFT, PAGE_SIZE, |
128 | page_address(page)); | 129 | page_address(page)); |
129 | if (err == -EUCLEAN) { | 130 | if (err == -EUCLEAN || err == -EBADMSG) { |
131 | /* -EBADMSG happens regularly on power failures */ | ||
130 | err = 0; | 132 | err = 0; |
131 | /* FIXME: force GC this segment */ | 133 | /* FIXME: force GC this segment */ |
132 | } | 134 | } |
@@ -233,12 +235,32 @@ static void mtd_put_device(struct super_block *sb) | |||
233 | put_mtd_device(logfs_super(sb)->s_mtd); | 235 | put_mtd_device(logfs_super(sb)->s_mtd); |
234 | } | 236 | } |
235 | 237 | ||
238 | static int mtd_can_write_buf(struct super_block *sb, u64 ofs) | ||
239 | { | ||
240 | struct logfs_super *super = logfs_super(sb); | ||
241 | void *buf; | ||
242 | int err; | ||
243 | |||
244 | buf = kmalloc(super->s_writesize, GFP_KERNEL); | ||
245 | if (!buf) | ||
246 | return -ENOMEM; | ||
247 | err = mtd_read(sb, ofs, super->s_writesize, buf); | ||
248 | if (err) | ||
249 | goto out; | ||
250 | if (memchr_inv(buf, 0xff, super->s_writesize)) | ||
251 | err = -EIO; | ||
252 | kfree(buf); | ||
253 | out: | ||
254 | return err; | ||
255 | } | ||
256 | |||
236 | static const struct logfs_device_ops mtd_devops = { | 257 | static const struct logfs_device_ops mtd_devops = { |
237 | .find_first_sb = mtd_find_first_sb, | 258 | .find_first_sb = mtd_find_first_sb, |
238 | .find_last_sb = mtd_find_last_sb, | 259 | .find_last_sb = mtd_find_last_sb, |
239 | .readpage = mtd_readpage, | 260 | .readpage = mtd_readpage, |
240 | .writeseg = mtd_writeseg, | 261 | .writeseg = mtd_writeseg, |
241 | .erase = mtd_erase, | 262 | .erase = mtd_erase, |
263 | .can_write_buf = mtd_can_write_buf, | ||
242 | .sync = mtd_sync, | 264 | .sync = mtd_sync, |
243 | .put_device = mtd_put_device, | 265 | .put_device = mtd_put_device, |
244 | }; | 266 | }; |
@@ -250,5 +272,7 @@ int logfs_get_sb_mtd(struct file_system_type *type, int flags, | |||
250 | const struct logfs_device_ops *devops = &mtd_devops; | 272 | const struct logfs_device_ops *devops = &mtd_devops; |
251 | 273 | ||
252 | mtd = get_mtd_device(NULL, mtdnr); | 274 | mtd = get_mtd_device(NULL, mtdnr); |
275 | if (IS_ERR(mtd)) | ||
276 | return PTR_ERR(mtd); | ||
253 | return logfs_get_sb_device(type, flags, mtd, NULL, devops, mnt); | 277 | return logfs_get_sb_device(type, flags, mtd, NULL, devops, mnt); |
254 | } | 278 | } |
diff --git a/fs/logfs/file.c b/fs/logfs/file.c index 370f367a933e..0de524071870 100644 --- a/fs/logfs/file.c +++ b/fs/logfs/file.c | |||
@@ -161,7 +161,17 @@ static int logfs_writepage(struct page *page, struct writeback_control *wbc) | |||
161 | 161 | ||
162 | static void logfs_invalidatepage(struct page *page, unsigned long offset) | 162 | static void logfs_invalidatepage(struct page *page, unsigned long offset) |
163 | { | 163 | { |
164 | move_page_to_btree(page); | 164 | struct logfs_block *block = logfs_block(page); |
165 | |||
166 | if (block->reserved_bytes) { | ||
167 | struct super_block *sb = page->mapping->host->i_sb; | ||
168 | struct logfs_super *super = logfs_super(sb); | ||
169 | |||
170 | super->s_dirty_pages -= block->reserved_bytes; | ||
171 | block->ops->free_block(sb, block); | ||
172 | BUG_ON(bitmap_weight(block->alias_map, LOGFS_BLOCK_FACTOR)); | ||
173 | } else | ||
174 | move_page_to_btree(page); | ||
165 | BUG_ON(PagePrivate(page) || page->private); | 175 | BUG_ON(PagePrivate(page) || page->private); |
166 | } | 176 | } |
167 | 177 | ||
@@ -212,10 +222,8 @@ int logfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
212 | int logfs_fsync(struct file *file, struct dentry *dentry, int datasync) | 222 | int logfs_fsync(struct file *file, struct dentry *dentry, int datasync) |
213 | { | 223 | { |
214 | struct super_block *sb = dentry->d_inode->i_sb; | 224 | struct super_block *sb = dentry->d_inode->i_sb; |
215 | struct logfs_super *super = logfs_super(sb); | ||
216 | 225 | ||
217 | /* FIXME: write anchor */ | 226 | logfs_write_anchor(sb); |
218 | super->s_devops->sync(sb); | ||
219 | return 0; | 227 | return 0; |
220 | } | 228 | } |
221 | 229 | ||
diff --git a/fs/logfs/gc.c b/fs/logfs/gc.c index 76c242fbe1b0..caa4419285dc 100644 --- a/fs/logfs/gc.c +++ b/fs/logfs/gc.c | |||
@@ -122,7 +122,7 @@ static void logfs_cleanse_block(struct super_block *sb, u64 ofs, u64 ino, | |||
122 | logfs_safe_iput(inode, cookie); | 122 | logfs_safe_iput(inode, cookie); |
123 | } | 123 | } |
124 | 124 | ||
125 | static u32 logfs_gc_segment(struct super_block *sb, u32 segno, u8 dist) | 125 | static u32 logfs_gc_segment(struct super_block *sb, u32 segno) |
126 | { | 126 | { |
127 | struct logfs_super *super = logfs_super(sb); | 127 | struct logfs_super *super = logfs_super(sb); |
128 | struct logfs_segment_header sh; | 128 | struct logfs_segment_header sh; |
@@ -401,7 +401,7 @@ static int __logfs_gc_once(struct super_block *sb, struct gc_candidate *cand) | |||
401 | segno, (u64)segno << super->s_segshift, | 401 | segno, (u64)segno << super->s_segshift, |
402 | dist, no_free_segments(sb), valid, | 402 | dist, no_free_segments(sb), valid, |
403 | super->s_free_bytes); | 403 | super->s_free_bytes); |
404 | cleaned = logfs_gc_segment(sb, segno, dist); | 404 | cleaned = logfs_gc_segment(sb, segno); |
405 | log_gc("GC segment #%02x complete - now %x valid\n", segno, | 405 | log_gc("GC segment #%02x complete - now %x valid\n", segno, |
406 | valid - cleaned); | 406 | valid - cleaned); |
407 | BUG_ON(cleaned != valid); | 407 | BUG_ON(cleaned != valid); |
@@ -632,38 +632,31 @@ static int check_area(struct super_block *sb, int i) | |||
632 | { | 632 | { |
633 | struct logfs_super *super = logfs_super(sb); | 633 | struct logfs_super *super = logfs_super(sb); |
634 | struct logfs_area *area = super->s_area[i]; | 634 | struct logfs_area *area = super->s_area[i]; |
635 | struct logfs_object_header oh; | 635 | gc_level_t gc_level; |
636 | u32 cleaned, valid, ec; | ||
636 | u32 segno = area->a_segno; | 637 | u32 segno = area->a_segno; |
637 | u32 ofs = area->a_used_bytes; | 638 | u64 ofs = dev_ofs(sb, area->a_segno, area->a_written_bytes); |
638 | __be32 crc; | ||
639 | int err; | ||
640 | 639 | ||
641 | if (!area->a_is_open) | 640 | if (!area->a_is_open) |
642 | return 0; | 641 | return 0; |
643 | 642 | ||
644 | for (ofs = area->a_used_bytes; | 643 | if (super->s_devops->can_write_buf(sb, ofs) == 0) |
645 | ofs <= super->s_segsize - sizeof(oh); | 644 | return 0; |
646 | ofs += (u32)be16_to_cpu(oh.len) + sizeof(oh)) { | ||
647 | err = wbuf_read(sb, dev_ofs(sb, segno, ofs), sizeof(oh), &oh); | ||
648 | if (err) | ||
649 | return err; | ||
650 | |||
651 | if (!memchr_inv(&oh, 0xff, sizeof(oh))) | ||
652 | break; | ||
653 | 645 | ||
654 | crc = logfs_crc32(&oh, sizeof(oh) - 4, 4); | 646 | printk(KERN_INFO"LogFS: Possibly incomplete write at %llx\n", ofs); |
655 | if (crc != oh.crc) { | 647 | /* |
656 | printk(KERN_INFO "interrupted header at %llx\n", | 648 | * The device cannot write back the write buffer. Most likely the |
657 | dev_ofs(sb, segno, ofs)); | 649 | * wbuf was already written out and the system crashed at some point |
658 | return 0; | 650 | * before the journal commit happened. In that case we wouldn't have |
659 | } | 651 | * to do anything. But if the crash happened before the wbuf was |
660 | } | 652 | * written out correctly, we must GC this segment. So assume the |
661 | if (ofs != area->a_used_bytes) { | 653 | * worst and always do the GC run. |
662 | printk(KERN_INFO "%x bytes unaccounted data found at %llx\n", | 654 | */ |
663 | ofs - area->a_used_bytes, | 655 | area->a_is_open = 0; |
664 | dev_ofs(sb, segno, area->a_used_bytes)); | 656 | valid = logfs_valid_bytes(sb, segno, &ec, &gc_level); |
665 | area->a_used_bytes = ofs; | 657 | cleaned = logfs_gc_segment(sb, segno); |
666 | } | 658 | if (cleaned != valid) |
659 | return -EIO; | ||
667 | return 0; | 660 | return 0; |
668 | } | 661 | } |
669 | 662 | ||
diff --git a/fs/logfs/inode.c b/fs/logfs/inode.c index 14ed27274da2..755a92e8daa7 100644 --- a/fs/logfs/inode.c +++ b/fs/logfs/inode.c | |||
@@ -193,6 +193,7 @@ static void logfs_init_inode(struct super_block *sb, struct inode *inode) | |||
193 | inode->i_ctime = CURRENT_TIME; | 193 | inode->i_ctime = CURRENT_TIME; |
194 | inode->i_mtime = CURRENT_TIME; | 194 | inode->i_mtime = CURRENT_TIME; |
195 | inode->i_nlink = 1; | 195 | inode->i_nlink = 1; |
196 | li->li_refcount = 1; | ||
196 | INIT_LIST_HEAD(&li->li_freeing_list); | 197 | INIT_LIST_HEAD(&li->li_freeing_list); |
197 | 198 | ||
198 | for (i = 0; i < LOGFS_EMBEDDED_FIELDS; i++) | 199 | for (i = 0; i < LOGFS_EMBEDDED_FIELDS; i++) |
@@ -326,7 +327,7 @@ static void logfs_set_ino_generation(struct super_block *sb, | |||
326 | u64 ino; | 327 | u64 ino; |
327 | 328 | ||
328 | mutex_lock(&super->s_journal_mutex); | 329 | mutex_lock(&super->s_journal_mutex); |
329 | ino = logfs_seek_hole(super->s_master_inode, super->s_last_ino); | 330 | ino = logfs_seek_hole(super->s_master_inode, super->s_last_ino + 1); |
330 | super->s_last_ino = ino; | 331 | super->s_last_ino = ino; |
331 | super->s_inos_till_wrap--; | 332 | super->s_inos_till_wrap--; |
332 | if (super->s_inos_till_wrap < 0) { | 333 | if (super->s_inos_till_wrap < 0) { |
@@ -386,8 +387,7 @@ static void logfs_init_once(void *_li) | |||
386 | 387 | ||
387 | static int logfs_sync_fs(struct super_block *sb, int wait) | 388 | static int logfs_sync_fs(struct super_block *sb, int wait) |
388 | { | 389 | { |
389 | /* FIXME: write anchor */ | 390 | logfs_write_anchor(sb); |
390 | logfs_super(sb)->s_devops->sync(sb); | ||
391 | return 0; | 391 | return 0; |
392 | } | 392 | } |
393 | 393 | ||
diff --git a/fs/logfs/journal.c b/fs/logfs/journal.c index fb0a613f885b..4b0e0616b357 100644 --- a/fs/logfs/journal.c +++ b/fs/logfs/journal.c | |||
@@ -132,10 +132,9 @@ static int read_area(struct super_block *sb, struct logfs_je_area *a) | |||
132 | 132 | ||
133 | ofs = dev_ofs(sb, area->a_segno, area->a_written_bytes); | 133 | ofs = dev_ofs(sb, area->a_segno, area->a_written_bytes); |
134 | if (super->s_writesize > 1) | 134 | if (super->s_writesize > 1) |
135 | logfs_buf_recover(area, ofs, a + 1, super->s_writesize); | 135 | return logfs_buf_recover(area, ofs, a + 1, super->s_writesize); |
136 | else | 136 | else |
137 | logfs_buf_recover(area, ofs, NULL, 0); | 137 | return logfs_buf_recover(area, ofs, NULL, 0); |
138 | return 0; | ||
139 | } | 138 | } |
140 | 139 | ||
141 | static void *unpack(void *from, void *to) | 140 | static void *unpack(void *from, void *to) |
@@ -245,7 +244,7 @@ static int read_je(struct super_block *sb, u64 ofs) | |||
245 | read_erasecount(sb, unpack(jh, scratch)); | 244 | read_erasecount(sb, unpack(jh, scratch)); |
246 | break; | 245 | break; |
247 | case JE_AREA: | 246 | case JE_AREA: |
248 | read_area(sb, unpack(jh, scratch)); | 247 | err = read_area(sb, unpack(jh, scratch)); |
249 | break; | 248 | break; |
250 | case JE_OBJ_ALIAS: | 249 | case JE_OBJ_ALIAS: |
251 | err = logfs_load_object_aliases(sb, unpack(jh, scratch), | 250 | err = logfs_load_object_aliases(sb, unpack(jh, scratch), |
diff --git a/fs/logfs/logfs.h b/fs/logfs/logfs.h index 0a3df1a0c936..93b55f337245 100644 --- a/fs/logfs/logfs.h +++ b/fs/logfs/logfs.h | |||
@@ -144,6 +144,7 @@ struct logfs_area_ops { | |||
144 | * @erase: erase one segment | 144 | * @erase: erase one segment |
145 | * @read: read from the device | 145 | * @read: read from the device |
146 | * @erase: erase part of the device | 146 | * @erase: erase part of the device |
147 | * @can_write_buf: decide whether wbuf can be written to ofs | ||
147 | */ | 148 | */ |
148 | struct logfs_device_ops { | 149 | struct logfs_device_ops { |
149 | struct page *(*find_first_sb)(struct super_block *sb, u64 *ofs); | 150 | struct page *(*find_first_sb)(struct super_block *sb, u64 *ofs); |
@@ -153,6 +154,7 @@ struct logfs_device_ops { | |||
153 | void (*writeseg)(struct super_block *sb, u64 ofs, size_t len); | 154 | void (*writeseg)(struct super_block *sb, u64 ofs, size_t len); |
154 | int (*erase)(struct super_block *sb, loff_t ofs, size_t len, | 155 | int (*erase)(struct super_block *sb, loff_t ofs, size_t len, |
155 | int ensure_write); | 156 | int ensure_write); |
157 | int (*can_write_buf)(struct super_block *sb, u64 ofs); | ||
156 | void (*sync)(struct super_block *sb); | 158 | void (*sync)(struct super_block *sb); |
157 | void (*put_device)(struct super_block *sb); | 159 | void (*put_device)(struct super_block *sb); |
158 | }; | 160 | }; |
@@ -394,6 +396,7 @@ struct logfs_super { | |||
394 | int s_lock_count; | 396 | int s_lock_count; |
395 | mempool_t *s_block_pool; /* struct logfs_block pool */ | 397 | mempool_t *s_block_pool; /* struct logfs_block pool */ |
396 | mempool_t *s_shadow_pool; /* struct logfs_shadow pool */ | 398 | mempool_t *s_shadow_pool; /* struct logfs_shadow pool */ |
399 | struct list_head s_writeback_list; /* writeback pages */ | ||
397 | /* | 400 | /* |
398 | * Space accounting: | 401 | * Space accounting: |
399 | * - s_used_bytes specifies space used to store valid data objects. | 402 | * - s_used_bytes specifies space used to store valid data objects. |
@@ -598,19 +601,19 @@ void freeseg(struct super_block *sb, u32 segno); | |||
598 | int logfs_init_areas(struct super_block *sb); | 601 | int logfs_init_areas(struct super_block *sb); |
599 | void logfs_cleanup_areas(struct super_block *sb); | 602 | void logfs_cleanup_areas(struct super_block *sb); |
600 | int logfs_open_area(struct logfs_area *area, size_t bytes); | 603 | int logfs_open_area(struct logfs_area *area, size_t bytes); |
601 | void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, | 604 | int __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, |
602 | int use_filler); | 605 | int use_filler); |
603 | 606 | ||
604 | static inline void logfs_buf_write(struct logfs_area *area, u64 ofs, | 607 | static inline int logfs_buf_write(struct logfs_area *area, u64 ofs, |
605 | void *buf, size_t len) | 608 | void *buf, size_t len) |
606 | { | 609 | { |
607 | __logfs_buf_write(area, ofs, buf, len, 0); | 610 | return __logfs_buf_write(area, ofs, buf, len, 0); |
608 | } | 611 | } |
609 | 612 | ||
610 | static inline void logfs_buf_recover(struct logfs_area *area, u64 ofs, | 613 | static inline int logfs_buf_recover(struct logfs_area *area, u64 ofs, |
611 | void *buf, size_t len) | 614 | void *buf, size_t len) |
612 | { | 615 | { |
613 | __logfs_buf_write(area, ofs, buf, len, 1); | 616 | return __logfs_buf_write(area, ofs, buf, len, 1); |
614 | } | 617 | } |
615 | 618 | ||
616 | /* super.c */ | 619 | /* super.c */ |
diff --git a/fs/logfs/readwrite.c b/fs/logfs/readwrite.c index 3159db6958e5..0718d112a1a5 100644 --- a/fs/logfs/readwrite.c +++ b/fs/logfs/readwrite.c | |||
@@ -892,6 +892,8 @@ u64 logfs_seek_hole(struct inode *inode, u64 bix) | |||
892 | return bix; | 892 | return bix; |
893 | else if (li->li_data[INDIRECT_INDEX] & LOGFS_FULLY_POPULATED) | 893 | else if (li->li_data[INDIRECT_INDEX] & LOGFS_FULLY_POPULATED) |
894 | bix = maxbix(li->li_height); | 894 | bix = maxbix(li->li_height); |
895 | else if (bix >= maxbix(li->li_height)) | ||
896 | return bix; | ||
895 | else { | 897 | else { |
896 | bix = seek_holedata_loop(inode, bix, 0); | 898 | bix = seek_holedata_loop(inode, bix, 0); |
897 | if (bix < maxbix(li->li_height)) | 899 | if (bix < maxbix(li->li_height)) |
@@ -1093,17 +1095,25 @@ static int logfs_reserve_bytes(struct inode *inode, int bytes) | |||
1093 | int get_page_reserve(struct inode *inode, struct page *page) | 1095 | int get_page_reserve(struct inode *inode, struct page *page) |
1094 | { | 1096 | { |
1095 | struct logfs_super *super = logfs_super(inode->i_sb); | 1097 | struct logfs_super *super = logfs_super(inode->i_sb); |
1098 | struct logfs_block *block = logfs_block(page); | ||
1096 | int ret; | 1099 | int ret; |
1097 | 1100 | ||
1098 | if (logfs_block(page) && logfs_block(page)->reserved_bytes) | 1101 | if (block && block->reserved_bytes) |
1099 | return 0; | 1102 | return 0; |
1100 | 1103 | ||
1101 | logfs_get_wblocks(inode->i_sb, page, WF_LOCK); | 1104 | logfs_get_wblocks(inode->i_sb, page, WF_LOCK); |
1102 | ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE); | 1105 | while ((ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE)) && |
1106 | !list_empty(&super->s_writeback_list)) { | ||
1107 | block = list_entry(super->s_writeback_list.next, | ||
1108 | struct logfs_block, alias_list); | ||
1109 | block->ops->write_block(block); | ||
1110 | } | ||
1103 | if (!ret) { | 1111 | if (!ret) { |
1104 | alloc_data_block(inode, page); | 1112 | alloc_data_block(inode, page); |
1105 | logfs_block(page)->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE; | 1113 | block = logfs_block(page); |
1114 | block->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE; | ||
1106 | super->s_dirty_pages += 6 * LOGFS_MAX_OBJECTSIZE; | 1115 | super->s_dirty_pages += 6 * LOGFS_MAX_OBJECTSIZE; |
1116 | list_move_tail(&block->alias_list, &super->s_writeback_list); | ||
1107 | } | 1117 | } |
1108 | logfs_put_wblocks(inode->i_sb, page, WF_LOCK); | 1118 | logfs_put_wblocks(inode->i_sb, page, WF_LOCK); |
1109 | return ret; | 1119 | return ret; |
@@ -1861,7 +1871,7 @@ int logfs_truncate(struct inode *inode, u64 target) | |||
1861 | size = target; | 1871 | size = target; |
1862 | 1872 | ||
1863 | logfs_get_wblocks(sb, NULL, 1); | 1873 | logfs_get_wblocks(sb, NULL, 1); |
1864 | err = __logfs_truncate(inode, target); | 1874 | err = __logfs_truncate(inode, size); |
1865 | if (!err) | 1875 | if (!err) |
1866 | err = __logfs_write_inode(inode, 0); | 1876 | err = __logfs_write_inode(inode, 0); |
1867 | logfs_put_wblocks(sb, NULL, 1); | 1877 | logfs_put_wblocks(sb, NULL, 1); |
@@ -2249,6 +2259,7 @@ int logfs_init_rw(struct super_block *sb) | |||
2249 | int min_fill = 3 * super->s_no_blocks; | 2259 | int min_fill = 3 * super->s_no_blocks; |
2250 | 2260 | ||
2251 | INIT_LIST_HEAD(&super->s_object_alias); | 2261 | INIT_LIST_HEAD(&super->s_object_alias); |
2262 | INIT_LIST_HEAD(&super->s_writeback_list); | ||
2252 | mutex_init(&super->s_write_mutex); | 2263 | mutex_init(&super->s_write_mutex); |
2253 | super->s_block_pool = mempool_create_kmalloc_pool(min_fill, | 2264 | super->s_block_pool = mempool_create_kmalloc_pool(min_fill, |
2254 | sizeof(struct logfs_block)); | 2265 | sizeof(struct logfs_block)); |
diff --git a/fs/logfs/segment.c b/fs/logfs/segment.c index f77ce2b470ba..a9657afb70ad 100644 --- a/fs/logfs/segment.c +++ b/fs/logfs/segment.c | |||
@@ -67,7 +67,7 @@ static struct page *get_mapping_page(struct super_block *sb, pgoff_t index, | |||
67 | return page; | 67 | return page; |
68 | } | 68 | } |
69 | 69 | ||
70 | void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, | 70 | int __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, |
71 | int use_filler) | 71 | int use_filler) |
72 | { | 72 | { |
73 | pgoff_t index = ofs >> PAGE_SHIFT; | 73 | pgoff_t index = ofs >> PAGE_SHIFT; |
@@ -81,8 +81,10 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, | |||
81 | copylen = min((ulong)len, PAGE_SIZE - offset); | 81 | copylen = min((ulong)len, PAGE_SIZE - offset); |
82 | 82 | ||
83 | page = get_mapping_page(area->a_sb, index, use_filler); | 83 | page = get_mapping_page(area->a_sb, index, use_filler); |
84 | SetPageUptodate(page); | 84 | if (IS_ERR(page)) |
85 | return PTR_ERR(page); | ||
85 | BUG_ON(!page); /* FIXME: reserve a pool */ | 86 | BUG_ON(!page); /* FIXME: reserve a pool */ |
87 | SetPageUptodate(page); | ||
86 | memcpy(page_address(page) + offset, buf, copylen); | 88 | memcpy(page_address(page) + offset, buf, copylen); |
87 | SetPagePrivate(page); | 89 | SetPagePrivate(page); |
88 | page_cache_release(page); | 90 | page_cache_release(page); |
@@ -92,6 +94,7 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len, | |||
92 | offset = 0; | 94 | offset = 0; |
93 | index++; | 95 | index++; |
94 | } while (len); | 96 | } while (len); |
97 | return 0; | ||
95 | } | 98 | } |
96 | 99 | ||
97 | static void pad_partial_page(struct logfs_area *area) | 100 | static void pad_partial_page(struct logfs_area *area) |
diff --git a/fs/logfs/super.c b/fs/logfs/super.c index 5866ee6e1327..d651e10a1e9c 100644 --- a/fs/logfs/super.c +++ b/fs/logfs/super.c | |||
@@ -138,10 +138,14 @@ static int logfs_sb_set(struct super_block *sb, void *_super) | |||
138 | sb->s_fs_info = super; | 138 | sb->s_fs_info = super; |
139 | sb->s_mtd = super->s_mtd; | 139 | sb->s_mtd = super->s_mtd; |
140 | sb->s_bdev = super->s_bdev; | 140 | sb->s_bdev = super->s_bdev; |
141 | #ifdef CONFIG_BLOCK | ||
141 | if (sb->s_bdev) | 142 | if (sb->s_bdev) |
142 | sb->s_bdi = &bdev_get_queue(sb->s_bdev)->backing_dev_info; | 143 | sb->s_bdi = &bdev_get_queue(sb->s_bdev)->backing_dev_info; |
144 | #endif | ||
145 | #ifdef CONFIG_MTD | ||
143 | if (sb->s_mtd) | 146 | if (sb->s_mtd) |
144 | sb->s_bdi = sb->s_mtd->backing_dev_info; | 147 | sb->s_bdi = sb->s_mtd->backing_dev_info; |
148 | #endif | ||
145 | return 0; | 149 | return 0; |
146 | } | 150 | } |
147 | 151 | ||
@@ -333,27 +337,27 @@ static int logfs_get_sb_final(struct super_block *sb, struct vfsmount *mnt) | |||
333 | goto fail; | 337 | goto fail; |
334 | 338 | ||
335 | sb->s_root = d_alloc_root(rootdir); | 339 | sb->s_root = d_alloc_root(rootdir); |
336 | if (!sb->s_root) | 340 | if (!sb->s_root) { |
337 | goto fail2; | 341 | iput(rootdir); |
342 | goto fail; | ||
343 | } | ||
338 | 344 | ||
339 | super->s_erase_page = alloc_pages(GFP_KERNEL, 0); | 345 | super->s_erase_page = alloc_pages(GFP_KERNEL, 0); |
340 | if (!super->s_erase_page) | 346 | if (!super->s_erase_page) |
341 | goto fail2; | 347 | goto fail; |
342 | memset(page_address(super->s_erase_page), 0xFF, PAGE_SIZE); | 348 | memset(page_address(super->s_erase_page), 0xFF, PAGE_SIZE); |
343 | 349 | ||
344 | /* FIXME: check for read-only mounts */ | 350 | /* FIXME: check for read-only mounts */ |
345 | err = logfs_make_writeable(sb); | 351 | err = logfs_make_writeable(sb); |
346 | if (err) | 352 | if (err) |
347 | goto fail3; | 353 | goto fail1; |
348 | 354 | ||
349 | log_super("LogFS: Finished mounting\n"); | 355 | log_super("LogFS: Finished mounting\n"); |
350 | simple_set_mnt(mnt, sb); | 356 | simple_set_mnt(mnt, sb); |
351 | return 0; | 357 | return 0; |
352 | 358 | ||
353 | fail3: | 359 | fail1: |
354 | __free_page(super->s_erase_page); | 360 | __free_page(super->s_erase_page); |
355 | fail2: | ||
356 | iput(rootdir); | ||
357 | fail: | 361 | fail: |
358 | iput(logfs_super(sb)->s_master_inode); | 362 | iput(logfs_super(sb)->s_master_inode); |
359 | return -EIO; | 363 | return -EIO; |
@@ -382,7 +386,7 @@ static struct page *find_super_block(struct super_block *sb) | |||
382 | if (!first || IS_ERR(first)) | 386 | if (!first || IS_ERR(first)) |
383 | return NULL; | 387 | return NULL; |
384 | last = super->s_devops->find_last_sb(sb, &super->s_sb_ofs[1]); | 388 | last = super->s_devops->find_last_sb(sb, &super->s_sb_ofs[1]); |
385 | if (!last || IS_ERR(first)) { | 389 | if (!last || IS_ERR(last)) { |
386 | page_cache_release(first); | 390 | page_cache_release(first); |
387 | return NULL; | 391 | return NULL; |
388 | } | 392 | } |
@@ -413,7 +417,7 @@ static int __logfs_read_sb(struct super_block *sb) | |||
413 | 417 | ||
414 | page = find_super_block(sb); | 418 | page = find_super_block(sb); |
415 | if (!page) | 419 | if (!page) |
416 | return -EIO; | 420 | return -EINVAL; |
417 | 421 | ||
418 | ds = page_address(page); | 422 | ds = page_address(page); |
419 | super->s_size = be64_to_cpu(ds->ds_filesystem_size); | 423 | super->s_size = be64_to_cpu(ds->ds_filesystem_size); |
diff --git a/fs/namei.c b/fs/namei.c index a7dce91a7e42..b86b96fe1dc3 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -1641,7 +1641,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path, | |||
1641 | if (nd->last.name[nd->last.len]) { | 1641 | if (nd->last.name[nd->last.len]) { |
1642 | if (open_flag & O_CREAT) | 1642 | if (open_flag & O_CREAT) |
1643 | goto exit; | 1643 | goto exit; |
1644 | nd->flags |= LOOKUP_DIRECTORY; | 1644 | nd->flags |= LOOKUP_DIRECTORY | LOOKUP_FOLLOW; |
1645 | } | 1645 | } |
1646 | 1646 | ||
1647 | /* just plain open? */ | 1647 | /* just plain open? */ |
@@ -1830,6 +1830,8 @@ reval: | |||
1830 | } | 1830 | } |
1831 | if (open_flag & O_DIRECTORY) | 1831 | if (open_flag & O_DIRECTORY) |
1832 | nd.flags |= LOOKUP_DIRECTORY; | 1832 | nd.flags |= LOOKUP_DIRECTORY; |
1833 | if (!(open_flag & O_NOFOLLOW)) | ||
1834 | nd.flags |= LOOKUP_FOLLOW; | ||
1833 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname); | 1835 | filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname); |
1834 | while (unlikely(!filp)) { /* trailing symlink */ | 1836 | while (unlikely(!filp)) { /* trailing symlink */ |
1835 | struct path holder; | 1837 | struct path holder; |
@@ -1837,7 +1839,7 @@ reval: | |||
1837 | void *cookie; | 1839 | void *cookie; |
1838 | error = -ELOOP; | 1840 | error = -ELOOP; |
1839 | /* S_ISDIR part is a temporary automount kludge */ | 1841 | /* S_ISDIR part is a temporary automount kludge */ |
1840 | if ((open_flag & O_NOFOLLOW) && !S_ISDIR(inode->i_mode)) | 1842 | if (!(nd.flags & LOOKUP_FOLLOW) && !S_ISDIR(inode->i_mode)) |
1841 | goto exit_dput; | 1843 | goto exit_dput; |
1842 | if (count++ == 32) | 1844 | if (count++ == 32) |
1843 | goto exit_dput; | 1845 | goto exit_dput; |
@@ -2174,8 +2176,10 @@ int vfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
2174 | error = security_inode_rmdir(dir, dentry); | 2176 | error = security_inode_rmdir(dir, dentry); |
2175 | if (!error) { | 2177 | if (!error) { |
2176 | error = dir->i_op->rmdir(dir, dentry); | 2178 | error = dir->i_op->rmdir(dir, dentry); |
2177 | if (!error) | 2179 | if (!error) { |
2178 | dentry->d_inode->i_flags |= S_DEAD; | 2180 | dentry->d_inode->i_flags |= S_DEAD; |
2181 | dont_mount(dentry); | ||
2182 | } | ||
2179 | } | 2183 | } |
2180 | } | 2184 | } |
2181 | mutex_unlock(&dentry->d_inode->i_mutex); | 2185 | mutex_unlock(&dentry->d_inode->i_mutex); |
@@ -2259,7 +2263,7 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry) | |||
2259 | if (!error) { | 2263 | if (!error) { |
2260 | error = dir->i_op->unlink(dir, dentry); | 2264 | error = dir->i_op->unlink(dir, dentry); |
2261 | if (!error) | 2265 | if (!error) |
2262 | dentry->d_inode->i_flags |= S_DEAD; | 2266 | dont_mount(dentry); |
2263 | } | 2267 | } |
2264 | } | 2268 | } |
2265 | mutex_unlock(&dentry->d_inode->i_mutex); | 2269 | mutex_unlock(&dentry->d_inode->i_mutex); |
@@ -2570,17 +2574,20 @@ static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry, | |||
2570 | return error; | 2574 | return error; |
2571 | 2575 | ||
2572 | target = new_dentry->d_inode; | 2576 | target = new_dentry->d_inode; |
2573 | if (target) { | 2577 | if (target) |
2574 | mutex_lock(&target->i_mutex); | 2578 | mutex_lock(&target->i_mutex); |
2575 | dentry_unhash(new_dentry); | ||
2576 | } | ||
2577 | if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry)) | 2579 | if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry)) |
2578 | error = -EBUSY; | 2580 | error = -EBUSY; |
2579 | else | 2581 | else { |
2582 | if (target) | ||
2583 | dentry_unhash(new_dentry); | ||
2580 | error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); | 2584 | error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); |
2585 | } | ||
2581 | if (target) { | 2586 | if (target) { |
2582 | if (!error) | 2587 | if (!error) { |
2583 | target->i_flags |= S_DEAD; | 2588 | target->i_flags |= S_DEAD; |
2589 | dont_mount(new_dentry); | ||
2590 | } | ||
2584 | mutex_unlock(&target->i_mutex); | 2591 | mutex_unlock(&target->i_mutex); |
2585 | if (d_unhashed(new_dentry)) | 2592 | if (d_unhashed(new_dentry)) |
2586 | d_rehash(new_dentry); | 2593 | d_rehash(new_dentry); |
@@ -2612,7 +2619,7 @@ static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry, | |||
2612 | error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); | 2619 | error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry); |
2613 | if (!error) { | 2620 | if (!error) { |
2614 | if (target) | 2621 | if (target) |
2615 | target->i_flags |= S_DEAD; | 2622 | dont_mount(new_dentry); |
2616 | if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE)) | 2623 | if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE)) |
2617 | d_move(old_dentry, new_dentry); | 2624 | d_move(old_dentry, new_dentry); |
2618 | } | 2625 | } |
diff --git a/fs/namespace.c b/fs/namespace.c index 8174c8ab5c70..f20cb57d1067 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -1432,7 +1432,7 @@ static int graft_tree(struct vfsmount *mnt, struct path *path) | |||
1432 | 1432 | ||
1433 | err = -ENOENT; | 1433 | err = -ENOENT; |
1434 | mutex_lock(&path->dentry->d_inode->i_mutex); | 1434 | mutex_lock(&path->dentry->d_inode->i_mutex); |
1435 | if (IS_DEADDIR(path->dentry->d_inode)) | 1435 | if (cant_mount(path->dentry)) |
1436 | goto out_unlock; | 1436 | goto out_unlock; |
1437 | 1437 | ||
1438 | err = security_sb_check_sb(mnt, path); | 1438 | err = security_sb_check_sb(mnt, path); |
@@ -1623,7 +1623,7 @@ static int do_move_mount(struct path *path, char *old_name) | |||
1623 | 1623 | ||
1624 | err = -ENOENT; | 1624 | err = -ENOENT; |
1625 | mutex_lock(&path->dentry->d_inode->i_mutex); | 1625 | mutex_lock(&path->dentry->d_inode->i_mutex); |
1626 | if (IS_DEADDIR(path->dentry->d_inode)) | 1626 | if (cant_mount(path->dentry)) |
1627 | goto out1; | 1627 | goto out1; |
1628 | 1628 | ||
1629 | if (d_unlinked(path->dentry)) | 1629 | if (d_unlinked(path->dentry)) |
@@ -2234,7 +2234,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, | |||
2234 | if (!check_mnt(root.mnt)) | 2234 | if (!check_mnt(root.mnt)) |
2235 | goto out2; | 2235 | goto out2; |
2236 | error = -ENOENT; | 2236 | error = -ENOENT; |
2237 | if (IS_DEADDIR(new.dentry->d_inode)) | 2237 | if (cant_mount(old.dentry)) |
2238 | goto out2; | 2238 | goto out2; |
2239 | if (d_unlinked(new.dentry)) | 2239 | if (d_unlinked(new.dentry)) |
2240 | goto out2; | 2240 | goto out2; |
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index 1afb0a10229f..e27960cd76ab 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/path.h> /* struct path */ | 28 | #include <linux/path.h> /* struct path */ |
29 | #include <linux/slab.h> /* kmem_* */ | 29 | #include <linux/slab.h> /* kmem_* */ |
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | #include <linux/sched.h> | ||
31 | 32 | ||
32 | #include "inotify.h" | 33 | #include "inotify.h" |
33 | 34 | ||
@@ -146,6 +147,7 @@ static void inotify_free_group_priv(struct fsnotify_group *group) | |||
146 | idr_for_each(&group->inotify_data.idr, idr_callback, group); | 147 | idr_for_each(&group->inotify_data.idr, idr_callback, group); |
147 | idr_remove_all(&group->inotify_data.idr); | 148 | idr_remove_all(&group->inotify_data.idr); |
148 | idr_destroy(&group->inotify_data.idr); | 149 | idr_destroy(&group->inotify_data.idr); |
150 | free_uid(group->inotify_data.user); | ||
149 | } | 151 | } |
150 | 152 | ||
151 | void inotify_free_event_priv(struct fsnotify_event_private_data *fsn_event_priv) | 153 | void inotify_free_event_priv(struct fsnotify_event_private_data *fsn_event_priv) |
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 472cdf29ef82..e46ca685b9be 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c | |||
@@ -546,21 +546,24 @@ retry: | |||
546 | if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL))) | 546 | if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL))) |
547 | goto out_err; | 547 | goto out_err; |
548 | 548 | ||
549 | /* we are putting the mark on the idr, take a reference */ | ||
550 | fsnotify_get_mark(&tmp_ientry->fsn_entry); | ||
551 | |||
549 | spin_lock(&group->inotify_data.idr_lock); | 552 | spin_lock(&group->inotify_data.idr_lock); |
550 | ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry, | 553 | ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry, |
551 | group->inotify_data.last_wd+1, | 554 | group->inotify_data.last_wd+1, |
552 | &tmp_ientry->wd); | 555 | &tmp_ientry->wd); |
553 | spin_unlock(&group->inotify_data.idr_lock); | 556 | spin_unlock(&group->inotify_data.idr_lock); |
554 | if (ret) { | 557 | if (ret) { |
558 | /* we didn't get on the idr, drop the idr reference */ | ||
559 | fsnotify_put_mark(&tmp_ientry->fsn_entry); | ||
560 | |||
555 | /* idr was out of memory allocate and try again */ | 561 | /* idr was out of memory allocate and try again */ |
556 | if (ret == -EAGAIN) | 562 | if (ret == -EAGAIN) |
557 | goto retry; | 563 | goto retry; |
558 | goto out_err; | 564 | goto out_err; |
559 | } | 565 | } |
560 | 566 | ||
561 | /* we put the mark on the idr, take a reference */ | ||
562 | fsnotify_get_mark(&tmp_ientry->fsn_entry); | ||
563 | |||
564 | /* we are on the idr, now get on the inode */ | 567 | /* we are on the idr, now get on the inode */ |
565 | ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode); | 568 | ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode); |
566 | if (ret) { | 569 | if (ret) { |
@@ -578,16 +581,13 @@ retry: | |||
578 | /* return the watch descriptor for this new entry */ | 581 | /* return the watch descriptor for this new entry */ |
579 | ret = tmp_ientry->wd; | 582 | ret = tmp_ientry->wd; |
580 | 583 | ||
581 | /* match the ref from fsnotify_init_markentry() */ | ||
582 | fsnotify_put_mark(&tmp_ientry->fsn_entry); | ||
583 | |||
584 | /* if this mark added a new event update the group mask */ | 584 | /* if this mark added a new event update the group mask */ |
585 | if (mask & ~group->mask) | 585 | if (mask & ~group->mask) |
586 | fsnotify_recalc_group_mask(group); | 586 | fsnotify_recalc_group_mask(group); |
587 | 587 | ||
588 | out_err: | 588 | out_err: |
589 | if (ret < 0) | 589 | /* match the ref from fsnotify_init_markentry() */ |
590 | kmem_cache_free(inotify_inode_mark_cachep, tmp_ientry); | 590 | fsnotify_put_mark(&tmp_ientry->fsn_entry); |
591 | 591 | ||
592 | return ret; | 592 | return ret; |
593 | } | 593 | } |
diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 4e50286a4cc3..1dabed286b4c 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c | |||
@@ -164,8 +164,8 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_ | |||
164 | name, de->name)) | 164 | name, de->name)) |
165 | goto found; | 165 | goto found; |
166 | } | 166 | } |
167 | dir_put_page(page); | ||
167 | } | 168 | } |
168 | dir_put_page(page); | ||
169 | 169 | ||
170 | if (++n >= npages) | 170 | if (++n >= npages) |
171 | n = 0; | 171 | n = 0; |
diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h index c99c64dc5f3d..c33749f95b32 100644 --- a/include/asm-generic/atomic.h +++ b/include/asm-generic/atomic.h | |||
@@ -33,7 +33,7 @@ | |||
33 | * Atomically reads the value of @v. Note that the guaranteed | 33 | * Atomically reads the value of @v. Note that the guaranteed |
34 | * useful range of an atomic_t is only 24 bits. | 34 | * useful range of an atomic_t is only 24 bits. |
35 | */ | 35 | */ |
36 | #define atomic_read(v) ((v)->counter) | 36 | #define atomic_read(v) (*(volatile int *)&(v)->counter) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * atomic_set - set atomic variable | 39 | * atomic_set - set atomic variable |
diff --git a/include/asm-generic/bitops/arch_hweight.h b/include/asm-generic/bitops/arch_hweight.h new file mode 100644 index 000000000000..6a211f40665c --- /dev/null +++ b/include/asm-generic/bitops/arch_hweight.h | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ | ||
2 | #define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_ | ||
3 | |||
4 | #include <asm/types.h> | ||
5 | |||
6 | static inline unsigned int __arch_hweight32(unsigned int w) | ||
7 | { | ||
8 | return __sw_hweight32(w); | ||
9 | } | ||
10 | |||
11 | static inline unsigned int __arch_hweight16(unsigned int w) | ||
12 | { | ||
13 | return __sw_hweight16(w); | ||
14 | } | ||
15 | |||
16 | static inline unsigned int __arch_hweight8(unsigned int w) | ||
17 | { | ||
18 | return __sw_hweight8(w); | ||
19 | } | ||
20 | |||
21 | static inline unsigned long __arch_hweight64(__u64 w) | ||
22 | { | ||
23 | return __sw_hweight64(w); | ||
24 | } | ||
25 | #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ | ||
diff --git a/include/asm-generic/bitops/const_hweight.h b/include/asm-generic/bitops/const_hweight.h new file mode 100644 index 000000000000..fa2a50b7ee66 --- /dev/null +++ b/include/asm-generic/bitops/const_hweight.h | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ | ||
2 | #define _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ | ||
3 | |||
4 | /* | ||
5 | * Compile time versions of __arch_hweightN() | ||
6 | */ | ||
7 | #define __const_hweight8(w) \ | ||
8 | ( (!!((w) & (1ULL << 0))) + \ | ||
9 | (!!((w) & (1ULL << 1))) + \ | ||
10 | (!!((w) & (1ULL << 2))) + \ | ||
11 | (!!((w) & (1ULL << 3))) + \ | ||
12 | (!!((w) & (1ULL << 4))) + \ | ||
13 | (!!((w) & (1ULL << 5))) + \ | ||
14 | (!!((w) & (1ULL << 6))) + \ | ||
15 | (!!((w) & (1ULL << 7))) ) | ||
16 | |||
17 | #define __const_hweight16(w) (__const_hweight8(w) + __const_hweight8((w) >> 8 )) | ||
18 | #define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16)) | ||
19 | #define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32)) | ||
20 | |||
21 | /* | ||
22 | * Generic interface. | ||
23 | */ | ||
24 | #define hweight8(w) (__builtin_constant_p(w) ? __const_hweight8(w) : __arch_hweight8(w)) | ||
25 | #define hweight16(w) (__builtin_constant_p(w) ? __const_hweight16(w) : __arch_hweight16(w)) | ||
26 | #define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w)) | ||
27 | #define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w)) | ||
28 | |||
29 | /* | ||
30 | * Interface for known constant arguments | ||
31 | */ | ||
32 | #define HWEIGHT8(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight8(w)) | ||
33 | #define HWEIGHT16(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight16(w)) | ||
34 | #define HWEIGHT32(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight32(w)) | ||
35 | #define HWEIGHT64(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight64(w)) | ||
36 | |||
37 | /* | ||
38 | * Type invariant interface to the compile time constant hweight functions. | ||
39 | */ | ||
40 | #define HWEIGHT(w) HWEIGHT64((u64)w) | ||
41 | |||
42 | #endif /* _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ */ | ||
diff --git a/include/asm-generic/bitops/hweight.h b/include/asm-generic/bitops/hweight.h index fbbc383771da..a94d6519c7ed 100644 --- a/include/asm-generic/bitops/hweight.h +++ b/include/asm-generic/bitops/hweight.h | |||
@@ -1,11 +1,7 @@ | |||
1 | #ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ | 1 | #ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ |
2 | #define _ASM_GENERIC_BITOPS_HWEIGHT_H_ | 2 | #define _ASM_GENERIC_BITOPS_HWEIGHT_H_ |
3 | 3 | ||
4 | #include <asm/types.h> | 4 | #include <asm-generic/bitops/arch_hweight.h> |
5 | 5 | #include <asm-generic/bitops/const_hweight.h> | |
6 | extern unsigned int hweight32(unsigned int w); | ||
7 | extern unsigned int hweight16(unsigned int w); | ||
8 | extern unsigned int hweight8(unsigned int w); | ||
9 | extern unsigned long hweight64(__u64 w); | ||
10 | 6 | ||
11 | #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ | 7 | #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ |
diff --git a/include/linux/acpi.h b/include/linux/acpi.h index b926afe8c03e..3da73f5f0ae9 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h | |||
@@ -116,11 +116,12 @@ extern unsigned long acpi_realmode_flags; | |||
116 | 116 | ||
117 | int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity); | 117 | int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity); |
118 | int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); | 118 | int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); |
119 | int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi); | ||
119 | 120 | ||
120 | #ifdef CONFIG_X86_IO_APIC | 121 | #ifdef CONFIG_X86_IO_APIC |
121 | extern int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity); | 122 | extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity); |
122 | #else | 123 | #else |
123 | #define acpi_get_override_irq(bus, trigger, polarity) (-1) | 124 | #define acpi_get_override_irq(gsi, trigger, polarity) (-1) |
124 | #endif | 125 | #endif |
125 | /* | 126 | /* |
126 | * This function undoes the effect of one call to acpi_register_gsi(). | 127 | * This function undoes the effect of one call to acpi_register_gsi(). |
diff --git a/include/linux/bitops.h b/include/linux/bitops.h index b796eab5ca75..fc68053378ce 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h | |||
@@ -10,6 +10,11 @@ | |||
10 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) | 10 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | extern unsigned int __sw_hweight8(unsigned int w); | ||
14 | extern unsigned int __sw_hweight16(unsigned int w); | ||
15 | extern unsigned int __sw_hweight32(unsigned int w); | ||
16 | extern unsigned long __sw_hweight64(__u64 w); | ||
17 | |||
13 | /* | 18 | /* |
14 | * Include this here because some architectures need generic_ffs/fls in | 19 | * Include this here because some architectures need generic_ffs/fls in |
15 | * scope | 20 | * scope |
@@ -44,31 +49,6 @@ static inline unsigned long hweight_long(unsigned long w) | |||
44 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | 49 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); |
45 | } | 50 | } |
46 | 51 | ||
47 | /* | ||
48 | * Clearly slow versions of the hweightN() functions, their benefit is | ||
49 | * of course compile time evaluation of constant arguments. | ||
50 | */ | ||
51 | #define HWEIGHT8(w) \ | ||
52 | ( BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + \ | ||
53 | (!!((w) & (1ULL << 0))) + \ | ||
54 | (!!((w) & (1ULL << 1))) + \ | ||
55 | (!!((w) & (1ULL << 2))) + \ | ||
56 | (!!((w) & (1ULL << 3))) + \ | ||
57 | (!!((w) & (1ULL << 4))) + \ | ||
58 | (!!((w) & (1ULL << 5))) + \ | ||
59 | (!!((w) & (1ULL << 6))) + \ | ||
60 | (!!((w) & (1ULL << 7))) ) | ||
61 | |||
62 | #define HWEIGHT16(w) (HWEIGHT8(w) + HWEIGHT8((w) >> 8)) | ||
63 | #define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16((w) >> 16)) | ||
64 | #define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32((w) >> 32)) | ||
65 | |||
66 | /* | ||
67 | * Type invariant version that simply casts things to the | ||
68 | * largest type. | ||
69 | */ | ||
70 | #define HWEIGHT(w) HWEIGHT64((u64)(w)) | ||
71 | |||
72 | /** | 52 | /** |
73 | * rol32 - rotate a 32-bit value left | 53 | * rol32 - rotate a 32-bit value left |
74 | * @word: value to rotate | 54 | * @word: value to rotate |
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 4de02b10007f..9f15150ce8d6 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h | |||
@@ -278,6 +278,27 @@ struct freq_attr { | |||
278 | ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count); | 278 | ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count); |
279 | }; | 279 | }; |
280 | 280 | ||
281 | #define cpufreq_freq_attr_ro(_name) \ | ||
282 | static struct freq_attr _name = \ | ||
283 | __ATTR(_name, 0444, show_##_name, NULL) | ||
284 | |||
285 | #define cpufreq_freq_attr_ro_perm(_name, _perm) \ | ||
286 | static struct freq_attr _name = \ | ||
287 | __ATTR(_name, _perm, show_##_name, NULL) | ||
288 | |||
289 | #define cpufreq_freq_attr_ro_old(_name) \ | ||
290 | static struct freq_attr _name##_old = \ | ||
291 | __ATTR(_name, 0444, show_##_name##_old, NULL) | ||
292 | |||
293 | #define cpufreq_freq_attr_rw(_name) \ | ||
294 | static struct freq_attr _name = \ | ||
295 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
296 | |||
297 | #define cpufreq_freq_attr_rw_old(_name) \ | ||
298 | static struct freq_attr _name##_old = \ | ||
299 | __ATTR(_name, 0644, show_##_name##_old, store_##_name##_old) | ||
300 | |||
301 | |||
281 | struct global_attr { | 302 | struct global_attr { |
282 | struct attribute attr; | 303 | struct attribute attr; |
283 | ssize_t (*show)(struct kobject *kobj, | 304 | ssize_t (*show)(struct kobject *kobj, |
@@ -286,6 +307,15 @@ struct global_attr { | |||
286 | const char *c, size_t count); | 307 | const char *c, size_t count); |
287 | }; | 308 | }; |
288 | 309 | ||
310 | #define define_one_global_ro(_name) \ | ||
311 | static struct global_attr _name = \ | ||
312 | __ATTR(_name, 0444, show_##_name, NULL) | ||
313 | |||
314 | #define define_one_global_rw(_name) \ | ||
315 | static struct global_attr _name = \ | ||
316 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
317 | |||
318 | |||
289 | /********************************************************************* | 319 | /********************************************************************* |
290 | * CPUFREQ 2.6. INTERFACE * | 320 | * CPUFREQ 2.6. INTERFACE * |
291 | *********************************************************************/ | 321 | *********************************************************************/ |
diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index a5740fc4d04b..a73454aec333 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h | |||
@@ -21,8 +21,7 @@ extern int number_of_cpusets; /* How many cpusets are defined in system? */ | |||
21 | extern int cpuset_init(void); | 21 | extern int cpuset_init(void); |
22 | extern void cpuset_init_smp(void); | 22 | extern void cpuset_init_smp(void); |
23 | extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); | 23 | extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); |
24 | extern void cpuset_cpus_allowed_locked(struct task_struct *p, | 24 | extern int cpuset_cpus_allowed_fallback(struct task_struct *p); |
25 | struct cpumask *mask); | ||
26 | extern nodemask_t cpuset_mems_allowed(struct task_struct *p); | 25 | extern nodemask_t cpuset_mems_allowed(struct task_struct *p); |
27 | #define cpuset_current_mems_allowed (current->mems_allowed) | 26 | #define cpuset_current_mems_allowed (current->mems_allowed) |
28 | void cpuset_init_current_mems_allowed(void); | 27 | void cpuset_init_current_mems_allowed(void); |
@@ -69,9 +68,6 @@ struct seq_file; | |||
69 | extern void cpuset_task_status_allowed(struct seq_file *m, | 68 | extern void cpuset_task_status_allowed(struct seq_file *m, |
70 | struct task_struct *task); | 69 | struct task_struct *task); |
71 | 70 | ||
72 | extern void cpuset_lock(void); | ||
73 | extern void cpuset_unlock(void); | ||
74 | |||
75 | extern int cpuset_mem_spread_node(void); | 71 | extern int cpuset_mem_spread_node(void); |
76 | 72 | ||
77 | static inline int cpuset_do_page_mem_spread(void) | 73 | static inline int cpuset_do_page_mem_spread(void) |
@@ -105,10 +101,11 @@ static inline void cpuset_cpus_allowed(struct task_struct *p, | |||
105 | { | 101 | { |
106 | cpumask_copy(mask, cpu_possible_mask); | 102 | cpumask_copy(mask, cpu_possible_mask); |
107 | } | 103 | } |
108 | static inline void cpuset_cpus_allowed_locked(struct task_struct *p, | 104 | |
109 | struct cpumask *mask) | 105 | static inline int cpuset_cpus_allowed_fallback(struct task_struct *p) |
110 | { | 106 | { |
111 | cpumask_copy(mask, cpu_possible_mask); | 107 | cpumask_copy(&p->cpus_allowed, cpu_possible_mask); |
108 | return cpumask_any(cpu_active_mask); | ||
112 | } | 109 | } |
113 | 110 | ||
114 | static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) | 111 | static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) |
@@ -157,9 +154,6 @@ static inline void cpuset_task_status_allowed(struct seq_file *m, | |||
157 | { | 154 | { |
158 | } | 155 | } |
159 | 156 | ||
160 | static inline void cpuset_lock(void) {} | ||
161 | static inline void cpuset_unlock(void) {} | ||
162 | |||
163 | static inline int cpuset_mem_spread_node(void) | 157 | static inline int cpuset_mem_spread_node(void) |
164 | { | 158 | { |
165 | return 0; | 159 | return 0; |
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 30b93b2a01a4..eebb617c17d8 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -186,6 +186,8 @@ d_iput: no no no yes | |||
186 | 186 | ||
187 | #define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */ | 187 | #define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */ |
188 | 188 | ||
189 | #define DCACHE_CANT_MOUNT 0x0100 | ||
190 | |||
189 | extern spinlock_t dcache_lock; | 191 | extern spinlock_t dcache_lock; |
190 | extern seqlock_t rename_lock; | 192 | extern seqlock_t rename_lock; |
191 | 193 | ||
@@ -358,6 +360,18 @@ static inline int d_unlinked(struct dentry *dentry) | |||
358 | return d_unhashed(dentry) && !IS_ROOT(dentry); | 360 | return d_unhashed(dentry) && !IS_ROOT(dentry); |
359 | } | 361 | } |
360 | 362 | ||
363 | static inline int cant_mount(struct dentry *dentry) | ||
364 | { | ||
365 | return (dentry->d_flags & DCACHE_CANT_MOUNT); | ||
366 | } | ||
367 | |||
368 | static inline void dont_mount(struct dentry *dentry) | ||
369 | { | ||
370 | spin_lock(&dentry->d_lock); | ||
371 | dentry->d_flags |= DCACHE_CANT_MOUNT; | ||
372 | spin_unlock(&dentry->d_lock); | ||
373 | } | ||
374 | |||
361 | static inline struct dentry *dget_parent(struct dentry *dentry) | 375 | static inline struct dentry *dget_parent(struct dentry *dentry) |
362 | { | 376 | { |
363 | struct dentry *ret; | 377 | struct dentry *ret; |
diff --git a/include/linux/debugobjects.h b/include/linux/debugobjects.h index 8c243aaa86a7..597692f1fc8d 100644 --- a/include/linux/debugobjects.h +++ b/include/linux/debugobjects.h | |||
@@ -20,12 +20,14 @@ struct debug_obj_descr; | |||
20 | * struct debug_obj - representaion of an tracked object | 20 | * struct debug_obj - representaion of an tracked object |
21 | * @node: hlist node to link the object into the tracker list | 21 | * @node: hlist node to link the object into the tracker list |
22 | * @state: tracked object state | 22 | * @state: tracked object state |
23 | * @astate: current active state | ||
23 | * @object: pointer to the real object | 24 | * @object: pointer to the real object |
24 | * @descr: pointer to an object type specific debug description structure | 25 | * @descr: pointer to an object type specific debug description structure |
25 | */ | 26 | */ |
26 | struct debug_obj { | 27 | struct debug_obj { |
27 | struct hlist_node node; | 28 | struct hlist_node node; |
28 | enum debug_obj_state state; | 29 | enum debug_obj_state state; |
30 | unsigned int astate; | ||
29 | void *object; | 31 | void *object; |
30 | struct debug_obj_descr *descr; | 32 | struct debug_obj_descr *descr; |
31 | }; | 33 | }; |
@@ -60,6 +62,15 @@ extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr); | |||
60 | extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr); | 62 | extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr); |
61 | extern void debug_object_free (void *addr, struct debug_obj_descr *descr); | 63 | extern void debug_object_free (void *addr, struct debug_obj_descr *descr); |
62 | 64 | ||
65 | /* | ||
66 | * Active state: | ||
67 | * - Set at 0 upon initialization. | ||
68 | * - Must return to 0 before deactivation. | ||
69 | */ | ||
70 | extern void | ||
71 | debug_object_active_state(void *addr, struct debug_obj_descr *descr, | ||
72 | unsigned int expect, unsigned int next); | ||
73 | |||
63 | extern void debug_objects_early_init(void); | 74 | extern void debug_objects_early_init(void); |
64 | extern void debug_objects_mem_init(void); | 75 | extern void debug_objects_mem_init(void); |
65 | #else | 76 | #else |
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 01e6adea07ec..41e46330d9be 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h | |||
@@ -82,9 +82,13 @@ void clear_ftrace_function(void); | |||
82 | extern void ftrace_stub(unsigned long a0, unsigned long a1); | 82 | extern void ftrace_stub(unsigned long a0, unsigned long a1); |
83 | 83 | ||
84 | #else /* !CONFIG_FUNCTION_TRACER */ | 84 | #else /* !CONFIG_FUNCTION_TRACER */ |
85 | # define register_ftrace_function(ops) do { } while (0) | 85 | /* |
86 | # define unregister_ftrace_function(ops) do { } while (0) | 86 | * (un)register_ftrace_function must be a macro since the ops parameter |
87 | # define clear_ftrace_function(ops) do { } while (0) | 87 | * must not be evaluated. |
88 | */ | ||
89 | #define register_ftrace_function(ops) ({ 0; }) | ||
90 | #define unregister_ftrace_function(ops) ({ 0; }) | ||
91 | static inline void clear_ftrace_function(void) { } | ||
88 | static inline void ftrace_kill(void) { } | 92 | static inline void ftrace_kill(void) { } |
89 | static inline void ftrace_stop(void) { } | 93 | static inline void ftrace_stop(void) { } |
90 | static inline void ftrace_start(void) { } | 94 | static inline void ftrace_start(void) { } |
@@ -237,11 +241,13 @@ extern int skip_trace(unsigned long ip); | |||
237 | extern void ftrace_disable_daemon(void); | 241 | extern void ftrace_disable_daemon(void); |
238 | extern void ftrace_enable_daemon(void); | 242 | extern void ftrace_enable_daemon(void); |
239 | #else | 243 | #else |
240 | # define skip_trace(ip) ({ 0; }) | 244 | static inline int skip_trace(unsigned long ip) { return 0; } |
241 | # define ftrace_force_update() ({ 0; }) | 245 | static inline int ftrace_force_update(void) { return 0; } |
242 | # define ftrace_set_filter(buf, len, reset) do { } while (0) | 246 | static inline void ftrace_set_filter(unsigned char *buf, int len, int reset) |
243 | # define ftrace_disable_daemon() do { } while (0) | 247 | { |
244 | # define ftrace_enable_daemon() do { } while (0) | 248 | } |
249 | static inline void ftrace_disable_daemon(void) { } | ||
250 | static inline void ftrace_enable_daemon(void) { } | ||
245 | static inline void ftrace_release_mod(struct module *mod) {} | 251 | static inline void ftrace_release_mod(struct module *mod) {} |
246 | static inline int register_ftrace_command(struct ftrace_func_command *cmd) | 252 | static inline int register_ftrace_command(struct ftrace_func_command *cmd) |
247 | { | 253 | { |
@@ -314,16 +320,16 @@ static inline void __ftrace_enabled_restore(int enabled) | |||
314 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); | 320 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); |
315 | extern void time_hardirqs_off(unsigned long a0, unsigned long a1); | 321 | extern void time_hardirqs_off(unsigned long a0, unsigned long a1); |
316 | #else | 322 | #else |
317 | # define time_hardirqs_on(a0, a1) do { } while (0) | 323 | static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { } |
318 | # define time_hardirqs_off(a0, a1) do { } while (0) | 324 | static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { } |
319 | #endif | 325 | #endif |
320 | 326 | ||
321 | #ifdef CONFIG_PREEMPT_TRACER | 327 | #ifdef CONFIG_PREEMPT_TRACER |
322 | extern void trace_preempt_on(unsigned long a0, unsigned long a1); | 328 | extern void trace_preempt_on(unsigned long a0, unsigned long a1); |
323 | extern void trace_preempt_off(unsigned long a0, unsigned long a1); | 329 | extern void trace_preempt_off(unsigned long a0, unsigned long a1); |
324 | #else | 330 | #else |
325 | # define trace_preempt_on(a0, a1) do { } while (0) | 331 | static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { } |
326 | # define trace_preempt_off(a0, a1) do { } while (0) | 332 | static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { } |
327 | #endif | 333 | #endif |
328 | 334 | ||
329 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | 335 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
@@ -352,6 +358,10 @@ struct ftrace_graph_ret { | |||
352 | int depth; | 358 | int depth; |
353 | }; | 359 | }; |
354 | 360 | ||
361 | /* Type of the callback handlers for tracing function graph*/ | ||
362 | typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */ | ||
363 | typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */ | ||
364 | |||
355 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 365 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
356 | 366 | ||
357 | /* for init task */ | 367 | /* for init task */ |
@@ -400,10 +410,6 @@ extern char __irqentry_text_end[]; | |||
400 | 410 | ||
401 | #define FTRACE_RETFUNC_DEPTH 50 | 411 | #define FTRACE_RETFUNC_DEPTH 50 |
402 | #define FTRACE_RETSTACK_ALLOC_SIZE 32 | 412 | #define FTRACE_RETSTACK_ALLOC_SIZE 32 |
403 | /* Type of the callback handlers for tracing function graph*/ | ||
404 | typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */ | ||
405 | typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */ | ||
406 | |||
407 | extern int register_ftrace_graph(trace_func_graph_ret_t retfunc, | 413 | extern int register_ftrace_graph(trace_func_graph_ret_t retfunc, |
408 | trace_func_graph_ent_t entryfunc); | 414 | trace_func_graph_ent_t entryfunc); |
409 | 415 | ||
@@ -441,6 +447,13 @@ static inline void unpause_graph_tracing(void) | |||
441 | static inline void ftrace_graph_init_task(struct task_struct *t) { } | 447 | static inline void ftrace_graph_init_task(struct task_struct *t) { } |
442 | static inline void ftrace_graph_exit_task(struct task_struct *t) { } | 448 | static inline void ftrace_graph_exit_task(struct task_struct *t) { } |
443 | 449 | ||
450 | static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc, | ||
451 | trace_func_graph_ent_t entryfunc) | ||
452 | { | ||
453 | return -1; | ||
454 | } | ||
455 | static inline void unregister_ftrace_graph(void) { } | ||
456 | |||
444 | static inline int task_curr_ret_stack(struct task_struct *tsk) | 457 | static inline int task_curr_ret_stack(struct task_struct *tsk) |
445 | { | 458 | { |
446 | return -1; | 459 | return -1; |
@@ -492,7 +505,9 @@ static inline int test_tsk_trace_graph(struct task_struct *tsk) | |||
492 | return tsk->trace & TSK_TRACE_FL_GRAPH; | 505 | return tsk->trace & TSK_TRACE_FL_GRAPH; |
493 | } | 506 | } |
494 | 507 | ||
495 | extern int ftrace_dump_on_oops; | 508 | enum ftrace_dump_mode; |
509 | |||
510 | extern enum ftrace_dump_mode ftrace_dump_on_oops; | ||
496 | 511 | ||
497 | #ifdef CONFIG_PREEMPT | 512 | #ifdef CONFIG_PREEMPT |
498 | #define INIT_TRACE_RECURSION .trace_recursion = 0, | 513 | #define INIT_TRACE_RECURSION .trace_recursion = 0, |
@@ -504,18 +519,6 @@ extern int ftrace_dump_on_oops; | |||
504 | #define INIT_TRACE_RECURSION | 519 | #define INIT_TRACE_RECURSION |
505 | #endif | 520 | #endif |
506 | 521 | ||
507 | #ifdef CONFIG_HW_BRANCH_TRACER | ||
508 | |||
509 | void trace_hw_branch(u64 from, u64 to); | ||
510 | void trace_hw_branch_oops(void); | ||
511 | |||
512 | #else /* CONFIG_HW_BRANCH_TRACER */ | ||
513 | |||
514 | static inline void trace_hw_branch(u64 from, u64 to) {} | ||
515 | static inline void trace_hw_branch_oops(void) {} | ||
516 | |||
517 | #endif /* CONFIG_HW_BRANCH_TRACER */ | ||
518 | |||
519 | #ifdef CONFIG_FTRACE_SYSCALLS | 522 | #ifdef CONFIG_FTRACE_SYSCALLS |
520 | 523 | ||
521 | unsigned long arch_syscall_addr(int nr); | 524 | unsigned long arch_syscall_addr(int nr); |
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h index c0f4b364c711..39e71b0a3bfd 100644 --- a/include/linux/ftrace_event.h +++ b/include/linux/ftrace_event.h | |||
@@ -58,6 +58,7 @@ struct trace_iterator { | |||
58 | /* The below is zeroed out in pipe_read */ | 58 | /* The below is zeroed out in pipe_read */ |
59 | struct trace_seq seq; | 59 | struct trace_seq seq; |
60 | struct trace_entry *ent; | 60 | struct trace_entry *ent; |
61 | unsigned long lost_events; | ||
61 | int leftover; | 62 | int leftover; |
62 | int cpu; | 63 | int cpu; |
63 | u64 ts; | 64 | u64 ts; |
diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h index c70d27af03f9..a2d6ea49ec56 100644 --- a/include/linux/hw_breakpoint.h +++ b/include/linux/hw_breakpoint.h | |||
@@ -9,9 +9,22 @@ enum { | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | enum { | 11 | enum { |
12 | HW_BREAKPOINT_R = 1, | 12 | HW_BREAKPOINT_EMPTY = 0, |
13 | HW_BREAKPOINT_W = 2, | 13 | HW_BREAKPOINT_R = 1, |
14 | HW_BREAKPOINT_X = 4, | 14 | HW_BREAKPOINT_W = 2, |
15 | HW_BREAKPOINT_RW = HW_BREAKPOINT_R | HW_BREAKPOINT_W, | ||
16 | HW_BREAKPOINT_X = 4, | ||
17 | HW_BREAKPOINT_INVALID = HW_BREAKPOINT_RW | HW_BREAKPOINT_X, | ||
18 | }; | ||
19 | |||
20 | enum bp_type_idx { | ||
21 | TYPE_INST = 0, | ||
22 | #ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS | ||
23 | TYPE_DATA = 0, | ||
24 | #else | ||
25 | TYPE_DATA = 1, | ||
26 | #endif | ||
27 | TYPE_MAX | ||
15 | }; | 28 | }; |
16 | 29 | ||
17 | #ifdef __KERNEL__ | 30 | #ifdef __KERNEL__ |
@@ -34,6 +47,12 @@ static inline void hw_breakpoint_init(struct perf_event_attr *attr) | |||
34 | attr->sample_period = 1; | 47 | attr->sample_period = 1; |
35 | } | 48 | } |
36 | 49 | ||
50 | static inline void ptrace_breakpoint_init(struct perf_event_attr *attr) | ||
51 | { | ||
52 | hw_breakpoint_init(attr); | ||
53 | attr->exclude_kernel = 1; | ||
54 | } | ||
55 | |||
37 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) | 56 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) |
38 | { | 57 | { |
39 | return bp->attr.bp_addr; | 58 | return bp->attr.bp_addr; |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index b1ed1cd8e2a8..7996fc2c9ba9 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
@@ -49,7 +49,6 @@ extern struct group_info init_groups; | |||
49 | { .first = &init_task.pids[PIDTYPE_PGID].node }, \ | 49 | { .first = &init_task.pids[PIDTYPE_PGID].node }, \ |
50 | { .first = &init_task.pids[PIDTYPE_SID].node }, \ | 50 | { .first = &init_task.pids[PIDTYPE_SID].node }, \ |
51 | }, \ | 51 | }, \ |
52 | .rcu = RCU_HEAD_INIT, \ | ||
53 | .level = 0, \ | 52 | .level = 0, \ |
54 | .numbers = { { \ | 53 | .numbers = { { \ |
55 | .nr = 0, \ | 54 | .nr = 0, \ |
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 3af4ffd591b9..be22ad83689c 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h | |||
@@ -37,9 +37,9 @@ struct iommu_ops { | |||
37 | int (*attach_dev)(struct iommu_domain *domain, struct device *dev); | 37 | int (*attach_dev)(struct iommu_domain *domain, struct device *dev); |
38 | void (*detach_dev)(struct iommu_domain *domain, struct device *dev); | 38 | void (*detach_dev)(struct iommu_domain *domain, struct device *dev); |
39 | int (*map)(struct iommu_domain *domain, unsigned long iova, | 39 | int (*map)(struct iommu_domain *domain, unsigned long iova, |
40 | phys_addr_t paddr, size_t size, int prot); | 40 | phys_addr_t paddr, int gfp_order, int prot); |
41 | void (*unmap)(struct iommu_domain *domain, unsigned long iova, | 41 | int (*unmap)(struct iommu_domain *domain, unsigned long iova, |
42 | size_t size); | 42 | int gfp_order); |
43 | phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, | 43 | phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, |
44 | unsigned long iova); | 44 | unsigned long iova); |
45 | int (*domain_has_cap)(struct iommu_domain *domain, | 45 | int (*domain_has_cap)(struct iommu_domain *domain, |
@@ -56,10 +56,10 @@ extern int iommu_attach_device(struct iommu_domain *domain, | |||
56 | struct device *dev); | 56 | struct device *dev); |
57 | extern void iommu_detach_device(struct iommu_domain *domain, | 57 | extern void iommu_detach_device(struct iommu_domain *domain, |
58 | struct device *dev); | 58 | struct device *dev); |
59 | extern int iommu_map_range(struct iommu_domain *domain, unsigned long iova, | 59 | extern int iommu_map(struct iommu_domain *domain, unsigned long iova, |
60 | phys_addr_t paddr, size_t size, int prot); | 60 | phys_addr_t paddr, int gfp_order, int prot); |
61 | extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova, | 61 | extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
62 | size_t size); | 62 | int gfp_order); |
63 | extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, | 63 | extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
64 | unsigned long iova); | 64 | unsigned long iova); |
65 | extern int iommu_domain_has_cap(struct iommu_domain *domain, | 65 | extern int iommu_domain_has_cap(struct iommu_domain *domain, |
@@ -96,16 +96,16 @@ static inline void iommu_detach_device(struct iommu_domain *domain, | |||
96 | { | 96 | { |
97 | } | 97 | } |
98 | 98 | ||
99 | static inline int iommu_map_range(struct iommu_domain *domain, | 99 | static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, |
100 | unsigned long iova, phys_addr_t paddr, | 100 | phys_addr_t paddr, int gfp_order, int prot) |
101 | size_t size, int prot) | ||
102 | { | 101 | { |
103 | return -ENODEV; | 102 | return -ENODEV; |
104 | } | 103 | } |
105 | 104 | ||
106 | static inline void iommu_unmap_range(struct iommu_domain *domain, | 105 | static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova, |
107 | unsigned long iova, size_t size) | 106 | int gfp_order) |
108 | { | 107 | { |
108 | return -ENODEV; | ||
109 | } | 109 | } |
110 | 110 | ||
111 | static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, | 111 | static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index a38d6bd6fde6..fc33af911852 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -492,6 +492,13 @@ static inline void tracing_off(void) { } | |||
492 | static inline void tracing_off_permanent(void) { } | 492 | static inline void tracing_off_permanent(void) { } |
493 | static inline int tracing_is_on(void) { return 0; } | 493 | static inline int tracing_is_on(void) { return 0; } |
494 | #endif | 494 | #endif |
495 | |||
496 | enum ftrace_dump_mode { | ||
497 | DUMP_NONE, | ||
498 | DUMP_ALL, | ||
499 | DUMP_ORIG, | ||
500 | }; | ||
501 | |||
495 | #ifdef CONFIG_TRACING | 502 | #ifdef CONFIG_TRACING |
496 | extern void tracing_start(void); | 503 | extern void tracing_start(void); |
497 | extern void tracing_stop(void); | 504 | extern void tracing_stop(void); |
@@ -573,7 +580,7 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); | |||
573 | extern int | 580 | extern int |
574 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); | 581 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); |
575 | 582 | ||
576 | extern void ftrace_dump(void); | 583 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
577 | #else | 584 | #else |
578 | static inline void | 585 | static inline void |
579 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } | 586 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } |
@@ -594,7 +601,7 @@ ftrace_vprintk(const char *fmt, va_list ap) | |||
594 | { | 601 | { |
595 | return 0; | 602 | return 0; |
596 | } | 603 | } |
597 | static inline void ftrace_dump(void) { } | 604 | static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } |
598 | #endif /* CONFIG_TRACING */ | 605 | #endif /* CONFIG_TRACING */ |
599 | 606 | ||
600 | /* | 607 | /* |
diff --git a/include/linux/mm.h b/include/linux/mm.h index 462acaf36f3a..fb19bb92b809 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h | |||
@@ -19,7 +19,6 @@ struct anon_vma; | |||
19 | struct file_ra_state; | 19 | struct file_ra_state; |
20 | struct user_struct; | 20 | struct user_struct; |
21 | struct writeback_control; | 21 | struct writeback_control; |
22 | struct rlimit; | ||
23 | 22 | ||
24 | #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */ | 23 | #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */ |
25 | extern unsigned long max_mapnr; | 24 | extern unsigned long max_mapnr; |
@@ -1449,9 +1448,6 @@ int vmemmap_populate_basepages(struct page *start_page, | |||
1449 | int vmemmap_populate(struct page *start_page, unsigned long pages, int node); | 1448 | int vmemmap_populate(struct page *start_page, unsigned long pages, int node); |
1450 | void vmemmap_populate_print_last(void); | 1449 | void vmemmap_populate_print_last(void); |
1451 | 1450 | ||
1452 | extern int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim, | ||
1453 | size_t size); | ||
1454 | extern void refund_locked_memory(struct mm_struct *mm, size_t size); | ||
1455 | 1451 | ||
1456 | enum mf_flags { | 1452 | enum mf_flags { |
1457 | MF_COUNT_INCREASED = 1 << 0, | 1453 | MF_COUNT_INCREASED = 1 << 0, |
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 55f1f9c9506c..007fbaafead0 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h | |||
@@ -500,4 +500,13 @@ struct mdio_device_id { | |||
500 | __u32 phy_id_mask; | 500 | __u32 phy_id_mask; |
501 | }; | 501 | }; |
502 | 502 | ||
503 | struct zorro_device_id { | ||
504 | __u32 id; /* Device ID or ZORRO_WILDCARD */ | ||
505 | kernel_ulong_t driver_data; /* Data private to the driver */ | ||
506 | }; | ||
507 | |||
508 | #define ZORRO_WILDCARD (0xffffffff) /* not official */ | ||
509 | |||
510 | #define ZORRO_DEVICE_MODALIAS_FMT "zorro:i%08X" | ||
511 | |||
503 | #endif /* LINUX_MOD_DEVICETABLE_H */ | 512 | #endif /* LINUX_MOD_DEVICETABLE_H */ |
diff --git a/include/linux/module.h b/include/linux/module.h index 515d53ae6a79..6914fcad4673 100644 --- a/include/linux/module.h +++ b/include/linux/module.h | |||
@@ -465,8 +465,7 @@ static inline void __module_get(struct module *module) | |||
465 | if (module) { | 465 | if (module) { |
466 | preempt_disable(); | 466 | preempt_disable(); |
467 | __this_cpu_inc(module->refptr->incs); | 467 | __this_cpu_inc(module->refptr->incs); |
468 | trace_module_get(module, _THIS_IP_, | 468 | trace_module_get(module, _THIS_IP_); |
469 | __this_cpu_read(module->refptr->incs)); | ||
470 | preempt_enable(); | 469 | preempt_enable(); |
471 | } | 470 | } |
472 | } | 471 | } |
@@ -480,8 +479,7 @@ static inline int try_module_get(struct module *module) | |||
480 | 479 | ||
481 | if (likely(module_is_live(module))) { | 480 | if (likely(module_is_live(module))) { |
482 | __this_cpu_inc(module->refptr->incs); | 481 | __this_cpu_inc(module->refptr->incs); |
483 | trace_module_get(module, _THIS_IP_, | 482 | trace_module_get(module, _THIS_IP_); |
484 | __this_cpu_read(module->refptr->incs)); | ||
485 | } else | 483 | } else |
486 | ret = 0; | 484 | ret = 0; |
487 | 485 | ||
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index c8e375440403..3fd5c82e0e18 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -203,8 +203,19 @@ struct perf_event_attr { | |||
203 | enable_on_exec : 1, /* next exec enables */ | 203 | enable_on_exec : 1, /* next exec enables */ |
204 | task : 1, /* trace fork/exit */ | 204 | task : 1, /* trace fork/exit */ |
205 | watermark : 1, /* wakeup_watermark */ | 205 | watermark : 1, /* wakeup_watermark */ |
206 | 206 | /* | |
207 | __reserved_1 : 49; | 207 | * precise_ip: |
208 | * | ||
209 | * 0 - SAMPLE_IP can have arbitrary skid | ||
210 | * 1 - SAMPLE_IP must have constant skid | ||
211 | * 2 - SAMPLE_IP requested to have 0 skid | ||
212 | * 3 - SAMPLE_IP must have 0 skid | ||
213 | * | ||
214 | * See also PERF_RECORD_MISC_EXACT_IP | ||
215 | */ | ||
216 | precise_ip : 2, /* skid constraint */ | ||
217 | |||
218 | __reserved_1 : 47; | ||
208 | 219 | ||
209 | union { | 220 | union { |
210 | __u32 wakeup_events; /* wakeup every n events */ | 221 | __u32 wakeup_events; /* wakeup every n events */ |
@@ -287,11 +298,24 @@ struct perf_event_mmap_page { | |||
287 | __u64 data_tail; /* user-space written tail */ | 298 | __u64 data_tail; /* user-space written tail */ |
288 | }; | 299 | }; |
289 | 300 | ||
290 | #define PERF_RECORD_MISC_CPUMODE_MASK (3 << 0) | 301 | #define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0) |
291 | #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0) | 302 | #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0) |
292 | #define PERF_RECORD_MISC_KERNEL (1 << 0) | 303 | #define PERF_RECORD_MISC_KERNEL (1 << 0) |
293 | #define PERF_RECORD_MISC_USER (2 << 0) | 304 | #define PERF_RECORD_MISC_USER (2 << 0) |
294 | #define PERF_RECORD_MISC_HYPERVISOR (3 << 0) | 305 | #define PERF_RECORD_MISC_HYPERVISOR (3 << 0) |
306 | #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0) | ||
307 | #define PERF_RECORD_MISC_GUEST_USER (5 << 0) | ||
308 | |||
309 | /* | ||
310 | * Indicates that the content of PERF_SAMPLE_IP points to | ||
311 | * the actual instruction that triggered the event. See also | ||
312 | * perf_event_attr::precise_ip. | ||
313 | */ | ||
314 | #define PERF_RECORD_MISC_EXACT_IP (1 << 14) | ||
315 | /* | ||
316 | * Reserve the last bit to indicate some extended misc field | ||
317 | */ | ||
318 | #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15) | ||
295 | 319 | ||
296 | struct perf_event_header { | 320 | struct perf_event_header { |
297 | __u32 type; | 321 | __u32 type; |
@@ -439,6 +463,12 @@ enum perf_callchain_context { | |||
439 | # include <asm/perf_event.h> | 463 | # include <asm/perf_event.h> |
440 | #endif | 464 | #endif |
441 | 465 | ||
466 | struct perf_guest_info_callbacks { | ||
467 | int (*is_in_guest) (void); | ||
468 | int (*is_user_mode) (void); | ||
469 | unsigned long (*get_guest_ip) (void); | ||
470 | }; | ||
471 | |||
442 | #ifdef CONFIG_HAVE_HW_BREAKPOINT | 472 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
443 | #include <asm/hw_breakpoint.h> | 473 | #include <asm/hw_breakpoint.h> |
444 | #endif | 474 | #endif |
@@ -468,6 +498,17 @@ struct perf_raw_record { | |||
468 | void *data; | 498 | void *data; |
469 | }; | 499 | }; |
470 | 500 | ||
501 | struct perf_branch_entry { | ||
502 | __u64 from; | ||
503 | __u64 to; | ||
504 | __u64 flags; | ||
505 | }; | ||
506 | |||
507 | struct perf_branch_stack { | ||
508 | __u64 nr; | ||
509 | struct perf_branch_entry entries[0]; | ||
510 | }; | ||
511 | |||
471 | struct task_struct; | 512 | struct task_struct; |
472 | 513 | ||
473 | /** | 514 | /** |
@@ -506,6 +547,8 @@ struct hw_perf_event { | |||
506 | 547 | ||
507 | struct perf_event; | 548 | struct perf_event; |
508 | 549 | ||
550 | #define PERF_EVENT_TXN_STARTED 1 | ||
551 | |||
509 | /** | 552 | /** |
510 | * struct pmu - generic performance monitoring unit | 553 | * struct pmu - generic performance monitoring unit |
511 | */ | 554 | */ |
@@ -516,6 +559,16 @@ struct pmu { | |||
516 | void (*stop) (struct perf_event *event); | 559 | void (*stop) (struct perf_event *event); |
517 | void (*read) (struct perf_event *event); | 560 | void (*read) (struct perf_event *event); |
518 | void (*unthrottle) (struct perf_event *event); | 561 | void (*unthrottle) (struct perf_event *event); |
562 | |||
563 | /* | ||
564 | * group events scheduling is treated as a transaction, | ||
565 | * add group events as a whole and perform one schedulability test. | ||
566 | * If test fails, roll back the whole group | ||
567 | */ | ||
568 | |||
569 | void (*start_txn) (const struct pmu *pmu); | ||
570 | void (*cancel_txn) (const struct pmu *pmu); | ||
571 | int (*commit_txn) (const struct pmu *pmu); | ||
519 | }; | 572 | }; |
520 | 573 | ||
521 | /** | 574 | /** |
@@ -571,6 +624,14 @@ enum perf_group_flag { | |||
571 | PERF_GROUP_SOFTWARE = 0x1, | 624 | PERF_GROUP_SOFTWARE = 0x1, |
572 | }; | 625 | }; |
573 | 626 | ||
627 | #define SWEVENT_HLIST_BITS 8 | ||
628 | #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS) | ||
629 | |||
630 | struct swevent_hlist { | ||
631 | struct hlist_head heads[SWEVENT_HLIST_SIZE]; | ||
632 | struct rcu_head rcu_head; | ||
633 | }; | ||
634 | |||
574 | /** | 635 | /** |
575 | * struct perf_event - performance event kernel representation: | 636 | * struct perf_event - performance event kernel representation: |
576 | */ | 637 | */ |
@@ -579,6 +640,7 @@ struct perf_event { | |||
579 | struct list_head group_entry; | 640 | struct list_head group_entry; |
580 | struct list_head event_entry; | 641 | struct list_head event_entry; |
581 | struct list_head sibling_list; | 642 | struct list_head sibling_list; |
643 | struct hlist_node hlist_entry; | ||
582 | int nr_siblings; | 644 | int nr_siblings; |
583 | int group_flags; | 645 | int group_flags; |
584 | struct perf_event *group_leader; | 646 | struct perf_event *group_leader; |
@@ -726,6 +788,9 @@ struct perf_cpu_context { | |||
726 | int active_oncpu; | 788 | int active_oncpu; |
727 | int max_pertask; | 789 | int max_pertask; |
728 | int exclusive; | 790 | int exclusive; |
791 | struct swevent_hlist *swevent_hlist; | ||
792 | struct mutex hlist_mutex; | ||
793 | int hlist_refcount; | ||
729 | 794 | ||
730 | /* | 795 | /* |
731 | * Recursion avoidance: | 796 | * Recursion avoidance: |
@@ -769,9 +834,6 @@ extern void perf_disable(void); | |||
769 | extern void perf_enable(void); | 834 | extern void perf_enable(void); |
770 | extern int perf_event_task_disable(void); | 835 | extern int perf_event_task_disable(void); |
771 | extern int perf_event_task_enable(void); | 836 | extern int perf_event_task_enable(void); |
772 | extern int hw_perf_group_sched_in(struct perf_event *group_leader, | ||
773 | struct perf_cpu_context *cpuctx, | ||
774 | struct perf_event_context *ctx); | ||
775 | extern void perf_event_update_userpage(struct perf_event *event); | 837 | extern void perf_event_update_userpage(struct perf_event *event); |
776 | extern int perf_event_release_kernel(struct perf_event *event); | 838 | extern int perf_event_release_kernel(struct perf_event *event); |
777 | extern struct perf_event * | 839 | extern struct perf_event * |
@@ -902,6 +964,10 @@ static inline void perf_event_mmap(struct vm_area_struct *vma) | |||
902 | __perf_event_mmap(vma); | 964 | __perf_event_mmap(vma); |
903 | } | 965 | } |
904 | 966 | ||
967 | extern struct perf_guest_info_callbacks *perf_guest_cbs; | ||
968 | extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); | ||
969 | extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); | ||
970 | |||
905 | extern void perf_event_comm(struct task_struct *tsk); | 971 | extern void perf_event_comm(struct task_struct *tsk); |
906 | extern void perf_event_fork(struct task_struct *tsk); | 972 | extern void perf_event_fork(struct task_struct *tsk); |
907 | 973 | ||
@@ -971,6 +1037,11 @@ perf_sw_event(u32 event_id, u64 nr, int nmi, | |||
971 | static inline void | 1037 | static inline void |
972 | perf_bp_event(struct perf_event *event, void *data) { } | 1038 | perf_bp_event(struct perf_event *event, void *data) { } |
973 | 1039 | ||
1040 | static inline int perf_register_guest_info_callbacks | ||
1041 | (struct perf_guest_info_callbacks *callbacks) { return 0; } | ||
1042 | static inline int perf_unregister_guest_info_callbacks | ||
1043 | (struct perf_guest_info_callbacks *callbacks) { return 0; } | ||
1044 | |||
974 | static inline void perf_event_mmap(struct vm_area_struct *vma) { } | 1045 | static inline void perf_event_mmap(struct vm_area_struct *vma) { } |
975 | static inline void perf_event_comm(struct task_struct *tsk) { } | 1046 | static inline void perf_event_comm(struct task_struct *tsk) { } |
976 | static inline void perf_event_fork(struct task_struct *tsk) { } | 1047 | static inline void perf_event_fork(struct task_struct *tsk) { } |
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 212da17d06af..5417944d3687 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h | |||
@@ -44,12 +44,14 @@ extern int platform_get_irq_byname(struct platform_device *, const char *); | |||
44 | extern int platform_add_devices(struct platform_device **, int); | 44 | extern int platform_add_devices(struct platform_device **, int); |
45 | 45 | ||
46 | extern struct platform_device *platform_device_register_simple(const char *, int id, | 46 | extern struct platform_device *platform_device_register_simple(const char *, int id, |
47 | struct resource *, unsigned int); | 47 | const struct resource *, unsigned int); |
48 | extern struct platform_device *platform_device_register_data(struct device *, | 48 | extern struct platform_device *platform_device_register_data(struct device *, |
49 | const char *, int, const void *, size_t); | 49 | const char *, int, const void *, size_t); |
50 | 50 | ||
51 | extern struct platform_device *platform_device_alloc(const char *name, int id); | 51 | extern struct platform_device *platform_device_alloc(const char *name, int id); |
52 | extern int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num); | 52 | extern int platform_device_add_resources(struct platform_device *pdev, |
53 | const struct resource *res, | ||
54 | unsigned int num); | ||
53 | extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size); | 55 | extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size); |
54 | extern int platform_device_add(struct platform_device *pdev); | 56 | extern int platform_device_add(struct platform_device *pdev); |
55 | extern void platform_device_del(struct platform_device *pdev); | 57 | extern void platform_device_del(struct platform_device *pdev); |
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index e1fb60729979..4272521e29e9 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -345,18 +345,6 @@ static inline void user_single_step_siginfo(struct task_struct *tsk, | |||
345 | #define arch_ptrace_stop(code, info) do { } while (0) | 345 | #define arch_ptrace_stop(code, info) do { } while (0) |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | #ifndef arch_ptrace_untrace | ||
349 | /* | ||
350 | * Do machine-specific work before untracing child. | ||
351 | * | ||
352 | * This is called for a normal detach as well as from ptrace_exit() | ||
353 | * when the tracing task dies. | ||
354 | * | ||
355 | * Called with write_lock(&tasklist_lock) held. | ||
356 | */ | ||
357 | #define arch_ptrace_untrace(task) do { } while (0) | ||
358 | #endif | ||
359 | |||
360 | extern int task_current_syscall(struct task_struct *target, long *callno, | 348 | extern int task_current_syscall(struct task_struct *target, long *callno, |
361 | unsigned long args[6], unsigned int maxargs, | 349 | unsigned long args[6], unsigned int maxargs, |
362 | unsigned long *sp, unsigned long *pc); | 350 | unsigned long *sp, unsigned long *pc); |
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h index 5210a5c60877..fe1872e5b37e 100644 --- a/include/linux/rbtree.h +++ b/include/linux/rbtree.h | |||
@@ -110,6 +110,7 @@ struct rb_node | |||
110 | struct rb_root | 110 | struct rb_root |
111 | { | 111 | { |
112 | struct rb_node *rb_node; | 112 | struct rb_node *rb_node; |
113 | void (*augment_cb)(struct rb_node *node); | ||
113 | }; | 114 | }; |
114 | 115 | ||
115 | 116 | ||
@@ -129,7 +130,9 @@ static inline void rb_set_color(struct rb_node *rb, int color) | |||
129 | rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; | 130 | rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; |
130 | } | 131 | } |
131 | 132 | ||
132 | #define RB_ROOT (struct rb_root) { NULL, } | 133 | #define RB_ROOT (struct rb_root) { NULL, NULL, } |
134 | #define RB_AUGMENT_ROOT(x) (struct rb_root) { NULL, x} | ||
135 | |||
133 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | 136 | #define rb_entry(ptr, type, member) container_of(ptr, type, member) |
134 | 137 | ||
135 | #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) | 138 | #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) |
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index db266bbed23f..b653b4aaa8a6 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h | |||
@@ -56,8 +56,6 @@ struct rcu_head { | |||
56 | }; | 56 | }; |
57 | 57 | ||
58 | /* Exported common interfaces */ | 58 | /* Exported common interfaces */ |
59 | extern void synchronize_rcu_bh(void); | ||
60 | extern void synchronize_sched(void); | ||
61 | extern void rcu_barrier(void); | 59 | extern void rcu_barrier(void); |
62 | extern void rcu_barrier_bh(void); | 60 | extern void rcu_barrier_bh(void); |
63 | extern void rcu_barrier_sched(void); | 61 | extern void rcu_barrier_sched(void); |
@@ -66,8 +64,6 @@ extern int sched_expedited_torture_stats(char *page); | |||
66 | 64 | ||
67 | /* Internal to kernel */ | 65 | /* Internal to kernel */ |
68 | extern void rcu_init(void); | 66 | extern void rcu_init(void); |
69 | extern int rcu_scheduler_active; | ||
70 | extern void rcu_scheduler_starting(void); | ||
71 | 67 | ||
72 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) | 68 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) |
73 | #include <linux/rcutree.h> | 69 | #include <linux/rcutree.h> |
@@ -83,6 +79,14 @@ extern void rcu_scheduler_starting(void); | |||
83 | (ptr)->next = NULL; (ptr)->func = NULL; \ | 79 | (ptr)->next = NULL; (ptr)->func = NULL; \ |
84 | } while (0) | 80 | } while (0) |
85 | 81 | ||
82 | static inline void init_rcu_head_on_stack(struct rcu_head *head) | ||
83 | { | ||
84 | } | ||
85 | |||
86 | static inline void destroy_rcu_head_on_stack(struct rcu_head *head) | ||
87 | { | ||
88 | } | ||
89 | |||
86 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 90 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
87 | 91 | ||
88 | extern struct lockdep_map rcu_lock_map; | 92 | extern struct lockdep_map rcu_lock_map; |
@@ -106,12 +110,13 @@ extern int debug_lockdep_rcu_enabled(void); | |||
106 | /** | 110 | /** |
107 | * rcu_read_lock_held - might we be in RCU read-side critical section? | 111 | * rcu_read_lock_held - might we be in RCU read-side critical section? |
108 | * | 112 | * |
109 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in | 113 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU |
110 | * an RCU read-side critical section. In absence of CONFIG_PROVE_LOCKING, | 114 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, |
111 | * this assumes we are in an RCU read-side critical section unless it can | 115 | * this assumes we are in an RCU read-side critical section unless it can |
112 | * prove otherwise. | 116 | * prove otherwise. |
113 | * | 117 | * |
114 | * Check rcu_scheduler_active to prevent false positives during boot. | 118 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot |
119 | * and while lockdep is disabled. | ||
115 | */ | 120 | */ |
116 | static inline int rcu_read_lock_held(void) | 121 | static inline int rcu_read_lock_held(void) |
117 | { | 122 | { |
@@ -129,13 +134,15 @@ extern int rcu_read_lock_bh_held(void); | |||
129 | /** | 134 | /** |
130 | * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section? | 135 | * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section? |
131 | * | 136 | * |
132 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in an | 137 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an |
133 | * RCU-sched read-side critical section. In absence of CONFIG_PROVE_LOCKING, | 138 | * RCU-sched read-side critical section. In absence of |
134 | * this assumes we are in an RCU-sched read-side critical section unless it | 139 | * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side |
135 | * can prove otherwise. Note that disabling of preemption (including | 140 | * critical section unless it can prove otherwise. Note that disabling |
136 | * disabling irqs) counts as an RCU-sched read-side critical section. | 141 | * of preemption (including disabling irqs) counts as an RCU-sched |
142 | * read-side critical section. | ||
137 | * | 143 | * |
138 | * Check rcu_scheduler_active to prevent false positives during boot. | 144 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot |
145 | * and while lockdep is disabled. | ||
139 | */ | 146 | */ |
140 | #ifdef CONFIG_PREEMPT | 147 | #ifdef CONFIG_PREEMPT |
141 | static inline int rcu_read_lock_sched_held(void) | 148 | static inline int rcu_read_lock_sched_held(void) |
@@ -177,7 +184,7 @@ static inline int rcu_read_lock_bh_held(void) | |||
177 | #ifdef CONFIG_PREEMPT | 184 | #ifdef CONFIG_PREEMPT |
178 | static inline int rcu_read_lock_sched_held(void) | 185 | static inline int rcu_read_lock_sched_held(void) |
179 | { | 186 | { |
180 | return !rcu_scheduler_active || preempt_count() != 0 || irqs_disabled(); | 187 | return preempt_count() != 0 || irqs_disabled(); |
181 | } | 188 | } |
182 | #else /* #ifdef CONFIG_PREEMPT */ | 189 | #else /* #ifdef CONFIG_PREEMPT */ |
183 | static inline int rcu_read_lock_sched_held(void) | 190 | static inline int rcu_read_lock_sched_held(void) |
@@ -192,6 +199,15 @@ static inline int rcu_read_lock_sched_held(void) | |||
192 | 199 | ||
193 | extern int rcu_my_thread_group_empty(void); | 200 | extern int rcu_my_thread_group_empty(void); |
194 | 201 | ||
202 | #define __do_rcu_dereference_check(c) \ | ||
203 | do { \ | ||
204 | static bool __warned; \ | ||
205 | if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \ | ||
206 | __warned = true; \ | ||
207 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | ||
208 | } \ | ||
209 | } while (0) | ||
210 | |||
195 | /** | 211 | /** |
196 | * rcu_dereference_check - rcu_dereference with debug checking | 212 | * rcu_dereference_check - rcu_dereference with debug checking |
197 | * @p: The pointer to read, prior to dereferencing | 213 | * @p: The pointer to read, prior to dereferencing |
@@ -221,8 +237,7 @@ extern int rcu_my_thread_group_empty(void); | |||
221 | */ | 237 | */ |
222 | #define rcu_dereference_check(p, c) \ | 238 | #define rcu_dereference_check(p, c) \ |
223 | ({ \ | 239 | ({ \ |
224 | if (debug_lockdep_rcu_enabled() && !(c)) \ | 240 | __do_rcu_dereference_check(c); \ |
225 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | ||
226 | rcu_dereference_raw(p); \ | 241 | rcu_dereference_raw(p); \ |
227 | }) | 242 | }) |
228 | 243 | ||
@@ -239,8 +254,7 @@ extern int rcu_my_thread_group_empty(void); | |||
239 | */ | 254 | */ |
240 | #define rcu_dereference_protected(p, c) \ | 255 | #define rcu_dereference_protected(p, c) \ |
241 | ({ \ | 256 | ({ \ |
242 | if (debug_lockdep_rcu_enabled() && !(c)) \ | 257 | __do_rcu_dereference_check(c); \ |
243 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | ||
244 | (p); \ | 258 | (p); \ |
245 | }) | 259 | }) |
246 | 260 | ||
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h index a5195875480a..e2e893144a84 100644 --- a/include/linux/rcutiny.h +++ b/include/linux/rcutiny.h | |||
@@ -29,6 +29,10 @@ | |||
29 | 29 | ||
30 | void rcu_sched_qs(int cpu); | 30 | void rcu_sched_qs(int cpu); |
31 | void rcu_bh_qs(int cpu); | 31 | void rcu_bh_qs(int cpu); |
32 | static inline void rcu_note_context_switch(int cpu) | ||
33 | { | ||
34 | rcu_sched_qs(cpu); | ||
35 | } | ||
32 | 36 | ||
33 | #define __rcu_read_lock() preempt_disable() | 37 | #define __rcu_read_lock() preempt_disable() |
34 | #define __rcu_read_unlock() preempt_enable() | 38 | #define __rcu_read_unlock() preempt_enable() |
@@ -60,8 +64,6 @@ static inline long rcu_batches_completed_bh(void) | |||
60 | return 0; | 64 | return 0; |
61 | } | 65 | } |
62 | 66 | ||
63 | extern int rcu_expedited_torture_stats(char *page); | ||
64 | |||
65 | static inline void rcu_force_quiescent_state(void) | 67 | static inline void rcu_force_quiescent_state(void) |
66 | { | 68 | { |
67 | } | 69 | } |
@@ -74,7 +76,17 @@ static inline void rcu_sched_force_quiescent_state(void) | |||
74 | { | 76 | { |
75 | } | 77 | } |
76 | 78 | ||
77 | #define synchronize_rcu synchronize_sched | 79 | extern void synchronize_sched(void); |
80 | |||
81 | static inline void synchronize_rcu(void) | ||
82 | { | ||
83 | synchronize_sched(); | ||
84 | } | ||
85 | |||
86 | static inline void synchronize_rcu_bh(void) | ||
87 | { | ||
88 | synchronize_sched(); | ||
89 | } | ||
78 | 90 | ||
79 | static inline void synchronize_rcu_expedited(void) | 91 | static inline void synchronize_rcu_expedited(void) |
80 | { | 92 | { |
@@ -114,4 +126,17 @@ static inline int rcu_preempt_depth(void) | |||
114 | return 0; | 126 | return 0; |
115 | } | 127 | } |
116 | 128 | ||
129 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
130 | |||
131 | extern int rcu_scheduler_active __read_mostly; | ||
132 | extern void rcu_scheduler_starting(void); | ||
133 | |||
134 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
135 | |||
136 | static inline void rcu_scheduler_starting(void) | ||
137 | { | ||
138 | } | ||
139 | |||
140 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
141 | |||
117 | #endif /* __LINUX_RCUTINY_H */ | 142 | #endif /* __LINUX_RCUTINY_H */ |
diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h index 42cc3a04779e..c0ed1c056f29 100644 --- a/include/linux/rcutree.h +++ b/include/linux/rcutree.h | |||
@@ -34,8 +34,8 @@ struct notifier_block; | |||
34 | 34 | ||
35 | extern void rcu_sched_qs(int cpu); | 35 | extern void rcu_sched_qs(int cpu); |
36 | extern void rcu_bh_qs(int cpu); | 36 | extern void rcu_bh_qs(int cpu); |
37 | extern void rcu_note_context_switch(int cpu); | ||
37 | extern int rcu_needs_cpu(int cpu); | 38 | extern int rcu_needs_cpu(int cpu); |
38 | extern int rcu_expedited_torture_stats(char *page); | ||
39 | 39 | ||
40 | #ifdef CONFIG_TREE_PREEMPT_RCU | 40 | #ifdef CONFIG_TREE_PREEMPT_RCU |
41 | 41 | ||
@@ -86,6 +86,8 @@ static inline void __rcu_read_unlock_bh(void) | |||
86 | 86 | ||
87 | extern void call_rcu_sched(struct rcu_head *head, | 87 | extern void call_rcu_sched(struct rcu_head *head, |
88 | void (*func)(struct rcu_head *rcu)); | 88 | void (*func)(struct rcu_head *rcu)); |
89 | extern void synchronize_rcu_bh(void); | ||
90 | extern void synchronize_sched(void); | ||
89 | extern void synchronize_rcu_expedited(void); | 91 | extern void synchronize_rcu_expedited(void); |
90 | 92 | ||
91 | static inline void synchronize_rcu_bh_expedited(void) | 93 | static inline void synchronize_rcu_bh_expedited(void) |
@@ -120,4 +122,7 @@ static inline int rcu_blocking_is_gp(void) | |||
120 | return num_online_cpus() == 1; | 122 | return num_online_cpus() == 1; |
121 | } | 123 | } |
122 | 124 | ||
125 | extern void rcu_scheduler_starting(void); | ||
126 | extern int rcu_scheduler_active __read_mostly; | ||
127 | |||
123 | #endif /* __LINUX_RCUTREE_H */ | 128 | #endif /* __LINUX_RCUTREE_H */ |
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h index 5fcc31ed5771..25b4f686d918 100644 --- a/include/linux/ring_buffer.h +++ b/include/linux/ring_buffer.h | |||
@@ -120,12 +120,16 @@ int ring_buffer_write(struct ring_buffer *buffer, | |||
120 | unsigned long length, void *data); | 120 | unsigned long length, void *data); |
121 | 121 | ||
122 | struct ring_buffer_event * | 122 | struct ring_buffer_event * |
123 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts); | 123 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts, |
124 | unsigned long *lost_events); | ||
124 | struct ring_buffer_event * | 125 | struct ring_buffer_event * |
125 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts); | 126 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts, |
127 | unsigned long *lost_events); | ||
126 | 128 | ||
127 | struct ring_buffer_iter * | 129 | struct ring_buffer_iter * |
128 | ring_buffer_read_start(struct ring_buffer *buffer, int cpu); | 130 | ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu); |
131 | void ring_buffer_read_prepare_sync(void); | ||
132 | void ring_buffer_read_start(struct ring_buffer_iter *iter); | ||
129 | void ring_buffer_read_finish(struct ring_buffer_iter *iter); | 133 | void ring_buffer_read_finish(struct ring_buffer_iter *iter); |
130 | 134 | ||
131 | struct ring_buffer_event * | 135 | struct ring_buffer_event * |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 2b7b81df78b3..b55e988988b5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -99,7 +99,6 @@ struct futex_pi_state; | |||
99 | struct robust_list_head; | 99 | struct robust_list_head; |
100 | struct bio_list; | 100 | struct bio_list; |
101 | struct fs_struct; | 101 | struct fs_struct; |
102 | struct bts_context; | ||
103 | struct perf_event_context; | 102 | struct perf_event_context; |
104 | 103 | ||
105 | /* | 104 | /* |
@@ -275,11 +274,17 @@ extern cpumask_var_t nohz_cpu_mask; | |||
275 | #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) | 274 | #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) |
276 | extern int select_nohz_load_balancer(int cpu); | 275 | extern int select_nohz_load_balancer(int cpu); |
277 | extern int get_nohz_load_balancer(void); | 276 | extern int get_nohz_load_balancer(void); |
277 | extern int nohz_ratelimit(int cpu); | ||
278 | #else | 278 | #else |
279 | static inline int select_nohz_load_balancer(int cpu) | 279 | static inline int select_nohz_load_balancer(int cpu) |
280 | { | 280 | { |
281 | return 0; | 281 | return 0; |
282 | } | 282 | } |
283 | |||
284 | static inline int nohz_ratelimit(int cpu) | ||
285 | { | ||
286 | return 0; | ||
287 | } | ||
283 | #endif | 288 | #endif |
284 | 289 | ||
285 | /* | 290 | /* |
@@ -954,6 +959,7 @@ struct sched_domain { | |||
954 | char *name; | 959 | char *name; |
955 | #endif | 960 | #endif |
956 | 961 | ||
962 | unsigned int span_weight; | ||
957 | /* | 963 | /* |
958 | * Span of all CPUs in this domain. | 964 | * Span of all CPUs in this domain. |
959 | * | 965 | * |
@@ -1026,12 +1032,17 @@ struct sched_domain; | |||
1026 | #define WF_SYNC 0x01 /* waker goes to sleep after wakup */ | 1032 | #define WF_SYNC 0x01 /* waker goes to sleep after wakup */ |
1027 | #define WF_FORK 0x02 /* child wakeup after fork */ | 1033 | #define WF_FORK 0x02 /* child wakeup after fork */ |
1028 | 1034 | ||
1035 | #define ENQUEUE_WAKEUP 1 | ||
1036 | #define ENQUEUE_WAKING 2 | ||
1037 | #define ENQUEUE_HEAD 4 | ||
1038 | |||
1039 | #define DEQUEUE_SLEEP 1 | ||
1040 | |||
1029 | struct sched_class { | 1041 | struct sched_class { |
1030 | const struct sched_class *next; | 1042 | const struct sched_class *next; |
1031 | 1043 | ||
1032 | void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup, | 1044 | void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags); |
1033 | bool head); | 1045 | void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags); |
1034 | void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep); | ||
1035 | void (*yield_task) (struct rq *rq); | 1046 | void (*yield_task) (struct rq *rq); |
1036 | 1047 | ||
1037 | void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); | 1048 | void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags); |
@@ -1040,7 +1051,8 @@ struct sched_class { | |||
1040 | void (*put_prev_task) (struct rq *rq, struct task_struct *p); | 1051 | void (*put_prev_task) (struct rq *rq, struct task_struct *p); |
1041 | 1052 | ||
1042 | #ifdef CONFIG_SMP | 1053 | #ifdef CONFIG_SMP |
1043 | int (*select_task_rq)(struct task_struct *p, int sd_flag, int flags); | 1054 | int (*select_task_rq)(struct rq *rq, struct task_struct *p, |
1055 | int sd_flag, int flags); | ||
1044 | 1056 | ||
1045 | void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); | 1057 | void (*pre_schedule) (struct rq *this_rq, struct task_struct *task); |
1046 | void (*post_schedule) (struct rq *this_rq); | 1058 | void (*post_schedule) (struct rq *this_rq); |
@@ -1077,36 +1089,8 @@ struct load_weight { | |||
1077 | unsigned long weight, inv_weight; | 1089 | unsigned long weight, inv_weight; |
1078 | }; | 1090 | }; |
1079 | 1091 | ||
1080 | /* | ||
1081 | * CFS stats for a schedulable entity (task, task-group etc) | ||
1082 | * | ||
1083 | * Current field usage histogram: | ||
1084 | * | ||
1085 | * 4 se->block_start | ||
1086 | * 4 se->run_node | ||
1087 | * 4 se->sleep_start | ||
1088 | * 6 se->load.weight | ||
1089 | */ | ||
1090 | struct sched_entity { | ||
1091 | struct load_weight load; /* for load-balancing */ | ||
1092 | struct rb_node run_node; | ||
1093 | struct list_head group_node; | ||
1094 | unsigned int on_rq; | ||
1095 | |||
1096 | u64 exec_start; | ||
1097 | u64 sum_exec_runtime; | ||
1098 | u64 vruntime; | ||
1099 | u64 prev_sum_exec_runtime; | ||
1100 | |||
1101 | u64 last_wakeup; | ||
1102 | u64 avg_overlap; | ||
1103 | |||
1104 | u64 nr_migrations; | ||
1105 | |||
1106 | u64 start_runtime; | ||
1107 | u64 avg_wakeup; | ||
1108 | |||
1109 | #ifdef CONFIG_SCHEDSTATS | 1092 | #ifdef CONFIG_SCHEDSTATS |
1093 | struct sched_statistics { | ||
1110 | u64 wait_start; | 1094 | u64 wait_start; |
1111 | u64 wait_max; | 1095 | u64 wait_max; |
1112 | u64 wait_count; | 1096 | u64 wait_count; |
@@ -1138,6 +1122,24 @@ struct sched_entity { | |||
1138 | u64 nr_wakeups_affine_attempts; | 1122 | u64 nr_wakeups_affine_attempts; |
1139 | u64 nr_wakeups_passive; | 1123 | u64 nr_wakeups_passive; |
1140 | u64 nr_wakeups_idle; | 1124 | u64 nr_wakeups_idle; |
1125 | }; | ||
1126 | #endif | ||
1127 | |||
1128 | struct sched_entity { | ||
1129 | struct load_weight load; /* for load-balancing */ | ||
1130 | struct rb_node run_node; | ||
1131 | struct list_head group_node; | ||
1132 | unsigned int on_rq; | ||
1133 | |||
1134 | u64 exec_start; | ||
1135 | u64 sum_exec_runtime; | ||
1136 | u64 vruntime; | ||
1137 | u64 prev_sum_exec_runtime; | ||
1138 | |||
1139 | u64 nr_migrations; | ||
1140 | |||
1141 | #ifdef CONFIG_SCHEDSTATS | ||
1142 | struct sched_statistics statistics; | ||
1141 | #endif | 1143 | #endif |
1142 | 1144 | ||
1143 | #ifdef CONFIG_FAIR_GROUP_SCHED | 1145 | #ifdef CONFIG_FAIR_GROUP_SCHED |
@@ -1272,12 +1274,6 @@ struct task_struct { | |||
1272 | struct list_head ptraced; | 1274 | struct list_head ptraced; |
1273 | struct list_head ptrace_entry; | 1275 | struct list_head ptrace_entry; |
1274 | 1276 | ||
1275 | /* | ||
1276 | * This is the tracer handle for the ptrace BTS extension. | ||
1277 | * This field actually belongs to the ptracer task. | ||
1278 | */ | ||
1279 | struct bts_context *bts; | ||
1280 | |||
1281 | /* PID/PID hash table linkage. */ | 1277 | /* PID/PID hash table linkage. */ |
1282 | struct pid_link pids[PIDTYPE_MAX]; | 1278 | struct pid_link pids[PIDTYPE_MAX]; |
1283 | struct list_head thread_group; | 1279 | struct list_head thread_group; |
@@ -1846,6 +1842,7 @@ extern void sched_clock_idle_sleep_event(void); | |||
1846 | extern void sched_clock_idle_wakeup_event(u64 delta_ns); | 1842 | extern void sched_clock_idle_wakeup_event(u64 delta_ns); |
1847 | 1843 | ||
1848 | #ifdef CONFIG_HOTPLUG_CPU | 1844 | #ifdef CONFIG_HOTPLUG_CPU |
1845 | extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p); | ||
1849 | extern void idle_task_exit(void); | 1846 | extern void idle_task_exit(void); |
1850 | #else | 1847 | #else |
1851 | static inline void idle_task_exit(void) {} | 1848 | static inline void idle_task_exit(void) {} |
@@ -2122,10 +2119,8 @@ extern void set_task_comm(struct task_struct *tsk, char *from); | |||
2122 | extern char *get_task_comm(char *to, struct task_struct *tsk); | 2119 | extern char *get_task_comm(char *to, struct task_struct *tsk); |
2123 | 2120 | ||
2124 | #ifdef CONFIG_SMP | 2121 | #ifdef CONFIG_SMP |
2125 | extern void wait_task_context_switch(struct task_struct *p); | ||
2126 | extern unsigned long wait_task_inactive(struct task_struct *, long match_state); | 2122 | extern unsigned long wait_task_inactive(struct task_struct *, long match_state); |
2127 | #else | 2123 | #else |
2128 | static inline void wait_task_context_switch(struct task_struct *p) {} | ||
2129 | static inline unsigned long wait_task_inactive(struct task_struct *p, | 2124 | static inline unsigned long wait_task_inactive(struct task_struct *p, |
2130 | long match_state) | 2125 | long match_state) |
2131 | { | 2126 | { |
diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 4d5ecb222af9..4d5d2f546dbf 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h | |||
@@ -27,6 +27,8 @@ | |||
27 | #ifndef _LINUX_SRCU_H | 27 | #ifndef _LINUX_SRCU_H |
28 | #define _LINUX_SRCU_H | 28 | #define _LINUX_SRCU_H |
29 | 29 | ||
30 | #include <linux/mutex.h> | ||
31 | |||
30 | struct srcu_struct_array { | 32 | struct srcu_struct_array { |
31 | int c[2]; | 33 | int c[2]; |
32 | }; | 34 | }; |
@@ -84,8 +86,8 @@ long srcu_batches_completed(struct srcu_struct *sp); | |||
84 | /** | 86 | /** |
85 | * srcu_read_lock_held - might we be in SRCU read-side critical section? | 87 | * srcu_read_lock_held - might we be in SRCU read-side critical section? |
86 | * | 88 | * |
87 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in | 89 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an SRCU |
88 | * an SRCU read-side critical section. In absence of CONFIG_PROVE_LOCKING, | 90 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, |
89 | * this assumes we are in an SRCU read-side critical section unless it can | 91 | * this assumes we are in an SRCU read-side critical section unless it can |
90 | * prove otherwise. | 92 | * prove otherwise. |
91 | */ | 93 | */ |
diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h index baba3a23a814..6b524a0d02e4 100644 --- a/include/linux/stop_machine.h +++ b/include/linux/stop_machine.h | |||
@@ -1,13 +1,101 @@ | |||
1 | #ifndef _LINUX_STOP_MACHINE | 1 | #ifndef _LINUX_STOP_MACHINE |
2 | #define _LINUX_STOP_MACHINE | 2 | #define _LINUX_STOP_MACHINE |
3 | /* "Bogolock": stop the entire machine, disable interrupts. This is a | 3 | |
4 | very heavy lock, which is equivalent to grabbing every spinlock | ||
5 | (and more). So the "read" side to such a lock is anything which | ||
6 | disables preeempt. */ | ||
7 | #include <linux/cpu.h> | 4 | #include <linux/cpu.h> |
8 | #include <linux/cpumask.h> | 5 | #include <linux/cpumask.h> |
6 | #include <linux/list.h> | ||
9 | #include <asm/system.h> | 7 | #include <asm/system.h> |
10 | 8 | ||
9 | /* | ||
10 | * stop_cpu[s]() is simplistic per-cpu maximum priority cpu | ||
11 | * monopolization mechanism. The caller can specify a non-sleeping | ||
12 | * function to be executed on a single or multiple cpus preempting all | ||
13 | * other processes and monopolizing those cpus until it finishes. | ||
14 | * | ||
15 | * Resources for this mechanism are preallocated when a cpu is brought | ||
16 | * up and requests are guaranteed to be served as long as the target | ||
17 | * cpus are online. | ||
18 | */ | ||
19 | typedef int (*cpu_stop_fn_t)(void *arg); | ||
20 | |||
21 | #ifdef CONFIG_SMP | ||
22 | |||
23 | struct cpu_stop_work { | ||
24 | struct list_head list; /* cpu_stopper->works */ | ||
25 | cpu_stop_fn_t fn; | ||
26 | void *arg; | ||
27 | struct cpu_stop_done *done; | ||
28 | }; | ||
29 | |||
30 | int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg); | ||
31 | void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg, | ||
32 | struct cpu_stop_work *work_buf); | ||
33 | int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); | ||
34 | int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg); | ||
35 | |||
36 | #else /* CONFIG_SMP */ | ||
37 | |||
38 | #include <linux/workqueue.h> | ||
39 | |||
40 | struct cpu_stop_work { | ||
41 | struct work_struct work; | ||
42 | cpu_stop_fn_t fn; | ||
43 | void *arg; | ||
44 | }; | ||
45 | |||
46 | static inline int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg) | ||
47 | { | ||
48 | int ret = -ENOENT; | ||
49 | preempt_disable(); | ||
50 | if (cpu == smp_processor_id()) | ||
51 | ret = fn(arg); | ||
52 | preempt_enable(); | ||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | static void stop_one_cpu_nowait_workfn(struct work_struct *work) | ||
57 | { | ||
58 | struct cpu_stop_work *stwork = | ||
59 | container_of(work, struct cpu_stop_work, work); | ||
60 | preempt_disable(); | ||
61 | stwork->fn(stwork->arg); | ||
62 | preempt_enable(); | ||
63 | } | ||
64 | |||
65 | static inline void stop_one_cpu_nowait(unsigned int cpu, | ||
66 | cpu_stop_fn_t fn, void *arg, | ||
67 | struct cpu_stop_work *work_buf) | ||
68 | { | ||
69 | if (cpu == smp_processor_id()) { | ||
70 | INIT_WORK(&work_buf->work, stop_one_cpu_nowait_workfn); | ||
71 | work_buf->fn = fn; | ||
72 | work_buf->arg = arg; | ||
73 | schedule_work(&work_buf->work); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | static inline int stop_cpus(const struct cpumask *cpumask, | ||
78 | cpu_stop_fn_t fn, void *arg) | ||
79 | { | ||
80 | if (cpumask_test_cpu(raw_smp_processor_id(), cpumask)) | ||
81 | return stop_one_cpu(raw_smp_processor_id(), fn, arg); | ||
82 | return -ENOENT; | ||
83 | } | ||
84 | |||
85 | static inline int try_stop_cpus(const struct cpumask *cpumask, | ||
86 | cpu_stop_fn_t fn, void *arg) | ||
87 | { | ||
88 | return stop_cpus(cpumask, fn, arg); | ||
89 | } | ||
90 | |||
91 | #endif /* CONFIG_SMP */ | ||
92 | |||
93 | /* | ||
94 | * stop_machine "Bogolock": stop the entire machine, disable | ||
95 | * interrupts. This is a very heavy lock, which is equivalent to | ||
96 | * grabbing every spinlock (and more). So the "read" side to such a | ||
97 | * lock is anything which disables preeempt. | ||
98 | */ | ||
11 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) | 99 | #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP) |
12 | 100 | ||
13 | /** | 101 | /** |
@@ -36,24 +124,7 @@ int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); | |||
36 | */ | 124 | */ |
37 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); | 125 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus); |
38 | 126 | ||
39 | /** | 127 | #else /* CONFIG_STOP_MACHINE && CONFIG_SMP */ |
40 | * stop_machine_create: create all stop_machine threads | ||
41 | * | ||
42 | * Description: This causes all stop_machine threads to be created before | ||
43 | * stop_machine actually gets called. This can be used by subsystems that | ||
44 | * need a non failing stop_machine infrastructure. | ||
45 | */ | ||
46 | int stop_machine_create(void); | ||
47 | |||
48 | /** | ||
49 | * stop_machine_destroy: destroy all stop_machine threads | ||
50 | * | ||
51 | * Description: This causes all stop_machine threads which were created with | ||
52 | * stop_machine_create to be destroyed again. | ||
53 | */ | ||
54 | void stop_machine_destroy(void); | ||
55 | |||
56 | #else | ||
57 | 128 | ||
58 | static inline int stop_machine(int (*fn)(void *), void *data, | 129 | static inline int stop_machine(int (*fn)(void *), void *data, |
59 | const struct cpumask *cpus) | 130 | const struct cpumask *cpus) |
@@ -65,8 +136,5 @@ static inline int stop_machine(int (*fn)(void *), void *data, | |||
65 | return ret; | 136 | return ret; |
66 | } | 137 | } |
67 | 138 | ||
68 | static inline int stop_machine_create(void) { return 0; } | 139 | #endif /* CONFIG_STOP_MACHINE && CONFIG_SMP */ |
69 | static inline void stop_machine_destroy(void) { } | 140 | #endif /* _LINUX_STOP_MACHINE */ |
70 | |||
71 | #endif /* CONFIG_SMP */ | ||
72 | #endif /* _LINUX_STOP_MACHINE */ | ||
diff --git a/include/linux/tick.h b/include/linux/tick.h index d2ae79e21be3..b232ccc0ee29 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h | |||
@@ -42,6 +42,7 @@ enum tick_nohz_mode { | |||
42 | * @idle_waketime: Time when the idle was interrupted | 42 | * @idle_waketime: Time when the idle was interrupted |
43 | * @idle_exittime: Time when the idle state was left | 43 | * @idle_exittime: Time when the idle state was left |
44 | * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped | 44 | * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped |
45 | * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding | ||
45 | * @sleep_length: Duration of the current idle sleep | 46 | * @sleep_length: Duration of the current idle sleep |
46 | * @do_timer_lst: CPU was the last one doing do_timer before going idle | 47 | * @do_timer_lst: CPU was the last one doing do_timer before going idle |
47 | */ | 48 | */ |
@@ -60,7 +61,7 @@ struct tick_sched { | |||
60 | ktime_t idle_waketime; | 61 | ktime_t idle_waketime; |
61 | ktime_t idle_exittime; | 62 | ktime_t idle_exittime; |
62 | ktime_t idle_sleeptime; | 63 | ktime_t idle_sleeptime; |
63 | ktime_t idle_lastupdate; | 64 | ktime_t iowait_sleeptime; |
64 | ktime_t sleep_length; | 65 | ktime_t sleep_length; |
65 | unsigned long last_jiffies; | 66 | unsigned long last_jiffies; |
66 | unsigned long next_jiffies; | 67 | unsigned long next_jiffies; |
@@ -124,6 +125,7 @@ extern void tick_nohz_stop_sched_tick(int inidle); | |||
124 | extern void tick_nohz_restart_sched_tick(void); | 125 | extern void tick_nohz_restart_sched_tick(void); |
125 | extern ktime_t tick_nohz_get_sleep_length(void); | 126 | extern ktime_t tick_nohz_get_sleep_length(void); |
126 | extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); | 127 | extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); |
128 | extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); | ||
127 | # else | 129 | # else |
128 | static inline void tick_nohz_stop_sched_tick(int inidle) { } | 130 | static inline void tick_nohz_stop_sched_tick(int inidle) { } |
129 | static inline void tick_nohz_restart_sched_tick(void) { } | 131 | static inline void tick_nohz_restart_sched_tick(void) { } |
@@ -134,6 +136,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void) | |||
134 | return len; | 136 | return len; |
135 | } | 137 | } |
136 | static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } | 138 | static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } |
139 | static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } | ||
137 | # endif /* !NO_HZ */ | 140 | # endif /* !NO_HZ */ |
138 | 141 | ||
139 | #endif | 142 | #endif |
diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 78b4bd3be496..1d85f9a6a199 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h | |||
@@ -33,6 +33,65 @@ struct tracepoint { | |||
33 | * Keep in sync with vmlinux.lds.h. | 33 | * Keep in sync with vmlinux.lds.h. |
34 | */ | 34 | */ |
35 | 35 | ||
36 | /* | ||
37 | * Connect a probe to a tracepoint. | ||
38 | * Internal API, should not be used directly. | ||
39 | */ | ||
40 | extern int tracepoint_probe_register(const char *name, void *probe); | ||
41 | |||
42 | /* | ||
43 | * Disconnect a probe from a tracepoint. | ||
44 | * Internal API, should not be used directly. | ||
45 | */ | ||
46 | extern int tracepoint_probe_unregister(const char *name, void *probe); | ||
47 | |||
48 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | ||
49 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | ||
50 | extern void tracepoint_probe_update_all(void); | ||
51 | |||
52 | struct tracepoint_iter { | ||
53 | struct module *module; | ||
54 | struct tracepoint *tracepoint; | ||
55 | }; | ||
56 | |||
57 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); | ||
58 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); | ||
59 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); | ||
60 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); | ||
61 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, | ||
62 | struct tracepoint *begin, struct tracepoint *end); | ||
63 | |||
64 | /* | ||
65 | * tracepoint_synchronize_unregister must be called between the last tracepoint | ||
66 | * probe unregistration and the end of module exit to make sure there is no | ||
67 | * caller executing a probe when it is freed. | ||
68 | */ | ||
69 | static inline void tracepoint_synchronize_unregister(void) | ||
70 | { | ||
71 | synchronize_sched(); | ||
72 | } | ||
73 | |||
74 | #define PARAMS(args...) args | ||
75 | |||
76 | #ifdef CONFIG_TRACEPOINTS | ||
77 | extern void tracepoint_update_probe_range(struct tracepoint *begin, | ||
78 | struct tracepoint *end); | ||
79 | #else | ||
80 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, | ||
81 | struct tracepoint *end) | ||
82 | { } | ||
83 | #endif /* CONFIG_TRACEPOINTS */ | ||
84 | |||
85 | #endif /* _LINUX_TRACEPOINT_H */ | ||
86 | |||
87 | /* | ||
88 | * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include | ||
89 | * file ifdef protection. | ||
90 | * This is due to the way trace events work. If a file includes two | ||
91 | * trace event headers under one "CREATE_TRACE_POINTS" the first include | ||
92 | * will override the TRACE_EVENT and break the second include. | ||
93 | */ | ||
94 | |||
36 | #ifndef DECLARE_TRACE | 95 | #ifndef DECLARE_TRACE |
37 | 96 | ||
38 | #define TP_PROTO(args...) args | 97 | #define TP_PROTO(args...) args |
@@ -96,9 +155,6 @@ struct tracepoint { | |||
96 | #define EXPORT_TRACEPOINT_SYMBOL(name) \ | 155 | #define EXPORT_TRACEPOINT_SYMBOL(name) \ |
97 | EXPORT_SYMBOL(__tracepoint_##name) | 156 | EXPORT_SYMBOL(__tracepoint_##name) |
98 | 157 | ||
99 | extern void tracepoint_update_probe_range(struct tracepoint *begin, | ||
100 | struct tracepoint *end); | ||
101 | |||
102 | #else /* !CONFIG_TRACEPOINTS */ | 158 | #else /* !CONFIG_TRACEPOINTS */ |
103 | #define DECLARE_TRACE(name, proto, args) \ | 159 | #define DECLARE_TRACE(name, proto, args) \ |
104 | static inline void _do_trace_##name(struct tracepoint *tp, proto) \ | 160 | static inline void _do_trace_##name(struct tracepoint *tp, proto) \ |
@@ -119,61 +175,9 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin, | |||
119 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) | 175 | #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) |
120 | #define EXPORT_TRACEPOINT_SYMBOL(name) | 176 | #define EXPORT_TRACEPOINT_SYMBOL(name) |
121 | 177 | ||
122 | static inline void tracepoint_update_probe_range(struct tracepoint *begin, | ||
123 | struct tracepoint *end) | ||
124 | { } | ||
125 | #endif /* CONFIG_TRACEPOINTS */ | 178 | #endif /* CONFIG_TRACEPOINTS */ |
126 | #endif /* DECLARE_TRACE */ | 179 | #endif /* DECLARE_TRACE */ |
127 | 180 | ||
128 | /* | ||
129 | * Connect a probe to a tracepoint. | ||
130 | * Internal API, should not be used directly. | ||
131 | */ | ||
132 | extern int tracepoint_probe_register(const char *name, void *probe); | ||
133 | |||
134 | /* | ||
135 | * Disconnect a probe from a tracepoint. | ||
136 | * Internal API, should not be used directly. | ||
137 | */ | ||
138 | extern int tracepoint_probe_unregister(const char *name, void *probe); | ||
139 | |||
140 | extern int tracepoint_probe_register_noupdate(const char *name, void *probe); | ||
141 | extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe); | ||
142 | extern void tracepoint_probe_update_all(void); | ||
143 | |||
144 | struct tracepoint_iter { | ||
145 | struct module *module; | ||
146 | struct tracepoint *tracepoint; | ||
147 | }; | ||
148 | |||
149 | extern void tracepoint_iter_start(struct tracepoint_iter *iter); | ||
150 | extern void tracepoint_iter_next(struct tracepoint_iter *iter); | ||
151 | extern void tracepoint_iter_stop(struct tracepoint_iter *iter); | ||
152 | extern void tracepoint_iter_reset(struct tracepoint_iter *iter); | ||
153 | extern int tracepoint_get_iter_range(struct tracepoint **tracepoint, | ||
154 | struct tracepoint *begin, struct tracepoint *end); | ||
155 | |||
156 | /* | ||
157 | * tracepoint_synchronize_unregister must be called between the last tracepoint | ||
158 | * probe unregistration and the end of module exit to make sure there is no | ||
159 | * caller executing a probe when it is freed. | ||
160 | */ | ||
161 | static inline void tracepoint_synchronize_unregister(void) | ||
162 | { | ||
163 | synchronize_sched(); | ||
164 | } | ||
165 | |||
166 | #define PARAMS(args...) args | ||
167 | |||
168 | #endif /* _LINUX_TRACEPOINT_H */ | ||
169 | |||
170 | /* | ||
171 | * Note: we keep the TRACE_EVENT outside the include file ifdef protection. | ||
172 | * This is due to the way trace events work. If a file includes two | ||
173 | * trace event headers under one "CREATE_TRACE_POINTS" the first include | ||
174 | * will override the TRACE_EVENT and break the second include. | ||
175 | */ | ||
176 | |||
177 | #ifndef TRACE_EVENT | 181 | #ifndef TRACE_EVENT |
178 | /* | 182 | /* |
179 | * For use with the TRACE_EVENT macro: | 183 | * For use with the TRACE_EVENT macro: |
diff --git a/include/linux/types.h b/include/linux/types.h index c42724f8c802..23d237a075e2 100644 --- a/include/linux/types.h +++ b/include/linux/types.h | |||
@@ -188,12 +188,12 @@ typedef u32 phys_addr_t; | |||
188 | typedef phys_addr_t resource_size_t; | 188 | typedef phys_addr_t resource_size_t; |
189 | 189 | ||
190 | typedef struct { | 190 | typedef struct { |
191 | volatile int counter; | 191 | int counter; |
192 | } atomic_t; | 192 | } atomic_t; |
193 | 193 | ||
194 | #ifdef CONFIG_64BIT | 194 | #ifdef CONFIG_64BIT |
195 | typedef struct { | 195 | typedef struct { |
196 | volatile long counter; | 196 | long counter; |
197 | } atomic64_t; | 197 | } atomic64_t; |
198 | #endif | 198 | #endif |
199 | 199 | ||
diff --git a/include/linux/wait.h b/include/linux/wait.h index a48e16b77d5e..76d96d035ea0 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
@@ -127,12 +127,26 @@ static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) | |||
127 | /* | 127 | /* |
128 | * Used for wake-one threads: | 128 | * Used for wake-one threads: |
129 | */ | 129 | */ |
130 | static inline void __add_wait_queue_exclusive(wait_queue_head_t *q, | ||
131 | wait_queue_t *wait) | ||
132 | { | ||
133 | wait->flags |= WQ_FLAG_EXCLUSIVE; | ||
134 | __add_wait_queue(q, wait); | ||
135 | } | ||
136 | |||
130 | static inline void __add_wait_queue_tail(wait_queue_head_t *head, | 137 | static inline void __add_wait_queue_tail(wait_queue_head_t *head, |
131 | wait_queue_t *new) | 138 | wait_queue_t *new) |
132 | { | 139 | { |
133 | list_add_tail(&new->task_list, &head->task_list); | 140 | list_add_tail(&new->task_list, &head->task_list); |
134 | } | 141 | } |
135 | 142 | ||
143 | static inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q, | ||
144 | wait_queue_t *wait) | ||
145 | { | ||
146 | wait->flags |= WQ_FLAG_EXCLUSIVE; | ||
147 | __add_wait_queue_tail(q, wait); | ||
148 | } | ||
149 | |||
136 | static inline void __remove_wait_queue(wait_queue_head_t *head, | 150 | static inline void __remove_wait_queue(wait_queue_head_t *head, |
137 | wait_queue_t *old) | 151 | wait_queue_t *old) |
138 | { | 152 | { |
@@ -404,25 +418,6 @@ do { \ | |||
404 | }) | 418 | }) |
405 | 419 | ||
406 | /* | 420 | /* |
407 | * Must be called with the spinlock in the wait_queue_head_t held. | ||
408 | */ | ||
409 | static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q, | ||
410 | wait_queue_t * wait) | ||
411 | { | ||
412 | wait->flags |= WQ_FLAG_EXCLUSIVE; | ||
413 | __add_wait_queue_tail(q, wait); | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * Must be called with the spinlock in the wait_queue_head_t held. | ||
418 | */ | ||
419 | static inline void remove_wait_queue_locked(wait_queue_head_t *q, | ||
420 | wait_queue_t * wait) | ||
421 | { | ||
422 | __remove_wait_queue(q, wait); | ||
423 | } | ||
424 | |||
425 | /* | ||
426 | * These are the old interfaces to sleep waiting for an event. | 421 | * These are the old interfaces to sleep waiting for an event. |
427 | * They are racy. DO NOT use them, use the wait_event* interfaces above. | 422 | * They are racy. DO NOT use them, use the wait_event* interfaces above. |
428 | * We plan to remove these interfaces. | 423 | * We plan to remove these interfaces. |
diff --git a/include/linux/zorro.h b/include/linux/zorro.h index 913bfc226dda..7bf9db525e9e 100644 --- a/include/linux/zorro.h +++ b/include/linux/zorro.h | |||
@@ -38,8 +38,6 @@ | |||
38 | typedef __u32 zorro_id; | 38 | typedef __u32 zorro_id; |
39 | 39 | ||
40 | 40 | ||
41 | #define ZORRO_WILDCARD (0xffffffff) /* not official */ | ||
42 | |||
43 | /* Include the ID list */ | 41 | /* Include the ID list */ |
44 | #include <linux/zorro_ids.h> | 42 | #include <linux/zorro_ids.h> |
45 | 43 | ||
@@ -116,6 +114,7 @@ struct ConfigDev { | |||
116 | 114 | ||
117 | #include <linux/init.h> | 115 | #include <linux/init.h> |
118 | #include <linux/ioport.h> | 116 | #include <linux/ioport.h> |
117 | #include <linux/mod_devicetable.h> | ||
119 | 118 | ||
120 | #include <asm/zorro.h> | 119 | #include <asm/zorro.h> |
121 | 120 | ||
@@ -142,29 +141,10 @@ struct zorro_dev { | |||
142 | * Zorro bus | 141 | * Zorro bus |
143 | */ | 142 | */ |
144 | 143 | ||
145 | struct zorro_bus { | ||
146 | struct list_head devices; /* list of devices on this bus */ | ||
147 | unsigned int num_resources; /* number of resources */ | ||
148 | struct resource resources[4]; /* address space routed to this bus */ | ||
149 | struct device dev; | ||
150 | char name[10]; | ||
151 | }; | ||
152 | |||
153 | extern struct zorro_bus zorro_bus; /* single Zorro bus */ | ||
154 | extern struct bus_type zorro_bus_type; | 144 | extern struct bus_type zorro_bus_type; |
155 | 145 | ||
156 | 146 | ||
157 | /* | 147 | /* |
158 | * Zorro device IDs | ||
159 | */ | ||
160 | |||
161 | struct zorro_device_id { | ||
162 | zorro_id id; /* Device ID or ZORRO_WILDCARD */ | ||
163 | unsigned long driver_data; /* Data private to the driver */ | ||
164 | }; | ||
165 | |||
166 | |||
167 | /* | ||
168 | * Zorro device drivers | 148 | * Zorro device drivers |
169 | */ | 149 | */ |
170 | 150 | ||
diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index 5acfb1eb4df9..1dfab5401511 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h | |||
@@ -65,6 +65,10 @@ | |||
65 | 65 | ||
66 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | 66 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
67 | 67 | ||
68 | /* Make all open coded DECLARE_TRACE nops */ | ||
69 | #undef DECLARE_TRACE | ||
70 | #define DECLARE_TRACE(name, proto, args) | ||
71 | |||
68 | #ifdef CONFIG_EVENT_TRACING | 72 | #ifdef CONFIG_EVENT_TRACING |
69 | #include <trace/ftrace.h> | 73 | #include <trace/ftrace.h> |
70 | #endif | 74 | #endif |
@@ -75,6 +79,7 @@ | |||
75 | #undef DEFINE_EVENT | 79 | #undef DEFINE_EVENT |
76 | #undef DEFINE_EVENT_PRINT | 80 | #undef DEFINE_EVENT_PRINT |
77 | #undef TRACE_HEADER_MULTI_READ | 81 | #undef TRACE_HEADER_MULTI_READ |
82 | #undef DECLARE_TRACE | ||
78 | 83 | ||
79 | /* Only undef what we defined in this file */ | 84 | /* Only undef what we defined in this file */ |
80 | #ifdef UNDEF_TRACE_INCLUDE_FILE | 85 | #ifdef UNDEF_TRACE_INCLUDE_FILE |
diff --git a/include/trace/events/lock.h b/include/trace/events/lock.h index 5c1dcfc16c60..2821b86de63b 100644 --- a/include/trace/events/lock.h +++ b/include/trace/events/lock.h | |||
@@ -35,15 +35,15 @@ TRACE_EVENT(lock_acquire, | |||
35 | __get_str(name)) | 35 | __get_str(name)) |
36 | ); | 36 | ); |
37 | 37 | ||
38 | TRACE_EVENT(lock_release, | 38 | DECLARE_EVENT_CLASS(lock, |
39 | 39 | ||
40 | TP_PROTO(struct lockdep_map *lock, int nested, unsigned long ip), | 40 | TP_PROTO(struct lockdep_map *lock, unsigned long ip), |
41 | 41 | ||
42 | TP_ARGS(lock, nested, ip), | 42 | TP_ARGS(lock, ip), |
43 | 43 | ||
44 | TP_STRUCT__entry( | 44 | TP_STRUCT__entry( |
45 | __string(name, lock->name) | 45 | __string( name, lock->name ) |
46 | __field(void *, lockdep_addr) | 46 | __field( void *, lockdep_addr ) |
47 | ), | 47 | ), |
48 | 48 | ||
49 | TP_fast_assign( | 49 | TP_fast_assign( |
@@ -51,51 +51,30 @@ TRACE_EVENT(lock_release, | |||
51 | __entry->lockdep_addr = lock; | 51 | __entry->lockdep_addr = lock; |
52 | ), | 52 | ), |
53 | 53 | ||
54 | TP_printk("%p %s", | 54 | TP_printk("%p %s", __entry->lockdep_addr, __get_str(name)) |
55 | __entry->lockdep_addr, __get_str(name)) | ||
56 | ); | 55 | ); |
57 | 56 | ||
58 | #ifdef CONFIG_LOCK_STAT | 57 | DEFINE_EVENT(lock, lock_release, |
59 | |||
60 | TRACE_EVENT(lock_contended, | ||
61 | 58 | ||
62 | TP_PROTO(struct lockdep_map *lock, unsigned long ip), | 59 | TP_PROTO(struct lockdep_map *lock, unsigned long ip), |
63 | 60 | ||
64 | TP_ARGS(lock, ip), | 61 | TP_ARGS(lock, ip) |
62 | ); | ||
65 | 63 | ||
66 | TP_STRUCT__entry( | 64 | #ifdef CONFIG_LOCK_STAT |
67 | __string(name, lock->name) | ||
68 | __field(void *, lockdep_addr) | ||
69 | ), | ||
70 | 65 | ||
71 | TP_fast_assign( | 66 | DEFINE_EVENT(lock, lock_contended, |
72 | __assign_str(name, lock->name); | ||
73 | __entry->lockdep_addr = lock; | ||
74 | ), | ||
75 | 67 | ||
76 | TP_printk("%p %s", | 68 | TP_PROTO(struct lockdep_map *lock, unsigned long ip), |
77 | __entry->lockdep_addr, __get_str(name)) | ||
78 | ); | ||
79 | 69 | ||
80 | TRACE_EVENT(lock_acquired, | 70 | TP_ARGS(lock, ip) |
81 | TP_PROTO(struct lockdep_map *lock, unsigned long ip, s64 waittime), | 71 | ); |
82 | 72 | ||
83 | TP_ARGS(lock, ip, waittime), | 73 | DEFINE_EVENT(lock, lock_acquired, |
84 | 74 | ||
85 | TP_STRUCT__entry( | 75 | TP_PROTO(struct lockdep_map *lock, unsigned long ip), |
86 | __string(name, lock->name) | ||
87 | __field(s64, wait_nsec) | ||
88 | __field(void *, lockdep_addr) | ||
89 | ), | ||
90 | 76 | ||
91 | TP_fast_assign( | 77 | TP_ARGS(lock, ip) |
92 | __assign_str(name, lock->name); | ||
93 | __entry->wait_nsec = waittime; | ||
94 | __entry->lockdep_addr = lock; | ||
95 | ), | ||
96 | TP_printk("%p %s (%llu ns)", __entry->lockdep_addr, | ||
97 | __get_str(name), | ||
98 | __entry->wait_nsec) | ||
99 | ); | 78 | ); |
100 | 79 | ||
101 | #endif | 80 | #endif |
diff --git a/include/trace/events/module.h b/include/trace/events/module.h index 4b0f48ba16a6..c7bb2f0482fe 100644 --- a/include/trace/events/module.h +++ b/include/trace/events/module.h | |||
@@ -51,11 +51,14 @@ TRACE_EVENT(module_free, | |||
51 | TP_printk("%s", __get_str(name)) | 51 | TP_printk("%s", __get_str(name)) |
52 | ); | 52 | ); |
53 | 53 | ||
54 | #ifdef CONFIG_MODULE_UNLOAD | ||
55 | /* trace_module_get/put are only used if CONFIG_MODULE_UNLOAD is defined */ | ||
56 | |||
54 | DECLARE_EVENT_CLASS(module_refcnt, | 57 | DECLARE_EVENT_CLASS(module_refcnt, |
55 | 58 | ||
56 | TP_PROTO(struct module *mod, unsigned long ip, int refcnt), | 59 | TP_PROTO(struct module *mod, unsigned long ip), |
57 | 60 | ||
58 | TP_ARGS(mod, ip, refcnt), | 61 | TP_ARGS(mod, ip), |
59 | 62 | ||
60 | TP_STRUCT__entry( | 63 | TP_STRUCT__entry( |
61 | __field( unsigned long, ip ) | 64 | __field( unsigned long, ip ) |
@@ -65,7 +68,7 @@ DECLARE_EVENT_CLASS(module_refcnt, | |||
65 | 68 | ||
66 | TP_fast_assign( | 69 | TP_fast_assign( |
67 | __entry->ip = ip; | 70 | __entry->ip = ip; |
68 | __entry->refcnt = refcnt; | 71 | __entry->refcnt = __this_cpu_read(mod->refptr->incs) + __this_cpu_read(mod->refptr->decs); |
69 | __assign_str(name, mod->name); | 72 | __assign_str(name, mod->name); |
70 | ), | 73 | ), |
71 | 74 | ||
@@ -75,17 +78,18 @@ DECLARE_EVENT_CLASS(module_refcnt, | |||
75 | 78 | ||
76 | DEFINE_EVENT(module_refcnt, module_get, | 79 | DEFINE_EVENT(module_refcnt, module_get, |
77 | 80 | ||
78 | TP_PROTO(struct module *mod, unsigned long ip, int refcnt), | 81 | TP_PROTO(struct module *mod, unsigned long ip), |
79 | 82 | ||
80 | TP_ARGS(mod, ip, refcnt) | 83 | TP_ARGS(mod, ip) |
81 | ); | 84 | ); |
82 | 85 | ||
83 | DEFINE_EVENT(module_refcnt, module_put, | 86 | DEFINE_EVENT(module_refcnt, module_put, |
84 | 87 | ||
85 | TP_PROTO(struct module *mod, unsigned long ip, int refcnt), | 88 | TP_PROTO(struct module *mod, unsigned long ip), |
86 | 89 | ||
87 | TP_ARGS(mod, ip, refcnt) | 90 | TP_ARGS(mod, ip) |
88 | ); | 91 | ); |
92 | #endif /* CONFIG_MODULE_UNLOAD */ | ||
89 | 93 | ||
90 | TRACE_EVENT(module_request, | 94 | TRACE_EVENT(module_request, |
91 | 95 | ||
diff --git a/include/trace/events/napi.h b/include/trace/events/napi.h index a8989c4547e7..188deca2f3c7 100644 --- a/include/trace/events/napi.h +++ b/include/trace/events/napi.h | |||
@@ -1,4 +1,7 @@ | |||
1 | #ifndef _TRACE_NAPI_H_ | 1 | #undef TRACE_SYSTEM |
2 | #define TRACE_SYSTEM napi | ||
3 | |||
4 | #if !defined(_TRACE_NAPI_H) || defined(TRACE_HEADER_MULTI_READ) | ||
2 | #define _TRACE_NAPI_H_ | 5 | #define _TRACE_NAPI_H_ |
3 | 6 | ||
4 | #include <linux/netdevice.h> | 7 | #include <linux/netdevice.h> |
@@ -8,4 +11,7 @@ DECLARE_TRACE(napi_poll, | |||
8 | TP_PROTO(struct napi_struct *napi), | 11 | TP_PROTO(struct napi_struct *napi), |
9 | TP_ARGS(napi)); | 12 | TP_ARGS(napi)); |
10 | 13 | ||
11 | #endif | 14 | #endif /* _TRACE_NAPI_H_ */ |
15 | |||
16 | /* This part must be outside protection */ | ||
17 | #include <trace/define_trace.h> | ||
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index cfceb0b73e20..4f733ecea46e 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h | |||
@@ -51,15 +51,12 @@ TRACE_EVENT(sched_kthread_stop_ret, | |||
51 | 51 | ||
52 | /* | 52 | /* |
53 | * Tracepoint for waiting on task to unschedule: | 53 | * Tracepoint for waiting on task to unschedule: |
54 | * | ||
55 | * (NOTE: the 'rq' argument is not used by generic trace events, | ||
56 | * but used by the latency tracer plugin. ) | ||
57 | */ | 54 | */ |
58 | TRACE_EVENT(sched_wait_task, | 55 | TRACE_EVENT(sched_wait_task, |
59 | 56 | ||
60 | TP_PROTO(struct rq *rq, struct task_struct *p), | 57 | TP_PROTO(struct task_struct *p), |
61 | 58 | ||
62 | TP_ARGS(rq, p), | 59 | TP_ARGS(p), |
63 | 60 | ||
64 | TP_STRUCT__entry( | 61 | TP_STRUCT__entry( |
65 | __array( char, comm, TASK_COMM_LEN ) | 62 | __array( char, comm, TASK_COMM_LEN ) |
@@ -79,15 +76,12 @@ TRACE_EVENT(sched_wait_task, | |||
79 | 76 | ||
80 | /* | 77 | /* |
81 | * Tracepoint for waking up a task: | 78 | * Tracepoint for waking up a task: |
82 | * | ||
83 | * (NOTE: the 'rq' argument is not used by generic trace events, | ||
84 | * but used by the latency tracer plugin. ) | ||
85 | */ | 79 | */ |
86 | DECLARE_EVENT_CLASS(sched_wakeup_template, | 80 | DECLARE_EVENT_CLASS(sched_wakeup_template, |
87 | 81 | ||
88 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), | 82 | TP_PROTO(struct task_struct *p, int success), |
89 | 83 | ||
90 | TP_ARGS(rq, p, success), | 84 | TP_ARGS(p, success), |
91 | 85 | ||
92 | TP_STRUCT__entry( | 86 | TP_STRUCT__entry( |
93 | __array( char, comm, TASK_COMM_LEN ) | 87 | __array( char, comm, TASK_COMM_LEN ) |
@@ -111,31 +105,25 @@ DECLARE_EVENT_CLASS(sched_wakeup_template, | |||
111 | ); | 105 | ); |
112 | 106 | ||
113 | DEFINE_EVENT(sched_wakeup_template, sched_wakeup, | 107 | DEFINE_EVENT(sched_wakeup_template, sched_wakeup, |
114 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), | 108 | TP_PROTO(struct task_struct *p, int success), |
115 | TP_ARGS(rq, p, success)); | 109 | TP_ARGS(p, success)); |
116 | 110 | ||
117 | /* | 111 | /* |
118 | * Tracepoint for waking up a new task: | 112 | * Tracepoint for waking up a new task: |
119 | * | ||
120 | * (NOTE: the 'rq' argument is not used by generic trace events, | ||
121 | * but used by the latency tracer plugin. ) | ||
122 | */ | 113 | */ |
123 | DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new, | 114 | DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new, |
124 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), | 115 | TP_PROTO(struct task_struct *p, int success), |
125 | TP_ARGS(rq, p, success)); | 116 | TP_ARGS(p, success)); |
126 | 117 | ||
127 | /* | 118 | /* |
128 | * Tracepoint for task switches, performed by the scheduler: | 119 | * Tracepoint for task switches, performed by the scheduler: |
129 | * | ||
130 | * (NOTE: the 'rq' argument is not used by generic trace events, | ||
131 | * but used by the latency tracer plugin. ) | ||
132 | */ | 120 | */ |
133 | TRACE_EVENT(sched_switch, | 121 | TRACE_EVENT(sched_switch, |
134 | 122 | ||
135 | TP_PROTO(struct rq *rq, struct task_struct *prev, | 123 | TP_PROTO(struct task_struct *prev, |
136 | struct task_struct *next), | 124 | struct task_struct *next), |
137 | 125 | ||
138 | TP_ARGS(rq, prev, next), | 126 | TP_ARGS(prev, next), |
139 | 127 | ||
140 | TP_STRUCT__entry( | 128 | TP_STRUCT__entry( |
141 | __array( char, prev_comm, TASK_COMM_LEN ) | 129 | __array( char, prev_comm, TASK_COMM_LEN ) |
diff --git a/include/trace/events/signal.h b/include/trace/events/signal.h index a510b75ac304..814566c99d29 100644 --- a/include/trace/events/signal.h +++ b/include/trace/events/signal.h | |||
@@ -100,18 +100,7 @@ TRACE_EVENT(signal_deliver, | |||
100 | __entry->sa_handler, __entry->sa_flags) | 100 | __entry->sa_handler, __entry->sa_flags) |
101 | ); | 101 | ); |
102 | 102 | ||
103 | /** | 103 | DECLARE_EVENT_CLASS(signal_queue_overflow, |
104 | * signal_overflow_fail - called when signal queue is overflow | ||
105 | * @sig: signal number | ||
106 | * @group: signal to process group or not (bool) | ||
107 | * @info: pointer to struct siginfo | ||
108 | * | ||
109 | * Kernel fails to generate 'sig' signal with 'info' siginfo, because | ||
110 | * siginfo queue is overflow, and the signal is dropped. | ||
111 | * 'group' is not 0 if the signal will be sent to a process group. | ||
112 | * 'sig' is always one of RT signals. | ||
113 | */ | ||
114 | TRACE_EVENT(signal_overflow_fail, | ||
115 | 104 | ||
116 | TP_PROTO(int sig, int group, struct siginfo *info), | 105 | TP_PROTO(int sig, int group, struct siginfo *info), |
117 | 106 | ||
@@ -135,6 +124,24 @@ TRACE_EVENT(signal_overflow_fail, | |||
135 | ); | 124 | ); |
136 | 125 | ||
137 | /** | 126 | /** |
127 | * signal_overflow_fail - called when signal queue is overflow | ||
128 | * @sig: signal number | ||
129 | * @group: signal to process group or not (bool) | ||
130 | * @info: pointer to struct siginfo | ||
131 | * | ||
132 | * Kernel fails to generate 'sig' signal with 'info' siginfo, because | ||
133 | * siginfo queue is overflow, and the signal is dropped. | ||
134 | * 'group' is not 0 if the signal will be sent to a process group. | ||
135 | * 'sig' is always one of RT signals. | ||
136 | */ | ||
137 | DEFINE_EVENT(signal_queue_overflow, signal_overflow_fail, | ||
138 | |||
139 | TP_PROTO(int sig, int group, struct siginfo *info), | ||
140 | |||
141 | TP_ARGS(sig, group, info) | ||
142 | ); | ||
143 | |||
144 | /** | ||
138 | * signal_lose_info - called when siginfo is lost | 145 | * signal_lose_info - called when siginfo is lost |
139 | * @sig: signal number | 146 | * @sig: signal number |
140 | * @group: signal to process group or not (bool) | 147 | * @group: signal to process group or not (bool) |
@@ -145,28 +152,13 @@ TRACE_EVENT(signal_overflow_fail, | |||
145 | * 'group' is not 0 if the signal will be sent to a process group. | 152 | * 'group' is not 0 if the signal will be sent to a process group. |
146 | * 'sig' is always one of non-RT signals. | 153 | * 'sig' is always one of non-RT signals. |
147 | */ | 154 | */ |
148 | TRACE_EVENT(signal_lose_info, | 155 | DEFINE_EVENT(signal_queue_overflow, signal_lose_info, |
149 | 156 | ||
150 | TP_PROTO(int sig, int group, struct siginfo *info), | 157 | TP_PROTO(int sig, int group, struct siginfo *info), |
151 | 158 | ||
152 | TP_ARGS(sig, group, info), | 159 | TP_ARGS(sig, group, info) |
153 | |||
154 | TP_STRUCT__entry( | ||
155 | __field( int, sig ) | ||
156 | __field( int, group ) | ||
157 | __field( int, errno ) | ||
158 | __field( int, code ) | ||
159 | ), | ||
160 | |||
161 | TP_fast_assign( | ||
162 | __entry->sig = sig; | ||
163 | __entry->group = group; | ||
164 | TP_STORE_SIGINFO(__entry, info); | ||
165 | ), | ||
166 | |||
167 | TP_printk("sig=%d group=%d errno=%d code=%d", | ||
168 | __entry->sig, __entry->group, __entry->errno, __entry->code) | ||
169 | ); | 160 | ); |
161 | |||
170 | #endif /* _TRACE_SIGNAL_H */ | 162 | #endif /* _TRACE_SIGNAL_H */ |
171 | 163 | ||
172 | /* This part must be outside protection */ | 164 | /* This part must be outside protection */ |
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h index ea6f9d4a20e9..16253db38d73 100644 --- a/include/trace/ftrace.h +++ b/include/trace/ftrace.h | |||
@@ -154,9 +154,11 @@ | |||
154 | * | 154 | * |
155 | * field = (typeof(field))entry; | 155 | * field = (typeof(field))entry; |
156 | * | 156 | * |
157 | * p = get_cpu_var(ftrace_event_seq); | 157 | * p = &get_cpu_var(ftrace_event_seq); |
158 | * trace_seq_init(p); | 158 | * trace_seq_init(p); |
159 | * ret = trace_seq_printf(s, <TP_printk> "\n"); | 159 | * ret = trace_seq_printf(s, "%s: ", <call>); |
160 | * if (ret) | ||
161 | * ret = trace_seq_printf(s, <TP_printk> "\n"); | ||
160 | * put_cpu(); | 162 | * put_cpu(); |
161 | * if (!ret) | 163 | * if (!ret) |
162 | * return TRACE_TYPE_PARTIAL_LINE; | 164 | * return TRACE_TYPE_PARTIAL_LINE; |
@@ -450,38 +452,38 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
450 | * | 452 | * |
451 | * static void ftrace_raw_event_<call>(proto) | 453 | * static void ftrace_raw_event_<call>(proto) |
452 | * { | 454 | * { |
455 | * struct ftrace_data_offsets_<call> __maybe_unused __data_offsets; | ||
453 | * struct ring_buffer_event *event; | 456 | * struct ring_buffer_event *event; |
454 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 | 457 | * struct ftrace_raw_<call> *entry; <-- defined in stage 1 |
455 | * struct ring_buffer *buffer; | 458 | * struct ring_buffer *buffer; |
456 | * unsigned long irq_flags; | 459 | * unsigned long irq_flags; |
460 | * int __data_size; | ||
457 | * int pc; | 461 | * int pc; |
458 | * | 462 | * |
459 | * local_save_flags(irq_flags); | 463 | * local_save_flags(irq_flags); |
460 | * pc = preempt_count(); | 464 | * pc = preempt_count(); |
461 | * | 465 | * |
466 | * __data_size = ftrace_get_offsets_<call>(&__data_offsets, args); | ||
467 | * | ||
462 | * event = trace_current_buffer_lock_reserve(&buffer, | 468 | * event = trace_current_buffer_lock_reserve(&buffer, |
463 | * event_<call>.id, | 469 | * event_<call>.id, |
464 | * sizeof(struct ftrace_raw_<call>), | 470 | * sizeof(*entry) + __data_size, |
465 | * irq_flags, pc); | 471 | * irq_flags, pc); |
466 | * if (!event) | 472 | * if (!event) |
467 | * return; | 473 | * return; |
468 | * entry = ring_buffer_event_data(event); | 474 | * entry = ring_buffer_event_data(event); |
469 | * | 475 | * |
470 | * <assign>; <-- Here we assign the entries by the __field and | 476 | * { <assign>; } <-- Here we assign the entries by the __field and |
471 | * __array macros. | 477 | * __array macros. |
472 | * | 478 | * |
473 | * trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc); | 479 | * if (!filter_current_check_discard(buffer, event_call, entry, event)) |
480 | * trace_current_buffer_unlock_commit(buffer, | ||
481 | * event, irq_flags, pc); | ||
474 | * } | 482 | * } |
475 | * | 483 | * |
476 | * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused) | 484 | * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused) |
477 | * { | 485 | * { |
478 | * int ret; | 486 | * return register_trace_<call>(ftrace_raw_event_<call>); |
479 | * | ||
480 | * ret = register_trace_<call>(ftrace_raw_event_<call>); | ||
481 | * if (!ret) | ||
482 | * pr_info("event trace: Could not activate trace point " | ||
483 | * "probe to <call>"); | ||
484 | * return ret; | ||
485 | * } | 487 | * } |
486 | * | 488 | * |
487 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) | 489 | * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused) |
@@ -493,6 +495,8 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
493 | * .trace = ftrace_raw_output_<call>, <-- stage 2 | 495 | * .trace = ftrace_raw_output_<call>, <-- stage 2 |
494 | * }; | 496 | * }; |
495 | * | 497 | * |
498 | * static const char print_fmt_<call>[] = <TP_printk>; | ||
499 | * | ||
496 | * static struct ftrace_event_call __used | 500 | * static struct ftrace_event_call __used |
497 | * __attribute__((__aligned__(4))) | 501 | * __attribute__((__aligned__(4))) |
498 | * __attribute__((section("_ftrace_events"))) event_<call> = { | 502 | * __attribute__((section("_ftrace_events"))) event_<call> = { |
@@ -501,6 +505,8 @@ perf_trace_disable_##name(struct ftrace_event_call *unused) \ | |||
501 | * .raw_init = trace_event_raw_init, | 505 | * .raw_init = trace_event_raw_init, |
502 | * .regfunc = ftrace_reg_event_<call>, | 506 | * .regfunc = ftrace_reg_event_<call>, |
503 | * .unregfunc = ftrace_unreg_event_<call>, | 507 | * .unregfunc = ftrace_unreg_event_<call>, |
508 | * .print_fmt = print_fmt_<call>, | ||
509 | * .define_fields = ftrace_define_fields_<call>, | ||
504 | * } | 510 | * } |
505 | * | 511 | * |
506 | */ | 512 | */ |
@@ -569,7 +575,6 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call, \ | |||
569 | return; \ | 575 | return; \ |
570 | entry = ring_buffer_event_data(event); \ | 576 | entry = ring_buffer_event_data(event); \ |
571 | \ | 577 | \ |
572 | \ | ||
573 | tstruct \ | 578 | tstruct \ |
574 | \ | 579 | \ |
575 | { assign; } \ | 580 | { assign; } \ |
@@ -758,13 +763,12 @@ __attribute__((section("_ftrace_events"))) event_##call = { \ | |||
758 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ | 763 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
759 | static notrace void \ | 764 | static notrace void \ |
760 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | 765 | perf_trace_templ_##call(struct ftrace_event_call *event_call, \ |
761 | proto) \ | 766 | struct pt_regs *__regs, proto) \ |
762 | { \ | 767 | { \ |
763 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ | 768 | struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\ |
764 | struct ftrace_raw_##call *entry; \ | 769 | struct ftrace_raw_##call *entry; \ |
765 | u64 __addr = 0, __count = 1; \ | 770 | u64 __addr = 0, __count = 1; \ |
766 | unsigned long irq_flags; \ | 771 | unsigned long irq_flags; \ |
767 | struct pt_regs *__regs; \ | ||
768 | int __entry_size; \ | 772 | int __entry_size; \ |
769 | int __data_size; \ | 773 | int __data_size; \ |
770 | int rctx; \ | 774 | int rctx; \ |
@@ -785,20 +789,22 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call, \ | |||
785 | \ | 789 | \ |
786 | { assign; } \ | 790 | { assign; } \ |
787 | \ | 791 | \ |
788 | __regs = &__get_cpu_var(perf_trace_regs); \ | ||
789 | perf_fetch_caller_regs(__regs, 2); \ | ||
790 | \ | ||
791 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ | 792 | perf_trace_buf_submit(entry, __entry_size, rctx, __addr, \ |
792 | __count, irq_flags, __regs); \ | 793 | __count, irq_flags, __regs); \ |
793 | } | 794 | } |
794 | 795 | ||
795 | #undef DEFINE_EVENT | 796 | #undef DEFINE_EVENT |
796 | #define DEFINE_EVENT(template, call, proto, args) \ | 797 | #define DEFINE_EVENT(template, call, proto, args) \ |
797 | static notrace void perf_trace_##call(proto) \ | 798 | static notrace void perf_trace_##call(proto) \ |
798 | { \ | 799 | { \ |
799 | struct ftrace_event_call *event_call = &event_##call; \ | 800 | struct ftrace_event_call *event_call = &event_##call; \ |
800 | \ | 801 | struct pt_regs *__regs = &get_cpu_var(perf_trace_regs); \ |
801 | perf_trace_templ_##template(event_call, args); \ | 802 | \ |
803 | perf_fetch_caller_regs(__regs, 1); \ | ||
804 | \ | ||
805 | perf_trace_templ_##template(event_call, __regs, args); \ | ||
806 | \ | ||
807 | put_cpu_var(perf_trace_regs); \ | ||
802 | } | 808 | } |
803 | 809 | ||
804 | #undef DEFINE_EVENT_PRINT | 810 | #undef DEFINE_EVENT_PRINT |
diff --git a/init/Kconfig b/init/Kconfig index eb77e8ccde1c..5fe94b82e4c0 100644 --- a/init/Kconfig +++ b/init/Kconfig | |||
@@ -604,8 +604,7 @@ config RT_GROUP_SCHED | |||
604 | default n | 604 | default n |
605 | help | 605 | help |
606 | This feature lets you explicitly allocate real CPU bandwidth | 606 | This feature lets you explicitly allocate real CPU bandwidth |
607 | to users or control groups (depending on the "Basis for grouping tasks" | 607 | to task groups. If enabled, it will also make it impossible to |
608 | setting below. If enabled, it will also make it impossible to | ||
609 | schedule realtime tasks for non-root users until you allocate | 608 | schedule realtime tasks for non-root users until you allocate |
610 | realtime bandwidth for them. | 609 | realtime bandwidth for them. |
611 | See Documentation/scheduler/sched-rt-group.txt for more information. | 610 | See Documentation/scheduler/sched-rt-group.txt for more information. |
diff --git a/kernel/Makefile b/kernel/Makefile index a987aa1676b5..149e18ef1ab1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -68,7 +68,7 @@ obj-$(CONFIG_USER_NS) += user_namespace.o | |||
68 | obj-$(CONFIG_PID_NS) += pid_namespace.o | 68 | obj-$(CONFIG_PID_NS) += pid_namespace.o |
69 | obj-$(CONFIG_IKCONFIG) += configs.o | 69 | obj-$(CONFIG_IKCONFIG) += configs.o |
70 | obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o | 70 | obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o |
71 | obj-$(CONFIG_STOP_MACHINE) += stop_machine.o | 71 | obj-$(CONFIG_SMP) += stop_machine.o |
72 | obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o | 72 | obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o |
73 | obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o | 73 | obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o |
74 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o | 74 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o |
diff --git a/kernel/capability.c b/kernel/capability.c index 9e4697e9b276..2f05303715a5 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/syscalls.h> | 15 | #include <linux/syscalls.h> |
16 | #include <linux/pid_namespace.h> | 16 | #include <linux/pid_namespace.h> |
17 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
18 | #include "cred-internals.h" | ||
19 | 18 | ||
20 | /* | 19 | /* |
21 | * Leveraged for setting/resetting capabilities | 20 | * Leveraged for setting/resetting capabilities |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 6d870f2d1228..e9ec642932ee 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -3016,7 +3016,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode, | |||
3016 | unsigned long flags = (unsigned long)key; | 3016 | unsigned long flags = (unsigned long)key; |
3017 | 3017 | ||
3018 | if (flags & POLLHUP) { | 3018 | if (flags & POLLHUP) { |
3019 | remove_wait_queue_locked(event->wqh, &event->wait); | 3019 | __remove_wait_queue(event->wqh, &event->wait); |
3020 | spin_lock(&cgrp->event_list_lock); | 3020 | spin_lock(&cgrp->event_list_lock); |
3021 | list_del(&event->list); | 3021 | list_del(&event->list); |
3022 | spin_unlock(&cgrp->event_list_lock); | 3022 | spin_unlock(&cgrp->event_list_lock); |
diff --git a/kernel/cpu.c b/kernel/cpu.c index 25bba73b1be3..545777574779 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c | |||
@@ -164,6 +164,7 @@ static inline void check_for_tasks(int cpu) | |||
164 | } | 164 | } |
165 | 165 | ||
166 | struct take_cpu_down_param { | 166 | struct take_cpu_down_param { |
167 | struct task_struct *caller; | ||
167 | unsigned long mod; | 168 | unsigned long mod; |
168 | void *hcpu; | 169 | void *hcpu; |
169 | }; | 170 | }; |
@@ -172,6 +173,7 @@ struct take_cpu_down_param { | |||
172 | static int __ref take_cpu_down(void *_param) | 173 | static int __ref take_cpu_down(void *_param) |
173 | { | 174 | { |
174 | struct take_cpu_down_param *param = _param; | 175 | struct take_cpu_down_param *param = _param; |
176 | unsigned int cpu = (unsigned long)param->hcpu; | ||
175 | int err; | 177 | int err; |
176 | 178 | ||
177 | /* Ensure this CPU doesn't handle any more interrupts. */ | 179 | /* Ensure this CPU doesn't handle any more interrupts. */ |
@@ -182,6 +184,8 @@ static int __ref take_cpu_down(void *_param) | |||
182 | raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod, | 184 | raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod, |
183 | param->hcpu); | 185 | param->hcpu); |
184 | 186 | ||
187 | if (task_cpu(param->caller) == cpu) | ||
188 | move_task_off_dead_cpu(cpu, param->caller); | ||
185 | /* Force idle task to run as soon as we yield: it should | 189 | /* Force idle task to run as soon as we yield: it should |
186 | immediately notice cpu is offline and die quickly. */ | 190 | immediately notice cpu is offline and die quickly. */ |
187 | sched_idle_next(); | 191 | sched_idle_next(); |
@@ -192,10 +196,10 @@ static int __ref take_cpu_down(void *_param) | |||
192 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | 196 | static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) |
193 | { | 197 | { |
194 | int err, nr_calls = 0; | 198 | int err, nr_calls = 0; |
195 | cpumask_var_t old_allowed; | ||
196 | void *hcpu = (void *)(long)cpu; | 199 | void *hcpu = (void *)(long)cpu; |
197 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; | 200 | unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0; |
198 | struct take_cpu_down_param tcd_param = { | 201 | struct take_cpu_down_param tcd_param = { |
202 | .caller = current, | ||
199 | .mod = mod, | 203 | .mod = mod, |
200 | .hcpu = hcpu, | 204 | .hcpu = hcpu, |
201 | }; | 205 | }; |
@@ -206,9 +210,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
206 | if (!cpu_online(cpu)) | 210 | if (!cpu_online(cpu)) |
207 | return -EINVAL; | 211 | return -EINVAL; |
208 | 212 | ||
209 | if (!alloc_cpumask_var(&old_allowed, GFP_KERNEL)) | ||
210 | return -ENOMEM; | ||
211 | |||
212 | cpu_hotplug_begin(); | 213 | cpu_hotplug_begin(); |
213 | set_cpu_active(cpu, false); | 214 | set_cpu_active(cpu, false); |
214 | err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod, | 215 | err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod, |
@@ -225,10 +226,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
225 | goto out_release; | 226 | goto out_release; |
226 | } | 227 | } |
227 | 228 | ||
228 | /* Ensure that we are not runnable on dying cpu */ | ||
229 | cpumask_copy(old_allowed, ¤t->cpus_allowed); | ||
230 | set_cpus_allowed_ptr(current, cpu_active_mask); | ||
231 | |||
232 | err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); | 229 | err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); |
233 | if (err) { | 230 | if (err) { |
234 | set_cpu_active(cpu, true); | 231 | set_cpu_active(cpu, true); |
@@ -237,7 +234,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
237 | hcpu) == NOTIFY_BAD) | 234 | hcpu) == NOTIFY_BAD) |
238 | BUG(); | 235 | BUG(); |
239 | 236 | ||
240 | goto out_allowed; | 237 | goto out_release; |
241 | } | 238 | } |
242 | BUG_ON(cpu_online(cpu)); | 239 | BUG_ON(cpu_online(cpu)); |
243 | 240 | ||
@@ -255,8 +252,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen) | |||
255 | 252 | ||
256 | check_for_tasks(cpu); | 253 | check_for_tasks(cpu); |
257 | 254 | ||
258 | out_allowed: | ||
259 | set_cpus_allowed_ptr(current, old_allowed); | ||
260 | out_release: | 255 | out_release: |
261 | cpu_hotplug_done(); | 256 | cpu_hotplug_done(); |
262 | if (!err) { | 257 | if (!err) { |
@@ -264,7 +259,6 @@ out_release: | |||
264 | hcpu) == NOTIFY_BAD) | 259 | hcpu) == NOTIFY_BAD) |
265 | BUG(); | 260 | BUG(); |
266 | } | 261 | } |
267 | free_cpumask_var(old_allowed); | ||
268 | return err; | 262 | return err; |
269 | } | 263 | } |
270 | 264 | ||
@@ -272,9 +266,6 @@ int __ref cpu_down(unsigned int cpu) | |||
272 | { | 266 | { |
273 | int err; | 267 | int err; |
274 | 268 | ||
275 | err = stop_machine_create(); | ||
276 | if (err) | ||
277 | return err; | ||
278 | cpu_maps_update_begin(); | 269 | cpu_maps_update_begin(); |
279 | 270 | ||
280 | if (cpu_hotplug_disabled) { | 271 | if (cpu_hotplug_disabled) { |
@@ -286,7 +277,6 @@ int __ref cpu_down(unsigned int cpu) | |||
286 | 277 | ||
287 | out: | 278 | out: |
288 | cpu_maps_update_done(); | 279 | cpu_maps_update_done(); |
289 | stop_machine_destroy(); | ||
290 | return err; | 280 | return err; |
291 | } | 281 | } |
292 | EXPORT_SYMBOL(cpu_down); | 282 | EXPORT_SYMBOL(cpu_down); |
@@ -367,9 +357,6 @@ int disable_nonboot_cpus(void) | |||
367 | { | 357 | { |
368 | int cpu, first_cpu, error; | 358 | int cpu, first_cpu, error; |
369 | 359 | ||
370 | error = stop_machine_create(); | ||
371 | if (error) | ||
372 | return error; | ||
373 | cpu_maps_update_begin(); | 360 | cpu_maps_update_begin(); |
374 | first_cpu = cpumask_first(cpu_online_mask); | 361 | first_cpu = cpumask_first(cpu_online_mask); |
375 | /* | 362 | /* |
@@ -400,7 +387,6 @@ int disable_nonboot_cpus(void) | |||
400 | printk(KERN_ERR "Non-boot CPUs are not disabled\n"); | 387 | printk(KERN_ERR "Non-boot CPUs are not disabled\n"); |
401 | } | 388 | } |
402 | cpu_maps_update_done(); | 389 | cpu_maps_update_done(); |
403 | stop_machine_destroy(); | ||
404 | return error; | 390 | return error; |
405 | } | 391 | } |
406 | 392 | ||
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index d10946748ec2..9a50c5f6e727 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -2182,19 +2182,52 @@ void __init cpuset_init_smp(void) | |||
2182 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) | 2182 | void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) |
2183 | { | 2183 | { |
2184 | mutex_lock(&callback_mutex); | 2184 | mutex_lock(&callback_mutex); |
2185 | cpuset_cpus_allowed_locked(tsk, pmask); | 2185 | task_lock(tsk); |
2186 | guarantee_online_cpus(task_cs(tsk), pmask); | ||
2187 | task_unlock(tsk); | ||
2186 | mutex_unlock(&callback_mutex); | 2188 | mutex_unlock(&callback_mutex); |
2187 | } | 2189 | } |
2188 | 2190 | ||
2189 | /** | 2191 | int cpuset_cpus_allowed_fallback(struct task_struct *tsk) |
2190 | * cpuset_cpus_allowed_locked - return cpus_allowed mask from a tasks cpuset. | ||
2191 | * Must be called with callback_mutex held. | ||
2192 | **/ | ||
2193 | void cpuset_cpus_allowed_locked(struct task_struct *tsk, struct cpumask *pmask) | ||
2194 | { | 2192 | { |
2195 | task_lock(tsk); | 2193 | const struct cpuset *cs; |
2196 | guarantee_online_cpus(task_cs(tsk), pmask); | 2194 | int cpu; |
2197 | task_unlock(tsk); | 2195 | |
2196 | rcu_read_lock(); | ||
2197 | cs = task_cs(tsk); | ||
2198 | if (cs) | ||
2199 | cpumask_copy(&tsk->cpus_allowed, cs->cpus_allowed); | ||
2200 | rcu_read_unlock(); | ||
2201 | |||
2202 | /* | ||
2203 | * We own tsk->cpus_allowed, nobody can change it under us. | ||
2204 | * | ||
2205 | * But we used cs && cs->cpus_allowed lockless and thus can | ||
2206 | * race with cgroup_attach_task() or update_cpumask() and get | ||
2207 | * the wrong tsk->cpus_allowed. However, both cases imply the | ||
2208 | * subsequent cpuset_change_cpumask()->set_cpus_allowed_ptr() | ||
2209 | * which takes task_rq_lock(). | ||
2210 | * | ||
2211 | * If we are called after it dropped the lock we must see all | ||
2212 | * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary | ||
2213 | * set any mask even if it is not right from task_cs() pov, | ||
2214 | * the pending set_cpus_allowed_ptr() will fix things. | ||
2215 | */ | ||
2216 | |||
2217 | cpu = cpumask_any_and(&tsk->cpus_allowed, cpu_active_mask); | ||
2218 | if (cpu >= nr_cpu_ids) { | ||
2219 | /* | ||
2220 | * Either tsk->cpus_allowed is wrong (see above) or it | ||
2221 | * is actually empty. The latter case is only possible | ||
2222 | * if we are racing with remove_tasks_in_empty_cpuset(). | ||
2223 | * Like above we can temporary set any mask and rely on | ||
2224 | * set_cpus_allowed_ptr() as synchronization point. | ||
2225 | */ | ||
2226 | cpumask_copy(&tsk->cpus_allowed, cpu_possible_mask); | ||
2227 | cpu = cpumask_any(cpu_active_mask); | ||
2228 | } | ||
2229 | |||
2230 | return cpu; | ||
2198 | } | 2231 | } |
2199 | 2232 | ||
2200 | void cpuset_init_current_mems_allowed(void) | 2233 | void cpuset_init_current_mems_allowed(void) |
@@ -2383,22 +2416,6 @@ int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask) | |||
2383 | } | 2416 | } |
2384 | 2417 | ||
2385 | /** | 2418 | /** |
2386 | * cpuset_lock - lock out any changes to cpuset structures | ||
2387 | * | ||
2388 | * The out of memory (oom) code needs to mutex_lock cpusets | ||
2389 | * from being changed while it scans the tasklist looking for a | ||
2390 | * task in an overlapping cpuset. Expose callback_mutex via this | ||
2391 | * cpuset_lock() routine, so the oom code can lock it, before | ||
2392 | * locking the task list. The tasklist_lock is a spinlock, so | ||
2393 | * must be taken inside callback_mutex. | ||
2394 | */ | ||
2395 | |||
2396 | void cpuset_lock(void) | ||
2397 | { | ||
2398 | mutex_lock(&callback_mutex); | ||
2399 | } | ||
2400 | |||
2401 | /** | ||
2402 | * cpuset_unlock - release lock on cpuset changes | 2419 | * cpuset_unlock - release lock on cpuset changes |
2403 | * | 2420 | * |
2404 | * Undo the lock taken in a previous cpuset_lock() call. | 2421 | * Undo the lock taken in a previous cpuset_lock() call. |
diff --git a/kernel/cred-internals.h b/kernel/cred-internals.h deleted file mode 100644 index 2dc4fc2d0bf1..000000000000 --- a/kernel/cred-internals.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | /* Internal credentials stuff | ||
2 | * | ||
3 | * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. | ||
4 | * Written by David Howells (dhowells@redhat.com) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public Licence | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the Licence, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * user.c | ||
14 | */ | ||
15 | static inline void sched_switch_user(struct task_struct *p) | ||
16 | { | ||
17 | #ifdef CONFIG_USER_SCHED | ||
18 | sched_move_task(p); | ||
19 | #endif /* CONFIG_USER_SCHED */ | ||
20 | } | ||
21 | |||
diff --git a/kernel/cred.c b/kernel/cred.c index 62af1816c235..8f3672a58a1e 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/init_task.h> | 17 | #include <linux/init_task.h> |
18 | #include <linux/security.h> | 18 | #include <linux/security.h> |
19 | #include <linux/cn_proc.h> | 19 | #include <linux/cn_proc.h> |
20 | #include "cred-internals.h" | ||
21 | 20 | ||
22 | #if 0 | 21 | #if 0 |
23 | #define kdebug(FMT, ...) \ | 22 | #define kdebug(FMT, ...) \ |
@@ -560,8 +559,6 @@ int commit_creds(struct cred *new) | |||
560 | atomic_dec(&old->user->processes); | 559 | atomic_dec(&old->user->processes); |
561 | alter_cred_subscribers(old, -2); | 560 | alter_cred_subscribers(old, -2); |
562 | 561 | ||
563 | sched_switch_user(task); | ||
564 | |||
565 | /* send notifications */ | 562 | /* send notifications */ |
566 | if (new->uid != old->uid || | 563 | if (new->uid != old->uid || |
567 | new->euid != old->euid || | 564 | new->euid != old->euid || |
diff --git a/kernel/exit.c b/kernel/exit.c index 7f2683a10ac4..eabca5a73a85 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -55,7 +55,6 @@ | |||
55 | #include <asm/unistd.h> | 55 | #include <asm/unistd.h> |
56 | #include <asm/pgtable.h> | 56 | #include <asm/pgtable.h> |
57 | #include <asm/mmu_context.h> | 57 | #include <asm/mmu_context.h> |
58 | #include "cred-internals.h" | ||
59 | 58 | ||
60 | static void exit_mm(struct task_struct * tsk); | 59 | static void exit_mm(struct task_struct * tsk); |
61 | 60 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index 4c14942a0ee3..4d57d9e3a6e9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1112,8 +1112,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1112 | p->memcg_batch.memcg = NULL; | 1112 | p->memcg_batch.memcg = NULL; |
1113 | #endif | 1113 | #endif |
1114 | 1114 | ||
1115 | p->bts = NULL; | ||
1116 | |||
1117 | /* Perform scheduler related setup. Assign this task to a CPU. */ | 1115 | /* Perform scheduler related setup. Assign this task to a CPU. */ |
1118 | sched_fork(p, clone_flags); | 1116 | sched_fork(p, clone_flags); |
1119 | 1117 | ||
diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c index 03808ed342a6..7a56b22e0602 100644 --- a/kernel/hw_breakpoint.c +++ b/kernel/hw_breakpoint.c | |||
@@ -40,23 +40,29 @@ | |||
40 | #include <linux/percpu.h> | 40 | #include <linux/percpu.h> |
41 | #include <linux/sched.h> | 41 | #include <linux/sched.h> |
42 | #include <linux/init.h> | 42 | #include <linux/init.h> |
43 | #include <linux/slab.h> | ||
43 | #include <linux/cpu.h> | 44 | #include <linux/cpu.h> |
44 | #include <linux/smp.h> | 45 | #include <linux/smp.h> |
45 | 46 | ||
46 | #include <linux/hw_breakpoint.h> | 47 | #include <linux/hw_breakpoint.h> |
47 | 48 | ||
49 | |||
48 | /* | 50 | /* |
49 | * Constraints data | 51 | * Constraints data |
50 | */ | 52 | */ |
51 | 53 | ||
52 | /* Number of pinned cpu breakpoints in a cpu */ | 54 | /* Number of pinned cpu breakpoints in a cpu */ |
53 | static DEFINE_PER_CPU(unsigned int, nr_cpu_bp_pinned); | 55 | static DEFINE_PER_CPU(unsigned int, nr_cpu_bp_pinned[TYPE_MAX]); |
54 | 56 | ||
55 | /* Number of pinned task breakpoints in a cpu */ | 57 | /* Number of pinned task breakpoints in a cpu */ |
56 | static DEFINE_PER_CPU(unsigned int, nr_task_bp_pinned[HBP_NUM]); | 58 | static DEFINE_PER_CPU(unsigned int *, nr_task_bp_pinned[TYPE_MAX]); |
57 | 59 | ||
58 | /* Number of non-pinned cpu/task breakpoints in a cpu */ | 60 | /* Number of non-pinned cpu/task breakpoints in a cpu */ |
59 | static DEFINE_PER_CPU(unsigned int, nr_bp_flexible); | 61 | static DEFINE_PER_CPU(unsigned int, nr_bp_flexible[TYPE_MAX]); |
62 | |||
63 | static int nr_slots[TYPE_MAX]; | ||
64 | |||
65 | static int constraints_initialized; | ||
60 | 66 | ||
61 | /* Gather the number of total pinned and un-pinned bp in a cpuset */ | 67 | /* Gather the number of total pinned and un-pinned bp in a cpuset */ |
62 | struct bp_busy_slots { | 68 | struct bp_busy_slots { |
@@ -67,16 +73,29 @@ struct bp_busy_slots { | |||
67 | /* Serialize accesses to the above constraints */ | 73 | /* Serialize accesses to the above constraints */ |
68 | static DEFINE_MUTEX(nr_bp_mutex); | 74 | static DEFINE_MUTEX(nr_bp_mutex); |
69 | 75 | ||
76 | __weak int hw_breakpoint_weight(struct perf_event *bp) | ||
77 | { | ||
78 | return 1; | ||
79 | } | ||
80 | |||
81 | static inline enum bp_type_idx find_slot_idx(struct perf_event *bp) | ||
82 | { | ||
83 | if (bp->attr.bp_type & HW_BREAKPOINT_RW) | ||
84 | return TYPE_DATA; | ||
85 | |||
86 | return TYPE_INST; | ||
87 | } | ||
88 | |||
70 | /* | 89 | /* |
71 | * Report the maximum number of pinned breakpoints a task | 90 | * Report the maximum number of pinned breakpoints a task |
72 | * have in this cpu | 91 | * have in this cpu |
73 | */ | 92 | */ |
74 | static unsigned int max_task_bp_pinned(int cpu) | 93 | static unsigned int max_task_bp_pinned(int cpu, enum bp_type_idx type) |
75 | { | 94 | { |
76 | int i; | 95 | int i; |
77 | unsigned int *tsk_pinned = per_cpu(nr_task_bp_pinned, cpu); | 96 | unsigned int *tsk_pinned = per_cpu(nr_task_bp_pinned[type], cpu); |
78 | 97 | ||
79 | for (i = HBP_NUM -1; i >= 0; i--) { | 98 | for (i = nr_slots[type] - 1; i >= 0; i--) { |
80 | if (tsk_pinned[i] > 0) | 99 | if (tsk_pinned[i] > 0) |
81 | return i + 1; | 100 | return i + 1; |
82 | } | 101 | } |
@@ -84,7 +103,7 @@ static unsigned int max_task_bp_pinned(int cpu) | |||
84 | return 0; | 103 | return 0; |
85 | } | 104 | } |
86 | 105 | ||
87 | static int task_bp_pinned(struct task_struct *tsk) | 106 | static int task_bp_pinned(struct task_struct *tsk, enum bp_type_idx type) |
88 | { | 107 | { |
89 | struct perf_event_context *ctx = tsk->perf_event_ctxp; | 108 | struct perf_event_context *ctx = tsk->perf_event_ctxp; |
90 | struct list_head *list; | 109 | struct list_head *list; |
@@ -105,7 +124,8 @@ static int task_bp_pinned(struct task_struct *tsk) | |||
105 | */ | 124 | */ |
106 | list_for_each_entry(bp, list, event_entry) { | 125 | list_for_each_entry(bp, list, event_entry) { |
107 | if (bp->attr.type == PERF_TYPE_BREAKPOINT) | 126 | if (bp->attr.type == PERF_TYPE_BREAKPOINT) |
108 | count++; | 127 | if (find_slot_idx(bp) == type) |
128 | count += hw_breakpoint_weight(bp); | ||
109 | } | 129 | } |
110 | 130 | ||
111 | raw_spin_unlock_irqrestore(&ctx->lock, flags); | 131 | raw_spin_unlock_irqrestore(&ctx->lock, flags); |
@@ -118,18 +138,19 @@ static int task_bp_pinned(struct task_struct *tsk) | |||
118 | * a given cpu (cpu > -1) or in all of them (cpu = -1). | 138 | * a given cpu (cpu > -1) or in all of them (cpu = -1). |
119 | */ | 139 | */ |
120 | static void | 140 | static void |
121 | fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp) | 141 | fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp, |
142 | enum bp_type_idx type) | ||
122 | { | 143 | { |
123 | int cpu = bp->cpu; | 144 | int cpu = bp->cpu; |
124 | struct task_struct *tsk = bp->ctx->task; | 145 | struct task_struct *tsk = bp->ctx->task; |
125 | 146 | ||
126 | if (cpu >= 0) { | 147 | if (cpu >= 0) { |
127 | slots->pinned = per_cpu(nr_cpu_bp_pinned, cpu); | 148 | slots->pinned = per_cpu(nr_cpu_bp_pinned[type], cpu); |
128 | if (!tsk) | 149 | if (!tsk) |
129 | slots->pinned += max_task_bp_pinned(cpu); | 150 | slots->pinned += max_task_bp_pinned(cpu, type); |
130 | else | 151 | else |
131 | slots->pinned += task_bp_pinned(tsk); | 152 | slots->pinned += task_bp_pinned(tsk, type); |
132 | slots->flexible = per_cpu(nr_bp_flexible, cpu); | 153 | slots->flexible = per_cpu(nr_bp_flexible[type], cpu); |
133 | 154 | ||
134 | return; | 155 | return; |
135 | } | 156 | } |
@@ -137,16 +158,16 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp) | |||
137 | for_each_online_cpu(cpu) { | 158 | for_each_online_cpu(cpu) { |
138 | unsigned int nr; | 159 | unsigned int nr; |
139 | 160 | ||
140 | nr = per_cpu(nr_cpu_bp_pinned, cpu); | 161 | nr = per_cpu(nr_cpu_bp_pinned[type], cpu); |
141 | if (!tsk) | 162 | if (!tsk) |
142 | nr += max_task_bp_pinned(cpu); | 163 | nr += max_task_bp_pinned(cpu, type); |
143 | else | 164 | else |
144 | nr += task_bp_pinned(tsk); | 165 | nr += task_bp_pinned(tsk, type); |
145 | 166 | ||
146 | if (nr > slots->pinned) | 167 | if (nr > slots->pinned) |
147 | slots->pinned = nr; | 168 | slots->pinned = nr; |
148 | 169 | ||
149 | nr = per_cpu(nr_bp_flexible, cpu); | 170 | nr = per_cpu(nr_bp_flexible[type], cpu); |
150 | 171 | ||
151 | if (nr > slots->flexible) | 172 | if (nr > slots->flexible) |
152 | slots->flexible = nr; | 173 | slots->flexible = nr; |
@@ -154,31 +175,49 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp) | |||
154 | } | 175 | } |
155 | 176 | ||
156 | /* | 177 | /* |
178 | * For now, continue to consider flexible as pinned, until we can | ||
179 | * ensure no flexible event can ever be scheduled before a pinned event | ||
180 | * in a same cpu. | ||
181 | */ | ||
182 | static void | ||
183 | fetch_this_slot(struct bp_busy_slots *slots, int weight) | ||
184 | { | ||
185 | slots->pinned += weight; | ||
186 | } | ||
187 | |||
188 | /* | ||
157 | * Add a pinned breakpoint for the given task in our constraint table | 189 | * Add a pinned breakpoint for the given task in our constraint table |
158 | */ | 190 | */ |
159 | static void toggle_bp_task_slot(struct task_struct *tsk, int cpu, bool enable) | 191 | static void toggle_bp_task_slot(struct task_struct *tsk, int cpu, bool enable, |
192 | enum bp_type_idx type, int weight) | ||
160 | { | 193 | { |
161 | unsigned int *tsk_pinned; | 194 | unsigned int *tsk_pinned; |
162 | int count = 0; | 195 | int old_count = 0; |
196 | int old_idx = 0; | ||
197 | int idx = 0; | ||
163 | 198 | ||
164 | count = task_bp_pinned(tsk); | 199 | old_count = task_bp_pinned(tsk, type); |
200 | old_idx = old_count - 1; | ||
201 | idx = old_idx + weight; | ||
165 | 202 | ||
166 | tsk_pinned = per_cpu(nr_task_bp_pinned, cpu); | 203 | tsk_pinned = per_cpu(nr_task_bp_pinned[type], cpu); |
167 | if (enable) { | 204 | if (enable) { |
168 | tsk_pinned[count]++; | 205 | tsk_pinned[idx]++; |
169 | if (count > 0) | 206 | if (old_count > 0) |
170 | tsk_pinned[count-1]--; | 207 | tsk_pinned[old_idx]--; |
171 | } else { | 208 | } else { |
172 | tsk_pinned[count]--; | 209 | tsk_pinned[idx]--; |
173 | if (count > 0) | 210 | if (old_count > 0) |
174 | tsk_pinned[count-1]++; | 211 | tsk_pinned[old_idx]++; |
175 | } | 212 | } |
176 | } | 213 | } |
177 | 214 | ||
178 | /* | 215 | /* |
179 | * Add/remove the given breakpoint in our constraint table | 216 | * Add/remove the given breakpoint in our constraint table |
180 | */ | 217 | */ |
181 | static void toggle_bp_slot(struct perf_event *bp, bool enable) | 218 | static void |
219 | toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type, | ||
220 | int weight) | ||
182 | { | 221 | { |
183 | int cpu = bp->cpu; | 222 | int cpu = bp->cpu; |
184 | struct task_struct *tsk = bp->ctx->task; | 223 | struct task_struct *tsk = bp->ctx->task; |
@@ -186,20 +225,20 @@ static void toggle_bp_slot(struct perf_event *bp, bool enable) | |||
186 | /* Pinned counter task profiling */ | 225 | /* Pinned counter task profiling */ |
187 | if (tsk) { | 226 | if (tsk) { |
188 | if (cpu >= 0) { | 227 | if (cpu >= 0) { |
189 | toggle_bp_task_slot(tsk, cpu, enable); | 228 | toggle_bp_task_slot(tsk, cpu, enable, type, weight); |
190 | return; | 229 | return; |
191 | } | 230 | } |
192 | 231 | ||
193 | for_each_online_cpu(cpu) | 232 | for_each_online_cpu(cpu) |
194 | toggle_bp_task_slot(tsk, cpu, enable); | 233 | toggle_bp_task_slot(tsk, cpu, enable, type, weight); |
195 | return; | 234 | return; |
196 | } | 235 | } |
197 | 236 | ||
198 | /* Pinned counter cpu profiling */ | 237 | /* Pinned counter cpu profiling */ |
199 | if (enable) | 238 | if (enable) |
200 | per_cpu(nr_cpu_bp_pinned, bp->cpu)++; | 239 | per_cpu(nr_cpu_bp_pinned[type], bp->cpu) += weight; |
201 | else | 240 | else |
202 | per_cpu(nr_cpu_bp_pinned, bp->cpu)--; | 241 | per_cpu(nr_cpu_bp_pinned[type], bp->cpu) -= weight; |
203 | } | 242 | } |
204 | 243 | ||
205 | /* | 244 | /* |
@@ -246,14 +285,29 @@ static void toggle_bp_slot(struct perf_event *bp, bool enable) | |||
246 | static int __reserve_bp_slot(struct perf_event *bp) | 285 | static int __reserve_bp_slot(struct perf_event *bp) |
247 | { | 286 | { |
248 | struct bp_busy_slots slots = {0}; | 287 | struct bp_busy_slots slots = {0}; |
288 | enum bp_type_idx type; | ||
289 | int weight; | ||
249 | 290 | ||
250 | fetch_bp_busy_slots(&slots, bp); | 291 | /* We couldn't initialize breakpoint constraints on boot */ |
292 | if (!constraints_initialized) | ||
293 | return -ENOMEM; | ||
294 | |||
295 | /* Basic checks */ | ||
296 | if (bp->attr.bp_type == HW_BREAKPOINT_EMPTY || | ||
297 | bp->attr.bp_type == HW_BREAKPOINT_INVALID) | ||
298 | return -EINVAL; | ||
299 | |||
300 | type = find_slot_idx(bp); | ||
301 | weight = hw_breakpoint_weight(bp); | ||
302 | |||
303 | fetch_bp_busy_slots(&slots, bp, type); | ||
304 | fetch_this_slot(&slots, weight); | ||
251 | 305 | ||
252 | /* Flexible counters need to keep at least one slot */ | 306 | /* Flexible counters need to keep at least one slot */ |
253 | if (slots.pinned + (!!slots.flexible) == HBP_NUM) | 307 | if (slots.pinned + (!!slots.flexible) > nr_slots[type]) |
254 | return -ENOSPC; | 308 | return -ENOSPC; |
255 | 309 | ||
256 | toggle_bp_slot(bp, true); | 310 | toggle_bp_slot(bp, true, type, weight); |
257 | 311 | ||
258 | return 0; | 312 | return 0; |
259 | } | 313 | } |
@@ -273,7 +327,12 @@ int reserve_bp_slot(struct perf_event *bp) | |||
273 | 327 | ||
274 | static void __release_bp_slot(struct perf_event *bp) | 328 | static void __release_bp_slot(struct perf_event *bp) |
275 | { | 329 | { |
276 | toggle_bp_slot(bp, false); | 330 | enum bp_type_idx type; |
331 | int weight; | ||
332 | |||
333 | type = find_slot_idx(bp); | ||
334 | weight = hw_breakpoint_weight(bp); | ||
335 | toggle_bp_slot(bp, false, type, weight); | ||
277 | } | 336 | } |
278 | 337 | ||
279 | void release_bp_slot(struct perf_event *bp) | 338 | void release_bp_slot(struct perf_event *bp) |
@@ -308,6 +367,28 @@ int dbg_release_bp_slot(struct perf_event *bp) | |||
308 | return 0; | 367 | return 0; |
309 | } | 368 | } |
310 | 369 | ||
370 | static int validate_hw_breakpoint(struct perf_event *bp) | ||
371 | { | ||
372 | int ret; | ||
373 | |||
374 | ret = arch_validate_hwbkpt_settings(bp); | ||
375 | if (ret) | ||
376 | return ret; | ||
377 | |||
378 | if (arch_check_bp_in_kernelspace(bp)) { | ||
379 | if (bp->attr.exclude_kernel) | ||
380 | return -EINVAL; | ||
381 | /* | ||
382 | * Don't let unprivileged users set a breakpoint in the trap | ||
383 | * path to avoid trap recursion attacks. | ||
384 | */ | ||
385 | if (!capable(CAP_SYS_ADMIN)) | ||
386 | return -EPERM; | ||
387 | } | ||
388 | |||
389 | return 0; | ||
390 | } | ||
391 | |||
311 | int register_perf_hw_breakpoint(struct perf_event *bp) | 392 | int register_perf_hw_breakpoint(struct perf_event *bp) |
312 | { | 393 | { |
313 | int ret; | 394 | int ret; |
@@ -316,17 +397,7 @@ int register_perf_hw_breakpoint(struct perf_event *bp) | |||
316 | if (ret) | 397 | if (ret) |
317 | return ret; | 398 | return ret; |
318 | 399 | ||
319 | /* | 400 | ret = validate_hw_breakpoint(bp); |
320 | * Ptrace breakpoints can be temporary perf events only | ||
321 | * meant to reserve a slot. In this case, it is created disabled and | ||
322 | * we don't want to check the params right now (as we put a null addr) | ||
323 | * But perf tools create events as disabled and we want to check | ||
324 | * the params for them. | ||
325 | * This is a quick hack that will be removed soon, once we remove | ||
326 | * the tmp breakpoints from ptrace | ||
327 | */ | ||
328 | if (!bp->attr.disabled || !bp->overflow_handler) | ||
329 | ret = arch_validate_hwbkpt_settings(bp, bp->ctx->task); | ||
330 | 401 | ||
331 | /* if arch_validate_hwbkpt_settings() fails then release bp slot */ | 402 | /* if arch_validate_hwbkpt_settings() fails then release bp slot */ |
332 | if (ret) | 403 | if (ret) |
@@ -373,7 +444,7 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att | |||
373 | if (attr->disabled) | 444 | if (attr->disabled) |
374 | goto end; | 445 | goto end; |
375 | 446 | ||
376 | err = arch_validate_hwbkpt_settings(bp, bp->ctx->task); | 447 | err = validate_hw_breakpoint(bp); |
377 | if (!err) | 448 | if (!err) |
378 | perf_event_enable(bp); | 449 | perf_event_enable(bp); |
379 | 450 | ||
@@ -480,7 +551,36 @@ static struct notifier_block hw_breakpoint_exceptions_nb = { | |||
480 | 551 | ||
481 | static int __init init_hw_breakpoint(void) | 552 | static int __init init_hw_breakpoint(void) |
482 | { | 553 | { |
554 | unsigned int **task_bp_pinned; | ||
555 | int cpu, err_cpu; | ||
556 | int i; | ||
557 | |||
558 | for (i = 0; i < TYPE_MAX; i++) | ||
559 | nr_slots[i] = hw_breakpoint_slots(i); | ||
560 | |||
561 | for_each_possible_cpu(cpu) { | ||
562 | for (i = 0; i < TYPE_MAX; i++) { | ||
563 | task_bp_pinned = &per_cpu(nr_task_bp_pinned[i], cpu); | ||
564 | *task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i], | ||
565 | GFP_KERNEL); | ||
566 | if (!*task_bp_pinned) | ||
567 | goto err_alloc; | ||
568 | } | ||
569 | } | ||
570 | |||
571 | constraints_initialized = 1; | ||
572 | |||
483 | return register_die_notifier(&hw_breakpoint_exceptions_nb); | 573 | return register_die_notifier(&hw_breakpoint_exceptions_nb); |
574 | |||
575 | err_alloc: | ||
576 | for_each_possible_cpu(err_cpu) { | ||
577 | if (err_cpu == cpu) | ||
578 | break; | ||
579 | for (i = 0; i < TYPE_MAX; i++) | ||
580 | kfree(per_cpu(nr_task_bp_pinned[i], cpu)); | ||
581 | } | ||
582 | |||
583 | return -ENOMEM; | ||
484 | } | 584 | } |
485 | core_initcall(init_hw_breakpoint); | 585 | core_initcall(init_hw_breakpoint); |
486 | 586 | ||
diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 0ed46f3e51e9..282035f3ae96 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c | |||
@@ -1588,6 +1588,72 @@ static void __kprobes kill_kprobe(struct kprobe *p) | |||
1588 | arch_remove_kprobe(p); | 1588 | arch_remove_kprobe(p); |
1589 | } | 1589 | } |
1590 | 1590 | ||
1591 | /* Disable one kprobe */ | ||
1592 | int __kprobes disable_kprobe(struct kprobe *kp) | ||
1593 | { | ||
1594 | int ret = 0; | ||
1595 | struct kprobe *p; | ||
1596 | |||
1597 | mutex_lock(&kprobe_mutex); | ||
1598 | |||
1599 | /* Check whether specified probe is valid. */ | ||
1600 | p = __get_valid_kprobe(kp); | ||
1601 | if (unlikely(p == NULL)) { | ||
1602 | ret = -EINVAL; | ||
1603 | goto out; | ||
1604 | } | ||
1605 | |||
1606 | /* If the probe is already disabled (or gone), just return */ | ||
1607 | if (kprobe_disabled(kp)) | ||
1608 | goto out; | ||
1609 | |||
1610 | kp->flags |= KPROBE_FLAG_DISABLED; | ||
1611 | if (p != kp) | ||
1612 | /* When kp != p, p is always enabled. */ | ||
1613 | try_to_disable_aggr_kprobe(p); | ||
1614 | |||
1615 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
1616 | disarm_kprobe(p); | ||
1617 | out: | ||
1618 | mutex_unlock(&kprobe_mutex); | ||
1619 | return ret; | ||
1620 | } | ||
1621 | EXPORT_SYMBOL_GPL(disable_kprobe); | ||
1622 | |||
1623 | /* Enable one kprobe */ | ||
1624 | int __kprobes enable_kprobe(struct kprobe *kp) | ||
1625 | { | ||
1626 | int ret = 0; | ||
1627 | struct kprobe *p; | ||
1628 | |||
1629 | mutex_lock(&kprobe_mutex); | ||
1630 | |||
1631 | /* Check whether specified probe is valid. */ | ||
1632 | p = __get_valid_kprobe(kp); | ||
1633 | if (unlikely(p == NULL)) { | ||
1634 | ret = -EINVAL; | ||
1635 | goto out; | ||
1636 | } | ||
1637 | |||
1638 | if (kprobe_gone(kp)) { | ||
1639 | /* This kprobe has gone, we couldn't enable it. */ | ||
1640 | ret = -EINVAL; | ||
1641 | goto out; | ||
1642 | } | ||
1643 | |||
1644 | if (p != kp) | ||
1645 | kp->flags &= ~KPROBE_FLAG_DISABLED; | ||
1646 | |||
1647 | if (!kprobes_all_disarmed && kprobe_disabled(p)) { | ||
1648 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
1649 | arm_kprobe(p); | ||
1650 | } | ||
1651 | out: | ||
1652 | mutex_unlock(&kprobe_mutex); | ||
1653 | return ret; | ||
1654 | } | ||
1655 | EXPORT_SYMBOL_GPL(enable_kprobe); | ||
1656 | |||
1591 | void __kprobes dump_kprobe(struct kprobe *kp) | 1657 | void __kprobes dump_kprobe(struct kprobe *kp) |
1592 | { | 1658 | { |
1593 | printk(KERN_WARNING "Dumping kprobe:\n"); | 1659 | printk(KERN_WARNING "Dumping kprobe:\n"); |
@@ -1805,72 +1871,6 @@ static const struct file_operations debugfs_kprobes_operations = { | |||
1805 | .release = seq_release, | 1871 | .release = seq_release, |
1806 | }; | 1872 | }; |
1807 | 1873 | ||
1808 | /* Disable one kprobe */ | ||
1809 | int __kprobes disable_kprobe(struct kprobe *kp) | ||
1810 | { | ||
1811 | int ret = 0; | ||
1812 | struct kprobe *p; | ||
1813 | |||
1814 | mutex_lock(&kprobe_mutex); | ||
1815 | |||
1816 | /* Check whether specified probe is valid. */ | ||
1817 | p = __get_valid_kprobe(kp); | ||
1818 | if (unlikely(p == NULL)) { | ||
1819 | ret = -EINVAL; | ||
1820 | goto out; | ||
1821 | } | ||
1822 | |||
1823 | /* If the probe is already disabled (or gone), just return */ | ||
1824 | if (kprobe_disabled(kp)) | ||
1825 | goto out; | ||
1826 | |||
1827 | kp->flags |= KPROBE_FLAG_DISABLED; | ||
1828 | if (p != kp) | ||
1829 | /* When kp != p, p is always enabled. */ | ||
1830 | try_to_disable_aggr_kprobe(p); | ||
1831 | |||
1832 | if (!kprobes_all_disarmed && kprobe_disabled(p)) | ||
1833 | disarm_kprobe(p); | ||
1834 | out: | ||
1835 | mutex_unlock(&kprobe_mutex); | ||
1836 | return ret; | ||
1837 | } | ||
1838 | EXPORT_SYMBOL_GPL(disable_kprobe); | ||
1839 | |||
1840 | /* Enable one kprobe */ | ||
1841 | int __kprobes enable_kprobe(struct kprobe *kp) | ||
1842 | { | ||
1843 | int ret = 0; | ||
1844 | struct kprobe *p; | ||
1845 | |||
1846 | mutex_lock(&kprobe_mutex); | ||
1847 | |||
1848 | /* Check whether specified probe is valid. */ | ||
1849 | p = __get_valid_kprobe(kp); | ||
1850 | if (unlikely(p == NULL)) { | ||
1851 | ret = -EINVAL; | ||
1852 | goto out; | ||
1853 | } | ||
1854 | |||
1855 | if (kprobe_gone(kp)) { | ||
1856 | /* This kprobe has gone, we couldn't enable it. */ | ||
1857 | ret = -EINVAL; | ||
1858 | goto out; | ||
1859 | } | ||
1860 | |||
1861 | if (p != kp) | ||
1862 | kp->flags &= ~KPROBE_FLAG_DISABLED; | ||
1863 | |||
1864 | if (!kprobes_all_disarmed && kprobe_disabled(p)) { | ||
1865 | p->flags &= ~KPROBE_FLAG_DISABLED; | ||
1866 | arm_kprobe(p); | ||
1867 | } | ||
1868 | out: | ||
1869 | mutex_unlock(&kprobe_mutex); | ||
1870 | return ret; | ||
1871 | } | ||
1872 | EXPORT_SYMBOL_GPL(enable_kprobe); | ||
1873 | |||
1874 | static void __kprobes arm_all_kprobes(void) | 1874 | static void __kprobes arm_all_kprobes(void) |
1875 | { | 1875 | { |
1876 | struct hlist_head *head; | 1876 | struct hlist_head *head; |
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 2594e1ce41cb..ec21304856d1 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -431,20 +431,7 @@ static struct stack_trace lockdep_init_trace = { | |||
431 | /* | 431 | /* |
432 | * Various lockdep statistics: | 432 | * Various lockdep statistics: |
433 | */ | 433 | */ |
434 | atomic_t chain_lookup_hits; | 434 | DEFINE_PER_CPU(struct lockdep_stats, lockdep_stats); |
435 | atomic_t chain_lookup_misses; | ||
436 | atomic_t hardirqs_on_events; | ||
437 | atomic_t hardirqs_off_events; | ||
438 | atomic_t redundant_hardirqs_on; | ||
439 | atomic_t redundant_hardirqs_off; | ||
440 | atomic_t softirqs_on_events; | ||
441 | atomic_t softirqs_off_events; | ||
442 | atomic_t redundant_softirqs_on; | ||
443 | atomic_t redundant_softirqs_off; | ||
444 | atomic_t nr_unused_locks; | ||
445 | atomic_t nr_cyclic_checks; | ||
446 | atomic_t nr_find_usage_forwards_checks; | ||
447 | atomic_t nr_find_usage_backwards_checks; | ||
448 | #endif | 435 | #endif |
449 | 436 | ||
450 | /* | 437 | /* |
@@ -748,7 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) | |||
748 | return NULL; | 735 | return NULL; |
749 | } | 736 | } |
750 | class = lock_classes + nr_lock_classes++; | 737 | class = lock_classes + nr_lock_classes++; |
751 | debug_atomic_inc(&nr_unused_locks); | 738 | debug_atomic_inc(nr_unused_locks); |
752 | class->key = key; | 739 | class->key = key; |
753 | class->name = lock->name; | 740 | class->name = lock->name; |
754 | class->subclass = subclass; | 741 | class->subclass = subclass; |
@@ -818,7 +805,8 @@ static struct lock_list *alloc_list_entry(void) | |||
818 | * Add a new dependency to the head of the list: | 805 | * Add a new dependency to the head of the list: |
819 | */ | 806 | */ |
820 | static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | 807 | static int add_lock_to_list(struct lock_class *class, struct lock_class *this, |
821 | struct list_head *head, unsigned long ip, int distance) | 808 | struct list_head *head, unsigned long ip, |
809 | int distance, struct stack_trace *trace) | ||
822 | { | 810 | { |
823 | struct lock_list *entry; | 811 | struct lock_list *entry; |
824 | /* | 812 | /* |
@@ -829,11 +817,9 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
829 | if (!entry) | 817 | if (!entry) |
830 | return 0; | 818 | return 0; |
831 | 819 | ||
832 | if (!save_trace(&entry->trace)) | ||
833 | return 0; | ||
834 | |||
835 | entry->class = this; | 820 | entry->class = this; |
836 | entry->distance = distance; | 821 | entry->distance = distance; |
822 | entry->trace = *trace; | ||
837 | /* | 823 | /* |
838 | * Since we never remove from the dependency list, the list can | 824 | * Since we never remove from the dependency list, the list can |
839 | * be walked lockless by other CPUs, it's only allocation | 825 | * be walked lockless by other CPUs, it's only allocation |
@@ -1205,7 +1191,7 @@ check_noncircular(struct lock_list *root, struct lock_class *target, | |||
1205 | { | 1191 | { |
1206 | int result; | 1192 | int result; |
1207 | 1193 | ||
1208 | debug_atomic_inc(&nr_cyclic_checks); | 1194 | debug_atomic_inc(nr_cyclic_checks); |
1209 | 1195 | ||
1210 | result = __bfs_forwards(root, target, class_equal, target_entry); | 1196 | result = __bfs_forwards(root, target, class_equal, target_entry); |
1211 | 1197 | ||
@@ -1242,7 +1228,7 @@ find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit, | |||
1242 | { | 1228 | { |
1243 | int result; | 1229 | int result; |
1244 | 1230 | ||
1245 | debug_atomic_inc(&nr_find_usage_forwards_checks); | 1231 | debug_atomic_inc(nr_find_usage_forwards_checks); |
1246 | 1232 | ||
1247 | result = __bfs_forwards(root, (void *)bit, usage_match, target_entry); | 1233 | result = __bfs_forwards(root, (void *)bit, usage_match, target_entry); |
1248 | 1234 | ||
@@ -1265,7 +1251,7 @@ find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit, | |||
1265 | { | 1251 | { |
1266 | int result; | 1252 | int result; |
1267 | 1253 | ||
1268 | debug_atomic_inc(&nr_find_usage_backwards_checks); | 1254 | debug_atomic_inc(nr_find_usage_backwards_checks); |
1269 | 1255 | ||
1270 | result = __bfs_backwards(root, (void *)bit, usage_match, target_entry); | 1256 | result = __bfs_backwards(root, (void *)bit, usage_match, target_entry); |
1271 | 1257 | ||
@@ -1635,12 +1621,20 @@ check_deadlock(struct task_struct *curr, struct held_lock *next, | |||
1635 | */ | 1621 | */ |
1636 | static int | 1622 | static int |
1637 | check_prev_add(struct task_struct *curr, struct held_lock *prev, | 1623 | check_prev_add(struct task_struct *curr, struct held_lock *prev, |
1638 | struct held_lock *next, int distance) | 1624 | struct held_lock *next, int distance, int trylock_loop) |
1639 | { | 1625 | { |
1640 | struct lock_list *entry; | 1626 | struct lock_list *entry; |
1641 | int ret; | 1627 | int ret; |
1642 | struct lock_list this; | 1628 | struct lock_list this; |
1643 | struct lock_list *uninitialized_var(target_entry); | 1629 | struct lock_list *uninitialized_var(target_entry); |
1630 | /* | ||
1631 | * Static variable, serialized by the graph_lock(). | ||
1632 | * | ||
1633 | * We use this static variable to save the stack trace in case | ||
1634 | * we call into this function multiple times due to encountering | ||
1635 | * trylocks in the held lock stack. | ||
1636 | */ | ||
1637 | static struct stack_trace trace; | ||
1644 | 1638 | ||
1645 | /* | 1639 | /* |
1646 | * Prove that the new <prev> -> <next> dependency would not | 1640 | * Prove that the new <prev> -> <next> dependency would not |
@@ -1688,20 +1682,23 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1688 | } | 1682 | } |
1689 | } | 1683 | } |
1690 | 1684 | ||
1685 | if (!trylock_loop && !save_trace(&trace)) | ||
1686 | return 0; | ||
1687 | |||
1691 | /* | 1688 | /* |
1692 | * Ok, all validations passed, add the new lock | 1689 | * Ok, all validations passed, add the new lock |
1693 | * to the previous lock's dependency list: | 1690 | * to the previous lock's dependency list: |
1694 | */ | 1691 | */ |
1695 | ret = add_lock_to_list(hlock_class(prev), hlock_class(next), | 1692 | ret = add_lock_to_list(hlock_class(prev), hlock_class(next), |
1696 | &hlock_class(prev)->locks_after, | 1693 | &hlock_class(prev)->locks_after, |
1697 | next->acquire_ip, distance); | 1694 | next->acquire_ip, distance, &trace); |
1698 | 1695 | ||
1699 | if (!ret) | 1696 | if (!ret) |
1700 | return 0; | 1697 | return 0; |
1701 | 1698 | ||
1702 | ret = add_lock_to_list(hlock_class(next), hlock_class(prev), | 1699 | ret = add_lock_to_list(hlock_class(next), hlock_class(prev), |
1703 | &hlock_class(next)->locks_before, | 1700 | &hlock_class(next)->locks_before, |
1704 | next->acquire_ip, distance); | 1701 | next->acquire_ip, distance, &trace); |
1705 | if (!ret) | 1702 | if (!ret) |
1706 | return 0; | 1703 | return 0; |
1707 | 1704 | ||
@@ -1731,6 +1728,7 @@ static int | |||
1731 | check_prevs_add(struct task_struct *curr, struct held_lock *next) | 1728 | check_prevs_add(struct task_struct *curr, struct held_lock *next) |
1732 | { | 1729 | { |
1733 | int depth = curr->lockdep_depth; | 1730 | int depth = curr->lockdep_depth; |
1731 | int trylock_loop = 0; | ||
1734 | struct held_lock *hlock; | 1732 | struct held_lock *hlock; |
1735 | 1733 | ||
1736 | /* | 1734 | /* |
@@ -1756,7 +1754,8 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next) | |||
1756 | * added: | 1754 | * added: |
1757 | */ | 1755 | */ |
1758 | if (hlock->read != 2) { | 1756 | if (hlock->read != 2) { |
1759 | if (!check_prev_add(curr, hlock, next, distance)) | 1757 | if (!check_prev_add(curr, hlock, next, |
1758 | distance, trylock_loop)) | ||
1760 | return 0; | 1759 | return 0; |
1761 | /* | 1760 | /* |
1762 | * Stop after the first non-trylock entry, | 1761 | * Stop after the first non-trylock entry, |
@@ -1779,6 +1778,7 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next) | |||
1779 | if (curr->held_locks[depth].irq_context != | 1778 | if (curr->held_locks[depth].irq_context != |
1780 | curr->held_locks[depth-1].irq_context) | 1779 | curr->held_locks[depth-1].irq_context) |
1781 | break; | 1780 | break; |
1781 | trylock_loop = 1; | ||
1782 | } | 1782 | } |
1783 | return 1; | 1783 | return 1; |
1784 | out_bug: | 1784 | out_bug: |
@@ -1825,7 +1825,7 @@ static inline int lookup_chain_cache(struct task_struct *curr, | |||
1825 | list_for_each_entry(chain, hash_head, entry) { | 1825 | list_for_each_entry(chain, hash_head, entry) { |
1826 | if (chain->chain_key == chain_key) { | 1826 | if (chain->chain_key == chain_key) { |
1827 | cache_hit: | 1827 | cache_hit: |
1828 | debug_atomic_inc(&chain_lookup_hits); | 1828 | debug_atomic_inc(chain_lookup_hits); |
1829 | if (very_verbose(class)) | 1829 | if (very_verbose(class)) |
1830 | printk("\nhash chain already cached, key: " | 1830 | printk("\nhash chain already cached, key: " |
1831 | "%016Lx tail class: [%p] %s\n", | 1831 | "%016Lx tail class: [%p] %s\n", |
@@ -1890,7 +1890,7 @@ cache_hit: | |||
1890 | chain_hlocks[chain->base + j] = class - lock_classes; | 1890 | chain_hlocks[chain->base + j] = class - lock_classes; |
1891 | } | 1891 | } |
1892 | list_add_tail_rcu(&chain->entry, hash_head); | 1892 | list_add_tail_rcu(&chain->entry, hash_head); |
1893 | debug_atomic_inc(&chain_lookup_misses); | 1893 | debug_atomic_inc(chain_lookup_misses); |
1894 | inc_chains(); | 1894 | inc_chains(); |
1895 | 1895 | ||
1896 | return 1; | 1896 | return 1; |
@@ -2311,7 +2311,12 @@ void trace_hardirqs_on_caller(unsigned long ip) | |||
2311 | return; | 2311 | return; |
2312 | 2312 | ||
2313 | if (unlikely(curr->hardirqs_enabled)) { | 2313 | if (unlikely(curr->hardirqs_enabled)) { |
2314 | debug_atomic_inc(&redundant_hardirqs_on); | 2314 | /* |
2315 | * Neither irq nor preemption are disabled here | ||
2316 | * so this is racy by nature but loosing one hit | ||
2317 | * in a stat is not a big deal. | ||
2318 | */ | ||
2319 | __debug_atomic_inc(redundant_hardirqs_on); | ||
2315 | return; | 2320 | return; |
2316 | } | 2321 | } |
2317 | /* we'll do an OFF -> ON transition: */ | 2322 | /* we'll do an OFF -> ON transition: */ |
@@ -2338,7 +2343,7 @@ void trace_hardirqs_on_caller(unsigned long ip) | |||
2338 | 2343 | ||
2339 | curr->hardirq_enable_ip = ip; | 2344 | curr->hardirq_enable_ip = ip; |
2340 | curr->hardirq_enable_event = ++curr->irq_events; | 2345 | curr->hardirq_enable_event = ++curr->irq_events; |
2341 | debug_atomic_inc(&hardirqs_on_events); | 2346 | debug_atomic_inc(hardirqs_on_events); |
2342 | } | 2347 | } |
2343 | EXPORT_SYMBOL(trace_hardirqs_on_caller); | 2348 | EXPORT_SYMBOL(trace_hardirqs_on_caller); |
2344 | 2349 | ||
@@ -2370,9 +2375,9 @@ void trace_hardirqs_off_caller(unsigned long ip) | |||
2370 | curr->hardirqs_enabled = 0; | 2375 | curr->hardirqs_enabled = 0; |
2371 | curr->hardirq_disable_ip = ip; | 2376 | curr->hardirq_disable_ip = ip; |
2372 | curr->hardirq_disable_event = ++curr->irq_events; | 2377 | curr->hardirq_disable_event = ++curr->irq_events; |
2373 | debug_atomic_inc(&hardirqs_off_events); | 2378 | debug_atomic_inc(hardirqs_off_events); |
2374 | } else | 2379 | } else |
2375 | debug_atomic_inc(&redundant_hardirqs_off); | 2380 | debug_atomic_inc(redundant_hardirqs_off); |
2376 | } | 2381 | } |
2377 | EXPORT_SYMBOL(trace_hardirqs_off_caller); | 2382 | EXPORT_SYMBOL(trace_hardirqs_off_caller); |
2378 | 2383 | ||
@@ -2396,7 +2401,7 @@ void trace_softirqs_on(unsigned long ip) | |||
2396 | return; | 2401 | return; |
2397 | 2402 | ||
2398 | if (curr->softirqs_enabled) { | 2403 | if (curr->softirqs_enabled) { |
2399 | debug_atomic_inc(&redundant_softirqs_on); | 2404 | debug_atomic_inc(redundant_softirqs_on); |
2400 | return; | 2405 | return; |
2401 | } | 2406 | } |
2402 | 2407 | ||
@@ -2406,7 +2411,7 @@ void trace_softirqs_on(unsigned long ip) | |||
2406 | curr->softirqs_enabled = 1; | 2411 | curr->softirqs_enabled = 1; |
2407 | curr->softirq_enable_ip = ip; | 2412 | curr->softirq_enable_ip = ip; |
2408 | curr->softirq_enable_event = ++curr->irq_events; | 2413 | curr->softirq_enable_event = ++curr->irq_events; |
2409 | debug_atomic_inc(&softirqs_on_events); | 2414 | debug_atomic_inc(softirqs_on_events); |
2410 | /* | 2415 | /* |
2411 | * We are going to turn softirqs on, so set the | 2416 | * We are going to turn softirqs on, so set the |
2412 | * usage bit for all held locks, if hardirqs are | 2417 | * usage bit for all held locks, if hardirqs are |
@@ -2436,10 +2441,10 @@ void trace_softirqs_off(unsigned long ip) | |||
2436 | curr->softirqs_enabled = 0; | 2441 | curr->softirqs_enabled = 0; |
2437 | curr->softirq_disable_ip = ip; | 2442 | curr->softirq_disable_ip = ip; |
2438 | curr->softirq_disable_event = ++curr->irq_events; | 2443 | curr->softirq_disable_event = ++curr->irq_events; |
2439 | debug_atomic_inc(&softirqs_off_events); | 2444 | debug_atomic_inc(softirqs_off_events); |
2440 | DEBUG_LOCKS_WARN_ON(!softirq_count()); | 2445 | DEBUG_LOCKS_WARN_ON(!softirq_count()); |
2441 | } else | 2446 | } else |
2442 | debug_atomic_inc(&redundant_softirqs_off); | 2447 | debug_atomic_inc(redundant_softirqs_off); |
2443 | } | 2448 | } |
2444 | 2449 | ||
2445 | static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags) | 2450 | static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags) |
@@ -2644,7 +2649,7 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, | |||
2644 | return 0; | 2649 | return 0; |
2645 | break; | 2650 | break; |
2646 | case LOCK_USED: | 2651 | case LOCK_USED: |
2647 | debug_atomic_dec(&nr_unused_locks); | 2652 | debug_atomic_dec(nr_unused_locks); |
2648 | break; | 2653 | break; |
2649 | default: | 2654 | default: |
2650 | if (!debug_locks_off_graph_unlock()) | 2655 | if (!debug_locks_off_graph_unlock()) |
@@ -2750,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, | |||
2750 | if (!class) | 2755 | if (!class) |
2751 | return 0; | 2756 | return 0; |
2752 | } | 2757 | } |
2753 | debug_atomic_inc((atomic_t *)&class->ops); | 2758 | atomic_inc((atomic_t *)&class->ops); |
2754 | if (very_verbose(class)) { | 2759 | if (very_verbose(class)) { |
2755 | printk("\nacquire class [%p] %s", class->key, class->name); | 2760 | printk("\nacquire class [%p] %s", class->key, class->name); |
2756 | if (class->name_version > 1) | 2761 | if (class->name_version > 1) |
@@ -3227,7 +3232,7 @@ void lock_release(struct lockdep_map *lock, int nested, | |||
3227 | raw_local_irq_save(flags); | 3232 | raw_local_irq_save(flags); |
3228 | check_flags(flags); | 3233 | check_flags(flags); |
3229 | current->lockdep_recursion = 1; | 3234 | current->lockdep_recursion = 1; |
3230 | trace_lock_release(lock, nested, ip); | 3235 | trace_lock_release(lock, ip); |
3231 | __lock_release(lock, nested, ip); | 3236 | __lock_release(lock, nested, ip); |
3232 | current->lockdep_recursion = 0; | 3237 | current->lockdep_recursion = 0; |
3233 | raw_local_irq_restore(flags); | 3238 | raw_local_irq_restore(flags); |
@@ -3380,7 +3385,7 @@ found_it: | |||
3380 | hlock->holdtime_stamp = now; | 3385 | hlock->holdtime_stamp = now; |
3381 | } | 3386 | } |
3382 | 3387 | ||
3383 | trace_lock_acquired(lock, ip, waittime); | 3388 | trace_lock_acquired(lock, ip); |
3384 | 3389 | ||
3385 | stats = get_lock_stats(hlock_class(hlock)); | 3390 | stats = get_lock_stats(hlock_class(hlock)); |
3386 | if (waittime) { | 3391 | if (waittime) { |
@@ -3801,8 +3806,11 @@ void lockdep_rcu_dereference(const char *file, const int line) | |||
3801 | { | 3806 | { |
3802 | struct task_struct *curr = current; | 3807 | struct task_struct *curr = current; |
3803 | 3808 | ||
3809 | #ifndef CONFIG_PROVE_RCU_REPEATEDLY | ||
3804 | if (!debug_locks_off()) | 3810 | if (!debug_locks_off()) |
3805 | return; | 3811 | return; |
3812 | #endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */ | ||
3813 | /* Note: the following can be executed concurrently, so be careful. */ | ||
3806 | printk("\n===================================================\n"); | 3814 | printk("\n===================================================\n"); |
3807 | printk( "[ INFO: suspicious rcu_dereference_check() usage. ]\n"); | 3815 | printk( "[ INFO: suspicious rcu_dereference_check() usage. ]\n"); |
3808 | printk( "---------------------------------------------------\n"); | 3816 | printk( "---------------------------------------------------\n"); |
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h index a2ee95ad1313..4f560cfedc8f 100644 --- a/kernel/lockdep_internals.h +++ b/kernel/lockdep_internals.h | |||
@@ -110,30 +110,60 @@ lockdep_count_backward_deps(struct lock_class *class) | |||
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | #ifdef CONFIG_DEBUG_LOCKDEP | 112 | #ifdef CONFIG_DEBUG_LOCKDEP |
113 | |||
114 | #include <asm/local.h> | ||
113 | /* | 115 | /* |
114 | * Various lockdep statistics: | 116 | * Various lockdep statistics. |
117 | * We want them per cpu as they are often accessed in fast path | ||
118 | * and we want to avoid too much cache bouncing. | ||
115 | */ | 119 | */ |
116 | extern atomic_t chain_lookup_hits; | 120 | struct lockdep_stats { |
117 | extern atomic_t chain_lookup_misses; | 121 | int chain_lookup_hits; |
118 | extern atomic_t hardirqs_on_events; | 122 | int chain_lookup_misses; |
119 | extern atomic_t hardirqs_off_events; | 123 | int hardirqs_on_events; |
120 | extern atomic_t redundant_hardirqs_on; | 124 | int hardirqs_off_events; |
121 | extern atomic_t redundant_hardirqs_off; | 125 | int redundant_hardirqs_on; |
122 | extern atomic_t softirqs_on_events; | 126 | int redundant_hardirqs_off; |
123 | extern atomic_t softirqs_off_events; | 127 | int softirqs_on_events; |
124 | extern atomic_t redundant_softirqs_on; | 128 | int softirqs_off_events; |
125 | extern atomic_t redundant_softirqs_off; | 129 | int redundant_softirqs_on; |
126 | extern atomic_t nr_unused_locks; | 130 | int redundant_softirqs_off; |
127 | extern atomic_t nr_cyclic_checks; | 131 | int nr_unused_locks; |
128 | extern atomic_t nr_cyclic_check_recursions; | 132 | int nr_cyclic_checks; |
129 | extern atomic_t nr_find_usage_forwards_checks; | 133 | int nr_cyclic_check_recursions; |
130 | extern atomic_t nr_find_usage_forwards_recursions; | 134 | int nr_find_usage_forwards_checks; |
131 | extern atomic_t nr_find_usage_backwards_checks; | 135 | int nr_find_usage_forwards_recursions; |
132 | extern atomic_t nr_find_usage_backwards_recursions; | 136 | int nr_find_usage_backwards_checks; |
133 | # define debug_atomic_inc(ptr) atomic_inc(ptr) | 137 | int nr_find_usage_backwards_recursions; |
134 | # define debug_atomic_dec(ptr) atomic_dec(ptr) | 138 | }; |
135 | # define debug_atomic_read(ptr) atomic_read(ptr) | 139 | |
140 | DECLARE_PER_CPU(struct lockdep_stats, lockdep_stats); | ||
141 | |||
142 | #define __debug_atomic_inc(ptr) \ | ||
143 | this_cpu_inc(lockdep_stats.ptr); | ||
144 | |||
145 | #define debug_atomic_inc(ptr) { \ | ||
146 | WARN_ON_ONCE(!irqs_disabled()); \ | ||
147 | __this_cpu_inc(lockdep_stats.ptr); \ | ||
148 | } | ||
149 | |||
150 | #define debug_atomic_dec(ptr) { \ | ||
151 | WARN_ON_ONCE(!irqs_disabled()); \ | ||
152 | __this_cpu_dec(lockdep_stats.ptr); \ | ||
153 | } | ||
154 | |||
155 | #define debug_atomic_read(ptr) ({ \ | ||
156 | struct lockdep_stats *__cpu_lockdep_stats; \ | ||
157 | unsigned long long __total = 0; \ | ||
158 | int __cpu; \ | ||
159 | for_each_possible_cpu(__cpu) { \ | ||
160 | __cpu_lockdep_stats = &per_cpu(lockdep_stats, __cpu); \ | ||
161 | __total += __cpu_lockdep_stats->ptr; \ | ||
162 | } \ | ||
163 | __total; \ | ||
164 | }) | ||
136 | #else | 165 | #else |
166 | # define __debug_atomic_inc(ptr) do { } while (0) | ||
137 | # define debug_atomic_inc(ptr) do { } while (0) | 167 | # define debug_atomic_inc(ptr) do { } while (0) |
138 | # define debug_atomic_dec(ptr) do { } while (0) | 168 | # define debug_atomic_dec(ptr) do { } while (0) |
139 | # define debug_atomic_read(ptr) 0 | 169 | # define debug_atomic_read(ptr) 0 |
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index d4aba4f3584c..59b76c8ce9d7 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
@@ -184,34 +184,34 @@ static const struct file_operations proc_lockdep_chains_operations = { | |||
184 | static void lockdep_stats_debug_show(struct seq_file *m) | 184 | static void lockdep_stats_debug_show(struct seq_file *m) |
185 | { | 185 | { |
186 | #ifdef CONFIG_DEBUG_LOCKDEP | 186 | #ifdef CONFIG_DEBUG_LOCKDEP |
187 | unsigned int hi1 = debug_atomic_read(&hardirqs_on_events), | 187 | unsigned long long hi1 = debug_atomic_read(hardirqs_on_events), |
188 | hi2 = debug_atomic_read(&hardirqs_off_events), | 188 | hi2 = debug_atomic_read(hardirqs_off_events), |
189 | hr1 = debug_atomic_read(&redundant_hardirqs_on), | 189 | hr1 = debug_atomic_read(redundant_hardirqs_on), |
190 | hr2 = debug_atomic_read(&redundant_hardirqs_off), | 190 | hr2 = debug_atomic_read(redundant_hardirqs_off), |
191 | si1 = debug_atomic_read(&softirqs_on_events), | 191 | si1 = debug_atomic_read(softirqs_on_events), |
192 | si2 = debug_atomic_read(&softirqs_off_events), | 192 | si2 = debug_atomic_read(softirqs_off_events), |
193 | sr1 = debug_atomic_read(&redundant_softirqs_on), | 193 | sr1 = debug_atomic_read(redundant_softirqs_on), |
194 | sr2 = debug_atomic_read(&redundant_softirqs_off); | 194 | sr2 = debug_atomic_read(redundant_softirqs_off); |
195 | 195 | ||
196 | seq_printf(m, " chain lookup misses: %11u\n", | 196 | seq_printf(m, " chain lookup misses: %11llu\n", |
197 | debug_atomic_read(&chain_lookup_misses)); | 197 | debug_atomic_read(chain_lookup_misses)); |
198 | seq_printf(m, " chain lookup hits: %11u\n", | 198 | seq_printf(m, " chain lookup hits: %11llu\n", |
199 | debug_atomic_read(&chain_lookup_hits)); | 199 | debug_atomic_read(chain_lookup_hits)); |
200 | seq_printf(m, " cyclic checks: %11u\n", | 200 | seq_printf(m, " cyclic checks: %11llu\n", |
201 | debug_atomic_read(&nr_cyclic_checks)); | 201 | debug_atomic_read(nr_cyclic_checks)); |
202 | seq_printf(m, " find-mask forwards checks: %11u\n", | 202 | seq_printf(m, " find-mask forwards checks: %11llu\n", |
203 | debug_atomic_read(&nr_find_usage_forwards_checks)); | 203 | debug_atomic_read(nr_find_usage_forwards_checks)); |
204 | seq_printf(m, " find-mask backwards checks: %11u\n", | 204 | seq_printf(m, " find-mask backwards checks: %11llu\n", |
205 | debug_atomic_read(&nr_find_usage_backwards_checks)); | 205 | debug_atomic_read(nr_find_usage_backwards_checks)); |
206 | 206 | ||
207 | seq_printf(m, " hardirq on events: %11u\n", hi1); | 207 | seq_printf(m, " hardirq on events: %11llu\n", hi1); |
208 | seq_printf(m, " hardirq off events: %11u\n", hi2); | 208 | seq_printf(m, " hardirq off events: %11llu\n", hi2); |
209 | seq_printf(m, " redundant hardirq ons: %11u\n", hr1); | 209 | seq_printf(m, " redundant hardirq ons: %11llu\n", hr1); |
210 | seq_printf(m, " redundant hardirq offs: %11u\n", hr2); | 210 | seq_printf(m, " redundant hardirq offs: %11llu\n", hr2); |
211 | seq_printf(m, " softirq on events: %11u\n", si1); | 211 | seq_printf(m, " softirq on events: %11llu\n", si1); |
212 | seq_printf(m, " softirq off events: %11u\n", si2); | 212 | seq_printf(m, " softirq off events: %11llu\n", si2); |
213 | seq_printf(m, " redundant softirq ons: %11u\n", sr1); | 213 | seq_printf(m, " redundant softirq ons: %11llu\n", sr1); |
214 | seq_printf(m, " redundant softirq offs: %11u\n", sr2); | 214 | seq_printf(m, " redundant softirq offs: %11llu\n", sr2); |
215 | #endif | 215 | #endif |
216 | } | 216 | } |
217 | 217 | ||
@@ -263,7 +263,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v) | |||
263 | #endif | 263 | #endif |
264 | } | 264 | } |
265 | #ifdef CONFIG_DEBUG_LOCKDEP | 265 | #ifdef CONFIG_DEBUG_LOCKDEP |
266 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused); | 266 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused); |
267 | #endif | 267 | #endif |
268 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", | 268 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", |
269 | nr_lock_classes, MAX_LOCKDEP_KEYS); | 269 | nr_lock_classes, MAX_LOCKDEP_KEYS); |
diff --git a/kernel/module.c b/kernel/module.c index 1016b75b026a..e2564580f3f1 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -59,8 +59,6 @@ | |||
59 | #define CREATE_TRACE_POINTS | 59 | #define CREATE_TRACE_POINTS |
60 | #include <trace/events/module.h> | 60 | #include <trace/events/module.h> |
61 | 61 | ||
62 | EXPORT_TRACEPOINT_SYMBOL(module_get); | ||
63 | |||
64 | #if 0 | 62 | #if 0 |
65 | #define DEBUGP printk | 63 | #define DEBUGP printk |
66 | #else | 64 | #else |
@@ -515,6 +513,9 @@ MODINFO_ATTR(srcversion); | |||
515 | static char last_unloaded_module[MODULE_NAME_LEN+1]; | 513 | static char last_unloaded_module[MODULE_NAME_LEN+1]; |
516 | 514 | ||
517 | #ifdef CONFIG_MODULE_UNLOAD | 515 | #ifdef CONFIG_MODULE_UNLOAD |
516 | |||
517 | EXPORT_TRACEPOINT_SYMBOL(module_get); | ||
518 | |||
518 | /* Init the unload section of the module. */ | 519 | /* Init the unload section of the module. */ |
519 | static void module_unload_init(struct module *mod) | 520 | static void module_unload_init(struct module *mod) |
520 | { | 521 | { |
@@ -723,16 +724,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, | |||
723 | return -EFAULT; | 724 | return -EFAULT; |
724 | name[MODULE_NAME_LEN-1] = '\0'; | 725 | name[MODULE_NAME_LEN-1] = '\0'; |
725 | 726 | ||
726 | /* Create stop_machine threads since free_module relies on | 727 | if (mutex_lock_interruptible(&module_mutex) != 0) |
727 | * a non-failing stop_machine call. */ | 728 | return -EINTR; |
728 | ret = stop_machine_create(); | ||
729 | if (ret) | ||
730 | return ret; | ||
731 | |||
732 | if (mutex_lock_interruptible(&module_mutex) != 0) { | ||
733 | ret = -EINTR; | ||
734 | goto out_stop; | ||
735 | } | ||
736 | 729 | ||
737 | mod = find_module(name); | 730 | mod = find_module(name); |
738 | if (!mod) { | 731 | if (!mod) { |
@@ -792,8 +785,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, | |||
792 | 785 | ||
793 | out: | 786 | out: |
794 | mutex_unlock(&module_mutex); | 787 | mutex_unlock(&module_mutex); |
795 | out_stop: | ||
796 | stop_machine_destroy(); | ||
797 | return ret; | 788 | return ret; |
798 | } | 789 | } |
799 | 790 | ||
@@ -867,8 +858,7 @@ void module_put(struct module *module) | |||
867 | smp_wmb(); /* see comment in module_refcount */ | 858 | smp_wmb(); /* see comment in module_refcount */ |
868 | __this_cpu_inc(module->refptr->decs); | 859 | __this_cpu_inc(module->refptr->decs); |
869 | 860 | ||
870 | trace_module_put(module, _RET_IP_, | 861 | trace_module_put(module, _RET_IP_); |
871 | __this_cpu_read(module->refptr->decs)); | ||
872 | /* Maybe they're waiting for us to drop reference? */ | 862 | /* Maybe they're waiting for us to drop reference? */ |
873 | if (unlikely(!module_is_live(module))) | 863 | if (unlikely(!module_is_live(module))) |
874 | wake_up_process(module->waiter); | 864 | wake_up_process(module->waiter); |
diff --git a/kernel/perf_event.c b/kernel/perf_event.c index 3d1552d3c12b..a4fa381db3c2 100644 --- a/kernel/perf_event.c +++ b/kernel/perf_event.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/file.h> | 16 | #include <linux/file.h> |
17 | #include <linux/poll.h> | 17 | #include <linux/poll.h> |
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/hash.h> | ||
19 | #include <linux/sysfs.h> | 20 | #include <linux/sysfs.h> |
20 | #include <linux/dcache.h> | 21 | #include <linux/dcache.h> |
21 | #include <linux/percpu.h> | 22 | #include <linux/percpu.h> |
@@ -82,14 +83,6 @@ extern __weak const struct pmu *hw_perf_event_init(struct perf_event *event) | |||
82 | void __weak hw_perf_disable(void) { barrier(); } | 83 | void __weak hw_perf_disable(void) { barrier(); } |
83 | void __weak hw_perf_enable(void) { barrier(); } | 84 | void __weak hw_perf_enable(void) { barrier(); } |
84 | 85 | ||
85 | int __weak | ||
86 | hw_perf_group_sched_in(struct perf_event *group_leader, | ||
87 | struct perf_cpu_context *cpuctx, | ||
88 | struct perf_event_context *ctx) | ||
89 | { | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | void __weak perf_event_print_debug(void) { } | 86 | void __weak perf_event_print_debug(void) { } |
94 | 87 | ||
95 | static DEFINE_PER_CPU(int, perf_disable_count); | 88 | static DEFINE_PER_CPU(int, perf_disable_count); |
@@ -262,6 +255,18 @@ static void update_event_times(struct perf_event *event) | |||
262 | event->total_time_running = run_end - event->tstamp_running; | 255 | event->total_time_running = run_end - event->tstamp_running; |
263 | } | 256 | } |
264 | 257 | ||
258 | /* | ||
259 | * Update total_time_enabled and total_time_running for all events in a group. | ||
260 | */ | ||
261 | static void update_group_times(struct perf_event *leader) | ||
262 | { | ||
263 | struct perf_event *event; | ||
264 | |||
265 | update_event_times(leader); | ||
266 | list_for_each_entry(event, &leader->sibling_list, group_entry) | ||
267 | update_event_times(event); | ||
268 | } | ||
269 | |||
265 | static struct list_head * | 270 | static struct list_head * |
266 | ctx_group_list(struct perf_event *event, struct perf_event_context *ctx) | 271 | ctx_group_list(struct perf_event *event, struct perf_event_context *ctx) |
267 | { | 272 | { |
@@ -315,8 +320,6 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx) | |||
315 | static void | 320 | static void |
316 | list_del_event(struct perf_event *event, struct perf_event_context *ctx) | 321 | list_del_event(struct perf_event *event, struct perf_event_context *ctx) |
317 | { | 322 | { |
318 | struct perf_event *sibling, *tmp; | ||
319 | |||
320 | if (list_empty(&event->group_entry)) | 323 | if (list_empty(&event->group_entry)) |
321 | return; | 324 | return; |
322 | ctx->nr_events--; | 325 | ctx->nr_events--; |
@@ -329,7 +332,7 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx) | |||
329 | if (event->group_leader != event) | 332 | if (event->group_leader != event) |
330 | event->group_leader->nr_siblings--; | 333 | event->group_leader->nr_siblings--; |
331 | 334 | ||
332 | update_event_times(event); | 335 | update_group_times(event); |
333 | 336 | ||
334 | /* | 337 | /* |
335 | * If event was in error state, then keep it | 338 | * If event was in error state, then keep it |
@@ -340,6 +343,12 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx) | |||
340 | */ | 343 | */ |
341 | if (event->state > PERF_EVENT_STATE_OFF) | 344 | if (event->state > PERF_EVENT_STATE_OFF) |
342 | event->state = PERF_EVENT_STATE_OFF; | 345 | event->state = PERF_EVENT_STATE_OFF; |
346 | } | ||
347 | |||
348 | static void | ||
349 | perf_destroy_group(struct perf_event *event, struct perf_event_context *ctx) | ||
350 | { | ||
351 | struct perf_event *sibling, *tmp; | ||
343 | 352 | ||
344 | /* | 353 | /* |
345 | * If this was a group event with sibling events then | 354 | * If this was a group event with sibling events then |
@@ -505,18 +514,6 @@ retry: | |||
505 | } | 514 | } |
506 | 515 | ||
507 | /* | 516 | /* |
508 | * Update total_time_enabled and total_time_running for all events in a group. | ||
509 | */ | ||
510 | static void update_group_times(struct perf_event *leader) | ||
511 | { | ||
512 | struct perf_event *event; | ||
513 | |||
514 | update_event_times(leader); | ||
515 | list_for_each_entry(event, &leader->sibling_list, group_entry) | ||
516 | update_event_times(event); | ||
517 | } | ||
518 | |||
519 | /* | ||
520 | * Cross CPU call to disable a performance event | 517 | * Cross CPU call to disable a performance event |
521 | */ | 518 | */ |
522 | static void __perf_event_disable(void *info) | 519 | static void __perf_event_disable(void *info) |
@@ -640,15 +637,20 @@ group_sched_in(struct perf_event *group_event, | |||
640 | struct perf_cpu_context *cpuctx, | 637 | struct perf_cpu_context *cpuctx, |
641 | struct perf_event_context *ctx) | 638 | struct perf_event_context *ctx) |
642 | { | 639 | { |
643 | struct perf_event *event, *partial_group; | 640 | struct perf_event *event, *partial_group = NULL; |
641 | const struct pmu *pmu = group_event->pmu; | ||
642 | bool txn = false; | ||
644 | int ret; | 643 | int ret; |
645 | 644 | ||
646 | if (group_event->state == PERF_EVENT_STATE_OFF) | 645 | if (group_event->state == PERF_EVENT_STATE_OFF) |
647 | return 0; | 646 | return 0; |
648 | 647 | ||
649 | ret = hw_perf_group_sched_in(group_event, cpuctx, ctx); | 648 | /* Check if group transaction availabe */ |
650 | if (ret) | 649 | if (pmu->start_txn) |
651 | return ret < 0 ? ret : 0; | 650 | txn = true; |
651 | |||
652 | if (txn) | ||
653 | pmu->start_txn(pmu); | ||
652 | 654 | ||
653 | if (event_sched_in(group_event, cpuctx, ctx)) | 655 | if (event_sched_in(group_event, cpuctx, ctx)) |
654 | return -EAGAIN; | 656 | return -EAGAIN; |
@@ -663,9 +665,19 @@ group_sched_in(struct perf_event *group_event, | |||
663 | } | 665 | } |
664 | } | 666 | } |
665 | 667 | ||
666 | return 0; | 668 | if (!txn) |
669 | return 0; | ||
670 | |||
671 | ret = pmu->commit_txn(pmu); | ||
672 | if (!ret) { | ||
673 | pmu->cancel_txn(pmu); | ||
674 | return 0; | ||
675 | } | ||
667 | 676 | ||
668 | group_error: | 677 | group_error: |
678 | if (txn) | ||
679 | pmu->cancel_txn(pmu); | ||
680 | |||
669 | /* | 681 | /* |
670 | * Groups can be scheduled in as one unit only, so undo any | 682 | * Groups can be scheduled in as one unit only, so undo any |
671 | * partial group before returning: | 683 | * partial group before returning: |
@@ -1367,6 +1379,8 @@ void perf_event_task_sched_in(struct task_struct *task) | |||
1367 | if (cpuctx->task_ctx == ctx) | 1379 | if (cpuctx->task_ctx == ctx) |
1368 | return; | 1380 | return; |
1369 | 1381 | ||
1382 | perf_disable(); | ||
1383 | |||
1370 | /* | 1384 | /* |
1371 | * We want to keep the following priority order: | 1385 | * We want to keep the following priority order: |
1372 | * cpu pinned (that don't need to move), task pinned, | 1386 | * cpu pinned (that don't need to move), task pinned, |
@@ -1379,6 +1393,8 @@ void perf_event_task_sched_in(struct task_struct *task) | |||
1379 | ctx_sched_in(ctx, cpuctx, EVENT_FLEXIBLE); | 1393 | ctx_sched_in(ctx, cpuctx, EVENT_FLEXIBLE); |
1380 | 1394 | ||
1381 | cpuctx->task_ctx = ctx; | 1395 | cpuctx->task_ctx = ctx; |
1396 | |||
1397 | perf_enable(); | ||
1382 | } | 1398 | } |
1383 | 1399 | ||
1384 | #define MAX_INTERRUPTS (~0ULL) | 1400 | #define MAX_INTERRUPTS (~0ULL) |
@@ -1856,9 +1872,30 @@ int perf_event_release_kernel(struct perf_event *event) | |||
1856 | { | 1872 | { |
1857 | struct perf_event_context *ctx = event->ctx; | 1873 | struct perf_event_context *ctx = event->ctx; |
1858 | 1874 | ||
1875 | /* | ||
1876 | * Remove from the PMU, can't get re-enabled since we got | ||
1877 | * here because the last ref went. | ||
1878 | */ | ||
1879 | perf_event_disable(event); | ||
1880 | |||
1859 | WARN_ON_ONCE(ctx->parent_ctx); | 1881 | WARN_ON_ONCE(ctx->parent_ctx); |
1860 | mutex_lock(&ctx->mutex); | 1882 | /* |
1861 | perf_event_remove_from_context(event); | 1883 | * There are two ways this annotation is useful: |
1884 | * | ||
1885 | * 1) there is a lock recursion from perf_event_exit_task | ||
1886 | * see the comment there. | ||
1887 | * | ||
1888 | * 2) there is a lock-inversion with mmap_sem through | ||
1889 | * perf_event_read_group(), which takes faults while | ||
1890 | * holding ctx->mutex, however this is called after | ||
1891 | * the last filedesc died, so there is no possibility | ||
1892 | * to trigger the AB-BA case. | ||
1893 | */ | ||
1894 | mutex_lock_nested(&ctx->mutex, SINGLE_DEPTH_NESTING); | ||
1895 | raw_spin_lock_irq(&ctx->lock); | ||
1896 | list_del_event(event, ctx); | ||
1897 | perf_destroy_group(event, ctx); | ||
1898 | raw_spin_unlock_irq(&ctx->lock); | ||
1862 | mutex_unlock(&ctx->mutex); | 1899 | mutex_unlock(&ctx->mutex); |
1863 | 1900 | ||
1864 | mutex_lock(&event->owner->perf_event_mutex); | 1901 | mutex_lock(&event->owner->perf_event_mutex); |
@@ -2642,6 +2679,7 @@ static int perf_fasync(int fd, struct file *filp, int on) | |||
2642 | } | 2679 | } |
2643 | 2680 | ||
2644 | static const struct file_operations perf_fops = { | 2681 | static const struct file_operations perf_fops = { |
2682 | .llseek = no_llseek, | ||
2645 | .release = perf_release, | 2683 | .release = perf_release, |
2646 | .read = perf_read, | 2684 | .read = perf_read, |
2647 | .poll = perf_poll, | 2685 | .poll = perf_poll, |
@@ -2792,6 +2830,27 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski | |||
2792 | 2830 | ||
2793 | 2831 | ||
2794 | /* | 2832 | /* |
2833 | * We assume there is only KVM supporting the callbacks. | ||
2834 | * Later on, we might change it to a list if there is | ||
2835 | * another virtualization implementation supporting the callbacks. | ||
2836 | */ | ||
2837 | struct perf_guest_info_callbacks *perf_guest_cbs; | ||
2838 | |||
2839 | int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) | ||
2840 | { | ||
2841 | perf_guest_cbs = cbs; | ||
2842 | return 0; | ||
2843 | } | ||
2844 | EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks); | ||
2845 | |||
2846 | int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) | ||
2847 | { | ||
2848 | perf_guest_cbs = NULL; | ||
2849 | return 0; | ||
2850 | } | ||
2851 | EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); | ||
2852 | |||
2853 | /* | ||
2795 | * Output | 2854 | * Output |
2796 | */ | 2855 | */ |
2797 | static bool perf_output_space(struct perf_mmap_data *data, unsigned long tail, | 2856 | static bool perf_output_space(struct perf_mmap_data *data, unsigned long tail, |
@@ -3743,7 +3802,7 @@ void __perf_event_mmap(struct vm_area_struct *vma) | |||
3743 | .event_id = { | 3802 | .event_id = { |
3744 | .header = { | 3803 | .header = { |
3745 | .type = PERF_RECORD_MMAP, | 3804 | .type = PERF_RECORD_MMAP, |
3746 | .misc = 0, | 3805 | .misc = PERF_RECORD_MISC_USER, |
3747 | /* .size */ | 3806 | /* .size */ |
3748 | }, | 3807 | }, |
3749 | /* .pid */ | 3808 | /* .pid */ |
@@ -3961,36 +4020,6 @@ static void perf_swevent_add(struct perf_event *event, u64 nr, | |||
3961 | perf_swevent_overflow(event, 0, nmi, data, regs); | 4020 | perf_swevent_overflow(event, 0, nmi, data, regs); |
3962 | } | 4021 | } |
3963 | 4022 | ||
3964 | static int perf_swevent_is_counting(struct perf_event *event) | ||
3965 | { | ||
3966 | /* | ||
3967 | * The event is active, we're good! | ||
3968 | */ | ||
3969 | if (event->state == PERF_EVENT_STATE_ACTIVE) | ||
3970 | return 1; | ||
3971 | |||
3972 | /* | ||
3973 | * The event is off/error, not counting. | ||
3974 | */ | ||
3975 | if (event->state != PERF_EVENT_STATE_INACTIVE) | ||
3976 | return 0; | ||
3977 | |||
3978 | /* | ||
3979 | * The event is inactive, if the context is active | ||
3980 | * we're part of a group that didn't make it on the 'pmu', | ||
3981 | * not counting. | ||
3982 | */ | ||
3983 | if (event->ctx->is_active) | ||
3984 | return 0; | ||
3985 | |||
3986 | /* | ||
3987 | * We're inactive and the context is too, this means the | ||
3988 | * task is scheduled out, we're counting events that happen | ||
3989 | * to us, like migration events. | ||
3990 | */ | ||
3991 | return 1; | ||
3992 | } | ||
3993 | |||
3994 | static int perf_tp_event_match(struct perf_event *event, | 4023 | static int perf_tp_event_match(struct perf_event *event, |
3995 | struct perf_sample_data *data); | 4024 | struct perf_sample_data *data); |
3996 | 4025 | ||
@@ -4014,12 +4043,6 @@ static int perf_swevent_match(struct perf_event *event, | |||
4014 | struct perf_sample_data *data, | 4043 | struct perf_sample_data *data, |
4015 | struct pt_regs *regs) | 4044 | struct pt_regs *regs) |
4016 | { | 4045 | { |
4017 | if (event->cpu != -1 && event->cpu != smp_processor_id()) | ||
4018 | return 0; | ||
4019 | |||
4020 | if (!perf_swevent_is_counting(event)) | ||
4021 | return 0; | ||
4022 | |||
4023 | if (event->attr.type != type) | 4046 | if (event->attr.type != type) |
4024 | return 0; | 4047 | return 0; |
4025 | 4048 | ||
@@ -4036,18 +4059,53 @@ static int perf_swevent_match(struct perf_event *event, | |||
4036 | return 1; | 4059 | return 1; |
4037 | } | 4060 | } |
4038 | 4061 | ||
4039 | static void perf_swevent_ctx_event(struct perf_event_context *ctx, | 4062 | static inline u64 swevent_hash(u64 type, u32 event_id) |
4040 | enum perf_type_id type, | ||
4041 | u32 event_id, u64 nr, int nmi, | ||
4042 | struct perf_sample_data *data, | ||
4043 | struct pt_regs *regs) | ||
4044 | { | 4063 | { |
4064 | u64 val = event_id | (type << 32); | ||
4065 | |||
4066 | return hash_64(val, SWEVENT_HLIST_BITS); | ||
4067 | } | ||
4068 | |||
4069 | static struct hlist_head * | ||
4070 | find_swevent_head(struct perf_cpu_context *ctx, u64 type, u32 event_id) | ||
4071 | { | ||
4072 | u64 hash; | ||
4073 | struct swevent_hlist *hlist; | ||
4074 | |||
4075 | hash = swevent_hash(type, event_id); | ||
4076 | |||
4077 | hlist = rcu_dereference(ctx->swevent_hlist); | ||
4078 | if (!hlist) | ||
4079 | return NULL; | ||
4080 | |||
4081 | return &hlist->heads[hash]; | ||
4082 | } | ||
4083 | |||
4084 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | ||
4085 | u64 nr, int nmi, | ||
4086 | struct perf_sample_data *data, | ||
4087 | struct pt_regs *regs) | ||
4088 | { | ||
4089 | struct perf_cpu_context *cpuctx; | ||
4045 | struct perf_event *event; | 4090 | struct perf_event *event; |
4091 | struct hlist_node *node; | ||
4092 | struct hlist_head *head; | ||
4046 | 4093 | ||
4047 | list_for_each_entry_rcu(event, &ctx->event_list, event_entry) { | 4094 | cpuctx = &__get_cpu_var(perf_cpu_context); |
4095 | |||
4096 | rcu_read_lock(); | ||
4097 | |||
4098 | head = find_swevent_head(cpuctx, type, event_id); | ||
4099 | |||
4100 | if (!head) | ||
4101 | goto end; | ||
4102 | |||
4103 | hlist_for_each_entry_rcu(event, node, head, hlist_entry) { | ||
4048 | if (perf_swevent_match(event, type, event_id, data, regs)) | 4104 | if (perf_swevent_match(event, type, event_id, data, regs)) |
4049 | perf_swevent_add(event, nr, nmi, data, regs); | 4105 | perf_swevent_add(event, nr, nmi, data, regs); |
4050 | } | 4106 | } |
4107 | end: | ||
4108 | rcu_read_unlock(); | ||
4051 | } | 4109 | } |
4052 | 4110 | ||
4053 | int perf_swevent_get_recursion_context(void) | 4111 | int perf_swevent_get_recursion_context(void) |
@@ -4085,27 +4143,6 @@ void perf_swevent_put_recursion_context(int rctx) | |||
4085 | } | 4143 | } |
4086 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); | 4144 | EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context); |
4087 | 4145 | ||
4088 | static void do_perf_sw_event(enum perf_type_id type, u32 event_id, | ||
4089 | u64 nr, int nmi, | ||
4090 | struct perf_sample_data *data, | ||
4091 | struct pt_regs *regs) | ||
4092 | { | ||
4093 | struct perf_cpu_context *cpuctx; | ||
4094 | struct perf_event_context *ctx; | ||
4095 | |||
4096 | cpuctx = &__get_cpu_var(perf_cpu_context); | ||
4097 | rcu_read_lock(); | ||
4098 | perf_swevent_ctx_event(&cpuctx->ctx, type, event_id, | ||
4099 | nr, nmi, data, regs); | ||
4100 | /* | ||
4101 | * doesn't really matter which of the child contexts the | ||
4102 | * events ends up in. | ||
4103 | */ | ||
4104 | ctx = rcu_dereference(current->perf_event_ctxp); | ||
4105 | if (ctx) | ||
4106 | perf_swevent_ctx_event(ctx, type, event_id, nr, nmi, data, regs); | ||
4107 | rcu_read_unlock(); | ||
4108 | } | ||
4109 | 4146 | ||
4110 | void __perf_sw_event(u32 event_id, u64 nr, int nmi, | 4147 | void __perf_sw_event(u32 event_id, u64 nr, int nmi, |
4111 | struct pt_regs *regs, u64 addr) | 4148 | struct pt_regs *regs, u64 addr) |
@@ -4131,16 +4168,28 @@ static void perf_swevent_read(struct perf_event *event) | |||
4131 | static int perf_swevent_enable(struct perf_event *event) | 4168 | static int perf_swevent_enable(struct perf_event *event) |
4132 | { | 4169 | { |
4133 | struct hw_perf_event *hwc = &event->hw; | 4170 | struct hw_perf_event *hwc = &event->hw; |
4171 | struct perf_cpu_context *cpuctx; | ||
4172 | struct hlist_head *head; | ||
4173 | |||
4174 | cpuctx = &__get_cpu_var(perf_cpu_context); | ||
4134 | 4175 | ||
4135 | if (hwc->sample_period) { | 4176 | if (hwc->sample_period) { |
4136 | hwc->last_period = hwc->sample_period; | 4177 | hwc->last_period = hwc->sample_period; |
4137 | perf_swevent_set_period(event); | 4178 | perf_swevent_set_period(event); |
4138 | } | 4179 | } |
4180 | |||
4181 | head = find_swevent_head(cpuctx, event->attr.type, event->attr.config); | ||
4182 | if (WARN_ON_ONCE(!head)) | ||
4183 | return -EINVAL; | ||
4184 | |||
4185 | hlist_add_head_rcu(&event->hlist_entry, head); | ||
4186 | |||
4139 | return 0; | 4187 | return 0; |
4140 | } | 4188 | } |
4141 | 4189 | ||
4142 | static void perf_swevent_disable(struct perf_event *event) | 4190 | static void perf_swevent_disable(struct perf_event *event) |
4143 | { | 4191 | { |
4192 | hlist_del_rcu(&event->hlist_entry); | ||
4144 | } | 4193 | } |
4145 | 4194 | ||
4146 | static const struct pmu perf_ops_generic = { | 4195 | static const struct pmu perf_ops_generic = { |
@@ -4168,15 +4217,8 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer) | |||
4168 | perf_sample_data_init(&data, 0); | 4217 | perf_sample_data_init(&data, 0); |
4169 | data.period = event->hw.last_period; | 4218 | data.period = event->hw.last_period; |
4170 | regs = get_irq_regs(); | 4219 | regs = get_irq_regs(); |
4171 | /* | ||
4172 | * In case we exclude kernel IPs or are somehow not in interrupt | ||
4173 | * context, provide the next best thing, the user IP. | ||
4174 | */ | ||
4175 | if ((event->attr.exclude_kernel || !regs) && | ||
4176 | !event->attr.exclude_user) | ||
4177 | regs = task_pt_regs(current); | ||
4178 | 4220 | ||
4179 | if (regs) { | 4221 | if (regs && !perf_exclude_event(event, regs)) { |
4180 | if (!(event->attr.exclude_idle && current->pid == 0)) | 4222 | if (!(event->attr.exclude_idle && current->pid == 0)) |
4181 | if (perf_event_overflow(event, 0, &data, regs)) | 4223 | if (perf_event_overflow(event, 0, &data, regs)) |
4182 | ret = HRTIMER_NORESTART; | 4224 | ret = HRTIMER_NORESTART; |
@@ -4324,6 +4366,105 @@ static const struct pmu perf_ops_task_clock = { | |||
4324 | .read = task_clock_perf_event_read, | 4366 | .read = task_clock_perf_event_read, |
4325 | }; | 4367 | }; |
4326 | 4368 | ||
4369 | static void swevent_hlist_release_rcu(struct rcu_head *rcu_head) | ||
4370 | { | ||
4371 | struct swevent_hlist *hlist; | ||
4372 | |||
4373 | hlist = container_of(rcu_head, struct swevent_hlist, rcu_head); | ||
4374 | kfree(hlist); | ||
4375 | } | ||
4376 | |||
4377 | static void swevent_hlist_release(struct perf_cpu_context *cpuctx) | ||
4378 | { | ||
4379 | struct swevent_hlist *hlist; | ||
4380 | |||
4381 | if (!cpuctx->swevent_hlist) | ||
4382 | return; | ||
4383 | |||
4384 | hlist = cpuctx->swevent_hlist; | ||
4385 | rcu_assign_pointer(cpuctx->swevent_hlist, NULL); | ||
4386 | call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu); | ||
4387 | } | ||
4388 | |||
4389 | static void swevent_hlist_put_cpu(struct perf_event *event, int cpu) | ||
4390 | { | ||
4391 | struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu); | ||
4392 | |||
4393 | mutex_lock(&cpuctx->hlist_mutex); | ||
4394 | |||
4395 | if (!--cpuctx->hlist_refcount) | ||
4396 | swevent_hlist_release(cpuctx); | ||
4397 | |||
4398 | mutex_unlock(&cpuctx->hlist_mutex); | ||
4399 | } | ||
4400 | |||
4401 | static void swevent_hlist_put(struct perf_event *event) | ||
4402 | { | ||
4403 | int cpu; | ||
4404 | |||
4405 | if (event->cpu != -1) { | ||
4406 | swevent_hlist_put_cpu(event, event->cpu); | ||
4407 | return; | ||
4408 | } | ||
4409 | |||
4410 | for_each_possible_cpu(cpu) | ||
4411 | swevent_hlist_put_cpu(event, cpu); | ||
4412 | } | ||
4413 | |||
4414 | static int swevent_hlist_get_cpu(struct perf_event *event, int cpu) | ||
4415 | { | ||
4416 | struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu); | ||
4417 | int err = 0; | ||
4418 | |||
4419 | mutex_lock(&cpuctx->hlist_mutex); | ||
4420 | |||
4421 | if (!cpuctx->swevent_hlist && cpu_online(cpu)) { | ||
4422 | struct swevent_hlist *hlist; | ||
4423 | |||
4424 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); | ||
4425 | if (!hlist) { | ||
4426 | err = -ENOMEM; | ||
4427 | goto exit; | ||
4428 | } | ||
4429 | rcu_assign_pointer(cpuctx->swevent_hlist, hlist); | ||
4430 | } | ||
4431 | cpuctx->hlist_refcount++; | ||
4432 | exit: | ||
4433 | mutex_unlock(&cpuctx->hlist_mutex); | ||
4434 | |||
4435 | return err; | ||
4436 | } | ||
4437 | |||
4438 | static int swevent_hlist_get(struct perf_event *event) | ||
4439 | { | ||
4440 | int err; | ||
4441 | int cpu, failed_cpu; | ||
4442 | |||
4443 | if (event->cpu != -1) | ||
4444 | return swevent_hlist_get_cpu(event, event->cpu); | ||
4445 | |||
4446 | get_online_cpus(); | ||
4447 | for_each_possible_cpu(cpu) { | ||
4448 | err = swevent_hlist_get_cpu(event, cpu); | ||
4449 | if (err) { | ||
4450 | failed_cpu = cpu; | ||
4451 | goto fail; | ||
4452 | } | ||
4453 | } | ||
4454 | put_online_cpus(); | ||
4455 | |||
4456 | return 0; | ||
4457 | fail: | ||
4458 | for_each_possible_cpu(cpu) { | ||
4459 | if (cpu == failed_cpu) | ||
4460 | break; | ||
4461 | swevent_hlist_put_cpu(event, cpu); | ||
4462 | } | ||
4463 | |||
4464 | put_online_cpus(); | ||
4465 | return err; | ||
4466 | } | ||
4467 | |||
4327 | #ifdef CONFIG_EVENT_TRACING | 4468 | #ifdef CONFIG_EVENT_TRACING |
4328 | 4469 | ||
4329 | void perf_tp_event(int event_id, u64 addr, u64 count, void *record, | 4470 | void perf_tp_event(int event_id, u64 addr, u64 count, void *record, |
@@ -4357,10 +4498,13 @@ static int perf_tp_event_match(struct perf_event *event, | |||
4357 | static void tp_perf_event_destroy(struct perf_event *event) | 4498 | static void tp_perf_event_destroy(struct perf_event *event) |
4358 | { | 4499 | { |
4359 | perf_trace_disable(event->attr.config); | 4500 | perf_trace_disable(event->attr.config); |
4501 | swevent_hlist_put(event); | ||
4360 | } | 4502 | } |
4361 | 4503 | ||
4362 | static const struct pmu *tp_perf_event_init(struct perf_event *event) | 4504 | static const struct pmu *tp_perf_event_init(struct perf_event *event) |
4363 | { | 4505 | { |
4506 | int err; | ||
4507 | |||
4364 | /* | 4508 | /* |
4365 | * Raw tracepoint data is a severe data leak, only allow root to | 4509 | * Raw tracepoint data is a severe data leak, only allow root to |
4366 | * have these. | 4510 | * have these. |
@@ -4374,6 +4518,11 @@ static const struct pmu *tp_perf_event_init(struct perf_event *event) | |||
4374 | return NULL; | 4518 | return NULL; |
4375 | 4519 | ||
4376 | event->destroy = tp_perf_event_destroy; | 4520 | event->destroy = tp_perf_event_destroy; |
4521 | err = swevent_hlist_get(event); | ||
4522 | if (err) { | ||
4523 | perf_trace_disable(event->attr.config); | ||
4524 | return ERR_PTR(err); | ||
4525 | } | ||
4377 | 4526 | ||
4378 | return &perf_ops_generic; | 4527 | return &perf_ops_generic; |
4379 | } | 4528 | } |
@@ -4474,6 +4623,7 @@ static void sw_perf_event_destroy(struct perf_event *event) | |||
4474 | WARN_ON(event->parent); | 4623 | WARN_ON(event->parent); |
4475 | 4624 | ||
4476 | atomic_dec(&perf_swevent_enabled[event_id]); | 4625 | atomic_dec(&perf_swevent_enabled[event_id]); |
4626 | swevent_hlist_put(event); | ||
4477 | } | 4627 | } |
4478 | 4628 | ||
4479 | static const struct pmu *sw_perf_event_init(struct perf_event *event) | 4629 | static const struct pmu *sw_perf_event_init(struct perf_event *event) |
@@ -4512,6 +4662,12 @@ static const struct pmu *sw_perf_event_init(struct perf_event *event) | |||
4512 | case PERF_COUNT_SW_ALIGNMENT_FAULTS: | 4662 | case PERF_COUNT_SW_ALIGNMENT_FAULTS: |
4513 | case PERF_COUNT_SW_EMULATION_FAULTS: | 4663 | case PERF_COUNT_SW_EMULATION_FAULTS: |
4514 | if (!event->parent) { | 4664 | if (!event->parent) { |
4665 | int err; | ||
4666 | |||
4667 | err = swevent_hlist_get(event); | ||
4668 | if (err) | ||
4669 | return ERR_PTR(err); | ||
4670 | |||
4515 | atomic_inc(&perf_swevent_enabled[event_id]); | 4671 | atomic_inc(&perf_swevent_enabled[event_id]); |
4516 | event->destroy = sw_perf_event_destroy; | 4672 | event->destroy = sw_perf_event_destroy; |
4517 | } | 4673 | } |
@@ -5176,7 +5332,7 @@ void perf_event_exit_task(struct task_struct *child) | |||
5176 | * | 5332 | * |
5177 | * But since its the parent context it won't be the same instance. | 5333 | * But since its the parent context it won't be the same instance. |
5178 | */ | 5334 | */ |
5179 | mutex_lock_nested(&child_ctx->mutex, SINGLE_DEPTH_NESTING); | 5335 | mutex_lock(&child_ctx->mutex); |
5180 | 5336 | ||
5181 | again: | 5337 | again: |
5182 | list_for_each_entry_safe(child_event, tmp, &child_ctx->pinned_groups, | 5338 | list_for_each_entry_safe(child_event, tmp, &child_ctx->pinned_groups, |
@@ -5384,6 +5540,7 @@ static void __init perf_event_init_all_cpus(void) | |||
5384 | 5540 | ||
5385 | for_each_possible_cpu(cpu) { | 5541 | for_each_possible_cpu(cpu) { |
5386 | cpuctx = &per_cpu(perf_cpu_context, cpu); | 5542 | cpuctx = &per_cpu(perf_cpu_context, cpu); |
5543 | mutex_init(&cpuctx->hlist_mutex); | ||
5387 | __perf_event_init_context(&cpuctx->ctx, NULL); | 5544 | __perf_event_init_context(&cpuctx->ctx, NULL); |
5388 | } | 5545 | } |
5389 | } | 5546 | } |
@@ -5397,6 +5554,16 @@ static void __cpuinit perf_event_init_cpu(int cpu) | |||
5397 | spin_lock(&perf_resource_lock); | 5554 | spin_lock(&perf_resource_lock); |
5398 | cpuctx->max_pertask = perf_max_events - perf_reserved_percpu; | 5555 | cpuctx->max_pertask = perf_max_events - perf_reserved_percpu; |
5399 | spin_unlock(&perf_resource_lock); | 5556 | spin_unlock(&perf_resource_lock); |
5557 | |||
5558 | mutex_lock(&cpuctx->hlist_mutex); | ||
5559 | if (cpuctx->hlist_refcount > 0) { | ||
5560 | struct swevent_hlist *hlist; | ||
5561 | |||
5562 | hlist = kzalloc(sizeof(*hlist), GFP_KERNEL); | ||
5563 | WARN_ON_ONCE(!hlist); | ||
5564 | rcu_assign_pointer(cpuctx->swevent_hlist, hlist); | ||
5565 | } | ||
5566 | mutex_unlock(&cpuctx->hlist_mutex); | ||
5400 | } | 5567 | } |
5401 | 5568 | ||
5402 | #ifdef CONFIG_HOTPLUG_CPU | 5569 | #ifdef CONFIG_HOTPLUG_CPU |
@@ -5416,6 +5583,10 @@ static void perf_event_exit_cpu(int cpu) | |||
5416 | struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu); | 5583 | struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu); |
5417 | struct perf_event_context *ctx = &cpuctx->ctx; | 5584 | struct perf_event_context *ctx = &cpuctx->ctx; |
5418 | 5585 | ||
5586 | mutex_lock(&cpuctx->hlist_mutex); | ||
5587 | swevent_hlist_release(cpuctx); | ||
5588 | mutex_unlock(&cpuctx->hlist_mutex); | ||
5589 | |||
5419 | mutex_lock(&ctx->mutex); | 5590 | mutex_lock(&ctx->mutex); |
5420 | smp_call_function_single(cpu, __perf_event_exit_cpu, NULL, 1); | 5591 | smp_call_function_single(cpu, __perf_event_exit_cpu, NULL, 1); |
5421 | mutex_unlock(&ctx->mutex); | 5592 | mutex_unlock(&ctx->mutex); |
diff --git a/kernel/profile.c b/kernel/profile.c index a55d3a367ae8..dfadc5b729f1 100644 --- a/kernel/profile.c +++ b/kernel/profile.c | |||
@@ -127,8 +127,10 @@ int __ref profile_init(void) | |||
127 | return 0; | 127 | return 0; |
128 | 128 | ||
129 | prof_buffer = vmalloc(buffer_bytes); | 129 | prof_buffer = vmalloc(buffer_bytes); |
130 | if (prof_buffer) | 130 | if (prof_buffer) { |
131 | memset(prof_buffer, 0, buffer_bytes); | ||
131 | return 0; | 132 | return 0; |
133 | } | ||
132 | 134 | ||
133 | free_cpumask_var(prof_cpu_mask); | 135 | free_cpumask_var(prof_cpu_mask); |
134 | return -ENOMEM; | 136 | return -ENOMEM; |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 42ad8ae729a0..6af9cdd558b7 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include <linux/mm.h> | 14 | #include <linux/mm.h> |
15 | #include <linux/highmem.h> | 15 | #include <linux/highmem.h> |
16 | #include <linux/pagemap.h> | 16 | #include <linux/pagemap.h> |
17 | #include <linux/smp_lock.h> | ||
18 | #include <linux/ptrace.h> | 17 | #include <linux/ptrace.h> |
19 | #include <linux/security.h> | 18 | #include <linux/security.h> |
20 | #include <linux/signal.h> | 19 | #include <linux/signal.h> |
@@ -76,7 +75,6 @@ void __ptrace_unlink(struct task_struct *child) | |||
76 | child->parent = child->real_parent; | 75 | child->parent = child->real_parent; |
77 | list_del_init(&child->ptrace_entry); | 76 | list_del_init(&child->ptrace_entry); |
78 | 77 | ||
79 | arch_ptrace_untrace(child); | ||
80 | if (task_is_traced(child)) | 78 | if (task_is_traced(child)) |
81 | ptrace_untrace(child); | 79 | ptrace_untrace(child); |
82 | } | 80 | } |
@@ -666,10 +664,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) | |||
666 | struct task_struct *child; | 664 | struct task_struct *child; |
667 | long ret; | 665 | long ret; |
668 | 666 | ||
669 | /* | ||
670 | * This lock_kernel fixes a subtle race with suid exec | ||
671 | */ | ||
672 | lock_kernel(); | ||
673 | if (request == PTRACE_TRACEME) { | 667 | if (request == PTRACE_TRACEME) { |
674 | ret = ptrace_traceme(); | 668 | ret = ptrace_traceme(); |
675 | if (!ret) | 669 | if (!ret) |
@@ -703,7 +697,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) | |||
703 | out_put_task_struct: | 697 | out_put_task_struct: |
704 | put_task_struct(child); | 698 | put_task_struct(child); |
705 | out: | 699 | out: |
706 | unlock_kernel(); | ||
707 | return ret; | 700 | return ret; |
708 | } | 701 | } |
709 | 702 | ||
@@ -813,10 +806,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, | |||
813 | struct task_struct *child; | 806 | struct task_struct *child; |
814 | long ret; | 807 | long ret; |
815 | 808 | ||
816 | /* | ||
817 | * This lock_kernel fixes a subtle race with suid exec | ||
818 | */ | ||
819 | lock_kernel(); | ||
820 | if (request == PTRACE_TRACEME) { | 809 | if (request == PTRACE_TRACEME) { |
821 | ret = ptrace_traceme(); | 810 | ret = ptrace_traceme(); |
822 | goto out; | 811 | goto out; |
@@ -846,7 +835,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, | |||
846 | out_put_task_struct: | 835 | out_put_task_struct: |
847 | put_task_struct(child); | 836 | put_task_struct(child); |
848 | out: | 837 | out: |
849 | unlock_kernel(); | ||
850 | return ret; | 838 | return ret; |
851 | } | 839 | } |
852 | #endif /* CONFIG_COMPAT */ | 840 | #endif /* CONFIG_COMPAT */ |
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index 49d808e833b0..72a8dc9567f5 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
@@ -44,7 +44,6 @@ | |||
44 | #include <linux/cpu.h> | 44 | #include <linux/cpu.h> |
45 | #include <linux/mutex.h> | 45 | #include <linux/mutex.h> |
46 | #include <linux/module.h> | 46 | #include <linux/module.h> |
47 | #include <linux/kernel_stat.h> | ||
48 | #include <linux/hardirq.h> | 47 | #include <linux/hardirq.h> |
49 | 48 | ||
50 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
@@ -64,9 +63,6 @@ struct lockdep_map rcu_sched_lock_map = | |||
64 | EXPORT_SYMBOL_GPL(rcu_sched_lock_map); | 63 | EXPORT_SYMBOL_GPL(rcu_sched_lock_map); |
65 | #endif | 64 | #endif |
66 | 65 | ||
67 | int rcu_scheduler_active __read_mostly; | ||
68 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); | ||
69 | |||
70 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 66 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
71 | 67 | ||
72 | int debug_lockdep_rcu_enabled(void) | 68 | int debug_lockdep_rcu_enabled(void) |
@@ -97,21 +93,6 @@ EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held); | |||
97 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | 93 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
98 | 94 | ||
99 | /* | 95 | /* |
100 | * This function is invoked towards the end of the scheduler's initialization | ||
101 | * process. Before this is called, the idle task might contain | ||
102 | * RCU read-side critical sections (during which time, this idle | ||
103 | * task is booting the system). After this function is called, the | ||
104 | * idle tasks are prohibited from containing RCU read-side critical | ||
105 | * sections. | ||
106 | */ | ||
107 | void rcu_scheduler_starting(void) | ||
108 | { | ||
109 | WARN_ON(num_online_cpus() != 1); | ||
110 | WARN_ON(nr_context_switches() > 0); | ||
111 | rcu_scheduler_active = 1; | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Awaken the corresponding synchronize_rcu() instance now that a | 96 | * Awaken the corresponding synchronize_rcu() instance now that a |
116 | * grace period has elapsed. | 97 | * grace period has elapsed. |
117 | */ | 98 | */ |
diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c index 9f6d9ff2572c..38729d3cd236 100644 --- a/kernel/rcutiny.c +++ b/kernel/rcutiny.c | |||
@@ -44,9 +44,9 @@ struct rcu_ctrlblk { | |||
44 | }; | 44 | }; |
45 | 45 | ||
46 | /* Definition for rcupdate control block. */ | 46 | /* Definition for rcupdate control block. */ |
47 | static struct rcu_ctrlblk rcu_ctrlblk = { | 47 | static struct rcu_ctrlblk rcu_sched_ctrlblk = { |
48 | .donetail = &rcu_ctrlblk.rcucblist, | 48 | .donetail = &rcu_sched_ctrlblk.rcucblist, |
49 | .curtail = &rcu_ctrlblk.rcucblist, | 49 | .curtail = &rcu_sched_ctrlblk.rcucblist, |
50 | }; | 50 | }; |
51 | 51 | ||
52 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { | 52 | static struct rcu_ctrlblk rcu_bh_ctrlblk = { |
@@ -54,6 +54,11 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = { | |||
54 | .curtail = &rcu_bh_ctrlblk.rcucblist, | 54 | .curtail = &rcu_bh_ctrlblk.rcucblist, |
55 | }; | 55 | }; |
56 | 56 | ||
57 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
58 | int rcu_scheduler_active __read_mostly; | ||
59 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); | ||
60 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
61 | |||
57 | #ifdef CONFIG_NO_HZ | 62 | #ifdef CONFIG_NO_HZ |
58 | 63 | ||
59 | static long rcu_dynticks_nesting = 1; | 64 | static long rcu_dynticks_nesting = 1; |
@@ -108,7 +113,8 @@ static int rcu_qsctr_help(struct rcu_ctrlblk *rcp) | |||
108 | */ | 113 | */ |
109 | void rcu_sched_qs(int cpu) | 114 | void rcu_sched_qs(int cpu) |
110 | { | 115 | { |
111 | if (rcu_qsctr_help(&rcu_ctrlblk) + rcu_qsctr_help(&rcu_bh_ctrlblk)) | 116 | if (rcu_qsctr_help(&rcu_sched_ctrlblk) + |
117 | rcu_qsctr_help(&rcu_bh_ctrlblk)) | ||
112 | raise_softirq(RCU_SOFTIRQ); | 118 | raise_softirq(RCU_SOFTIRQ); |
113 | } | 119 | } |
114 | 120 | ||
@@ -173,7 +179,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp) | |||
173 | */ | 179 | */ |
174 | static void rcu_process_callbacks(struct softirq_action *unused) | 180 | static void rcu_process_callbacks(struct softirq_action *unused) |
175 | { | 181 | { |
176 | __rcu_process_callbacks(&rcu_ctrlblk); | 182 | __rcu_process_callbacks(&rcu_sched_ctrlblk); |
177 | __rcu_process_callbacks(&rcu_bh_ctrlblk); | 183 | __rcu_process_callbacks(&rcu_bh_ctrlblk); |
178 | } | 184 | } |
179 | 185 | ||
@@ -187,7 +193,8 @@ static void rcu_process_callbacks(struct softirq_action *unused) | |||
187 | * | 193 | * |
188 | * Cool, huh? (Due to Josh Triplett.) | 194 | * Cool, huh? (Due to Josh Triplett.) |
189 | * | 195 | * |
190 | * But we want to make this a static inline later. | 196 | * But we want to make this a static inline later. The cond_resched() |
197 | * currently makes this problematic. | ||
191 | */ | 198 | */ |
192 | void synchronize_sched(void) | 199 | void synchronize_sched(void) |
193 | { | 200 | { |
@@ -195,12 +202,6 @@ void synchronize_sched(void) | |||
195 | } | 202 | } |
196 | EXPORT_SYMBOL_GPL(synchronize_sched); | 203 | EXPORT_SYMBOL_GPL(synchronize_sched); |
197 | 204 | ||
198 | void synchronize_rcu_bh(void) | ||
199 | { | ||
200 | synchronize_sched(); | ||
201 | } | ||
202 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | ||
203 | |||
204 | /* | 205 | /* |
205 | * Helper function for call_rcu() and call_rcu_bh(). | 206 | * Helper function for call_rcu() and call_rcu_bh(). |
206 | */ | 207 | */ |
@@ -226,7 +227,7 @@ static void __call_rcu(struct rcu_head *head, | |||
226 | */ | 227 | */ |
227 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) | 228 | void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) |
228 | { | 229 | { |
229 | __call_rcu(head, func, &rcu_ctrlblk); | 230 | __call_rcu(head, func, &rcu_sched_ctrlblk); |
230 | } | 231 | } |
231 | EXPORT_SYMBOL_GPL(call_rcu); | 232 | EXPORT_SYMBOL_GPL(call_rcu); |
232 | 233 | ||
@@ -244,11 +245,13 @@ void rcu_barrier(void) | |||
244 | { | 245 | { |
245 | struct rcu_synchronize rcu; | 246 | struct rcu_synchronize rcu; |
246 | 247 | ||
248 | init_rcu_head_on_stack(&rcu.head); | ||
247 | init_completion(&rcu.completion); | 249 | init_completion(&rcu.completion); |
248 | /* Will wake me after RCU finished. */ | 250 | /* Will wake me after RCU finished. */ |
249 | call_rcu(&rcu.head, wakeme_after_rcu); | 251 | call_rcu(&rcu.head, wakeme_after_rcu); |
250 | /* Wait for it. */ | 252 | /* Wait for it. */ |
251 | wait_for_completion(&rcu.completion); | 253 | wait_for_completion(&rcu.completion); |
254 | destroy_rcu_head_on_stack(&rcu.head); | ||
252 | } | 255 | } |
253 | EXPORT_SYMBOL_GPL(rcu_barrier); | 256 | EXPORT_SYMBOL_GPL(rcu_barrier); |
254 | 257 | ||
@@ -256,11 +259,13 @@ void rcu_barrier_bh(void) | |||
256 | { | 259 | { |
257 | struct rcu_synchronize rcu; | 260 | struct rcu_synchronize rcu; |
258 | 261 | ||
262 | init_rcu_head_on_stack(&rcu.head); | ||
259 | init_completion(&rcu.completion); | 263 | init_completion(&rcu.completion); |
260 | /* Will wake me after RCU finished. */ | 264 | /* Will wake me after RCU finished. */ |
261 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | 265 | call_rcu_bh(&rcu.head, wakeme_after_rcu); |
262 | /* Wait for it. */ | 266 | /* Wait for it. */ |
263 | wait_for_completion(&rcu.completion); | 267 | wait_for_completion(&rcu.completion); |
268 | destroy_rcu_head_on_stack(&rcu.head); | ||
264 | } | 269 | } |
265 | EXPORT_SYMBOL_GPL(rcu_barrier_bh); | 270 | EXPORT_SYMBOL_GPL(rcu_barrier_bh); |
266 | 271 | ||
@@ -268,11 +273,13 @@ void rcu_barrier_sched(void) | |||
268 | { | 273 | { |
269 | struct rcu_synchronize rcu; | 274 | struct rcu_synchronize rcu; |
270 | 275 | ||
276 | init_rcu_head_on_stack(&rcu.head); | ||
271 | init_completion(&rcu.completion); | 277 | init_completion(&rcu.completion); |
272 | /* Will wake me after RCU finished. */ | 278 | /* Will wake me after RCU finished. */ |
273 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | 279 | call_rcu_sched(&rcu.head, wakeme_after_rcu); |
274 | /* Wait for it. */ | 280 | /* Wait for it. */ |
275 | wait_for_completion(&rcu.completion); | 281 | wait_for_completion(&rcu.completion); |
282 | destroy_rcu_head_on_stack(&rcu.head); | ||
276 | } | 283 | } |
277 | EXPORT_SYMBOL_GPL(rcu_barrier_sched); | 284 | EXPORT_SYMBOL_GPL(rcu_barrier_sched); |
278 | 285 | ||
@@ -280,3 +287,5 @@ void __init rcu_init(void) | |||
280 | { | 287 | { |
281 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); | 288 | open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); |
282 | } | 289 | } |
290 | |||
291 | #include "rcutiny_plugin.h" | ||
diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h new file mode 100644 index 000000000000..d223a92bc742 --- /dev/null +++ b/kernel/rcutiny_plugin.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Read-Copy Update mechanism for mutual exclusion (tree-based version) | ||
3 | * Internal non-public definitions that provide either classic | ||
4 | * or preemptable semantics. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
19 | * | ||
20 | * Copyright IBM Corporation, 2009 | ||
21 | * | ||
22 | * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> | ||
23 | */ | ||
24 | |||
25 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
26 | |||
27 | #include <linux/kernel_stat.h> | ||
28 | |||
29 | /* | ||
30 | * During boot, we forgive RCU lockdep issues. After this function is | ||
31 | * invoked, we start taking RCU lockdep issues seriously. | ||
32 | */ | ||
33 | void rcu_scheduler_starting(void) | ||
34 | { | ||
35 | WARN_ON(nr_context_switches() > 0); | ||
36 | rcu_scheduler_active = 1; | ||
37 | } | ||
38 | |||
39 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 58df55bf83ed..6535ac8bc6a5 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c | |||
@@ -464,9 +464,11 @@ static void rcu_bh_torture_synchronize(void) | |||
464 | { | 464 | { |
465 | struct rcu_bh_torture_synchronize rcu; | 465 | struct rcu_bh_torture_synchronize rcu; |
466 | 466 | ||
467 | init_rcu_head_on_stack(&rcu.head); | ||
467 | init_completion(&rcu.completion); | 468 | init_completion(&rcu.completion); |
468 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); | 469 | call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb); |
469 | wait_for_completion(&rcu.completion); | 470 | wait_for_completion(&rcu.completion); |
471 | destroy_rcu_head_on_stack(&rcu.head); | ||
470 | } | 472 | } |
471 | 473 | ||
472 | static struct rcu_torture_ops rcu_bh_ops = { | 474 | static struct rcu_torture_ops rcu_bh_ops = { |
@@ -669,7 +671,7 @@ static struct rcu_torture_ops sched_expedited_ops = { | |||
669 | .sync = synchronize_sched_expedited, | 671 | .sync = synchronize_sched_expedited, |
670 | .cb_barrier = NULL, | 672 | .cb_barrier = NULL, |
671 | .fqs = rcu_sched_force_quiescent_state, | 673 | .fqs = rcu_sched_force_quiescent_state, |
672 | .stats = rcu_expedited_torture_stats, | 674 | .stats = NULL, |
673 | .irq_capable = 1, | 675 | .irq_capable = 1, |
674 | .name = "sched_expedited" | 676 | .name = "sched_expedited" |
675 | }; | 677 | }; |
diff --git a/kernel/rcutree.c b/kernel/rcutree.c index 3ec8160fc75f..d4437345706f 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include <linux/cpu.h> | 46 | #include <linux/cpu.h> |
47 | #include <linux/mutex.h> | 47 | #include <linux/mutex.h> |
48 | #include <linux/time.h> | 48 | #include <linux/time.h> |
49 | #include <linux/kernel_stat.h> | ||
49 | 50 | ||
50 | #include "rcutree.h" | 51 | #include "rcutree.h" |
51 | 52 | ||
@@ -53,8 +54,8 @@ | |||
53 | 54 | ||
54 | static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; | 55 | static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; |
55 | 56 | ||
56 | #define RCU_STATE_INITIALIZER(name) { \ | 57 | #define RCU_STATE_INITIALIZER(structname) { \ |
57 | .level = { &name.node[0] }, \ | 58 | .level = { &structname.node[0] }, \ |
58 | .levelcnt = { \ | 59 | .levelcnt = { \ |
59 | NUM_RCU_LVL_0, /* root of hierarchy. */ \ | 60 | NUM_RCU_LVL_0, /* root of hierarchy. */ \ |
60 | NUM_RCU_LVL_1, \ | 61 | NUM_RCU_LVL_1, \ |
@@ -65,13 +66,14 @@ static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; | |||
65 | .signaled = RCU_GP_IDLE, \ | 66 | .signaled = RCU_GP_IDLE, \ |
66 | .gpnum = -300, \ | 67 | .gpnum = -300, \ |
67 | .completed = -300, \ | 68 | .completed = -300, \ |
68 | .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&name.onofflock), \ | 69 | .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&structname.onofflock), \ |
69 | .orphan_cbs_list = NULL, \ | 70 | .orphan_cbs_list = NULL, \ |
70 | .orphan_cbs_tail = &name.orphan_cbs_list, \ | 71 | .orphan_cbs_tail = &structname.orphan_cbs_list, \ |
71 | .orphan_qlen = 0, \ | 72 | .orphan_qlen = 0, \ |
72 | .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&name.fqslock), \ | 73 | .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&structname.fqslock), \ |
73 | .n_force_qs = 0, \ | 74 | .n_force_qs = 0, \ |
74 | .n_force_qs_ngp = 0, \ | 75 | .n_force_qs_ngp = 0, \ |
76 | .name = #structname, \ | ||
75 | } | 77 | } |
76 | 78 | ||
77 | struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state); | 79 | struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state); |
@@ -80,6 +82,9 @@ DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); | |||
80 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); | 82 | struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state); |
81 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); | 83 | DEFINE_PER_CPU(struct rcu_data, rcu_bh_data); |
82 | 84 | ||
85 | int rcu_scheduler_active __read_mostly; | ||
86 | EXPORT_SYMBOL_GPL(rcu_scheduler_active); | ||
87 | |||
83 | /* | 88 | /* |
84 | * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s | 89 | * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s |
85 | * permit this function to be invoked without holding the root rcu_node | 90 | * permit this function to be invoked without holding the root rcu_node |
@@ -97,25 +102,32 @@ static int rcu_gp_in_progress(struct rcu_state *rsp) | |||
97 | */ | 102 | */ |
98 | void rcu_sched_qs(int cpu) | 103 | void rcu_sched_qs(int cpu) |
99 | { | 104 | { |
100 | struct rcu_data *rdp; | 105 | struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu); |
101 | 106 | ||
102 | rdp = &per_cpu(rcu_sched_data, cpu); | ||
103 | rdp->passed_quiesc_completed = rdp->gpnum - 1; | 107 | rdp->passed_quiesc_completed = rdp->gpnum - 1; |
104 | barrier(); | 108 | barrier(); |
105 | rdp->passed_quiesc = 1; | 109 | rdp->passed_quiesc = 1; |
106 | rcu_preempt_note_context_switch(cpu); | ||
107 | } | 110 | } |
108 | 111 | ||
109 | void rcu_bh_qs(int cpu) | 112 | void rcu_bh_qs(int cpu) |
110 | { | 113 | { |
111 | struct rcu_data *rdp; | 114 | struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu); |
112 | 115 | ||
113 | rdp = &per_cpu(rcu_bh_data, cpu); | ||
114 | rdp->passed_quiesc_completed = rdp->gpnum - 1; | 116 | rdp->passed_quiesc_completed = rdp->gpnum - 1; |
115 | barrier(); | 117 | barrier(); |
116 | rdp->passed_quiesc = 1; | 118 | rdp->passed_quiesc = 1; |
117 | } | 119 | } |
118 | 120 | ||
121 | /* | ||
122 | * Note a context switch. This is a quiescent state for RCU-sched, | ||
123 | * and requires special handling for preemptible RCU. | ||
124 | */ | ||
125 | void rcu_note_context_switch(int cpu) | ||
126 | { | ||
127 | rcu_sched_qs(cpu); | ||
128 | rcu_preempt_note_context_switch(cpu); | ||
129 | } | ||
130 | |||
119 | #ifdef CONFIG_NO_HZ | 131 | #ifdef CONFIG_NO_HZ |
120 | DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { | 132 | DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = { |
121 | .dynticks_nesting = 1, | 133 | .dynticks_nesting = 1, |
@@ -438,6 +450,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp) | |||
438 | 450 | ||
439 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 451 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR |
440 | 452 | ||
453 | int rcu_cpu_stall_panicking __read_mostly; | ||
454 | |||
441 | static void record_gp_stall_check_time(struct rcu_state *rsp) | 455 | static void record_gp_stall_check_time(struct rcu_state *rsp) |
442 | { | 456 | { |
443 | rsp->gp_start = jiffies; | 457 | rsp->gp_start = jiffies; |
@@ -470,7 +484,8 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
470 | 484 | ||
471 | /* OK, time to rat on our buddy... */ | 485 | /* OK, time to rat on our buddy... */ |
472 | 486 | ||
473 | printk(KERN_ERR "INFO: RCU detected CPU stalls:"); | 487 | printk(KERN_ERR "INFO: %s detected stalls on CPUs/tasks: {", |
488 | rsp->name); | ||
474 | rcu_for_each_leaf_node(rsp, rnp) { | 489 | rcu_for_each_leaf_node(rsp, rnp) { |
475 | raw_spin_lock_irqsave(&rnp->lock, flags); | 490 | raw_spin_lock_irqsave(&rnp->lock, flags); |
476 | rcu_print_task_stall(rnp); | 491 | rcu_print_task_stall(rnp); |
@@ -481,7 +496,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp) | |||
481 | if (rnp->qsmask & (1UL << cpu)) | 496 | if (rnp->qsmask & (1UL << cpu)) |
482 | printk(" %d", rnp->grplo + cpu); | 497 | printk(" %d", rnp->grplo + cpu); |
483 | } | 498 | } |
484 | printk(" (detected by %d, t=%ld jiffies)\n", | 499 | printk("} (detected by %d, t=%ld jiffies)\n", |
485 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); | 500 | smp_processor_id(), (long)(jiffies - rsp->gp_start)); |
486 | trigger_all_cpu_backtrace(); | 501 | trigger_all_cpu_backtrace(); |
487 | 502 | ||
@@ -497,8 +512,8 @@ static void print_cpu_stall(struct rcu_state *rsp) | |||
497 | unsigned long flags; | 512 | unsigned long flags; |
498 | struct rcu_node *rnp = rcu_get_root(rsp); | 513 | struct rcu_node *rnp = rcu_get_root(rsp); |
499 | 514 | ||
500 | printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n", | 515 | printk(KERN_ERR "INFO: %s detected stall on CPU %d (t=%lu jiffies)\n", |
501 | smp_processor_id(), jiffies - rsp->gp_start); | 516 | rsp->name, smp_processor_id(), jiffies - rsp->gp_start); |
502 | trigger_all_cpu_backtrace(); | 517 | trigger_all_cpu_backtrace(); |
503 | 518 | ||
504 | raw_spin_lock_irqsave(&rnp->lock, flags); | 519 | raw_spin_lock_irqsave(&rnp->lock, flags); |
@@ -515,6 +530,8 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
515 | long delta; | 530 | long delta; |
516 | struct rcu_node *rnp; | 531 | struct rcu_node *rnp; |
517 | 532 | ||
533 | if (rcu_cpu_stall_panicking) | ||
534 | return; | ||
518 | delta = jiffies - rsp->jiffies_stall; | 535 | delta = jiffies - rsp->jiffies_stall; |
519 | rnp = rdp->mynode; | 536 | rnp = rdp->mynode; |
520 | if ((rnp->qsmask & rdp->grpmask) && delta >= 0) { | 537 | if ((rnp->qsmask & rdp->grpmask) && delta >= 0) { |
@@ -529,6 +546,21 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
529 | } | 546 | } |
530 | } | 547 | } |
531 | 548 | ||
549 | static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr) | ||
550 | { | ||
551 | rcu_cpu_stall_panicking = 1; | ||
552 | return NOTIFY_DONE; | ||
553 | } | ||
554 | |||
555 | static struct notifier_block rcu_panic_block = { | ||
556 | .notifier_call = rcu_panic, | ||
557 | }; | ||
558 | |||
559 | static void __init check_cpu_stall_init(void) | ||
560 | { | ||
561 | atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block); | ||
562 | } | ||
563 | |||
532 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 564 | #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
533 | 565 | ||
534 | static void record_gp_stall_check_time(struct rcu_state *rsp) | 566 | static void record_gp_stall_check_time(struct rcu_state *rsp) |
@@ -539,6 +571,10 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp) | |||
539 | { | 571 | { |
540 | } | 572 | } |
541 | 573 | ||
574 | static void __init check_cpu_stall_init(void) | ||
575 | { | ||
576 | } | ||
577 | |||
542 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 578 | #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
543 | 579 | ||
544 | /* | 580 | /* |
@@ -1125,8 +1161,6 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1125 | */ | 1161 | */ |
1126 | void rcu_check_callbacks(int cpu, int user) | 1162 | void rcu_check_callbacks(int cpu, int user) |
1127 | { | 1163 | { |
1128 | if (!rcu_pending(cpu)) | ||
1129 | return; /* if nothing for RCU to do. */ | ||
1130 | if (user || | 1164 | if (user || |
1131 | (idle_cpu(cpu) && rcu_scheduler_active && | 1165 | (idle_cpu(cpu) && rcu_scheduler_active && |
1132 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { | 1166 | !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) { |
@@ -1158,7 +1192,8 @@ void rcu_check_callbacks(int cpu, int user) | |||
1158 | rcu_bh_qs(cpu); | 1192 | rcu_bh_qs(cpu); |
1159 | } | 1193 | } |
1160 | rcu_preempt_check_callbacks(cpu); | 1194 | rcu_preempt_check_callbacks(cpu); |
1161 | raise_softirq(RCU_SOFTIRQ); | 1195 | if (rcu_pending(cpu)) |
1196 | raise_softirq(RCU_SOFTIRQ); | ||
1162 | } | 1197 | } |
1163 | 1198 | ||
1164 | #ifdef CONFIG_SMP | 1199 | #ifdef CONFIG_SMP |
@@ -1236,11 +1271,11 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed) | |||
1236 | break; /* grace period idle or initializing, ignore. */ | 1271 | break; /* grace period idle or initializing, ignore. */ |
1237 | 1272 | ||
1238 | case RCU_SAVE_DYNTICK: | 1273 | case RCU_SAVE_DYNTICK: |
1239 | |||
1240 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled */ | ||
1241 | if (RCU_SIGNAL_INIT != RCU_SAVE_DYNTICK) | 1274 | if (RCU_SIGNAL_INIT != RCU_SAVE_DYNTICK) |
1242 | break; /* So gcc recognizes the dead code. */ | 1275 | break; /* So gcc recognizes the dead code. */ |
1243 | 1276 | ||
1277 | raw_spin_unlock(&rnp->lock); /* irqs remain disabled */ | ||
1278 | |||
1244 | /* Record dyntick-idle state. */ | 1279 | /* Record dyntick-idle state. */ |
1245 | force_qs_rnp(rsp, dyntick_save_progress_counter); | 1280 | force_qs_rnp(rsp, dyntick_save_progress_counter); |
1246 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ | 1281 | raw_spin_lock(&rnp->lock); /* irqs already disabled */ |
@@ -1449,11 +1484,13 @@ void synchronize_sched(void) | |||
1449 | if (rcu_blocking_is_gp()) | 1484 | if (rcu_blocking_is_gp()) |
1450 | return; | 1485 | return; |
1451 | 1486 | ||
1487 | init_rcu_head_on_stack(&rcu.head); | ||
1452 | init_completion(&rcu.completion); | 1488 | init_completion(&rcu.completion); |
1453 | /* Will wake me after RCU finished. */ | 1489 | /* Will wake me after RCU finished. */ |
1454 | call_rcu_sched(&rcu.head, wakeme_after_rcu); | 1490 | call_rcu_sched(&rcu.head, wakeme_after_rcu); |
1455 | /* Wait for it. */ | 1491 | /* Wait for it. */ |
1456 | wait_for_completion(&rcu.completion); | 1492 | wait_for_completion(&rcu.completion); |
1493 | destroy_rcu_head_on_stack(&rcu.head); | ||
1457 | } | 1494 | } |
1458 | EXPORT_SYMBOL_GPL(synchronize_sched); | 1495 | EXPORT_SYMBOL_GPL(synchronize_sched); |
1459 | 1496 | ||
@@ -1473,11 +1510,13 @@ void synchronize_rcu_bh(void) | |||
1473 | if (rcu_blocking_is_gp()) | 1510 | if (rcu_blocking_is_gp()) |
1474 | return; | 1511 | return; |
1475 | 1512 | ||
1513 | init_rcu_head_on_stack(&rcu.head); | ||
1476 | init_completion(&rcu.completion); | 1514 | init_completion(&rcu.completion); |
1477 | /* Will wake me after RCU finished. */ | 1515 | /* Will wake me after RCU finished. */ |
1478 | call_rcu_bh(&rcu.head, wakeme_after_rcu); | 1516 | call_rcu_bh(&rcu.head, wakeme_after_rcu); |
1479 | /* Wait for it. */ | 1517 | /* Wait for it. */ |
1480 | wait_for_completion(&rcu.completion); | 1518 | wait_for_completion(&rcu.completion); |
1519 | destroy_rcu_head_on_stack(&rcu.head); | ||
1481 | } | 1520 | } |
1482 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); | 1521 | EXPORT_SYMBOL_GPL(synchronize_rcu_bh); |
1483 | 1522 | ||
@@ -1498,8 +1537,20 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) | |||
1498 | check_cpu_stall(rsp, rdp); | 1537 | check_cpu_stall(rsp, rdp); |
1499 | 1538 | ||
1500 | /* Is the RCU core waiting for a quiescent state from this CPU? */ | 1539 | /* Is the RCU core waiting for a quiescent state from this CPU? */ |
1501 | if (rdp->qs_pending) { | 1540 | if (rdp->qs_pending && !rdp->passed_quiesc) { |
1541 | |||
1542 | /* | ||
1543 | * If force_quiescent_state() coming soon and this CPU | ||
1544 | * needs a quiescent state, and this is either RCU-sched | ||
1545 | * or RCU-bh, force a local reschedule. | ||
1546 | */ | ||
1502 | rdp->n_rp_qs_pending++; | 1547 | rdp->n_rp_qs_pending++; |
1548 | if (!rdp->preemptable && | ||
1549 | ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs) - 1, | ||
1550 | jiffies)) | ||
1551 | set_need_resched(); | ||
1552 | } else if (rdp->qs_pending && rdp->passed_quiesc) { | ||
1553 | rdp->n_rp_report_qs++; | ||
1503 | return 1; | 1554 | return 1; |
1504 | } | 1555 | } |
1505 | 1556 | ||
@@ -1767,6 +1818,21 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self, | |||
1767 | } | 1818 | } |
1768 | 1819 | ||
1769 | /* | 1820 | /* |
1821 | * This function is invoked towards the end of the scheduler's initialization | ||
1822 | * process. Before this is called, the idle task might contain | ||
1823 | * RCU read-side critical sections (during which time, this idle | ||
1824 | * task is booting the system). After this function is called, the | ||
1825 | * idle tasks are prohibited from containing RCU read-side critical | ||
1826 | * sections. This function also enables RCU lockdep checking. | ||
1827 | */ | ||
1828 | void rcu_scheduler_starting(void) | ||
1829 | { | ||
1830 | WARN_ON(num_online_cpus() != 1); | ||
1831 | WARN_ON(nr_context_switches() > 0); | ||
1832 | rcu_scheduler_active = 1; | ||
1833 | } | ||
1834 | |||
1835 | /* | ||
1770 | * Compute the per-level fanout, either using the exact fanout specified | 1836 | * Compute the per-level fanout, either using the exact fanout specified |
1771 | * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT. | 1837 | * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT. |
1772 | */ | 1838 | */ |
@@ -1849,6 +1915,14 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
1849 | INIT_LIST_HEAD(&rnp->blocked_tasks[3]); | 1915 | INIT_LIST_HEAD(&rnp->blocked_tasks[3]); |
1850 | } | 1916 | } |
1851 | } | 1917 | } |
1918 | |||
1919 | rnp = rsp->level[NUM_RCU_LVLS - 1]; | ||
1920 | for_each_possible_cpu(i) { | ||
1921 | while (i > rnp->grphi) | ||
1922 | rnp++; | ||
1923 | rsp->rda[i]->mynode = rnp; | ||
1924 | rcu_boot_init_percpu_data(i, rsp); | ||
1925 | } | ||
1852 | } | 1926 | } |
1853 | 1927 | ||
1854 | /* | 1928 | /* |
@@ -1859,19 +1933,11 @@ static void __init rcu_init_one(struct rcu_state *rsp) | |||
1859 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ | 1933 | #define RCU_INIT_FLAVOR(rsp, rcu_data) \ |
1860 | do { \ | 1934 | do { \ |
1861 | int i; \ | 1935 | int i; \ |
1862 | int j; \ | ||
1863 | struct rcu_node *rnp; \ | ||
1864 | \ | 1936 | \ |
1865 | rcu_init_one(rsp); \ | ||
1866 | rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \ | ||
1867 | j = 0; \ | ||
1868 | for_each_possible_cpu(i) { \ | 1937 | for_each_possible_cpu(i) { \ |
1869 | if (i > rnp[j].grphi) \ | ||
1870 | j++; \ | ||
1871 | per_cpu(rcu_data, i).mynode = &rnp[j]; \ | ||
1872 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ | 1938 | (rsp)->rda[i] = &per_cpu(rcu_data, i); \ |
1873 | rcu_boot_init_percpu_data(i, rsp); \ | ||
1874 | } \ | 1939 | } \ |
1940 | rcu_init_one(rsp); \ | ||
1875 | } while (0) | 1941 | } while (0) |
1876 | 1942 | ||
1877 | void __init rcu_init(void) | 1943 | void __init rcu_init(void) |
@@ -1879,12 +1945,6 @@ void __init rcu_init(void) | |||
1879 | int cpu; | 1945 | int cpu; |
1880 | 1946 | ||
1881 | rcu_bootup_announce(); | 1947 | rcu_bootup_announce(); |
1882 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | ||
1883 | printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n"); | ||
1884 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | ||
1885 | #if NUM_RCU_LVL_4 != 0 | ||
1886 | printk(KERN_INFO "Experimental four-level hierarchy is enabled.\n"); | ||
1887 | #endif /* #if NUM_RCU_LVL_4 != 0 */ | ||
1888 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); | 1948 | RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data); |
1889 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); | 1949 | RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data); |
1890 | __rcu_init_preempt(); | 1950 | __rcu_init_preempt(); |
@@ -1898,6 +1958,7 @@ void __init rcu_init(void) | |||
1898 | cpu_notifier(rcu_cpu_notify, 0); | 1958 | cpu_notifier(rcu_cpu_notify, 0); |
1899 | for_each_online_cpu(cpu) | 1959 | for_each_online_cpu(cpu) |
1900 | rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu); | 1960 | rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu); |
1961 | check_cpu_stall_init(); | ||
1901 | } | 1962 | } |
1902 | 1963 | ||
1903 | #include "rcutree_plugin.h" | 1964 | #include "rcutree_plugin.h" |
diff --git a/kernel/rcutree.h b/kernel/rcutree.h index 4a525a30e08e..14c040b18ed0 100644 --- a/kernel/rcutree.h +++ b/kernel/rcutree.h | |||
@@ -223,6 +223,7 @@ struct rcu_data { | |||
223 | /* 5) __rcu_pending() statistics. */ | 223 | /* 5) __rcu_pending() statistics. */ |
224 | unsigned long n_rcu_pending; /* rcu_pending() calls since boot. */ | 224 | unsigned long n_rcu_pending; /* rcu_pending() calls since boot. */ |
225 | unsigned long n_rp_qs_pending; | 225 | unsigned long n_rp_qs_pending; |
226 | unsigned long n_rp_report_qs; | ||
226 | unsigned long n_rp_cb_ready; | 227 | unsigned long n_rp_cb_ready; |
227 | unsigned long n_rp_cpu_needs_gp; | 228 | unsigned long n_rp_cpu_needs_gp; |
228 | unsigned long n_rp_gp_completed; | 229 | unsigned long n_rp_gp_completed; |
@@ -326,6 +327,7 @@ struct rcu_state { | |||
326 | unsigned long jiffies_stall; /* Time at which to check */ | 327 | unsigned long jiffies_stall; /* Time at which to check */ |
327 | /* for CPU stalls. */ | 328 | /* for CPU stalls. */ |
328 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 329 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ |
330 | char *name; /* Name of structure. */ | ||
329 | }; | 331 | }; |
330 | 332 | ||
331 | /* Return values for rcu_preempt_offline_tasks(). */ | 333 | /* Return values for rcu_preempt_offline_tasks(). */ |
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h index 79b53bda8943..0e4f420245d9 100644 --- a/kernel/rcutree_plugin.h +++ b/kernel/rcutree_plugin.h | |||
@@ -26,6 +26,45 @@ | |||
26 | 26 | ||
27 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
28 | 28 | ||
29 | /* | ||
30 | * Check the RCU kernel configuration parameters and print informative | ||
31 | * messages about anything out of the ordinary. If you like #ifdef, you | ||
32 | * will love this function. | ||
33 | */ | ||
34 | static void __init rcu_bootup_announce_oddness(void) | ||
35 | { | ||
36 | #ifdef CONFIG_RCU_TRACE | ||
37 | printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n"); | ||
38 | #endif | ||
39 | #if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32) | ||
40 | printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n", | ||
41 | CONFIG_RCU_FANOUT); | ||
42 | #endif | ||
43 | #ifdef CONFIG_RCU_FANOUT_EXACT | ||
44 | printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n"); | ||
45 | #endif | ||
46 | #ifdef CONFIG_RCU_FAST_NO_HZ | ||
47 | printk(KERN_INFO | ||
48 | "\tRCU dyntick-idle grace-period acceleration is enabled.\n"); | ||
49 | #endif | ||
50 | #ifdef CONFIG_PROVE_RCU | ||
51 | printk(KERN_INFO "\tRCU lockdep checking is enabled.\n"); | ||
52 | #endif | ||
53 | #ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE | ||
54 | printk(KERN_INFO "\tRCU torture testing starts during boot.\n"); | ||
55 | #endif | ||
56 | #ifndef CONFIG_RCU_CPU_STALL_DETECTOR | ||
57 | printk(KERN_INFO | ||
58 | "\tRCU-based detection of stalled CPUs is disabled.\n"); | ||
59 | #endif | ||
60 | #ifndef CONFIG_RCU_CPU_STALL_VERBOSE | ||
61 | printk(KERN_INFO "\tVerbose stalled-CPUs detection is disabled.\n"); | ||
62 | #endif | ||
63 | #if NUM_RCU_LVL_4 != 0 | ||
64 | printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n"); | ||
65 | #endif | ||
66 | } | ||
67 | |||
29 | #ifdef CONFIG_TREE_PREEMPT_RCU | 68 | #ifdef CONFIG_TREE_PREEMPT_RCU |
30 | 69 | ||
31 | struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); | 70 | struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state); |
@@ -38,8 +77,8 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp); | |||
38 | */ | 77 | */ |
39 | static void __init rcu_bootup_announce(void) | 78 | static void __init rcu_bootup_announce(void) |
40 | { | 79 | { |
41 | printk(KERN_INFO | 80 | printk(KERN_INFO "Preemptable hierarchical RCU implementation.\n"); |
42 | "Experimental preemptable hierarchical RCU implementation.\n"); | 81 | rcu_bootup_announce_oddness(); |
43 | } | 82 | } |
44 | 83 | ||
45 | /* | 84 | /* |
@@ -75,13 +114,19 @@ EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); | |||
75 | * that this just means that the task currently running on the CPU is | 114 | * that this just means that the task currently running on the CPU is |
76 | * not in a quiescent state. There might be any number of tasks blocked | 115 | * not in a quiescent state. There might be any number of tasks blocked |
77 | * while in an RCU read-side critical section. | 116 | * while in an RCU read-side critical section. |
117 | * | ||
118 | * Unlike the other rcu_*_qs() functions, callers to this function | ||
119 | * must disable irqs in order to protect the assignment to | ||
120 | * ->rcu_read_unlock_special. | ||
78 | */ | 121 | */ |
79 | static void rcu_preempt_qs(int cpu) | 122 | static void rcu_preempt_qs(int cpu) |
80 | { | 123 | { |
81 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); | 124 | struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu); |
125 | |||
82 | rdp->passed_quiesc_completed = rdp->gpnum - 1; | 126 | rdp->passed_quiesc_completed = rdp->gpnum - 1; |
83 | barrier(); | 127 | barrier(); |
84 | rdp->passed_quiesc = 1; | 128 | rdp->passed_quiesc = 1; |
129 | current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | ||
85 | } | 130 | } |
86 | 131 | ||
87 | /* | 132 | /* |
@@ -144,9 +189,8 @@ static void rcu_preempt_note_context_switch(int cpu) | |||
144 | * grace period, then the fact that the task has been enqueued | 189 | * grace period, then the fact that the task has been enqueued |
145 | * means that we continue to block the current grace period. | 190 | * means that we continue to block the current grace period. |
146 | */ | 191 | */ |
147 | rcu_preempt_qs(cpu); | ||
148 | local_irq_save(flags); | 192 | local_irq_save(flags); |
149 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | 193 | rcu_preempt_qs(cpu); |
150 | local_irq_restore(flags); | 194 | local_irq_restore(flags); |
151 | } | 195 | } |
152 | 196 | ||
@@ -236,7 +280,6 @@ static void rcu_read_unlock_special(struct task_struct *t) | |||
236 | */ | 280 | */ |
237 | special = t->rcu_read_unlock_special; | 281 | special = t->rcu_read_unlock_special; |
238 | if (special & RCU_READ_UNLOCK_NEED_QS) { | 282 | if (special & RCU_READ_UNLOCK_NEED_QS) { |
239 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | ||
240 | rcu_preempt_qs(smp_processor_id()); | 283 | rcu_preempt_qs(smp_processor_id()); |
241 | } | 284 | } |
242 | 285 | ||
@@ -473,7 +516,6 @@ static void rcu_preempt_check_callbacks(int cpu) | |||
473 | struct task_struct *t = current; | 516 | struct task_struct *t = current; |
474 | 517 | ||
475 | if (t->rcu_read_lock_nesting == 0) { | 518 | if (t->rcu_read_lock_nesting == 0) { |
476 | t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS; | ||
477 | rcu_preempt_qs(cpu); | 519 | rcu_preempt_qs(cpu); |
478 | return; | 520 | return; |
479 | } | 521 | } |
@@ -515,11 +557,13 @@ void synchronize_rcu(void) | |||
515 | if (!rcu_scheduler_active) | 557 | if (!rcu_scheduler_active) |
516 | return; | 558 | return; |
517 | 559 | ||
560 | init_rcu_head_on_stack(&rcu.head); | ||
518 | init_completion(&rcu.completion); | 561 | init_completion(&rcu.completion); |
519 | /* Will wake me after RCU finished. */ | 562 | /* Will wake me after RCU finished. */ |
520 | call_rcu(&rcu.head, wakeme_after_rcu); | 563 | call_rcu(&rcu.head, wakeme_after_rcu); |
521 | /* Wait for it. */ | 564 | /* Wait for it. */ |
522 | wait_for_completion(&rcu.completion); | 565 | wait_for_completion(&rcu.completion); |
566 | destroy_rcu_head_on_stack(&rcu.head); | ||
523 | } | 567 | } |
524 | EXPORT_SYMBOL_GPL(synchronize_rcu); | 568 | EXPORT_SYMBOL_GPL(synchronize_rcu); |
525 | 569 | ||
@@ -754,6 +798,7 @@ void exit_rcu(void) | |||
754 | static void __init rcu_bootup_announce(void) | 798 | static void __init rcu_bootup_announce(void) |
755 | { | 799 | { |
756 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); | 800 | printk(KERN_INFO "Hierarchical RCU implementation.\n"); |
801 | rcu_bootup_announce_oddness(); | ||
757 | } | 802 | } |
758 | 803 | ||
759 | /* | 804 | /* |
@@ -1008,6 +1053,8 @@ static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff); | |||
1008 | int rcu_needs_cpu(int cpu) | 1053 | int rcu_needs_cpu(int cpu) |
1009 | { | 1054 | { |
1010 | int c = 0; | 1055 | int c = 0; |
1056 | int snap; | ||
1057 | int snap_nmi; | ||
1011 | int thatcpu; | 1058 | int thatcpu; |
1012 | 1059 | ||
1013 | /* Check for being in the holdoff period. */ | 1060 | /* Check for being in the holdoff period. */ |
@@ -1015,12 +1062,18 @@ int rcu_needs_cpu(int cpu) | |||
1015 | return rcu_needs_cpu_quick_check(cpu); | 1062 | return rcu_needs_cpu_quick_check(cpu); |
1016 | 1063 | ||
1017 | /* Don't bother unless we are the last non-dyntick-idle CPU. */ | 1064 | /* Don't bother unless we are the last non-dyntick-idle CPU. */ |
1018 | for_each_cpu_not(thatcpu, nohz_cpu_mask) | 1065 | for_each_online_cpu(thatcpu) { |
1019 | if (thatcpu != cpu) { | 1066 | if (thatcpu == cpu) |
1067 | continue; | ||
1068 | snap = per_cpu(rcu_dynticks, thatcpu).dynticks; | ||
1069 | snap_nmi = per_cpu(rcu_dynticks, thatcpu).dynticks_nmi; | ||
1070 | smp_mb(); /* Order sampling of snap with end of grace period. */ | ||
1071 | if (((snap & 0x1) != 0) || ((snap_nmi & 0x1) != 0)) { | ||
1020 | per_cpu(rcu_dyntick_drain, cpu) = 0; | 1072 | per_cpu(rcu_dyntick_drain, cpu) = 0; |
1021 | per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1; | 1073 | per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1; |
1022 | return rcu_needs_cpu_quick_check(cpu); | 1074 | return rcu_needs_cpu_quick_check(cpu); |
1023 | } | 1075 | } |
1076 | } | ||
1024 | 1077 | ||
1025 | /* Check and update the rcu_dyntick_drain sequencing. */ | 1078 | /* Check and update the rcu_dyntick_drain sequencing. */ |
1026 | if (per_cpu(rcu_dyntick_drain, cpu) <= 0) { | 1079 | if (per_cpu(rcu_dyntick_drain, cpu) <= 0) { |
diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c index d45db2e35d27..36c95b45738e 100644 --- a/kernel/rcutree_trace.c +++ b/kernel/rcutree_trace.c | |||
@@ -241,11 +241,13 @@ static const struct file_operations rcugp_fops = { | |||
241 | static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp) | 241 | static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp) |
242 | { | 242 | { |
243 | seq_printf(m, "%3d%cnp=%ld " | 243 | seq_printf(m, "%3d%cnp=%ld " |
244 | "qsp=%ld cbr=%ld cng=%ld gpc=%ld gps=%ld nf=%ld nn=%ld\n", | 244 | "qsp=%ld rpq=%ld cbr=%ld cng=%ld " |
245 | "gpc=%ld gps=%ld nf=%ld nn=%ld\n", | ||
245 | rdp->cpu, | 246 | rdp->cpu, |
246 | cpu_is_offline(rdp->cpu) ? '!' : ' ', | 247 | cpu_is_offline(rdp->cpu) ? '!' : ' ', |
247 | rdp->n_rcu_pending, | 248 | rdp->n_rcu_pending, |
248 | rdp->n_rp_qs_pending, | 249 | rdp->n_rp_qs_pending, |
250 | rdp->n_rp_report_qs, | ||
249 | rdp->n_rp_cb_ready, | 251 | rdp->n_rp_cb_ready, |
250 | rdp->n_rp_cpu_needs_gp, | 252 | rdp->n_rp_cpu_needs_gp, |
251 | rdp->n_rp_gp_completed, | 253 | rdp->n_rp_gp_completed, |
diff --git a/kernel/sched.c b/kernel/sched.c index 3c2a54f70ffe..1d93cd0ae4d3 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -55,9 +55,9 @@ | |||
55 | #include <linux/cpu.h> | 55 | #include <linux/cpu.h> |
56 | #include <linux/cpuset.h> | 56 | #include <linux/cpuset.h> |
57 | #include <linux/percpu.h> | 57 | #include <linux/percpu.h> |
58 | #include <linux/kthread.h> | ||
59 | #include <linux/proc_fs.h> | 58 | #include <linux/proc_fs.h> |
60 | #include <linux/seq_file.h> | 59 | #include <linux/seq_file.h> |
60 | #include <linux/stop_machine.h> | ||
61 | #include <linux/sysctl.h> | 61 | #include <linux/sysctl.h> |
62 | #include <linux/syscalls.h> | 62 | #include <linux/syscalls.h> |
63 | #include <linux/times.h> | 63 | #include <linux/times.h> |
@@ -503,8 +503,11 @@ struct rq { | |||
503 | #define CPU_LOAD_IDX_MAX 5 | 503 | #define CPU_LOAD_IDX_MAX 5 |
504 | unsigned long cpu_load[CPU_LOAD_IDX_MAX]; | 504 | unsigned long cpu_load[CPU_LOAD_IDX_MAX]; |
505 | #ifdef CONFIG_NO_HZ | 505 | #ifdef CONFIG_NO_HZ |
506 | u64 nohz_stamp; | ||
506 | unsigned char in_nohz_recently; | 507 | unsigned char in_nohz_recently; |
507 | #endif | 508 | #endif |
509 | unsigned int skip_clock_update; | ||
510 | |||
508 | /* capture load from *all* tasks on this cpu: */ | 511 | /* capture load from *all* tasks on this cpu: */ |
509 | struct load_weight load; | 512 | struct load_weight load; |
510 | unsigned long nr_load_updates; | 513 | unsigned long nr_load_updates; |
@@ -546,15 +549,13 @@ struct rq { | |||
546 | int post_schedule; | 549 | int post_schedule; |
547 | int active_balance; | 550 | int active_balance; |
548 | int push_cpu; | 551 | int push_cpu; |
552 | struct cpu_stop_work active_balance_work; | ||
549 | /* cpu of this runqueue: */ | 553 | /* cpu of this runqueue: */ |
550 | int cpu; | 554 | int cpu; |
551 | int online; | 555 | int online; |
552 | 556 | ||
553 | unsigned long avg_load_per_task; | 557 | unsigned long avg_load_per_task; |
554 | 558 | ||
555 | struct task_struct *migration_thread; | ||
556 | struct list_head migration_queue; | ||
557 | |||
558 | u64 rt_avg; | 559 | u64 rt_avg; |
559 | u64 age_stamp; | 560 | u64 age_stamp; |
560 | u64 idle_stamp; | 561 | u64 idle_stamp; |
@@ -602,6 +603,13 @@ static inline | |||
602 | void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) | 603 | void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) |
603 | { | 604 | { |
604 | rq->curr->sched_class->check_preempt_curr(rq, p, flags); | 605 | rq->curr->sched_class->check_preempt_curr(rq, p, flags); |
606 | |||
607 | /* | ||
608 | * A queue event has occurred, and we're going to schedule. In | ||
609 | * this case, we can save a useless back to back clock update. | ||
610 | */ | ||
611 | if (test_tsk_need_resched(p)) | ||
612 | rq->skip_clock_update = 1; | ||
605 | } | 613 | } |
606 | 614 | ||
607 | static inline int cpu_of(struct rq *rq) | 615 | static inline int cpu_of(struct rq *rq) |
@@ -636,7 +644,8 @@ static inline int cpu_of(struct rq *rq) | |||
636 | 644 | ||
637 | inline void update_rq_clock(struct rq *rq) | 645 | inline void update_rq_clock(struct rq *rq) |
638 | { | 646 | { |
639 | rq->clock = sched_clock_cpu(cpu_of(rq)); | 647 | if (!rq->skip_clock_update) |
648 | rq->clock = sched_clock_cpu(cpu_of(rq)); | ||
640 | } | 649 | } |
641 | 650 | ||
642 | /* | 651 | /* |
@@ -914,16 +923,12 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev) | |||
914 | #endif /* __ARCH_WANT_UNLOCKED_CTXSW */ | 923 | #endif /* __ARCH_WANT_UNLOCKED_CTXSW */ |
915 | 924 | ||
916 | /* | 925 | /* |
917 | * Check whether the task is waking, we use this to synchronize against | 926 | * Check whether the task is waking, we use this to synchronize ->cpus_allowed |
918 | * ttwu() so that task_cpu() reports a stable number. | 927 | * against ttwu(). |
919 | * | ||
920 | * We need to make an exception for PF_STARTING tasks because the fork | ||
921 | * path might require task_rq_lock() to work, eg. it can call | ||
922 | * set_cpus_allowed_ptr() from the cpuset clone_ns code. | ||
923 | */ | 928 | */ |
924 | static inline int task_is_waking(struct task_struct *p) | 929 | static inline int task_is_waking(struct task_struct *p) |
925 | { | 930 | { |
926 | return unlikely((p->state == TASK_WAKING) && !(p->flags & PF_STARTING)); | 931 | return unlikely(p->state == TASK_WAKING); |
927 | } | 932 | } |
928 | 933 | ||
929 | /* | 934 | /* |
@@ -936,11 +941,9 @@ static inline struct rq *__task_rq_lock(struct task_struct *p) | |||
936 | struct rq *rq; | 941 | struct rq *rq; |
937 | 942 | ||
938 | for (;;) { | 943 | for (;;) { |
939 | while (task_is_waking(p)) | ||
940 | cpu_relax(); | ||
941 | rq = task_rq(p); | 944 | rq = task_rq(p); |
942 | raw_spin_lock(&rq->lock); | 945 | raw_spin_lock(&rq->lock); |
943 | if (likely(rq == task_rq(p) && !task_is_waking(p))) | 946 | if (likely(rq == task_rq(p))) |
944 | return rq; | 947 | return rq; |
945 | raw_spin_unlock(&rq->lock); | 948 | raw_spin_unlock(&rq->lock); |
946 | } | 949 | } |
@@ -957,12 +960,10 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags) | |||
957 | struct rq *rq; | 960 | struct rq *rq; |
958 | 961 | ||
959 | for (;;) { | 962 | for (;;) { |
960 | while (task_is_waking(p)) | ||
961 | cpu_relax(); | ||
962 | local_irq_save(*flags); | 963 | local_irq_save(*flags); |
963 | rq = task_rq(p); | 964 | rq = task_rq(p); |
964 | raw_spin_lock(&rq->lock); | 965 | raw_spin_lock(&rq->lock); |
965 | if (likely(rq == task_rq(p) && !task_is_waking(p))) | 966 | if (likely(rq == task_rq(p))) |
966 | return rq; | 967 | return rq; |
967 | raw_spin_unlock_irqrestore(&rq->lock, *flags); | 968 | raw_spin_unlock_irqrestore(&rq->lock, *flags); |
968 | } | 969 | } |
@@ -1239,6 +1240,17 @@ void wake_up_idle_cpu(int cpu) | |||
1239 | if (!tsk_is_polling(rq->idle)) | 1240 | if (!tsk_is_polling(rq->idle)) |
1240 | smp_send_reschedule(cpu); | 1241 | smp_send_reschedule(cpu); |
1241 | } | 1242 | } |
1243 | |||
1244 | int nohz_ratelimit(int cpu) | ||
1245 | { | ||
1246 | struct rq *rq = cpu_rq(cpu); | ||
1247 | u64 diff = rq->clock - rq->nohz_stamp; | ||
1248 | |||
1249 | rq->nohz_stamp = rq->clock; | ||
1250 | |||
1251 | return diff < (NSEC_PER_SEC / HZ) >> 1; | ||
1252 | } | ||
1253 | |||
1242 | #endif /* CONFIG_NO_HZ */ | 1254 | #endif /* CONFIG_NO_HZ */ |
1243 | 1255 | ||
1244 | static u64 sched_avg_period(void) | 1256 | static u64 sched_avg_period(void) |
@@ -1781,8 +1793,6 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2) | |||
1781 | raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); | 1793 | raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); |
1782 | } | 1794 | } |
1783 | } | 1795 | } |
1784 | update_rq_clock(rq1); | ||
1785 | update_rq_clock(rq2); | ||
1786 | } | 1796 | } |
1787 | 1797 | ||
1788 | /* | 1798 | /* |
@@ -1813,7 +1823,7 @@ static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares) | |||
1813 | } | 1823 | } |
1814 | #endif | 1824 | #endif |
1815 | 1825 | ||
1816 | static void calc_load_account_active(struct rq *this_rq); | 1826 | static void calc_load_account_idle(struct rq *this_rq); |
1817 | static void update_sysctl(void); | 1827 | static void update_sysctl(void); |
1818 | static int get_update_sysctl_factor(void); | 1828 | static int get_update_sysctl_factor(void); |
1819 | 1829 | ||
@@ -1870,62 +1880,43 @@ static void set_load_weight(struct task_struct *p) | |||
1870 | p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO]; | 1880 | p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO]; |
1871 | } | 1881 | } |
1872 | 1882 | ||
1873 | static void update_avg(u64 *avg, u64 sample) | 1883 | static void enqueue_task(struct rq *rq, struct task_struct *p, int flags) |
1874 | { | ||
1875 | s64 diff = sample - *avg; | ||
1876 | *avg += diff >> 3; | ||
1877 | } | ||
1878 | |||
1879 | static void | ||
1880 | enqueue_task(struct rq *rq, struct task_struct *p, int wakeup, bool head) | ||
1881 | { | 1884 | { |
1882 | if (wakeup) | 1885 | update_rq_clock(rq); |
1883 | p->se.start_runtime = p->se.sum_exec_runtime; | ||
1884 | |||
1885 | sched_info_queued(p); | 1886 | sched_info_queued(p); |
1886 | p->sched_class->enqueue_task(rq, p, wakeup, head); | 1887 | p->sched_class->enqueue_task(rq, p, flags); |
1887 | p->se.on_rq = 1; | 1888 | p->se.on_rq = 1; |
1888 | } | 1889 | } |
1889 | 1890 | ||
1890 | static void dequeue_task(struct rq *rq, struct task_struct *p, int sleep) | 1891 | static void dequeue_task(struct rq *rq, struct task_struct *p, int flags) |
1891 | { | 1892 | { |
1892 | if (sleep) { | 1893 | update_rq_clock(rq); |
1893 | if (p->se.last_wakeup) { | ||
1894 | update_avg(&p->se.avg_overlap, | ||
1895 | p->se.sum_exec_runtime - p->se.last_wakeup); | ||
1896 | p->se.last_wakeup = 0; | ||
1897 | } else { | ||
1898 | update_avg(&p->se.avg_wakeup, | ||
1899 | sysctl_sched_wakeup_granularity); | ||
1900 | } | ||
1901 | } | ||
1902 | |||
1903 | sched_info_dequeued(p); | 1894 | sched_info_dequeued(p); |
1904 | p->sched_class->dequeue_task(rq, p, sleep); | 1895 | p->sched_class->dequeue_task(rq, p, flags); |
1905 | p->se.on_rq = 0; | 1896 | p->se.on_rq = 0; |
1906 | } | 1897 | } |
1907 | 1898 | ||
1908 | /* | 1899 | /* |
1909 | * activate_task - move a task to the runqueue. | 1900 | * activate_task - move a task to the runqueue. |
1910 | */ | 1901 | */ |
1911 | static void activate_task(struct rq *rq, struct task_struct *p, int wakeup) | 1902 | static void activate_task(struct rq *rq, struct task_struct *p, int flags) |
1912 | { | 1903 | { |
1913 | if (task_contributes_to_load(p)) | 1904 | if (task_contributes_to_load(p)) |
1914 | rq->nr_uninterruptible--; | 1905 | rq->nr_uninterruptible--; |
1915 | 1906 | ||
1916 | enqueue_task(rq, p, wakeup, false); | 1907 | enqueue_task(rq, p, flags); |
1917 | inc_nr_running(rq); | 1908 | inc_nr_running(rq); |
1918 | } | 1909 | } |
1919 | 1910 | ||
1920 | /* | 1911 | /* |
1921 | * deactivate_task - remove a task from the runqueue. | 1912 | * deactivate_task - remove a task from the runqueue. |
1922 | */ | 1913 | */ |
1923 | static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep) | 1914 | static void deactivate_task(struct rq *rq, struct task_struct *p, int flags) |
1924 | { | 1915 | { |
1925 | if (task_contributes_to_load(p)) | 1916 | if (task_contributes_to_load(p)) |
1926 | rq->nr_uninterruptible++; | 1917 | rq->nr_uninterruptible++; |
1927 | 1918 | ||
1928 | dequeue_task(rq, p, sleep); | 1919 | dequeue_task(rq, p, flags); |
1929 | dec_nr_running(rq); | 1920 | dec_nr_running(rq); |
1930 | } | 1921 | } |
1931 | 1922 | ||
@@ -2054,21 +2045,18 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu) | |||
2054 | __set_task_cpu(p, new_cpu); | 2045 | __set_task_cpu(p, new_cpu); |
2055 | } | 2046 | } |
2056 | 2047 | ||
2057 | struct migration_req { | 2048 | struct migration_arg { |
2058 | struct list_head list; | ||
2059 | |||
2060 | struct task_struct *task; | 2049 | struct task_struct *task; |
2061 | int dest_cpu; | 2050 | int dest_cpu; |
2062 | |||
2063 | struct completion done; | ||
2064 | }; | 2051 | }; |
2065 | 2052 | ||
2053 | static int migration_cpu_stop(void *data); | ||
2054 | |||
2066 | /* | 2055 | /* |
2067 | * The task's runqueue lock must be held. | 2056 | * The task's runqueue lock must be held. |
2068 | * Returns true if you have to wait for migration thread. | 2057 | * Returns true if you have to wait for migration thread. |
2069 | */ | 2058 | */ |
2070 | static int | 2059 | static bool migrate_task(struct task_struct *p, int dest_cpu) |
2071 | migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | ||
2072 | { | 2060 | { |
2073 | struct rq *rq = task_rq(p); | 2061 | struct rq *rq = task_rq(p); |
2074 | 2062 | ||
@@ -2076,58 +2064,7 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | |||
2076 | * If the task is not on a runqueue (and not running), then | 2064 | * If the task is not on a runqueue (and not running), then |
2077 | * the next wake-up will properly place the task. | 2065 | * the next wake-up will properly place the task. |
2078 | */ | 2066 | */ |
2079 | if (!p->se.on_rq && !task_running(rq, p)) | 2067 | return p->se.on_rq || task_running(rq, p); |
2080 | return 0; | ||
2081 | |||
2082 | init_completion(&req->done); | ||
2083 | req->task = p; | ||
2084 | req->dest_cpu = dest_cpu; | ||
2085 | list_add(&req->list, &rq->migration_queue); | ||
2086 | |||
2087 | return 1; | ||
2088 | } | ||
2089 | |||
2090 | /* | ||
2091 | * wait_task_context_switch - wait for a thread to complete at least one | ||
2092 | * context switch. | ||
2093 | * | ||
2094 | * @p must not be current. | ||
2095 | */ | ||
2096 | void wait_task_context_switch(struct task_struct *p) | ||
2097 | { | ||
2098 | unsigned long nvcsw, nivcsw, flags; | ||
2099 | int running; | ||
2100 | struct rq *rq; | ||
2101 | |||
2102 | nvcsw = p->nvcsw; | ||
2103 | nivcsw = p->nivcsw; | ||
2104 | for (;;) { | ||
2105 | /* | ||
2106 | * The runqueue is assigned before the actual context | ||
2107 | * switch. We need to take the runqueue lock. | ||
2108 | * | ||
2109 | * We could check initially without the lock but it is | ||
2110 | * very likely that we need to take the lock in every | ||
2111 | * iteration. | ||
2112 | */ | ||
2113 | rq = task_rq_lock(p, &flags); | ||
2114 | running = task_running(rq, p); | ||
2115 | task_rq_unlock(rq, &flags); | ||
2116 | |||
2117 | if (likely(!running)) | ||
2118 | break; | ||
2119 | /* | ||
2120 | * The switch count is incremented before the actual | ||
2121 | * context switch. We thus wait for two switches to be | ||
2122 | * sure at least one completed. | ||
2123 | */ | ||
2124 | if ((p->nvcsw - nvcsw) > 1) | ||
2125 | break; | ||
2126 | if ((p->nivcsw - nivcsw) > 1) | ||
2127 | break; | ||
2128 | |||
2129 | cpu_relax(); | ||
2130 | } | ||
2131 | } | 2068 | } |
2132 | 2069 | ||
2133 | /* | 2070 | /* |
@@ -2185,7 +2122,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state) | |||
2185 | * just go back and repeat. | 2122 | * just go back and repeat. |
2186 | */ | 2123 | */ |
2187 | rq = task_rq_lock(p, &flags); | 2124 | rq = task_rq_lock(p, &flags); |
2188 | trace_sched_wait_task(rq, p); | 2125 | trace_sched_wait_task(p); |
2189 | running = task_running(rq, p); | 2126 | running = task_running(rq, p); |
2190 | on_rq = p->se.on_rq; | 2127 | on_rq = p->se.on_rq; |
2191 | ncsw = 0; | 2128 | ncsw = 0; |
@@ -2283,6 +2220,9 @@ void task_oncpu_function_call(struct task_struct *p, | |||
2283 | } | 2220 | } |
2284 | 2221 | ||
2285 | #ifdef CONFIG_SMP | 2222 | #ifdef CONFIG_SMP |
2223 | /* | ||
2224 | * ->cpus_allowed is protected by either TASK_WAKING or rq->lock held. | ||
2225 | */ | ||
2286 | static int select_fallback_rq(int cpu, struct task_struct *p) | 2226 | static int select_fallback_rq(int cpu, struct task_struct *p) |
2287 | { | 2227 | { |
2288 | int dest_cpu; | 2228 | int dest_cpu; |
@@ -2299,12 +2239,8 @@ static int select_fallback_rq(int cpu, struct task_struct *p) | |||
2299 | return dest_cpu; | 2239 | return dest_cpu; |
2300 | 2240 | ||
2301 | /* No more Mr. Nice Guy. */ | 2241 | /* No more Mr. Nice Guy. */ |
2302 | if (dest_cpu >= nr_cpu_ids) { | 2242 | if (unlikely(dest_cpu >= nr_cpu_ids)) { |
2303 | rcu_read_lock(); | 2243 | dest_cpu = cpuset_cpus_allowed_fallback(p); |
2304 | cpuset_cpus_allowed_locked(p, &p->cpus_allowed); | ||
2305 | rcu_read_unlock(); | ||
2306 | dest_cpu = cpumask_any_and(cpu_active_mask, &p->cpus_allowed); | ||
2307 | |||
2308 | /* | 2244 | /* |
2309 | * Don't tell them about moving exiting tasks or | 2245 | * Don't tell them about moving exiting tasks or |
2310 | * kernel threads (both mm NULL), since they never | 2246 | * kernel threads (both mm NULL), since they never |
@@ -2321,17 +2257,12 @@ static int select_fallback_rq(int cpu, struct task_struct *p) | |||
2321 | } | 2257 | } |
2322 | 2258 | ||
2323 | /* | 2259 | /* |
2324 | * Gets called from 3 sites (exec, fork, wakeup), since it is called without | 2260 | * The caller (fork, wakeup) owns TASK_WAKING, ->cpus_allowed is stable. |
2325 | * holding rq->lock we need to ensure ->cpus_allowed is stable, this is done | ||
2326 | * by: | ||
2327 | * | ||
2328 | * exec: is unstable, retry loop | ||
2329 | * fork & wake-up: serialize ->cpus_allowed against TASK_WAKING | ||
2330 | */ | 2261 | */ |
2331 | static inline | 2262 | static inline |
2332 | int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags) | 2263 | int select_task_rq(struct rq *rq, struct task_struct *p, int sd_flags, int wake_flags) |
2333 | { | 2264 | { |
2334 | int cpu = p->sched_class->select_task_rq(p, sd_flags, wake_flags); | 2265 | int cpu = p->sched_class->select_task_rq(rq, p, sd_flags, wake_flags); |
2335 | 2266 | ||
2336 | /* | 2267 | /* |
2337 | * In order not to call set_task_cpu() on a blocking task we need | 2268 | * In order not to call set_task_cpu() on a blocking task we need |
@@ -2349,6 +2280,12 @@ int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags) | |||
2349 | 2280 | ||
2350 | return cpu; | 2281 | return cpu; |
2351 | } | 2282 | } |
2283 | |||
2284 | static void update_avg(u64 *avg, u64 sample) | ||
2285 | { | ||
2286 | s64 diff = sample - *avg; | ||
2287 | *avg += diff >> 3; | ||
2288 | } | ||
2352 | #endif | 2289 | #endif |
2353 | 2290 | ||
2354 | /*** | 2291 | /*** |
@@ -2370,16 +2307,13 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2370 | { | 2307 | { |
2371 | int cpu, orig_cpu, this_cpu, success = 0; | 2308 | int cpu, orig_cpu, this_cpu, success = 0; |
2372 | unsigned long flags; | 2309 | unsigned long flags; |
2310 | unsigned long en_flags = ENQUEUE_WAKEUP; | ||
2373 | struct rq *rq; | 2311 | struct rq *rq; |
2374 | 2312 | ||
2375 | if (!sched_feat(SYNC_WAKEUPS)) | ||
2376 | wake_flags &= ~WF_SYNC; | ||
2377 | |||
2378 | this_cpu = get_cpu(); | 2313 | this_cpu = get_cpu(); |
2379 | 2314 | ||
2380 | smp_wmb(); | 2315 | smp_wmb(); |
2381 | rq = task_rq_lock(p, &flags); | 2316 | rq = task_rq_lock(p, &flags); |
2382 | update_rq_clock(rq); | ||
2383 | if (!(p->state & state)) | 2317 | if (!(p->state & state)) |
2384 | goto out; | 2318 | goto out; |
2385 | 2319 | ||
@@ -2399,28 +2333,26 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2399 | * | 2333 | * |
2400 | * First fix up the nr_uninterruptible count: | 2334 | * First fix up the nr_uninterruptible count: |
2401 | */ | 2335 | */ |
2402 | if (task_contributes_to_load(p)) | 2336 | if (task_contributes_to_load(p)) { |
2403 | rq->nr_uninterruptible--; | 2337 | if (likely(cpu_online(orig_cpu))) |
2338 | rq->nr_uninterruptible--; | ||
2339 | else | ||
2340 | this_rq()->nr_uninterruptible--; | ||
2341 | } | ||
2404 | p->state = TASK_WAKING; | 2342 | p->state = TASK_WAKING; |
2405 | 2343 | ||
2406 | if (p->sched_class->task_waking) | 2344 | if (p->sched_class->task_waking) { |
2407 | p->sched_class->task_waking(rq, p); | 2345 | p->sched_class->task_waking(rq, p); |
2346 | en_flags |= ENQUEUE_WAKING; | ||
2347 | } | ||
2408 | 2348 | ||
2409 | __task_rq_unlock(rq); | 2349 | cpu = select_task_rq(rq, p, SD_BALANCE_WAKE, wake_flags); |
2410 | 2350 | if (cpu != orig_cpu) | |
2411 | cpu = select_task_rq(p, SD_BALANCE_WAKE, wake_flags); | ||
2412 | if (cpu != orig_cpu) { | ||
2413 | /* | ||
2414 | * Since we migrate the task without holding any rq->lock, | ||
2415 | * we need to be careful with task_rq_lock(), since that | ||
2416 | * might end up locking an invalid rq. | ||
2417 | */ | ||
2418 | set_task_cpu(p, cpu); | 2351 | set_task_cpu(p, cpu); |
2419 | } | 2352 | __task_rq_unlock(rq); |
2420 | 2353 | ||
2421 | rq = cpu_rq(cpu); | 2354 | rq = cpu_rq(cpu); |
2422 | raw_spin_lock(&rq->lock); | 2355 | raw_spin_lock(&rq->lock); |
2423 | update_rq_clock(rq); | ||
2424 | 2356 | ||
2425 | /* | 2357 | /* |
2426 | * We migrated the task without holding either rq->lock, however | 2358 | * We migrated the task without holding either rq->lock, however |
@@ -2448,36 +2380,20 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2448 | 2380 | ||
2449 | out_activate: | 2381 | out_activate: |
2450 | #endif /* CONFIG_SMP */ | 2382 | #endif /* CONFIG_SMP */ |
2451 | schedstat_inc(p, se.nr_wakeups); | 2383 | schedstat_inc(p, se.statistics.nr_wakeups); |
2452 | if (wake_flags & WF_SYNC) | 2384 | if (wake_flags & WF_SYNC) |
2453 | schedstat_inc(p, se.nr_wakeups_sync); | 2385 | schedstat_inc(p, se.statistics.nr_wakeups_sync); |
2454 | if (orig_cpu != cpu) | 2386 | if (orig_cpu != cpu) |
2455 | schedstat_inc(p, se.nr_wakeups_migrate); | 2387 | schedstat_inc(p, se.statistics.nr_wakeups_migrate); |
2456 | if (cpu == this_cpu) | 2388 | if (cpu == this_cpu) |
2457 | schedstat_inc(p, se.nr_wakeups_local); | 2389 | schedstat_inc(p, se.statistics.nr_wakeups_local); |
2458 | else | 2390 | else |
2459 | schedstat_inc(p, se.nr_wakeups_remote); | 2391 | schedstat_inc(p, se.statistics.nr_wakeups_remote); |
2460 | activate_task(rq, p, 1); | 2392 | activate_task(rq, p, en_flags); |
2461 | success = 1; | 2393 | success = 1; |
2462 | 2394 | ||
2463 | /* | ||
2464 | * Only attribute actual wakeups done by this task. | ||
2465 | */ | ||
2466 | if (!in_interrupt()) { | ||
2467 | struct sched_entity *se = ¤t->se; | ||
2468 | u64 sample = se->sum_exec_runtime; | ||
2469 | |||
2470 | if (se->last_wakeup) | ||
2471 | sample -= se->last_wakeup; | ||
2472 | else | ||
2473 | sample -= se->start_runtime; | ||
2474 | update_avg(&se->avg_wakeup, sample); | ||
2475 | |||
2476 | se->last_wakeup = se->sum_exec_runtime; | ||
2477 | } | ||
2478 | |||
2479 | out_running: | 2395 | out_running: |
2480 | trace_sched_wakeup(rq, p, success); | 2396 | trace_sched_wakeup(p, success); |
2481 | check_preempt_curr(rq, p, wake_flags); | 2397 | check_preempt_curr(rq, p, wake_flags); |
2482 | 2398 | ||
2483 | p->state = TASK_RUNNING; | 2399 | p->state = TASK_RUNNING; |
@@ -2537,42 +2453,9 @@ static void __sched_fork(struct task_struct *p) | |||
2537 | p->se.sum_exec_runtime = 0; | 2453 | p->se.sum_exec_runtime = 0; |
2538 | p->se.prev_sum_exec_runtime = 0; | 2454 | p->se.prev_sum_exec_runtime = 0; |
2539 | p->se.nr_migrations = 0; | 2455 | p->se.nr_migrations = 0; |
2540 | p->se.last_wakeup = 0; | ||
2541 | p->se.avg_overlap = 0; | ||
2542 | p->se.start_runtime = 0; | ||
2543 | p->se.avg_wakeup = sysctl_sched_wakeup_granularity; | ||
2544 | 2456 | ||
2545 | #ifdef CONFIG_SCHEDSTATS | 2457 | #ifdef CONFIG_SCHEDSTATS |
2546 | p->se.wait_start = 0; | 2458 | memset(&p->se.statistics, 0, sizeof(p->se.statistics)); |
2547 | p->se.wait_max = 0; | ||
2548 | p->se.wait_count = 0; | ||
2549 | p->se.wait_sum = 0; | ||
2550 | |||
2551 | p->se.sleep_start = 0; | ||
2552 | p->se.sleep_max = 0; | ||
2553 | p->se.sum_sleep_runtime = 0; | ||
2554 | |||
2555 | p->se.block_start = 0; | ||
2556 | p->se.block_max = 0; | ||
2557 | p->se.exec_max = 0; | ||
2558 | p->se.slice_max = 0; | ||
2559 | |||
2560 | p->se.nr_migrations_cold = 0; | ||
2561 | p->se.nr_failed_migrations_affine = 0; | ||
2562 | p->se.nr_failed_migrations_running = 0; | ||
2563 | p->se.nr_failed_migrations_hot = 0; | ||
2564 | p->se.nr_forced_migrations = 0; | ||
2565 | |||
2566 | p->se.nr_wakeups = 0; | ||
2567 | p->se.nr_wakeups_sync = 0; | ||
2568 | p->se.nr_wakeups_migrate = 0; | ||
2569 | p->se.nr_wakeups_local = 0; | ||
2570 | p->se.nr_wakeups_remote = 0; | ||
2571 | p->se.nr_wakeups_affine = 0; | ||
2572 | p->se.nr_wakeups_affine_attempts = 0; | ||
2573 | p->se.nr_wakeups_passive = 0; | ||
2574 | p->se.nr_wakeups_idle = 0; | ||
2575 | |||
2576 | #endif | 2459 | #endif |
2577 | 2460 | ||
2578 | INIT_LIST_HEAD(&p->rt.run_list); | 2461 | INIT_LIST_HEAD(&p->rt.run_list); |
@@ -2593,11 +2476,11 @@ void sched_fork(struct task_struct *p, int clone_flags) | |||
2593 | 2476 | ||
2594 | __sched_fork(p); | 2477 | __sched_fork(p); |
2595 | /* | 2478 | /* |
2596 | * We mark the process as waking here. This guarantees that | 2479 | * We mark the process as running here. This guarantees that |
2597 | * nobody will actually run it, and a signal or other external | 2480 | * nobody will actually run it, and a signal or other external |
2598 | * event cannot wake it up and insert it on the runqueue either. | 2481 | * event cannot wake it up and insert it on the runqueue either. |
2599 | */ | 2482 | */ |
2600 | p->state = TASK_WAKING; | 2483 | p->state = TASK_RUNNING; |
2601 | 2484 | ||
2602 | /* | 2485 | /* |
2603 | * Revert to default priority/policy on fork if requested. | 2486 | * Revert to default priority/policy on fork if requested. |
@@ -2664,31 +2547,27 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags) | |||
2664 | int cpu __maybe_unused = get_cpu(); | 2547 | int cpu __maybe_unused = get_cpu(); |
2665 | 2548 | ||
2666 | #ifdef CONFIG_SMP | 2549 | #ifdef CONFIG_SMP |
2550 | rq = task_rq_lock(p, &flags); | ||
2551 | p->state = TASK_WAKING; | ||
2552 | |||
2667 | /* | 2553 | /* |
2668 | * Fork balancing, do it here and not earlier because: | 2554 | * Fork balancing, do it here and not earlier because: |
2669 | * - cpus_allowed can change in the fork path | 2555 | * - cpus_allowed can change in the fork path |
2670 | * - any previously selected cpu might disappear through hotplug | 2556 | * - any previously selected cpu might disappear through hotplug |
2671 | * | 2557 | * |
2672 | * We still have TASK_WAKING but PF_STARTING is gone now, meaning | 2558 | * We set TASK_WAKING so that select_task_rq() can drop rq->lock |
2673 | * ->cpus_allowed is stable, we have preemption disabled, meaning | 2559 | * without people poking at ->cpus_allowed. |
2674 | * cpu_online_mask is stable. | ||
2675 | */ | 2560 | */ |
2676 | cpu = select_task_rq(p, SD_BALANCE_FORK, 0); | 2561 | cpu = select_task_rq(rq, p, SD_BALANCE_FORK, 0); |
2677 | set_task_cpu(p, cpu); | 2562 | set_task_cpu(p, cpu); |
2678 | #endif | ||
2679 | |||
2680 | /* | ||
2681 | * Since the task is not on the rq and we still have TASK_WAKING set | ||
2682 | * nobody else will migrate this task. | ||
2683 | */ | ||
2684 | rq = cpu_rq(cpu); | ||
2685 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
2686 | 2563 | ||
2687 | BUG_ON(p->state != TASK_WAKING); | ||
2688 | p->state = TASK_RUNNING; | 2564 | p->state = TASK_RUNNING; |
2689 | update_rq_clock(rq); | 2565 | task_rq_unlock(rq, &flags); |
2566 | #endif | ||
2567 | |||
2568 | rq = task_rq_lock(p, &flags); | ||
2690 | activate_task(rq, p, 0); | 2569 | activate_task(rq, p, 0); |
2691 | trace_sched_wakeup_new(rq, p, 1); | 2570 | trace_sched_wakeup_new(p, 1); |
2692 | check_preempt_curr(rq, p, WF_FORK); | 2571 | check_preempt_curr(rq, p, WF_FORK); |
2693 | #ifdef CONFIG_SMP | 2572 | #ifdef CONFIG_SMP |
2694 | if (p->sched_class->task_woken) | 2573 | if (p->sched_class->task_woken) |
@@ -2908,7 +2787,7 @@ context_switch(struct rq *rq, struct task_struct *prev, | |||
2908 | struct mm_struct *mm, *oldmm; | 2787 | struct mm_struct *mm, *oldmm; |
2909 | 2788 | ||
2910 | prepare_task_switch(rq, prev, next); | 2789 | prepare_task_switch(rq, prev, next); |
2911 | trace_sched_switch(rq, prev, next); | 2790 | trace_sched_switch(prev, next); |
2912 | mm = next->mm; | 2791 | mm = next->mm; |
2913 | oldmm = prev->active_mm; | 2792 | oldmm = prev->active_mm; |
2914 | /* | 2793 | /* |
@@ -3025,6 +2904,61 @@ static unsigned long calc_load_update; | |||
3025 | unsigned long avenrun[3]; | 2904 | unsigned long avenrun[3]; |
3026 | EXPORT_SYMBOL(avenrun); | 2905 | EXPORT_SYMBOL(avenrun); |
3027 | 2906 | ||
2907 | static long calc_load_fold_active(struct rq *this_rq) | ||
2908 | { | ||
2909 | long nr_active, delta = 0; | ||
2910 | |||
2911 | nr_active = this_rq->nr_running; | ||
2912 | nr_active += (long) this_rq->nr_uninterruptible; | ||
2913 | |||
2914 | if (nr_active != this_rq->calc_load_active) { | ||
2915 | delta = nr_active - this_rq->calc_load_active; | ||
2916 | this_rq->calc_load_active = nr_active; | ||
2917 | } | ||
2918 | |||
2919 | return delta; | ||
2920 | } | ||
2921 | |||
2922 | #ifdef CONFIG_NO_HZ | ||
2923 | /* | ||
2924 | * For NO_HZ we delay the active fold to the next LOAD_FREQ update. | ||
2925 | * | ||
2926 | * When making the ILB scale, we should try to pull this in as well. | ||
2927 | */ | ||
2928 | static atomic_long_t calc_load_tasks_idle; | ||
2929 | |||
2930 | static void calc_load_account_idle(struct rq *this_rq) | ||
2931 | { | ||
2932 | long delta; | ||
2933 | |||
2934 | delta = calc_load_fold_active(this_rq); | ||
2935 | if (delta) | ||
2936 | atomic_long_add(delta, &calc_load_tasks_idle); | ||
2937 | } | ||
2938 | |||
2939 | static long calc_load_fold_idle(void) | ||
2940 | { | ||
2941 | long delta = 0; | ||
2942 | |||
2943 | /* | ||
2944 | * Its got a race, we don't care... | ||
2945 | */ | ||
2946 | if (atomic_long_read(&calc_load_tasks_idle)) | ||
2947 | delta = atomic_long_xchg(&calc_load_tasks_idle, 0); | ||
2948 | |||
2949 | return delta; | ||
2950 | } | ||
2951 | #else | ||
2952 | static void calc_load_account_idle(struct rq *this_rq) | ||
2953 | { | ||
2954 | } | ||
2955 | |||
2956 | static inline long calc_load_fold_idle(void) | ||
2957 | { | ||
2958 | return 0; | ||
2959 | } | ||
2960 | #endif | ||
2961 | |||
3028 | /** | 2962 | /** |
3029 | * get_avenrun - get the load average array | 2963 | * get_avenrun - get the load average array |
3030 | * @loads: pointer to dest load array | 2964 | * @loads: pointer to dest load array |
@@ -3071,20 +3005,22 @@ void calc_global_load(void) | |||
3071 | } | 3005 | } |
3072 | 3006 | ||
3073 | /* | 3007 | /* |
3074 | * Either called from update_cpu_load() or from a cpu going idle | 3008 | * Called from update_cpu_load() to periodically update this CPU's |
3009 | * active count. | ||
3075 | */ | 3010 | */ |
3076 | static void calc_load_account_active(struct rq *this_rq) | 3011 | static void calc_load_account_active(struct rq *this_rq) |
3077 | { | 3012 | { |
3078 | long nr_active, delta; | 3013 | long delta; |
3079 | 3014 | ||
3080 | nr_active = this_rq->nr_running; | 3015 | if (time_before(jiffies, this_rq->calc_load_update)) |
3081 | nr_active += (long) this_rq->nr_uninterruptible; | 3016 | return; |
3082 | 3017 | ||
3083 | if (nr_active != this_rq->calc_load_active) { | 3018 | delta = calc_load_fold_active(this_rq); |
3084 | delta = nr_active - this_rq->calc_load_active; | 3019 | delta += calc_load_fold_idle(); |
3085 | this_rq->calc_load_active = nr_active; | 3020 | if (delta) |
3086 | atomic_long_add(delta, &calc_load_tasks); | 3021 | atomic_long_add(delta, &calc_load_tasks); |
3087 | } | 3022 | |
3023 | this_rq->calc_load_update += LOAD_FREQ; | ||
3088 | } | 3024 | } |
3089 | 3025 | ||
3090 | /* | 3026 | /* |
@@ -3116,10 +3052,7 @@ static void update_cpu_load(struct rq *this_rq) | |||
3116 | this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i; | 3052 | this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i; |
3117 | } | 3053 | } |
3118 | 3054 | ||
3119 | if (time_after_eq(jiffies, this_rq->calc_load_update)) { | 3055 | calc_load_account_active(this_rq); |
3120 | this_rq->calc_load_update += LOAD_FREQ; | ||
3121 | calc_load_account_active(this_rq); | ||
3122 | } | ||
3123 | } | 3056 | } |
3124 | 3057 | ||
3125 | #ifdef CONFIG_SMP | 3058 | #ifdef CONFIG_SMP |
@@ -3131,44 +3064,27 @@ static void update_cpu_load(struct rq *this_rq) | |||
3131 | void sched_exec(void) | 3064 | void sched_exec(void) |
3132 | { | 3065 | { |
3133 | struct task_struct *p = current; | 3066 | struct task_struct *p = current; |
3134 | struct migration_req req; | ||
3135 | int dest_cpu, this_cpu; | ||
3136 | unsigned long flags; | 3067 | unsigned long flags; |
3137 | struct rq *rq; | 3068 | struct rq *rq; |
3138 | 3069 | int dest_cpu; | |
3139 | again: | ||
3140 | this_cpu = get_cpu(); | ||
3141 | dest_cpu = select_task_rq(p, SD_BALANCE_EXEC, 0); | ||
3142 | if (dest_cpu == this_cpu) { | ||
3143 | put_cpu(); | ||
3144 | return; | ||
3145 | } | ||
3146 | 3070 | ||
3147 | rq = task_rq_lock(p, &flags); | 3071 | rq = task_rq_lock(p, &flags); |
3148 | put_cpu(); | 3072 | dest_cpu = p->sched_class->select_task_rq(rq, p, SD_BALANCE_EXEC, 0); |
3073 | if (dest_cpu == smp_processor_id()) | ||
3074 | goto unlock; | ||
3149 | 3075 | ||
3150 | /* | 3076 | /* |
3151 | * select_task_rq() can race against ->cpus_allowed | 3077 | * select_task_rq() can race against ->cpus_allowed |
3152 | */ | 3078 | */ |
3153 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed) | 3079 | if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed) && |
3154 | || unlikely(!cpu_active(dest_cpu))) { | 3080 | likely(cpu_active(dest_cpu)) && migrate_task(p, dest_cpu)) { |
3155 | task_rq_unlock(rq, &flags); | 3081 | struct migration_arg arg = { p, dest_cpu }; |
3156 | goto again; | ||
3157 | } | ||
3158 | 3082 | ||
3159 | /* force the process onto the specified CPU */ | ||
3160 | if (migrate_task(p, dest_cpu, &req)) { | ||
3161 | /* Need to wait for migration thread (might exit: take ref). */ | ||
3162 | struct task_struct *mt = rq->migration_thread; | ||
3163 | |||
3164 | get_task_struct(mt); | ||
3165 | task_rq_unlock(rq, &flags); | 3083 | task_rq_unlock(rq, &flags); |
3166 | wake_up_process(mt); | 3084 | stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); |
3167 | put_task_struct(mt); | ||
3168 | wait_for_completion(&req.done); | ||
3169 | |||
3170 | return; | 3085 | return; |
3171 | } | 3086 | } |
3087 | unlock: | ||
3172 | task_rq_unlock(rq, &flags); | 3088 | task_rq_unlock(rq, &flags); |
3173 | } | 3089 | } |
3174 | 3090 | ||
@@ -3640,23 +3556,9 @@ static inline void schedule_debug(struct task_struct *prev) | |||
3640 | 3556 | ||
3641 | static void put_prev_task(struct rq *rq, struct task_struct *prev) | 3557 | static void put_prev_task(struct rq *rq, struct task_struct *prev) |
3642 | { | 3558 | { |
3643 | if (prev->state == TASK_RUNNING) { | 3559 | if (prev->se.on_rq) |
3644 | u64 runtime = prev->se.sum_exec_runtime; | 3560 | update_rq_clock(rq); |
3645 | 3561 | rq->skip_clock_update = 0; | |
3646 | runtime -= prev->se.prev_sum_exec_runtime; | ||
3647 | runtime = min_t(u64, runtime, 2*sysctl_sched_migration_cost); | ||
3648 | |||
3649 | /* | ||
3650 | * In order to avoid avg_overlap growing stale when we are | ||
3651 | * indeed overlapping and hence not getting put to sleep, grow | ||
3652 | * the avg_overlap on preemption. | ||
3653 | * | ||
3654 | * We use the average preemption runtime because that | ||
3655 | * correlates to the amount of cache footprint a task can | ||
3656 | * build up. | ||
3657 | */ | ||
3658 | update_avg(&prev->se.avg_overlap, runtime); | ||
3659 | } | ||
3660 | prev->sched_class->put_prev_task(rq, prev); | 3562 | prev->sched_class->put_prev_task(rq, prev); |
3661 | } | 3563 | } |
3662 | 3564 | ||
@@ -3706,7 +3608,7 @@ need_resched: | |||
3706 | preempt_disable(); | 3608 | preempt_disable(); |
3707 | cpu = smp_processor_id(); | 3609 | cpu = smp_processor_id(); |
3708 | rq = cpu_rq(cpu); | 3610 | rq = cpu_rq(cpu); |
3709 | rcu_sched_qs(cpu); | 3611 | rcu_note_context_switch(cpu); |
3710 | prev = rq->curr; | 3612 | prev = rq->curr; |
3711 | switch_count = &prev->nivcsw; | 3613 | switch_count = &prev->nivcsw; |
3712 | 3614 | ||
@@ -3719,14 +3621,13 @@ need_resched_nonpreemptible: | |||
3719 | hrtick_clear(rq); | 3621 | hrtick_clear(rq); |
3720 | 3622 | ||
3721 | raw_spin_lock_irq(&rq->lock); | 3623 | raw_spin_lock_irq(&rq->lock); |
3722 | update_rq_clock(rq); | ||
3723 | clear_tsk_need_resched(prev); | 3624 | clear_tsk_need_resched(prev); |
3724 | 3625 | ||
3725 | if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) { | 3626 | if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) { |
3726 | if (unlikely(signal_pending_state(prev->state, prev))) | 3627 | if (unlikely(signal_pending_state(prev->state, prev))) |
3727 | prev->state = TASK_RUNNING; | 3628 | prev->state = TASK_RUNNING; |
3728 | else | 3629 | else |
3729 | deactivate_task(rq, prev, 1); | 3630 | deactivate_task(rq, prev, DEQUEUE_SLEEP); |
3730 | switch_count = &prev->nvcsw; | 3631 | switch_count = &prev->nvcsw; |
3731 | } | 3632 | } |
3732 | 3633 | ||
@@ -4049,8 +3950,7 @@ do_wait_for_common(struct completion *x, long timeout, int state) | |||
4049 | if (!x->done) { | 3950 | if (!x->done) { |
4050 | DECLARE_WAITQUEUE(wait, current); | 3951 | DECLARE_WAITQUEUE(wait, current); |
4051 | 3952 | ||
4052 | wait.flags |= WQ_FLAG_EXCLUSIVE; | 3953 | __add_wait_queue_tail_exclusive(&x->wait, &wait); |
4053 | __add_wait_queue_tail(&x->wait, &wait); | ||
4054 | do { | 3954 | do { |
4055 | if (signal_pending_state(state, current)) { | 3955 | if (signal_pending_state(state, current)) { |
4056 | timeout = -ERESTARTSYS; | 3956 | timeout = -ERESTARTSYS; |
@@ -4276,7 +4176,6 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
4276 | BUG_ON(prio < 0 || prio > MAX_PRIO); | 4176 | BUG_ON(prio < 0 || prio > MAX_PRIO); |
4277 | 4177 | ||
4278 | rq = task_rq_lock(p, &flags); | 4178 | rq = task_rq_lock(p, &flags); |
4279 | update_rq_clock(rq); | ||
4280 | 4179 | ||
4281 | oldprio = p->prio; | 4180 | oldprio = p->prio; |
4282 | prev_class = p->sched_class; | 4181 | prev_class = p->sched_class; |
@@ -4297,7 +4196,7 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
4297 | if (running) | 4196 | if (running) |
4298 | p->sched_class->set_curr_task(rq); | 4197 | p->sched_class->set_curr_task(rq); |
4299 | if (on_rq) { | 4198 | if (on_rq) { |
4300 | enqueue_task(rq, p, 0, oldprio < prio); | 4199 | enqueue_task(rq, p, oldprio < prio ? ENQUEUE_HEAD : 0); |
4301 | 4200 | ||
4302 | check_class_changed(rq, p, prev_class, oldprio, running); | 4201 | check_class_changed(rq, p, prev_class, oldprio, running); |
4303 | } | 4202 | } |
@@ -4319,7 +4218,6 @@ void set_user_nice(struct task_struct *p, long nice) | |||
4319 | * the task might be in the middle of scheduling on another CPU. | 4218 | * the task might be in the middle of scheduling on another CPU. |
4320 | */ | 4219 | */ |
4321 | rq = task_rq_lock(p, &flags); | 4220 | rq = task_rq_lock(p, &flags); |
4322 | update_rq_clock(rq); | ||
4323 | /* | 4221 | /* |
4324 | * The RT priorities are set via sched_setscheduler(), but we still | 4222 | * The RT priorities are set via sched_setscheduler(), but we still |
4325 | * allow the 'normal' nice value to be set - but as expected | 4223 | * allow the 'normal' nice value to be set - but as expected |
@@ -4341,7 +4239,7 @@ void set_user_nice(struct task_struct *p, long nice) | |||
4341 | delta = p->prio - old_prio; | 4239 | delta = p->prio - old_prio; |
4342 | 4240 | ||
4343 | if (on_rq) { | 4241 | if (on_rq) { |
4344 | enqueue_task(rq, p, 0, false); | 4242 | enqueue_task(rq, p, 0); |
4345 | /* | 4243 | /* |
4346 | * If the task increased its priority or is running and | 4244 | * If the task increased its priority or is running and |
4347 | * lowered its priority, then reschedule its CPU: | 4245 | * lowered its priority, then reschedule its CPU: |
@@ -4602,7 +4500,6 @@ recheck: | |||
4602 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); | 4500 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); |
4603 | goto recheck; | 4501 | goto recheck; |
4604 | } | 4502 | } |
4605 | update_rq_clock(rq); | ||
4606 | on_rq = p->se.on_rq; | 4503 | on_rq = p->se.on_rq; |
4607 | running = task_current(rq, p); | 4504 | running = task_current(rq, p); |
4608 | if (on_rq) | 4505 | if (on_rq) |
@@ -5339,17 +5236,15 @@ static inline void sched_init_granularity(void) | |||
5339 | /* | 5236 | /* |
5340 | * This is how migration works: | 5237 | * This is how migration works: |
5341 | * | 5238 | * |
5342 | * 1) we queue a struct migration_req structure in the source CPU's | 5239 | * 1) we invoke migration_cpu_stop() on the target CPU using |
5343 | * runqueue and wake up that CPU's migration thread. | 5240 | * stop_one_cpu(). |
5344 | * 2) we down() the locked semaphore => thread blocks. | 5241 | * 2) stopper starts to run (implicitly forcing the migrated thread |
5345 | * 3) migration thread wakes up (implicitly it forces the migrated | 5242 | * off the CPU) |
5346 | * thread off the CPU) | 5243 | * 3) it checks whether the migrated task is still in the wrong runqueue. |
5347 | * 4) it gets the migration request and checks whether the migrated | 5244 | * 4) if it's in the wrong runqueue then the migration thread removes |
5348 | * task is still in the wrong runqueue. | ||
5349 | * 5) if it's in the wrong runqueue then the migration thread removes | ||
5350 | * it and puts it into the right queue. | 5245 | * it and puts it into the right queue. |
5351 | * 6) migration thread up()s the semaphore. | 5246 | * 5) stopper completes and stop_one_cpu() returns and the migration |
5352 | * 7) we wake up and the migration is done. | 5247 | * is done. |
5353 | */ | 5248 | */ |
5354 | 5249 | ||
5355 | /* | 5250 | /* |
@@ -5363,12 +5258,23 @@ static inline void sched_init_granularity(void) | |||
5363 | */ | 5258 | */ |
5364 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | 5259 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) |
5365 | { | 5260 | { |
5366 | struct migration_req req; | ||
5367 | unsigned long flags; | 5261 | unsigned long flags; |
5368 | struct rq *rq; | 5262 | struct rq *rq; |
5263 | unsigned int dest_cpu; | ||
5369 | int ret = 0; | 5264 | int ret = 0; |
5370 | 5265 | ||
5266 | /* | ||
5267 | * Serialize against TASK_WAKING so that ttwu() and wunt() can | ||
5268 | * drop the rq->lock and still rely on ->cpus_allowed. | ||
5269 | */ | ||
5270 | again: | ||
5271 | while (task_is_waking(p)) | ||
5272 | cpu_relax(); | ||
5371 | rq = task_rq_lock(p, &flags); | 5273 | rq = task_rq_lock(p, &flags); |
5274 | if (task_is_waking(p)) { | ||
5275 | task_rq_unlock(rq, &flags); | ||
5276 | goto again; | ||
5277 | } | ||
5372 | 5278 | ||
5373 | if (!cpumask_intersects(new_mask, cpu_active_mask)) { | 5279 | if (!cpumask_intersects(new_mask, cpu_active_mask)) { |
5374 | ret = -EINVAL; | 5280 | ret = -EINVAL; |
@@ -5392,15 +5298,12 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | |||
5392 | if (cpumask_test_cpu(task_cpu(p), new_mask)) | 5298 | if (cpumask_test_cpu(task_cpu(p), new_mask)) |
5393 | goto out; | 5299 | goto out; |
5394 | 5300 | ||
5395 | if (migrate_task(p, cpumask_any_and(cpu_active_mask, new_mask), &req)) { | 5301 | dest_cpu = cpumask_any_and(cpu_active_mask, new_mask); |
5302 | if (migrate_task(p, dest_cpu)) { | ||
5303 | struct migration_arg arg = { p, dest_cpu }; | ||
5396 | /* Need help from migration thread: drop lock and wait. */ | 5304 | /* Need help from migration thread: drop lock and wait. */ |
5397 | struct task_struct *mt = rq->migration_thread; | ||
5398 | |||
5399 | get_task_struct(mt); | ||
5400 | task_rq_unlock(rq, &flags); | 5305 | task_rq_unlock(rq, &flags); |
5401 | wake_up_process(mt); | 5306 | stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); |
5402 | put_task_struct(mt); | ||
5403 | wait_for_completion(&req.done); | ||
5404 | tlb_migrate_finish(p->mm); | 5307 | tlb_migrate_finish(p->mm); |
5405 | return 0; | 5308 | return 0; |
5406 | } | 5309 | } |
@@ -5458,98 +5361,49 @@ fail: | |||
5458 | return ret; | 5361 | return ret; |
5459 | } | 5362 | } |
5460 | 5363 | ||
5461 | #define RCU_MIGRATION_IDLE 0 | ||
5462 | #define RCU_MIGRATION_NEED_QS 1 | ||
5463 | #define RCU_MIGRATION_GOT_QS 2 | ||
5464 | #define RCU_MIGRATION_MUST_SYNC 3 | ||
5465 | |||
5466 | /* | 5364 | /* |
5467 | * migration_thread - this is a highprio system thread that performs | 5365 | * migration_cpu_stop - this will be executed by a highprio stopper thread |
5468 | * thread migration by bumping thread off CPU then 'pushing' onto | 5366 | * and performs thread migration by bumping thread off CPU then |
5469 | * another runqueue. | 5367 | * 'pushing' onto another runqueue. |
5470 | */ | 5368 | */ |
5471 | static int migration_thread(void *data) | 5369 | static int migration_cpu_stop(void *data) |
5472 | { | ||
5473 | int badcpu; | ||
5474 | int cpu = (long)data; | ||
5475 | struct rq *rq; | ||
5476 | |||
5477 | rq = cpu_rq(cpu); | ||
5478 | BUG_ON(rq->migration_thread != current); | ||
5479 | |||
5480 | set_current_state(TASK_INTERRUPTIBLE); | ||
5481 | while (!kthread_should_stop()) { | ||
5482 | struct migration_req *req; | ||
5483 | struct list_head *head; | ||
5484 | |||
5485 | raw_spin_lock_irq(&rq->lock); | ||
5486 | |||
5487 | if (cpu_is_offline(cpu)) { | ||
5488 | raw_spin_unlock_irq(&rq->lock); | ||
5489 | break; | ||
5490 | } | ||
5491 | |||
5492 | if (rq->active_balance) { | ||
5493 | active_load_balance(rq, cpu); | ||
5494 | rq->active_balance = 0; | ||
5495 | } | ||
5496 | |||
5497 | head = &rq->migration_queue; | ||
5498 | |||
5499 | if (list_empty(head)) { | ||
5500 | raw_spin_unlock_irq(&rq->lock); | ||
5501 | schedule(); | ||
5502 | set_current_state(TASK_INTERRUPTIBLE); | ||
5503 | continue; | ||
5504 | } | ||
5505 | req = list_entry(head->next, struct migration_req, list); | ||
5506 | list_del_init(head->next); | ||
5507 | |||
5508 | if (req->task != NULL) { | ||
5509 | raw_spin_unlock(&rq->lock); | ||
5510 | __migrate_task(req->task, cpu, req->dest_cpu); | ||
5511 | } else if (likely(cpu == (badcpu = smp_processor_id()))) { | ||
5512 | req->dest_cpu = RCU_MIGRATION_GOT_QS; | ||
5513 | raw_spin_unlock(&rq->lock); | ||
5514 | } else { | ||
5515 | req->dest_cpu = RCU_MIGRATION_MUST_SYNC; | ||
5516 | raw_spin_unlock(&rq->lock); | ||
5517 | WARN_ONCE(1, "migration_thread() on CPU %d, expected %d\n", badcpu, cpu); | ||
5518 | } | ||
5519 | local_irq_enable(); | ||
5520 | |||
5521 | complete(&req->done); | ||
5522 | } | ||
5523 | __set_current_state(TASK_RUNNING); | ||
5524 | |||
5525 | return 0; | ||
5526 | } | ||
5527 | |||
5528 | #ifdef CONFIG_HOTPLUG_CPU | ||
5529 | |||
5530 | static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu) | ||
5531 | { | 5370 | { |
5532 | int ret; | 5371 | struct migration_arg *arg = data; |
5533 | 5372 | ||
5373 | /* | ||
5374 | * The original target cpu might have gone down and we might | ||
5375 | * be on another cpu but it doesn't matter. | ||
5376 | */ | ||
5534 | local_irq_disable(); | 5377 | local_irq_disable(); |
5535 | ret = __migrate_task(p, src_cpu, dest_cpu); | 5378 | __migrate_task(arg->task, raw_smp_processor_id(), arg->dest_cpu); |
5536 | local_irq_enable(); | 5379 | local_irq_enable(); |
5537 | return ret; | 5380 | return 0; |
5538 | } | 5381 | } |
5539 | 5382 | ||
5383 | #ifdef CONFIG_HOTPLUG_CPU | ||
5540 | /* | 5384 | /* |
5541 | * Figure out where task on dead CPU should go, use force if necessary. | 5385 | * Figure out where task on dead CPU should go, use force if necessary. |
5542 | */ | 5386 | */ |
5543 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | 5387 | void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) |
5544 | { | 5388 | { |
5545 | int dest_cpu; | 5389 | struct rq *rq = cpu_rq(dead_cpu); |
5390 | int needs_cpu, uninitialized_var(dest_cpu); | ||
5391 | unsigned long flags; | ||
5546 | 5392 | ||
5547 | again: | 5393 | local_irq_save(flags); |
5548 | dest_cpu = select_fallback_rq(dead_cpu, p); | ||
5549 | 5394 | ||
5550 | /* It can have affinity changed while we were choosing. */ | 5395 | raw_spin_lock(&rq->lock); |
5551 | if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu))) | 5396 | needs_cpu = (task_cpu(p) == dead_cpu) && (p->state != TASK_WAKING); |
5552 | goto again; | 5397 | if (needs_cpu) |
5398 | dest_cpu = select_fallback_rq(dead_cpu, p); | ||
5399 | raw_spin_unlock(&rq->lock); | ||
5400 | /* | ||
5401 | * It can only fail if we race with set_cpus_allowed(), | ||
5402 | * in the racer should migrate the task anyway. | ||
5403 | */ | ||
5404 | if (needs_cpu) | ||
5405 | __migrate_task(p, dead_cpu, dest_cpu); | ||
5406 | local_irq_restore(flags); | ||
5553 | } | 5407 | } |
5554 | 5408 | ||
5555 | /* | 5409 | /* |
@@ -5613,7 +5467,6 @@ void sched_idle_next(void) | |||
5613 | 5467 | ||
5614 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); | 5468 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); |
5615 | 5469 | ||
5616 | update_rq_clock(rq); | ||
5617 | activate_task(rq, p, 0); | 5470 | activate_task(rq, p, 0); |
5618 | 5471 | ||
5619 | raw_spin_unlock_irqrestore(&rq->lock, flags); | 5472 | raw_spin_unlock_irqrestore(&rq->lock, flags); |
@@ -5668,7 +5521,6 @@ static void migrate_dead_tasks(unsigned int dead_cpu) | |||
5668 | for ( ; ; ) { | 5521 | for ( ; ; ) { |
5669 | if (!rq->nr_running) | 5522 | if (!rq->nr_running) |
5670 | break; | 5523 | break; |
5671 | update_rq_clock(rq); | ||
5672 | next = pick_next_task(rq); | 5524 | next = pick_next_task(rq); |
5673 | if (!next) | 5525 | if (!next) |
5674 | break; | 5526 | break; |
@@ -5891,35 +5743,20 @@ static void set_rq_offline(struct rq *rq) | |||
5891 | static int __cpuinit | 5743 | static int __cpuinit |
5892 | migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | 5744 | migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) |
5893 | { | 5745 | { |
5894 | struct task_struct *p; | ||
5895 | int cpu = (long)hcpu; | 5746 | int cpu = (long)hcpu; |
5896 | unsigned long flags; | 5747 | unsigned long flags; |
5897 | struct rq *rq; | 5748 | struct rq *rq = cpu_rq(cpu); |
5898 | 5749 | ||
5899 | switch (action) { | 5750 | switch (action) { |
5900 | 5751 | ||
5901 | case CPU_UP_PREPARE: | 5752 | case CPU_UP_PREPARE: |
5902 | case CPU_UP_PREPARE_FROZEN: | 5753 | case CPU_UP_PREPARE_FROZEN: |
5903 | p = kthread_create(migration_thread, hcpu, "migration/%d", cpu); | ||
5904 | if (IS_ERR(p)) | ||
5905 | return NOTIFY_BAD; | ||
5906 | kthread_bind(p, cpu); | ||
5907 | /* Must be high prio: stop_machine expects to yield to it. */ | ||
5908 | rq = task_rq_lock(p, &flags); | ||
5909 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); | ||
5910 | task_rq_unlock(rq, &flags); | ||
5911 | get_task_struct(p); | ||
5912 | cpu_rq(cpu)->migration_thread = p; | ||
5913 | rq->calc_load_update = calc_load_update; | 5754 | rq->calc_load_update = calc_load_update; |
5914 | break; | 5755 | break; |
5915 | 5756 | ||
5916 | case CPU_ONLINE: | 5757 | case CPU_ONLINE: |
5917 | case CPU_ONLINE_FROZEN: | 5758 | case CPU_ONLINE_FROZEN: |
5918 | /* Strictly unnecessary, as first user will wake it. */ | ||
5919 | wake_up_process(cpu_rq(cpu)->migration_thread); | ||
5920 | |||
5921 | /* Update our root-domain */ | 5759 | /* Update our root-domain */ |
5922 | rq = cpu_rq(cpu); | ||
5923 | raw_spin_lock_irqsave(&rq->lock, flags); | 5760 | raw_spin_lock_irqsave(&rq->lock, flags); |
5924 | if (rq->rd) { | 5761 | if (rq->rd) { |
5925 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); | 5762 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
@@ -5930,61 +5767,24 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
5930 | break; | 5767 | break; |
5931 | 5768 | ||
5932 | #ifdef CONFIG_HOTPLUG_CPU | 5769 | #ifdef CONFIG_HOTPLUG_CPU |
5933 | case CPU_UP_CANCELED: | ||
5934 | case CPU_UP_CANCELED_FROZEN: | ||
5935 | if (!cpu_rq(cpu)->migration_thread) | ||
5936 | break; | ||
5937 | /* Unbind it from offline cpu so it can run. Fall thru. */ | ||
5938 | kthread_bind(cpu_rq(cpu)->migration_thread, | ||
5939 | cpumask_any(cpu_online_mask)); | ||
5940 | kthread_stop(cpu_rq(cpu)->migration_thread); | ||
5941 | put_task_struct(cpu_rq(cpu)->migration_thread); | ||
5942 | cpu_rq(cpu)->migration_thread = NULL; | ||
5943 | break; | ||
5944 | |||
5945 | case CPU_DEAD: | 5770 | case CPU_DEAD: |
5946 | case CPU_DEAD_FROZEN: | 5771 | case CPU_DEAD_FROZEN: |
5947 | cpuset_lock(); /* around calls to cpuset_cpus_allowed_lock() */ | ||
5948 | migrate_live_tasks(cpu); | 5772 | migrate_live_tasks(cpu); |
5949 | rq = cpu_rq(cpu); | ||
5950 | kthread_stop(rq->migration_thread); | ||
5951 | put_task_struct(rq->migration_thread); | ||
5952 | rq->migration_thread = NULL; | ||
5953 | /* Idle task back to normal (off runqueue, low prio) */ | 5773 | /* Idle task back to normal (off runqueue, low prio) */ |
5954 | raw_spin_lock_irq(&rq->lock); | 5774 | raw_spin_lock_irq(&rq->lock); |
5955 | update_rq_clock(rq); | ||
5956 | deactivate_task(rq, rq->idle, 0); | 5775 | deactivate_task(rq, rq->idle, 0); |
5957 | __setscheduler(rq, rq->idle, SCHED_NORMAL, 0); | 5776 | __setscheduler(rq, rq->idle, SCHED_NORMAL, 0); |
5958 | rq->idle->sched_class = &idle_sched_class; | 5777 | rq->idle->sched_class = &idle_sched_class; |
5959 | migrate_dead_tasks(cpu); | 5778 | migrate_dead_tasks(cpu); |
5960 | raw_spin_unlock_irq(&rq->lock); | 5779 | raw_spin_unlock_irq(&rq->lock); |
5961 | cpuset_unlock(); | ||
5962 | migrate_nr_uninterruptible(rq); | 5780 | migrate_nr_uninterruptible(rq); |
5963 | BUG_ON(rq->nr_running != 0); | 5781 | BUG_ON(rq->nr_running != 0); |
5964 | calc_global_load_remove(rq); | 5782 | calc_global_load_remove(rq); |
5965 | /* | ||
5966 | * No need to migrate the tasks: it was best-effort if | ||
5967 | * they didn't take sched_hotcpu_mutex. Just wake up | ||
5968 | * the requestors. | ||
5969 | */ | ||
5970 | raw_spin_lock_irq(&rq->lock); | ||
5971 | while (!list_empty(&rq->migration_queue)) { | ||
5972 | struct migration_req *req; | ||
5973 | |||
5974 | req = list_entry(rq->migration_queue.next, | ||
5975 | struct migration_req, list); | ||
5976 | list_del_init(&req->list); | ||
5977 | raw_spin_unlock_irq(&rq->lock); | ||
5978 | complete(&req->done); | ||
5979 | raw_spin_lock_irq(&rq->lock); | ||
5980 | } | ||
5981 | raw_spin_unlock_irq(&rq->lock); | ||
5982 | break; | 5783 | break; |
5983 | 5784 | ||
5984 | case CPU_DYING: | 5785 | case CPU_DYING: |
5985 | case CPU_DYING_FROZEN: | 5786 | case CPU_DYING_FROZEN: |
5986 | /* Update our root-domain */ | 5787 | /* Update our root-domain */ |
5987 | rq = cpu_rq(cpu); | ||
5988 | raw_spin_lock_irqsave(&rq->lock, flags); | 5788 | raw_spin_lock_irqsave(&rq->lock, flags); |
5989 | if (rq->rd) { | 5789 | if (rq->rd) { |
5990 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); | 5790 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
@@ -6315,6 +6115,9 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6315 | struct rq *rq = cpu_rq(cpu); | 6115 | struct rq *rq = cpu_rq(cpu); |
6316 | struct sched_domain *tmp; | 6116 | struct sched_domain *tmp; |
6317 | 6117 | ||
6118 | for (tmp = sd; tmp; tmp = tmp->parent) | ||
6119 | tmp->span_weight = cpumask_weight(sched_domain_span(tmp)); | ||
6120 | |||
6318 | /* Remove the sched domains which do not contribute to scheduling. */ | 6121 | /* Remove the sched domains which do not contribute to scheduling. */ |
6319 | for (tmp = sd; tmp; ) { | 6122 | for (tmp = sd; tmp; ) { |
6320 | struct sched_domain *parent = tmp->parent; | 6123 | struct sched_domain *parent = tmp->parent; |
@@ -7798,10 +7601,8 @@ void __init sched_init(void) | |||
7798 | rq->push_cpu = 0; | 7601 | rq->push_cpu = 0; |
7799 | rq->cpu = i; | 7602 | rq->cpu = i; |
7800 | rq->online = 0; | 7603 | rq->online = 0; |
7801 | rq->migration_thread = NULL; | ||
7802 | rq->idle_stamp = 0; | 7604 | rq->idle_stamp = 0; |
7803 | rq->avg_idle = 2*sysctl_sched_migration_cost; | 7605 | rq->avg_idle = 2*sysctl_sched_migration_cost; |
7804 | INIT_LIST_HEAD(&rq->migration_queue); | ||
7805 | rq_attach_root(rq, &def_root_domain); | 7606 | rq_attach_root(rq, &def_root_domain); |
7806 | #endif | 7607 | #endif |
7807 | init_rq_hrtick(rq); | 7608 | init_rq_hrtick(rq); |
@@ -7902,7 +7703,6 @@ static void normalize_task(struct rq *rq, struct task_struct *p) | |||
7902 | { | 7703 | { |
7903 | int on_rq; | 7704 | int on_rq; |
7904 | 7705 | ||
7905 | update_rq_clock(rq); | ||
7906 | on_rq = p->se.on_rq; | 7706 | on_rq = p->se.on_rq; |
7907 | if (on_rq) | 7707 | if (on_rq) |
7908 | deactivate_task(rq, p, 0); | 7708 | deactivate_task(rq, p, 0); |
@@ -7929,9 +7729,9 @@ void normalize_rt_tasks(void) | |||
7929 | 7729 | ||
7930 | p->se.exec_start = 0; | 7730 | p->se.exec_start = 0; |
7931 | #ifdef CONFIG_SCHEDSTATS | 7731 | #ifdef CONFIG_SCHEDSTATS |
7932 | p->se.wait_start = 0; | 7732 | p->se.statistics.wait_start = 0; |
7933 | p->se.sleep_start = 0; | 7733 | p->se.statistics.sleep_start = 0; |
7934 | p->se.block_start = 0; | 7734 | p->se.statistics.block_start = 0; |
7935 | #endif | 7735 | #endif |
7936 | 7736 | ||
7937 | if (!rt_task(p)) { | 7737 | if (!rt_task(p)) { |
@@ -8264,8 +8064,6 @@ void sched_move_task(struct task_struct *tsk) | |||
8264 | 8064 | ||
8265 | rq = task_rq_lock(tsk, &flags); | 8065 | rq = task_rq_lock(tsk, &flags); |
8266 | 8066 | ||
8267 | update_rq_clock(rq); | ||
8268 | |||
8269 | running = task_current(rq, tsk); | 8067 | running = task_current(rq, tsk); |
8270 | on_rq = tsk->se.on_rq; | 8068 | on_rq = tsk->se.on_rq; |
8271 | 8069 | ||
@@ -8284,7 +8082,7 @@ void sched_move_task(struct task_struct *tsk) | |||
8284 | if (unlikely(running)) | 8082 | if (unlikely(running)) |
8285 | tsk->sched_class->set_curr_task(rq); | 8083 | tsk->sched_class->set_curr_task(rq); |
8286 | if (on_rq) | 8084 | if (on_rq) |
8287 | enqueue_task(rq, tsk, 0, false); | 8085 | enqueue_task(rq, tsk, 0); |
8288 | 8086 | ||
8289 | task_rq_unlock(rq, &flags); | 8087 | task_rq_unlock(rq, &flags); |
8290 | } | 8088 | } |
@@ -9098,43 +8896,32 @@ struct cgroup_subsys cpuacct_subsys = { | |||
9098 | 8896 | ||
9099 | #ifndef CONFIG_SMP | 8897 | #ifndef CONFIG_SMP |
9100 | 8898 | ||
9101 | int rcu_expedited_torture_stats(char *page) | ||
9102 | { | ||
9103 | return 0; | ||
9104 | } | ||
9105 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
9106 | |||
9107 | void synchronize_sched_expedited(void) | 8899 | void synchronize_sched_expedited(void) |
9108 | { | 8900 | { |
8901 | barrier(); | ||
9109 | } | 8902 | } |
9110 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | 8903 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
9111 | 8904 | ||
9112 | #else /* #ifndef CONFIG_SMP */ | 8905 | #else /* #ifndef CONFIG_SMP */ |
9113 | 8906 | ||
9114 | static DEFINE_PER_CPU(struct migration_req, rcu_migration_req); | 8907 | static atomic_t synchronize_sched_expedited_count = ATOMIC_INIT(0); |
9115 | static DEFINE_MUTEX(rcu_sched_expedited_mutex); | ||
9116 | 8908 | ||
9117 | #define RCU_EXPEDITED_STATE_POST -2 | 8909 | static int synchronize_sched_expedited_cpu_stop(void *data) |
9118 | #define RCU_EXPEDITED_STATE_IDLE -1 | ||
9119 | |||
9120 | static int rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
9121 | |||
9122 | int rcu_expedited_torture_stats(char *page) | ||
9123 | { | 8910 | { |
9124 | int cnt = 0; | 8911 | /* |
9125 | int cpu; | 8912 | * There must be a full memory barrier on each affected CPU |
9126 | 8913 | * between the time that try_stop_cpus() is called and the | |
9127 | cnt += sprintf(&page[cnt], "state: %d /", rcu_expedited_state); | 8914 | * time that it returns. |
9128 | for_each_online_cpu(cpu) { | 8915 | * |
9129 | cnt += sprintf(&page[cnt], " %d:%d", | 8916 | * In the current initial implementation of cpu_stop, the |
9130 | cpu, per_cpu(rcu_migration_req, cpu).dest_cpu); | 8917 | * above condition is already met when the control reaches |
9131 | } | 8918 | * this point and the following smp_mb() is not strictly |
9132 | cnt += sprintf(&page[cnt], "\n"); | 8919 | * necessary. Do smp_mb() anyway for documentation and |
9133 | return cnt; | 8920 | * robustness against future implementation changes. |
8921 | */ | ||
8922 | smp_mb(); /* See above comment block. */ | ||
8923 | return 0; | ||
9134 | } | 8924 | } |
9135 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
9136 | |||
9137 | static long synchronize_sched_expedited_count; | ||
9138 | 8925 | ||
9139 | /* | 8926 | /* |
9140 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" | 8927 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" |
@@ -9148,18 +8935,14 @@ static long synchronize_sched_expedited_count; | |||
9148 | */ | 8935 | */ |
9149 | void synchronize_sched_expedited(void) | 8936 | void synchronize_sched_expedited(void) |
9150 | { | 8937 | { |
9151 | int cpu; | 8938 | int snap, trycount = 0; |
9152 | unsigned long flags; | ||
9153 | bool need_full_sync = 0; | ||
9154 | struct rq *rq; | ||
9155 | struct migration_req *req; | ||
9156 | long snap; | ||
9157 | int trycount = 0; | ||
9158 | 8939 | ||
9159 | smp_mb(); /* ensure prior mod happens before capturing snap. */ | 8940 | smp_mb(); /* ensure prior mod happens before capturing snap. */ |
9160 | snap = ACCESS_ONCE(synchronize_sched_expedited_count) + 1; | 8941 | snap = atomic_read(&synchronize_sched_expedited_count) + 1; |
9161 | get_online_cpus(); | 8942 | get_online_cpus(); |
9162 | while (!mutex_trylock(&rcu_sched_expedited_mutex)) { | 8943 | while (try_stop_cpus(cpu_online_mask, |
8944 | synchronize_sched_expedited_cpu_stop, | ||
8945 | NULL) == -EAGAIN) { | ||
9163 | put_online_cpus(); | 8946 | put_online_cpus(); |
9164 | if (trycount++ < 10) | 8947 | if (trycount++ < 10) |
9165 | udelay(trycount * num_online_cpus()); | 8948 | udelay(trycount * num_online_cpus()); |
@@ -9167,41 +8950,15 @@ void synchronize_sched_expedited(void) | |||
9167 | synchronize_sched(); | 8950 | synchronize_sched(); |
9168 | return; | 8951 | return; |
9169 | } | 8952 | } |
9170 | if (ACCESS_ONCE(synchronize_sched_expedited_count) - snap > 0) { | 8953 | if (atomic_read(&synchronize_sched_expedited_count) - snap > 0) { |
9171 | smp_mb(); /* ensure test happens before caller kfree */ | 8954 | smp_mb(); /* ensure test happens before caller kfree */ |
9172 | return; | 8955 | return; |
9173 | } | 8956 | } |
9174 | get_online_cpus(); | 8957 | get_online_cpus(); |
9175 | } | 8958 | } |
9176 | rcu_expedited_state = RCU_EXPEDITED_STATE_POST; | 8959 | atomic_inc(&synchronize_sched_expedited_count); |
9177 | for_each_online_cpu(cpu) { | 8960 | smp_mb__after_atomic_inc(); /* ensure post-GP actions seen after GP. */ |
9178 | rq = cpu_rq(cpu); | ||
9179 | req = &per_cpu(rcu_migration_req, cpu); | ||
9180 | init_completion(&req->done); | ||
9181 | req->task = NULL; | ||
9182 | req->dest_cpu = RCU_MIGRATION_NEED_QS; | ||
9183 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
9184 | list_add(&req->list, &rq->migration_queue); | ||
9185 | raw_spin_unlock_irqrestore(&rq->lock, flags); | ||
9186 | wake_up_process(rq->migration_thread); | ||
9187 | } | ||
9188 | for_each_online_cpu(cpu) { | ||
9189 | rcu_expedited_state = cpu; | ||
9190 | req = &per_cpu(rcu_migration_req, cpu); | ||
9191 | rq = cpu_rq(cpu); | ||
9192 | wait_for_completion(&req->done); | ||
9193 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
9194 | if (unlikely(req->dest_cpu == RCU_MIGRATION_MUST_SYNC)) | ||
9195 | need_full_sync = 1; | ||
9196 | req->dest_cpu = RCU_MIGRATION_IDLE; | ||
9197 | raw_spin_unlock_irqrestore(&rq->lock, flags); | ||
9198 | } | ||
9199 | rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
9200 | synchronize_sched_expedited_count++; | ||
9201 | mutex_unlock(&rcu_sched_expedited_mutex); | ||
9202 | put_online_cpus(); | 8961 | put_online_cpus(); |
9203 | if (need_full_sync) | ||
9204 | synchronize_sched(); | ||
9205 | } | 8962 | } |
9206 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | 8963 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
9207 | 8964 | ||
diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c index 19be00ba6123..87a330a7185f 100644 --- a/kernel/sched_debug.c +++ b/kernel/sched_debug.c | |||
@@ -70,16 +70,16 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu, | |||
70 | PN(se->vruntime); | 70 | PN(se->vruntime); |
71 | PN(se->sum_exec_runtime); | 71 | PN(se->sum_exec_runtime); |
72 | #ifdef CONFIG_SCHEDSTATS | 72 | #ifdef CONFIG_SCHEDSTATS |
73 | PN(se->wait_start); | 73 | PN(se->statistics.wait_start); |
74 | PN(se->sleep_start); | 74 | PN(se->statistics.sleep_start); |
75 | PN(se->block_start); | 75 | PN(se->statistics.block_start); |
76 | PN(se->sleep_max); | 76 | PN(se->statistics.sleep_max); |
77 | PN(se->block_max); | 77 | PN(se->statistics.block_max); |
78 | PN(se->exec_max); | 78 | PN(se->statistics.exec_max); |
79 | PN(se->slice_max); | 79 | PN(se->statistics.slice_max); |
80 | PN(se->wait_max); | 80 | PN(se->statistics.wait_max); |
81 | PN(se->wait_sum); | 81 | PN(se->statistics.wait_sum); |
82 | P(se->wait_count); | 82 | P(se->statistics.wait_count); |
83 | #endif | 83 | #endif |
84 | P(se->load.weight); | 84 | P(se->load.weight); |
85 | #undef PN | 85 | #undef PN |
@@ -104,7 +104,7 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p) | |||
104 | SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld", | 104 | SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld", |
105 | SPLIT_NS(p->se.vruntime), | 105 | SPLIT_NS(p->se.vruntime), |
106 | SPLIT_NS(p->se.sum_exec_runtime), | 106 | SPLIT_NS(p->se.sum_exec_runtime), |
107 | SPLIT_NS(p->se.sum_sleep_runtime)); | 107 | SPLIT_NS(p->se.statistics.sum_sleep_runtime)); |
108 | #else | 108 | #else |
109 | SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld", | 109 | SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld", |
110 | 0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L); | 110 | 0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L); |
@@ -175,11 +175,6 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq) | |||
175 | task_group_path(tg, path, sizeof(path)); | 175 | task_group_path(tg, path, sizeof(path)); |
176 | 176 | ||
177 | SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, path); | 177 | SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, path); |
178 | #elif defined(CONFIG_USER_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED) | ||
179 | { | ||
180 | uid_t uid = cfs_rq->tg->uid; | ||
181 | SEQ_printf(m, "\ncfs_rq[%d] for UID: %u\n", cpu, uid); | ||
182 | } | ||
183 | #else | 178 | #else |
184 | SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu); | 179 | SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu); |
185 | #endif | 180 | #endif |
@@ -409,40 +404,38 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m) | |||
409 | PN(se.exec_start); | 404 | PN(se.exec_start); |
410 | PN(se.vruntime); | 405 | PN(se.vruntime); |
411 | PN(se.sum_exec_runtime); | 406 | PN(se.sum_exec_runtime); |
412 | PN(se.avg_overlap); | ||
413 | PN(se.avg_wakeup); | ||
414 | 407 | ||
415 | nr_switches = p->nvcsw + p->nivcsw; | 408 | nr_switches = p->nvcsw + p->nivcsw; |
416 | 409 | ||
417 | #ifdef CONFIG_SCHEDSTATS | 410 | #ifdef CONFIG_SCHEDSTATS |
418 | PN(se.wait_start); | 411 | PN(se.statistics.wait_start); |
419 | PN(se.sleep_start); | 412 | PN(se.statistics.sleep_start); |
420 | PN(se.block_start); | 413 | PN(se.statistics.block_start); |
421 | PN(se.sleep_max); | 414 | PN(se.statistics.sleep_max); |
422 | PN(se.block_max); | 415 | PN(se.statistics.block_max); |
423 | PN(se.exec_max); | 416 | PN(se.statistics.exec_max); |
424 | PN(se.slice_max); | 417 | PN(se.statistics.slice_max); |
425 | PN(se.wait_max); | 418 | PN(se.statistics.wait_max); |
426 | PN(se.wait_sum); | 419 | PN(se.statistics.wait_sum); |
427 | P(se.wait_count); | 420 | P(se.statistics.wait_count); |
428 | PN(se.iowait_sum); | 421 | PN(se.statistics.iowait_sum); |
429 | P(se.iowait_count); | 422 | P(se.statistics.iowait_count); |
430 | P(sched_info.bkl_count); | 423 | P(sched_info.bkl_count); |
431 | P(se.nr_migrations); | 424 | P(se.nr_migrations); |
432 | P(se.nr_migrations_cold); | 425 | P(se.statistics.nr_migrations_cold); |
433 | P(se.nr_failed_migrations_affine); | 426 | P(se.statistics.nr_failed_migrations_affine); |
434 | P(se.nr_failed_migrations_running); | 427 | P(se.statistics.nr_failed_migrations_running); |
435 | P(se.nr_failed_migrations_hot); | 428 | P(se.statistics.nr_failed_migrations_hot); |
436 | P(se.nr_forced_migrations); | 429 | P(se.statistics.nr_forced_migrations); |
437 | P(se.nr_wakeups); | 430 | P(se.statistics.nr_wakeups); |
438 | P(se.nr_wakeups_sync); | 431 | P(se.statistics.nr_wakeups_sync); |
439 | P(se.nr_wakeups_migrate); | 432 | P(se.statistics.nr_wakeups_migrate); |
440 | P(se.nr_wakeups_local); | 433 | P(se.statistics.nr_wakeups_local); |
441 | P(se.nr_wakeups_remote); | 434 | P(se.statistics.nr_wakeups_remote); |
442 | P(se.nr_wakeups_affine); | 435 | P(se.statistics.nr_wakeups_affine); |
443 | P(se.nr_wakeups_affine_attempts); | 436 | P(se.statistics.nr_wakeups_affine_attempts); |
444 | P(se.nr_wakeups_passive); | 437 | P(se.statistics.nr_wakeups_passive); |
445 | P(se.nr_wakeups_idle); | 438 | P(se.statistics.nr_wakeups_idle); |
446 | 439 | ||
447 | { | 440 | { |
448 | u64 avg_atom, avg_per_cpu; | 441 | u64 avg_atom, avg_per_cpu; |
@@ -493,31 +486,6 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m) | |||
493 | void proc_sched_set_task(struct task_struct *p) | 486 | void proc_sched_set_task(struct task_struct *p) |
494 | { | 487 | { |
495 | #ifdef CONFIG_SCHEDSTATS | 488 | #ifdef CONFIG_SCHEDSTATS |
496 | p->se.wait_max = 0; | 489 | memset(&p->se.statistics, 0, sizeof(p->se.statistics)); |
497 | p->se.wait_sum = 0; | ||
498 | p->se.wait_count = 0; | ||
499 | p->se.iowait_sum = 0; | ||
500 | p->se.iowait_count = 0; | ||
501 | p->se.sleep_max = 0; | ||
502 | p->se.sum_sleep_runtime = 0; | ||
503 | p->se.block_max = 0; | ||
504 | p->se.exec_max = 0; | ||
505 | p->se.slice_max = 0; | ||
506 | p->se.nr_migrations = 0; | ||
507 | p->se.nr_migrations_cold = 0; | ||
508 | p->se.nr_failed_migrations_affine = 0; | ||
509 | p->se.nr_failed_migrations_running = 0; | ||
510 | p->se.nr_failed_migrations_hot = 0; | ||
511 | p->se.nr_forced_migrations = 0; | ||
512 | p->se.nr_wakeups = 0; | ||
513 | p->se.nr_wakeups_sync = 0; | ||
514 | p->se.nr_wakeups_migrate = 0; | ||
515 | p->se.nr_wakeups_local = 0; | ||
516 | p->se.nr_wakeups_remote = 0; | ||
517 | p->se.nr_wakeups_affine = 0; | ||
518 | p->se.nr_wakeups_affine_attempts = 0; | ||
519 | p->se.nr_wakeups_passive = 0; | ||
520 | p->se.nr_wakeups_idle = 0; | ||
521 | p->sched_info.bkl_count = 0; | ||
522 | #endif | 490 | #endif |
523 | } | 491 | } |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 5a5ea2cd924f..217e4a9393e4 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -35,8 +35,8 @@ | |||
35 | * (to see the precise effective timeslice length of your workload, | 35 | * (to see the precise effective timeslice length of your workload, |
36 | * run vmstat and monitor the context-switches (cs) field) | 36 | * run vmstat and monitor the context-switches (cs) field) |
37 | */ | 37 | */ |
38 | unsigned int sysctl_sched_latency = 5000000ULL; | 38 | unsigned int sysctl_sched_latency = 6000000ULL; |
39 | unsigned int normalized_sysctl_sched_latency = 5000000ULL; | 39 | unsigned int normalized_sysctl_sched_latency = 6000000ULL; |
40 | 40 | ||
41 | /* | 41 | /* |
42 | * The initial- and re-scaling of tunables is configurable | 42 | * The initial- and re-scaling of tunables is configurable |
@@ -52,15 +52,15 @@ enum sched_tunable_scaling sysctl_sched_tunable_scaling | |||
52 | 52 | ||
53 | /* | 53 | /* |
54 | * Minimal preemption granularity for CPU-bound tasks: | 54 | * Minimal preemption granularity for CPU-bound tasks: |
55 | * (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds) | 55 | * (default: 2 msec * (1 + ilog(ncpus)), units: nanoseconds) |
56 | */ | 56 | */ |
57 | unsigned int sysctl_sched_min_granularity = 1000000ULL; | 57 | unsigned int sysctl_sched_min_granularity = 2000000ULL; |
58 | unsigned int normalized_sysctl_sched_min_granularity = 1000000ULL; | 58 | unsigned int normalized_sysctl_sched_min_granularity = 2000000ULL; |
59 | 59 | ||
60 | /* | 60 | /* |
61 | * is kept at sysctl_sched_latency / sysctl_sched_min_granularity | 61 | * is kept at sysctl_sched_latency / sysctl_sched_min_granularity |
62 | */ | 62 | */ |
63 | static unsigned int sched_nr_latency = 5; | 63 | static unsigned int sched_nr_latency = 3; |
64 | 64 | ||
65 | /* | 65 | /* |
66 | * After fork, child runs first. If set to 0 (default) then | 66 | * After fork, child runs first. If set to 0 (default) then |
@@ -505,7 +505,8 @@ __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr, | |||
505 | { | 505 | { |
506 | unsigned long delta_exec_weighted; | 506 | unsigned long delta_exec_weighted; |
507 | 507 | ||
508 | schedstat_set(curr->exec_max, max((u64)delta_exec, curr->exec_max)); | 508 | schedstat_set(curr->statistics.exec_max, |
509 | max((u64)delta_exec, curr->statistics.exec_max)); | ||
509 | 510 | ||
510 | curr->sum_exec_runtime += delta_exec; | 511 | curr->sum_exec_runtime += delta_exec; |
511 | schedstat_add(cfs_rq, exec_clock, delta_exec); | 512 | schedstat_add(cfs_rq, exec_clock, delta_exec); |
@@ -548,7 +549,7 @@ static void update_curr(struct cfs_rq *cfs_rq) | |||
548 | static inline void | 549 | static inline void |
549 | update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) | 550 | update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) |
550 | { | 551 | { |
551 | schedstat_set(se->wait_start, rq_of(cfs_rq)->clock); | 552 | schedstat_set(se->statistics.wait_start, rq_of(cfs_rq)->clock); |
552 | } | 553 | } |
553 | 554 | ||
554 | /* | 555 | /* |
@@ -567,18 +568,18 @@ static void update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
567 | static void | 568 | static void |
568 | update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) | 569 | update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) |
569 | { | 570 | { |
570 | schedstat_set(se->wait_max, max(se->wait_max, | 571 | schedstat_set(se->statistics.wait_max, max(se->statistics.wait_max, |
571 | rq_of(cfs_rq)->clock - se->wait_start)); | 572 | rq_of(cfs_rq)->clock - se->statistics.wait_start)); |
572 | schedstat_set(se->wait_count, se->wait_count + 1); | 573 | schedstat_set(se->statistics.wait_count, se->statistics.wait_count + 1); |
573 | schedstat_set(se->wait_sum, se->wait_sum + | 574 | schedstat_set(se->statistics.wait_sum, se->statistics.wait_sum + |
574 | rq_of(cfs_rq)->clock - se->wait_start); | 575 | rq_of(cfs_rq)->clock - se->statistics.wait_start); |
575 | #ifdef CONFIG_SCHEDSTATS | 576 | #ifdef CONFIG_SCHEDSTATS |
576 | if (entity_is_task(se)) { | 577 | if (entity_is_task(se)) { |
577 | trace_sched_stat_wait(task_of(se), | 578 | trace_sched_stat_wait(task_of(se), |
578 | rq_of(cfs_rq)->clock - se->wait_start); | 579 | rq_of(cfs_rq)->clock - se->statistics.wait_start); |
579 | } | 580 | } |
580 | #endif | 581 | #endif |
581 | schedstat_set(se->wait_start, 0); | 582 | schedstat_set(se->statistics.wait_start, 0); |
582 | } | 583 | } |
583 | 584 | ||
584 | static inline void | 585 | static inline void |
@@ -657,39 +658,39 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
657 | if (entity_is_task(se)) | 658 | if (entity_is_task(se)) |
658 | tsk = task_of(se); | 659 | tsk = task_of(se); |
659 | 660 | ||
660 | if (se->sleep_start) { | 661 | if (se->statistics.sleep_start) { |
661 | u64 delta = rq_of(cfs_rq)->clock - se->sleep_start; | 662 | u64 delta = rq_of(cfs_rq)->clock - se->statistics.sleep_start; |
662 | 663 | ||
663 | if ((s64)delta < 0) | 664 | if ((s64)delta < 0) |
664 | delta = 0; | 665 | delta = 0; |
665 | 666 | ||
666 | if (unlikely(delta > se->sleep_max)) | 667 | if (unlikely(delta > se->statistics.sleep_max)) |
667 | se->sleep_max = delta; | 668 | se->statistics.sleep_max = delta; |
668 | 669 | ||
669 | se->sleep_start = 0; | 670 | se->statistics.sleep_start = 0; |
670 | se->sum_sleep_runtime += delta; | 671 | se->statistics.sum_sleep_runtime += delta; |
671 | 672 | ||
672 | if (tsk) { | 673 | if (tsk) { |
673 | account_scheduler_latency(tsk, delta >> 10, 1); | 674 | account_scheduler_latency(tsk, delta >> 10, 1); |
674 | trace_sched_stat_sleep(tsk, delta); | 675 | trace_sched_stat_sleep(tsk, delta); |
675 | } | 676 | } |
676 | } | 677 | } |
677 | if (se->block_start) { | 678 | if (se->statistics.block_start) { |
678 | u64 delta = rq_of(cfs_rq)->clock - se->block_start; | 679 | u64 delta = rq_of(cfs_rq)->clock - se->statistics.block_start; |
679 | 680 | ||
680 | if ((s64)delta < 0) | 681 | if ((s64)delta < 0) |
681 | delta = 0; | 682 | delta = 0; |
682 | 683 | ||
683 | if (unlikely(delta > se->block_max)) | 684 | if (unlikely(delta > se->statistics.block_max)) |
684 | se->block_max = delta; | 685 | se->statistics.block_max = delta; |
685 | 686 | ||
686 | se->block_start = 0; | 687 | se->statistics.block_start = 0; |
687 | se->sum_sleep_runtime += delta; | 688 | se->statistics.sum_sleep_runtime += delta; |
688 | 689 | ||
689 | if (tsk) { | 690 | if (tsk) { |
690 | if (tsk->in_iowait) { | 691 | if (tsk->in_iowait) { |
691 | se->iowait_sum += delta; | 692 | se->statistics.iowait_sum += delta; |
692 | se->iowait_count++; | 693 | se->statistics.iowait_count++; |
693 | trace_sched_stat_iowait(tsk, delta); | 694 | trace_sched_stat_iowait(tsk, delta); |
694 | } | 695 | } |
695 | 696 | ||
@@ -737,20 +738,10 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) | |||
737 | vruntime += sched_vslice(cfs_rq, se); | 738 | vruntime += sched_vslice(cfs_rq, se); |
738 | 739 | ||
739 | /* sleeps up to a single latency don't count. */ | 740 | /* sleeps up to a single latency don't count. */ |
740 | if (!initial && sched_feat(FAIR_SLEEPERS)) { | 741 | if (!initial) { |
741 | unsigned long thresh = sysctl_sched_latency; | 742 | unsigned long thresh = sysctl_sched_latency; |
742 | 743 | ||
743 | /* | 744 | /* |
744 | * Convert the sleeper threshold into virtual time. | ||
745 | * SCHED_IDLE is a special sub-class. We care about | ||
746 | * fairness only relative to other SCHED_IDLE tasks, | ||
747 | * all of which have the same weight. | ||
748 | */ | ||
749 | if (sched_feat(NORMALIZED_SLEEPER) && (!entity_is_task(se) || | ||
750 | task_of(se)->policy != SCHED_IDLE)) | ||
751 | thresh = calc_delta_fair(thresh, se); | ||
752 | |||
753 | /* | ||
754 | * Halve their sleep time's effect, to allow | 745 | * Halve their sleep time's effect, to allow |
755 | * for a gentler effect of sleepers: | 746 | * for a gentler effect of sleepers: |
756 | */ | 747 | */ |
@@ -766,9 +757,6 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) | |||
766 | se->vruntime = vruntime; | 757 | se->vruntime = vruntime; |
767 | } | 758 | } |
768 | 759 | ||
769 | #define ENQUEUE_WAKEUP 1 | ||
770 | #define ENQUEUE_MIGRATE 2 | ||
771 | |||
772 | static void | 760 | static void |
773 | enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) | 761 | enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) |
774 | { | 762 | { |
@@ -776,7 +764,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) | |||
776 | * Update the normalized vruntime before updating min_vruntime | 764 | * Update the normalized vruntime before updating min_vruntime |
777 | * through callig update_curr(). | 765 | * through callig update_curr(). |
778 | */ | 766 | */ |
779 | if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_MIGRATE)) | 767 | if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING)) |
780 | se->vruntime += cfs_rq->min_vruntime; | 768 | se->vruntime += cfs_rq->min_vruntime; |
781 | 769 | ||
782 | /* | 770 | /* |
@@ -812,7 +800,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
812 | } | 800 | } |
813 | 801 | ||
814 | static void | 802 | static void |
815 | dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep) | 803 | dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) |
816 | { | 804 | { |
817 | /* | 805 | /* |
818 | * Update run-time statistics of the 'current'. | 806 | * Update run-time statistics of the 'current'. |
@@ -820,15 +808,15 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep) | |||
820 | update_curr(cfs_rq); | 808 | update_curr(cfs_rq); |
821 | 809 | ||
822 | update_stats_dequeue(cfs_rq, se); | 810 | update_stats_dequeue(cfs_rq, se); |
823 | if (sleep) { | 811 | if (flags & DEQUEUE_SLEEP) { |
824 | #ifdef CONFIG_SCHEDSTATS | 812 | #ifdef CONFIG_SCHEDSTATS |
825 | if (entity_is_task(se)) { | 813 | if (entity_is_task(se)) { |
826 | struct task_struct *tsk = task_of(se); | 814 | struct task_struct *tsk = task_of(se); |
827 | 815 | ||
828 | if (tsk->state & TASK_INTERRUPTIBLE) | 816 | if (tsk->state & TASK_INTERRUPTIBLE) |
829 | se->sleep_start = rq_of(cfs_rq)->clock; | 817 | se->statistics.sleep_start = rq_of(cfs_rq)->clock; |
830 | if (tsk->state & TASK_UNINTERRUPTIBLE) | 818 | if (tsk->state & TASK_UNINTERRUPTIBLE) |
831 | se->block_start = rq_of(cfs_rq)->clock; | 819 | se->statistics.block_start = rq_of(cfs_rq)->clock; |
832 | } | 820 | } |
833 | #endif | 821 | #endif |
834 | } | 822 | } |
@@ -845,7 +833,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep) | |||
845 | * update can refer to the ->curr item and we need to reflect this | 833 | * update can refer to the ->curr item and we need to reflect this |
846 | * movement in our normalized position. | 834 | * movement in our normalized position. |
847 | */ | 835 | */ |
848 | if (!sleep) | 836 | if (!(flags & DEQUEUE_SLEEP)) |
849 | se->vruntime -= cfs_rq->min_vruntime; | 837 | se->vruntime -= cfs_rq->min_vruntime; |
850 | } | 838 | } |
851 | 839 | ||
@@ -912,7 +900,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) | |||
912 | * when there are only lesser-weight tasks around): | 900 | * when there are only lesser-weight tasks around): |
913 | */ | 901 | */ |
914 | if (rq_of(cfs_rq)->load.weight >= 2*se->load.weight) { | 902 | if (rq_of(cfs_rq)->load.weight >= 2*se->load.weight) { |
915 | se->slice_max = max(se->slice_max, | 903 | se->statistics.slice_max = max(se->statistics.slice_max, |
916 | se->sum_exec_runtime - se->prev_sum_exec_runtime); | 904 | se->sum_exec_runtime - se->prev_sum_exec_runtime); |
917 | } | 905 | } |
918 | #endif | 906 | #endif |
@@ -1054,16 +1042,10 @@ static inline void hrtick_update(struct rq *rq) | |||
1054 | * then put the task into the rbtree: | 1042 | * then put the task into the rbtree: |
1055 | */ | 1043 | */ |
1056 | static void | 1044 | static void |
1057 | enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head) | 1045 | enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) |
1058 | { | 1046 | { |
1059 | struct cfs_rq *cfs_rq; | 1047 | struct cfs_rq *cfs_rq; |
1060 | struct sched_entity *se = &p->se; | 1048 | struct sched_entity *se = &p->se; |
1061 | int flags = 0; | ||
1062 | |||
1063 | if (wakeup) | ||
1064 | flags |= ENQUEUE_WAKEUP; | ||
1065 | if (p->state == TASK_WAKING) | ||
1066 | flags |= ENQUEUE_MIGRATE; | ||
1067 | 1049 | ||
1068 | for_each_sched_entity(se) { | 1050 | for_each_sched_entity(se) { |
1069 | if (se->on_rq) | 1051 | if (se->on_rq) |
@@ -1081,18 +1063,18 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head) | |||
1081 | * decreased. We remove the task from the rbtree and | 1063 | * decreased. We remove the task from the rbtree and |
1082 | * update the fair scheduling stats: | 1064 | * update the fair scheduling stats: |
1083 | */ | 1065 | */ |
1084 | static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int sleep) | 1066 | static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) |
1085 | { | 1067 | { |
1086 | struct cfs_rq *cfs_rq; | 1068 | struct cfs_rq *cfs_rq; |
1087 | struct sched_entity *se = &p->se; | 1069 | struct sched_entity *se = &p->se; |
1088 | 1070 | ||
1089 | for_each_sched_entity(se) { | 1071 | for_each_sched_entity(se) { |
1090 | cfs_rq = cfs_rq_of(se); | 1072 | cfs_rq = cfs_rq_of(se); |
1091 | dequeue_entity(cfs_rq, se, sleep); | 1073 | dequeue_entity(cfs_rq, se, flags); |
1092 | /* Don't dequeue parent if it has other entities besides us */ | 1074 | /* Don't dequeue parent if it has other entities besides us */ |
1093 | if (cfs_rq->load.weight) | 1075 | if (cfs_rq->load.weight) |
1094 | break; | 1076 | break; |
1095 | sleep = 1; | 1077 | flags |= DEQUEUE_SLEEP; |
1096 | } | 1078 | } |
1097 | 1079 | ||
1098 | hrtick_update(rq); | 1080 | hrtick_update(rq); |
@@ -1240,7 +1222,6 @@ static inline unsigned long effective_load(struct task_group *tg, int cpu, | |||
1240 | 1222 | ||
1241 | static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) | 1223 | static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) |
1242 | { | 1224 | { |
1243 | struct task_struct *curr = current; | ||
1244 | unsigned long this_load, load; | 1225 | unsigned long this_load, load; |
1245 | int idx, this_cpu, prev_cpu; | 1226 | int idx, this_cpu, prev_cpu; |
1246 | unsigned long tl_per_task; | 1227 | unsigned long tl_per_task; |
@@ -1255,18 +1236,6 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) | |||
1255 | load = source_load(prev_cpu, idx); | 1236 | load = source_load(prev_cpu, idx); |
1256 | this_load = target_load(this_cpu, idx); | 1237 | this_load = target_load(this_cpu, idx); |
1257 | 1238 | ||
1258 | if (sync) { | ||
1259 | if (sched_feat(SYNC_LESS) && | ||
1260 | (curr->se.avg_overlap > sysctl_sched_migration_cost || | ||
1261 | p->se.avg_overlap > sysctl_sched_migration_cost)) | ||
1262 | sync = 0; | ||
1263 | } else { | ||
1264 | if (sched_feat(SYNC_MORE) && | ||
1265 | (curr->se.avg_overlap < sysctl_sched_migration_cost && | ||
1266 | p->se.avg_overlap < sysctl_sched_migration_cost)) | ||
1267 | sync = 1; | ||
1268 | } | ||
1269 | |||
1270 | /* | 1239 | /* |
1271 | * If sync wakeup then subtract the (maximum possible) | 1240 | * If sync wakeup then subtract the (maximum possible) |
1272 | * effect of the currently running task from the load | 1241 | * effect of the currently running task from the load |
@@ -1306,7 +1275,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) | |||
1306 | if (sync && balanced) | 1275 | if (sync && balanced) |
1307 | return 1; | 1276 | return 1; |
1308 | 1277 | ||
1309 | schedstat_inc(p, se.nr_wakeups_affine_attempts); | 1278 | schedstat_inc(p, se.statistics.nr_wakeups_affine_attempts); |
1310 | tl_per_task = cpu_avg_load_per_task(this_cpu); | 1279 | tl_per_task = cpu_avg_load_per_task(this_cpu); |
1311 | 1280 | ||
1312 | if (balanced || | 1281 | if (balanced || |
@@ -1318,7 +1287,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) | |||
1318 | * there is no bad imbalance. | 1287 | * there is no bad imbalance. |
1319 | */ | 1288 | */ |
1320 | schedstat_inc(sd, ttwu_move_affine); | 1289 | schedstat_inc(sd, ttwu_move_affine); |
1321 | schedstat_inc(p, se.nr_wakeups_affine); | 1290 | schedstat_inc(p, se.statistics.nr_wakeups_affine); |
1322 | 1291 | ||
1323 | return 1; | 1292 | return 1; |
1324 | } | 1293 | } |
@@ -1406,29 +1375,48 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) | |||
1406 | /* | 1375 | /* |
1407 | * Try and locate an idle CPU in the sched_domain. | 1376 | * Try and locate an idle CPU in the sched_domain. |
1408 | */ | 1377 | */ |
1409 | static int | 1378 | static int select_idle_sibling(struct task_struct *p, int target) |
1410 | select_idle_sibling(struct task_struct *p, struct sched_domain *sd, int target) | ||
1411 | { | 1379 | { |
1412 | int cpu = smp_processor_id(); | 1380 | int cpu = smp_processor_id(); |
1413 | int prev_cpu = task_cpu(p); | 1381 | int prev_cpu = task_cpu(p); |
1382 | struct sched_domain *sd; | ||
1414 | int i; | 1383 | int i; |
1415 | 1384 | ||
1416 | /* | 1385 | /* |
1417 | * If this domain spans both cpu and prev_cpu (see the SD_WAKE_AFFINE | 1386 | * If the task is going to be woken-up on this cpu and if it is |
1418 | * test in select_task_rq_fair) and the prev_cpu is idle then that's | 1387 | * already idle, then it is the right target. |
1419 | * always a better target than the current cpu. | ||
1420 | */ | 1388 | */ |
1421 | if (target == cpu && !cpu_rq(prev_cpu)->cfs.nr_running) | 1389 | if (target == cpu && idle_cpu(cpu)) |
1390 | return cpu; | ||
1391 | |||
1392 | /* | ||
1393 | * If the task is going to be woken-up on the cpu where it previously | ||
1394 | * ran and if it is currently idle, then it the right target. | ||
1395 | */ | ||
1396 | if (target == prev_cpu && idle_cpu(prev_cpu)) | ||
1422 | return prev_cpu; | 1397 | return prev_cpu; |
1423 | 1398 | ||
1424 | /* | 1399 | /* |
1425 | * Otherwise, iterate the domain and find an elegible idle cpu. | 1400 | * Otherwise, iterate the domains and find an elegible idle cpu. |
1426 | */ | 1401 | */ |
1427 | for_each_cpu_and(i, sched_domain_span(sd), &p->cpus_allowed) { | 1402 | for_each_domain(target, sd) { |
1428 | if (!cpu_rq(i)->cfs.nr_running) { | 1403 | if (!(sd->flags & SD_SHARE_PKG_RESOURCES)) |
1429 | target = i; | ||
1430 | break; | 1404 | break; |
1405 | |||
1406 | for_each_cpu_and(i, sched_domain_span(sd), &p->cpus_allowed) { | ||
1407 | if (idle_cpu(i)) { | ||
1408 | target = i; | ||
1409 | break; | ||
1410 | } | ||
1431 | } | 1411 | } |
1412 | |||
1413 | /* | ||
1414 | * Lets stop looking for an idle sibling when we reached | ||
1415 | * the domain that spans the current cpu and prev_cpu. | ||
1416 | */ | ||
1417 | if (cpumask_test_cpu(cpu, sched_domain_span(sd)) && | ||
1418 | cpumask_test_cpu(prev_cpu, sched_domain_span(sd))) | ||
1419 | break; | ||
1432 | } | 1420 | } |
1433 | 1421 | ||
1434 | return target; | 1422 | return target; |
@@ -1445,7 +1433,8 @@ select_idle_sibling(struct task_struct *p, struct sched_domain *sd, int target) | |||
1445 | * | 1433 | * |
1446 | * preempt must be disabled. | 1434 | * preempt must be disabled. |
1447 | */ | 1435 | */ |
1448 | static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags) | 1436 | static int |
1437 | select_task_rq_fair(struct rq *rq, struct task_struct *p, int sd_flag, int wake_flags) | ||
1449 | { | 1438 | { |
1450 | struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL; | 1439 | struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL; |
1451 | int cpu = smp_processor_id(); | 1440 | int cpu = smp_processor_id(); |
@@ -1456,8 +1445,7 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag | |||
1456 | int sync = wake_flags & WF_SYNC; | 1445 | int sync = wake_flags & WF_SYNC; |
1457 | 1446 | ||
1458 | if (sd_flag & SD_BALANCE_WAKE) { | 1447 | if (sd_flag & SD_BALANCE_WAKE) { |
1459 | if (sched_feat(AFFINE_WAKEUPS) && | 1448 | if (cpumask_test_cpu(cpu, &p->cpus_allowed)) |
1460 | cpumask_test_cpu(cpu, &p->cpus_allowed)) | ||
1461 | want_affine = 1; | 1449 | want_affine = 1; |
1462 | new_cpu = prev_cpu; | 1450 | new_cpu = prev_cpu; |
1463 | } | 1451 | } |
@@ -1491,34 +1479,13 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag | |||
1491 | } | 1479 | } |
1492 | 1480 | ||
1493 | /* | 1481 | /* |
1494 | * While iterating the domains looking for a spanning | 1482 | * If both cpu and prev_cpu are part of this domain, |
1495 | * WAKE_AFFINE domain, adjust the affine target to any idle cpu | 1483 | * cpu is a valid SD_WAKE_AFFINE target. |
1496 | * in cache sharing domains along the way. | ||
1497 | */ | 1484 | */ |
1498 | if (want_affine) { | 1485 | if (want_affine && (tmp->flags & SD_WAKE_AFFINE) && |
1499 | int target = -1; | 1486 | cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) { |
1500 | 1487 | affine_sd = tmp; | |
1501 | /* | 1488 | want_affine = 0; |
1502 | * If both cpu and prev_cpu are part of this domain, | ||
1503 | * cpu is a valid SD_WAKE_AFFINE target. | ||
1504 | */ | ||
1505 | if (cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) | ||
1506 | target = cpu; | ||
1507 | |||
1508 | /* | ||
1509 | * If there's an idle sibling in this domain, make that | ||
1510 | * the wake_affine target instead of the current cpu. | ||
1511 | */ | ||
1512 | if (tmp->flags & SD_SHARE_PKG_RESOURCES) | ||
1513 | target = select_idle_sibling(p, tmp, target); | ||
1514 | |||
1515 | if (target >= 0) { | ||
1516 | if (tmp->flags & SD_WAKE_AFFINE) { | ||
1517 | affine_sd = tmp; | ||
1518 | want_affine = 0; | ||
1519 | } | ||
1520 | cpu = target; | ||
1521 | } | ||
1522 | } | 1489 | } |
1523 | 1490 | ||
1524 | if (!want_sd && !want_affine) | 1491 | if (!want_sd && !want_affine) |
@@ -1531,22 +1498,29 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag | |||
1531 | sd = tmp; | 1498 | sd = tmp; |
1532 | } | 1499 | } |
1533 | 1500 | ||
1501 | #ifdef CONFIG_FAIR_GROUP_SCHED | ||
1534 | if (sched_feat(LB_SHARES_UPDATE)) { | 1502 | if (sched_feat(LB_SHARES_UPDATE)) { |
1535 | /* | 1503 | /* |
1536 | * Pick the largest domain to update shares over | 1504 | * Pick the largest domain to update shares over |
1537 | */ | 1505 | */ |
1538 | tmp = sd; | 1506 | tmp = sd; |
1539 | if (affine_sd && (!tmp || | 1507 | if (affine_sd && (!tmp || affine_sd->span_weight > sd->span_weight)) |
1540 | cpumask_weight(sched_domain_span(affine_sd)) > | ||
1541 | cpumask_weight(sched_domain_span(sd)))) | ||
1542 | tmp = affine_sd; | 1508 | tmp = affine_sd; |
1543 | 1509 | ||
1544 | if (tmp) | 1510 | if (tmp) { |
1511 | raw_spin_unlock(&rq->lock); | ||
1545 | update_shares(tmp); | 1512 | update_shares(tmp); |
1513 | raw_spin_lock(&rq->lock); | ||
1514 | } | ||
1546 | } | 1515 | } |
1516 | #endif | ||
1547 | 1517 | ||
1548 | if (affine_sd && wake_affine(affine_sd, p, sync)) | 1518 | if (affine_sd) { |
1549 | return cpu; | 1519 | if (cpu == prev_cpu || wake_affine(affine_sd, p, sync)) |
1520 | return select_idle_sibling(p, cpu); | ||
1521 | else | ||
1522 | return select_idle_sibling(p, prev_cpu); | ||
1523 | } | ||
1550 | 1524 | ||
1551 | while (sd) { | 1525 | while (sd) { |
1552 | int load_idx = sd->forkexec_idx; | 1526 | int load_idx = sd->forkexec_idx; |
@@ -1576,10 +1550,10 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag | |||
1576 | 1550 | ||
1577 | /* Now try balancing at a lower domain level of new_cpu */ | 1551 | /* Now try balancing at a lower domain level of new_cpu */ |
1578 | cpu = new_cpu; | 1552 | cpu = new_cpu; |
1579 | weight = cpumask_weight(sched_domain_span(sd)); | 1553 | weight = sd->span_weight; |
1580 | sd = NULL; | 1554 | sd = NULL; |
1581 | for_each_domain(cpu, tmp) { | 1555 | for_each_domain(cpu, tmp) { |
1582 | if (weight <= cpumask_weight(sched_domain_span(tmp))) | 1556 | if (weight <= tmp->span_weight) |
1583 | break; | 1557 | break; |
1584 | if (tmp->flags & sd_flag) | 1558 | if (tmp->flags & sd_flag) |
1585 | sd = tmp; | 1559 | sd = tmp; |
@@ -1591,63 +1565,26 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag | |||
1591 | } | 1565 | } |
1592 | #endif /* CONFIG_SMP */ | 1566 | #endif /* CONFIG_SMP */ |
1593 | 1567 | ||
1594 | /* | ||
1595 | * Adaptive granularity | ||
1596 | * | ||
1597 | * se->avg_wakeup gives the average time a task runs until it does a wakeup, | ||
1598 | * with the limit of wakeup_gran -- when it never does a wakeup. | ||
1599 | * | ||
1600 | * So the smaller avg_wakeup is the faster we want this task to preempt, | ||
1601 | * but we don't want to treat the preemptee unfairly and therefore allow it | ||
1602 | * to run for at least the amount of time we'd like to run. | ||
1603 | * | ||
1604 | * NOTE: we use 2*avg_wakeup to increase the probability of actually doing one | ||
1605 | * | ||
1606 | * NOTE: we use *nr_running to scale with load, this nicely matches the | ||
1607 | * degrading latency on load. | ||
1608 | */ | ||
1609 | static unsigned long | ||
1610 | adaptive_gran(struct sched_entity *curr, struct sched_entity *se) | ||
1611 | { | ||
1612 | u64 this_run = curr->sum_exec_runtime - curr->prev_sum_exec_runtime; | ||
1613 | u64 expected_wakeup = 2*se->avg_wakeup * cfs_rq_of(se)->nr_running; | ||
1614 | u64 gran = 0; | ||
1615 | |||
1616 | if (this_run < expected_wakeup) | ||
1617 | gran = expected_wakeup - this_run; | ||
1618 | |||
1619 | return min_t(s64, gran, sysctl_sched_wakeup_granularity); | ||
1620 | } | ||
1621 | |||
1622 | static unsigned long | 1568 | static unsigned long |
1623 | wakeup_gran(struct sched_entity *curr, struct sched_entity *se) | 1569 | wakeup_gran(struct sched_entity *curr, struct sched_entity *se) |
1624 | { | 1570 | { |
1625 | unsigned long gran = sysctl_sched_wakeup_granularity; | 1571 | unsigned long gran = sysctl_sched_wakeup_granularity; |
1626 | 1572 | ||
1627 | if (cfs_rq_of(curr)->curr && sched_feat(ADAPTIVE_GRAN)) | ||
1628 | gran = adaptive_gran(curr, se); | ||
1629 | |||
1630 | /* | 1573 | /* |
1631 | * Since its curr running now, convert the gran from real-time | 1574 | * Since its curr running now, convert the gran from real-time |
1632 | * to virtual-time in his units. | 1575 | * to virtual-time in his units. |
1576 | * | ||
1577 | * By using 'se' instead of 'curr' we penalize light tasks, so | ||
1578 | * they get preempted easier. That is, if 'se' < 'curr' then | ||
1579 | * the resulting gran will be larger, therefore penalizing the | ||
1580 | * lighter, if otoh 'se' > 'curr' then the resulting gran will | ||
1581 | * be smaller, again penalizing the lighter task. | ||
1582 | * | ||
1583 | * This is especially important for buddies when the leftmost | ||
1584 | * task is higher priority than the buddy. | ||
1633 | */ | 1585 | */ |
1634 | if (sched_feat(ASYM_GRAN)) { | 1586 | if (unlikely(se->load.weight != NICE_0_LOAD)) |
1635 | /* | 1587 | gran = calc_delta_fair(gran, se); |
1636 | * By using 'se' instead of 'curr' we penalize light tasks, so | ||
1637 | * they get preempted easier. That is, if 'se' < 'curr' then | ||
1638 | * the resulting gran will be larger, therefore penalizing the | ||
1639 | * lighter, if otoh 'se' > 'curr' then the resulting gran will | ||
1640 | * be smaller, again penalizing the lighter task. | ||
1641 | * | ||
1642 | * This is especially important for buddies when the leftmost | ||
1643 | * task is higher priority than the buddy. | ||
1644 | */ | ||
1645 | if (unlikely(se->load.weight != NICE_0_LOAD)) | ||
1646 | gran = calc_delta_fair(gran, se); | ||
1647 | } else { | ||
1648 | if (unlikely(curr->load.weight != NICE_0_LOAD)) | ||
1649 | gran = calc_delta_fair(gran, curr); | ||
1650 | } | ||
1651 | 1588 | ||
1652 | return gran; | 1589 | return gran; |
1653 | } | 1590 | } |
@@ -1705,7 +1642,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ | |||
1705 | struct task_struct *curr = rq->curr; | 1642 | struct task_struct *curr = rq->curr; |
1706 | struct sched_entity *se = &curr->se, *pse = &p->se; | 1643 | struct sched_entity *se = &curr->se, *pse = &p->se; |
1707 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); | 1644 | struct cfs_rq *cfs_rq = task_cfs_rq(curr); |
1708 | int sync = wake_flags & WF_SYNC; | ||
1709 | int scale = cfs_rq->nr_running >= sched_nr_latency; | 1645 | int scale = cfs_rq->nr_running >= sched_nr_latency; |
1710 | 1646 | ||
1711 | if (unlikely(rt_prio(p->prio))) | 1647 | if (unlikely(rt_prio(p->prio))) |
@@ -1738,14 +1674,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ | |||
1738 | if (unlikely(curr->policy == SCHED_IDLE)) | 1674 | if (unlikely(curr->policy == SCHED_IDLE)) |
1739 | goto preempt; | 1675 | goto preempt; |
1740 | 1676 | ||
1741 | if (sched_feat(WAKEUP_SYNC) && sync) | ||
1742 | goto preempt; | ||
1743 | |||
1744 | if (sched_feat(WAKEUP_OVERLAP) && | ||
1745 | se->avg_overlap < sysctl_sched_migration_cost && | ||
1746 | pse->avg_overlap < sysctl_sched_migration_cost) | ||
1747 | goto preempt; | ||
1748 | |||
1749 | if (!sched_feat(WAKEUP_PREEMPT)) | 1677 | if (!sched_feat(WAKEUP_PREEMPT)) |
1750 | return; | 1678 | return; |
1751 | 1679 | ||
@@ -1844,13 +1772,13 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu, | |||
1844 | * 3) are cache-hot on their current CPU. | 1772 | * 3) are cache-hot on their current CPU. |
1845 | */ | 1773 | */ |
1846 | if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) { | 1774 | if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) { |
1847 | schedstat_inc(p, se.nr_failed_migrations_affine); | 1775 | schedstat_inc(p, se.statistics.nr_failed_migrations_affine); |
1848 | return 0; | 1776 | return 0; |
1849 | } | 1777 | } |
1850 | *all_pinned = 0; | 1778 | *all_pinned = 0; |
1851 | 1779 | ||
1852 | if (task_running(rq, p)) { | 1780 | if (task_running(rq, p)) { |
1853 | schedstat_inc(p, se.nr_failed_migrations_running); | 1781 | schedstat_inc(p, se.statistics.nr_failed_migrations_running); |
1854 | return 0; | 1782 | return 0; |
1855 | } | 1783 | } |
1856 | 1784 | ||
@@ -1866,14 +1794,14 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu, | |||
1866 | #ifdef CONFIG_SCHEDSTATS | 1794 | #ifdef CONFIG_SCHEDSTATS |
1867 | if (tsk_cache_hot) { | 1795 | if (tsk_cache_hot) { |
1868 | schedstat_inc(sd, lb_hot_gained[idle]); | 1796 | schedstat_inc(sd, lb_hot_gained[idle]); |
1869 | schedstat_inc(p, se.nr_forced_migrations); | 1797 | schedstat_inc(p, se.statistics.nr_forced_migrations); |
1870 | } | 1798 | } |
1871 | #endif | 1799 | #endif |
1872 | return 1; | 1800 | return 1; |
1873 | } | 1801 | } |
1874 | 1802 | ||
1875 | if (tsk_cache_hot) { | 1803 | if (tsk_cache_hot) { |
1876 | schedstat_inc(p, se.nr_failed_migrations_hot); | 1804 | schedstat_inc(p, se.statistics.nr_failed_migrations_hot); |
1877 | return 0; | 1805 | return 0; |
1878 | } | 1806 | } |
1879 | return 1; | 1807 | return 1; |
@@ -2311,7 +2239,7 @@ unsigned long __weak arch_scale_freq_power(struct sched_domain *sd, int cpu) | |||
2311 | 2239 | ||
2312 | unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu) | 2240 | unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu) |
2313 | { | 2241 | { |
2314 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | 2242 | unsigned long weight = sd->span_weight; |
2315 | unsigned long smt_gain = sd->smt_gain; | 2243 | unsigned long smt_gain = sd->smt_gain; |
2316 | 2244 | ||
2317 | smt_gain /= weight; | 2245 | smt_gain /= weight; |
@@ -2344,7 +2272,7 @@ unsigned long scale_rt_power(int cpu) | |||
2344 | 2272 | ||
2345 | static void update_cpu_power(struct sched_domain *sd, int cpu) | 2273 | static void update_cpu_power(struct sched_domain *sd, int cpu) |
2346 | { | 2274 | { |
2347 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | 2275 | unsigned long weight = sd->span_weight; |
2348 | unsigned long power = SCHED_LOAD_SCALE; | 2276 | unsigned long power = SCHED_LOAD_SCALE; |
2349 | struct sched_group *sdg = sd->groups; | 2277 | struct sched_group *sdg = sd->groups; |
2350 | 2278 | ||
@@ -2870,6 +2798,8 @@ static int need_active_balance(struct sched_domain *sd, int sd_idle, int idle) | |||
2870 | return unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2); | 2798 | return unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2); |
2871 | } | 2799 | } |
2872 | 2800 | ||
2801 | static int active_load_balance_cpu_stop(void *data); | ||
2802 | |||
2873 | /* | 2803 | /* |
2874 | * Check this_cpu to ensure it is balanced within domain. Attempt to move | 2804 | * Check this_cpu to ensure it is balanced within domain. Attempt to move |
2875 | * tasks if there is an imbalance. | 2805 | * tasks if there is an imbalance. |
@@ -2959,8 +2889,9 @@ redo: | |||
2959 | if (need_active_balance(sd, sd_idle, idle)) { | 2889 | if (need_active_balance(sd, sd_idle, idle)) { |
2960 | raw_spin_lock_irqsave(&busiest->lock, flags); | 2890 | raw_spin_lock_irqsave(&busiest->lock, flags); |
2961 | 2891 | ||
2962 | /* don't kick the migration_thread, if the curr | 2892 | /* don't kick the active_load_balance_cpu_stop, |
2963 | * task on busiest cpu can't be moved to this_cpu | 2893 | * if the curr task on busiest cpu can't be |
2894 | * moved to this_cpu | ||
2964 | */ | 2895 | */ |
2965 | if (!cpumask_test_cpu(this_cpu, | 2896 | if (!cpumask_test_cpu(this_cpu, |
2966 | &busiest->curr->cpus_allowed)) { | 2897 | &busiest->curr->cpus_allowed)) { |
@@ -2970,14 +2901,22 @@ redo: | |||
2970 | goto out_one_pinned; | 2901 | goto out_one_pinned; |
2971 | } | 2902 | } |
2972 | 2903 | ||
2904 | /* | ||
2905 | * ->active_balance synchronizes accesses to | ||
2906 | * ->active_balance_work. Once set, it's cleared | ||
2907 | * only after active load balance is finished. | ||
2908 | */ | ||
2973 | if (!busiest->active_balance) { | 2909 | if (!busiest->active_balance) { |
2974 | busiest->active_balance = 1; | 2910 | busiest->active_balance = 1; |
2975 | busiest->push_cpu = this_cpu; | 2911 | busiest->push_cpu = this_cpu; |
2976 | active_balance = 1; | 2912 | active_balance = 1; |
2977 | } | 2913 | } |
2978 | raw_spin_unlock_irqrestore(&busiest->lock, flags); | 2914 | raw_spin_unlock_irqrestore(&busiest->lock, flags); |
2915 | |||
2979 | if (active_balance) | 2916 | if (active_balance) |
2980 | wake_up_process(busiest->migration_thread); | 2917 | stop_one_cpu_nowait(cpu_of(busiest), |
2918 | active_load_balance_cpu_stop, busiest, | ||
2919 | &busiest->active_balance_work); | ||
2981 | 2920 | ||
2982 | /* | 2921 | /* |
2983 | * We've kicked active balancing, reset the failure | 2922 | * We've kicked active balancing, reset the failure |
@@ -3084,24 +3023,29 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3084 | } | 3023 | } |
3085 | 3024 | ||
3086 | /* | 3025 | /* |
3087 | * active_load_balance is run by migration threads. It pushes running tasks | 3026 | * active_load_balance_cpu_stop is run by cpu stopper. It pushes |
3088 | * off the busiest CPU onto idle CPUs. It requires at least 1 task to be | 3027 | * running tasks off the busiest CPU onto idle CPUs. It requires at |
3089 | * running on each physical CPU where possible, and avoids physical / | 3028 | * least 1 task to be running on each physical CPU where possible, and |
3090 | * logical imbalances. | 3029 | * avoids physical / logical imbalances. |
3091 | * | ||
3092 | * Called with busiest_rq locked. | ||
3093 | */ | 3030 | */ |
3094 | static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | 3031 | static int active_load_balance_cpu_stop(void *data) |
3095 | { | 3032 | { |
3033 | struct rq *busiest_rq = data; | ||
3034 | int busiest_cpu = cpu_of(busiest_rq); | ||
3096 | int target_cpu = busiest_rq->push_cpu; | 3035 | int target_cpu = busiest_rq->push_cpu; |
3036 | struct rq *target_rq = cpu_rq(target_cpu); | ||
3097 | struct sched_domain *sd; | 3037 | struct sched_domain *sd; |
3098 | struct rq *target_rq; | 3038 | |
3039 | raw_spin_lock_irq(&busiest_rq->lock); | ||
3040 | |||
3041 | /* make sure the requested cpu hasn't gone down in the meantime */ | ||
3042 | if (unlikely(busiest_cpu != smp_processor_id() || | ||
3043 | !busiest_rq->active_balance)) | ||
3044 | goto out_unlock; | ||
3099 | 3045 | ||
3100 | /* Is there any task to move? */ | 3046 | /* Is there any task to move? */ |
3101 | if (busiest_rq->nr_running <= 1) | 3047 | if (busiest_rq->nr_running <= 1) |
3102 | return; | 3048 | goto out_unlock; |
3103 | |||
3104 | target_rq = cpu_rq(target_cpu); | ||
3105 | 3049 | ||
3106 | /* | 3050 | /* |
3107 | * This condition is "impossible", if it occurs | 3051 | * This condition is "impossible", if it occurs |
@@ -3112,8 +3056,6 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3112 | 3056 | ||
3113 | /* move a task from busiest_rq to target_rq */ | 3057 | /* move a task from busiest_rq to target_rq */ |
3114 | double_lock_balance(busiest_rq, target_rq); | 3058 | double_lock_balance(busiest_rq, target_rq); |
3115 | update_rq_clock(busiest_rq); | ||
3116 | update_rq_clock(target_rq); | ||
3117 | 3059 | ||
3118 | /* Search for an sd spanning us and the target CPU. */ | 3060 | /* Search for an sd spanning us and the target CPU. */ |
3119 | for_each_domain(target_cpu, sd) { | 3061 | for_each_domain(target_cpu, sd) { |
@@ -3132,6 +3074,10 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3132 | schedstat_inc(sd, alb_failed); | 3074 | schedstat_inc(sd, alb_failed); |
3133 | } | 3075 | } |
3134 | double_unlock_balance(busiest_rq, target_rq); | 3076 | double_unlock_balance(busiest_rq, target_rq); |
3077 | out_unlock: | ||
3078 | busiest_rq->active_balance = 0; | ||
3079 | raw_spin_unlock_irq(&busiest_rq->lock); | ||
3080 | return 0; | ||
3135 | } | 3081 | } |
3136 | 3082 | ||
3137 | #ifdef CONFIG_NO_HZ | 3083 | #ifdef CONFIG_NO_HZ |
diff --git a/kernel/sched_features.h b/kernel/sched_features.h index d5059fd761d9..83c66e8ad3ee 100644 --- a/kernel/sched_features.h +++ b/kernel/sched_features.h | |||
@@ -1,11 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Disregards a certain amount of sleep time (sched_latency_ns) and | ||
3 | * considers the task to be running during that period. This gives it | ||
4 | * a service deficit on wakeup, allowing it to run sooner. | ||
5 | */ | ||
6 | SCHED_FEAT(FAIR_SLEEPERS, 1) | ||
7 | |||
8 | /* | ||
9 | * Only give sleepers 50% of their service deficit. This allows | 2 | * Only give sleepers 50% of their service deficit. This allows |
10 | * them to run sooner, but does not allow tons of sleepers to | 3 | * them to run sooner, but does not allow tons of sleepers to |
11 | * rip the spread apart. | 4 | * rip the spread apart. |
@@ -13,13 +6,6 @@ SCHED_FEAT(FAIR_SLEEPERS, 1) | |||
13 | SCHED_FEAT(GENTLE_FAIR_SLEEPERS, 1) | 6 | SCHED_FEAT(GENTLE_FAIR_SLEEPERS, 1) |
14 | 7 | ||
15 | /* | 8 | /* |
16 | * By not normalizing the sleep time, heavy tasks get an effective | ||
17 | * longer period, and lighter task an effective shorter period they | ||
18 | * are considered running. | ||
19 | */ | ||
20 | SCHED_FEAT(NORMALIZED_SLEEPER, 0) | ||
21 | |||
22 | /* | ||
23 | * Place new tasks ahead so that they do not starve already running | 9 | * Place new tasks ahead so that they do not starve already running |
24 | * tasks | 10 | * tasks |
25 | */ | 11 | */ |
@@ -31,37 +17,6 @@ SCHED_FEAT(START_DEBIT, 1) | |||
31 | SCHED_FEAT(WAKEUP_PREEMPT, 1) | 17 | SCHED_FEAT(WAKEUP_PREEMPT, 1) |
32 | 18 | ||
33 | /* | 19 | /* |
34 | * Compute wakeup_gran based on task behaviour, clipped to | ||
35 | * [0, sched_wakeup_gran_ns] | ||
36 | */ | ||
37 | SCHED_FEAT(ADAPTIVE_GRAN, 1) | ||
38 | |||
39 | /* | ||
40 | * When converting the wakeup granularity to virtual time, do it such | ||
41 | * that heavier tasks preempting a lighter task have an edge. | ||
42 | */ | ||
43 | SCHED_FEAT(ASYM_GRAN, 1) | ||
44 | |||
45 | /* | ||
46 | * Always wakeup-preempt SYNC wakeups, see SYNC_WAKEUPS. | ||
47 | */ | ||
48 | SCHED_FEAT(WAKEUP_SYNC, 0) | ||
49 | |||
50 | /* | ||
51 | * Wakeup preempt based on task behaviour. Tasks that do not overlap | ||
52 | * don't get preempted. | ||
53 | */ | ||
54 | SCHED_FEAT(WAKEUP_OVERLAP, 0) | ||
55 | |||
56 | /* | ||
57 | * Use the SYNC wakeup hint, pipes and the likes use this to indicate | ||
58 | * the remote end is likely to consume the data we just wrote, and | ||
59 | * therefore has cache benefit from being placed on the same cpu, see | ||
60 | * also AFFINE_WAKEUPS. | ||
61 | */ | ||
62 | SCHED_FEAT(SYNC_WAKEUPS, 1) | ||
63 | |||
64 | /* | ||
65 | * Based on load and program behaviour, see if it makes sense to place | 20 | * Based on load and program behaviour, see if it makes sense to place |
66 | * a newly woken task on the same cpu as the task that woke it -- | 21 | * a newly woken task on the same cpu as the task that woke it -- |
67 | * improve cache locality. Typically used with SYNC wakeups as | 22 | * improve cache locality. Typically used with SYNC wakeups as |
@@ -70,16 +25,6 @@ SCHED_FEAT(SYNC_WAKEUPS, 1) | |||
70 | SCHED_FEAT(AFFINE_WAKEUPS, 1) | 25 | SCHED_FEAT(AFFINE_WAKEUPS, 1) |
71 | 26 | ||
72 | /* | 27 | /* |
73 | * Weaken SYNC hint based on overlap | ||
74 | */ | ||
75 | SCHED_FEAT(SYNC_LESS, 1) | ||
76 | |||
77 | /* | ||
78 | * Add SYNC hint based on overlap | ||
79 | */ | ||
80 | SCHED_FEAT(SYNC_MORE, 0) | ||
81 | |||
82 | /* | ||
83 | * Prefer to schedule the task we woke last (assuming it failed | 28 | * Prefer to schedule the task we woke last (assuming it failed |
84 | * wakeup-preemption), since its likely going to consume data we | 29 | * wakeup-preemption), since its likely going to consume data we |
85 | * touched, increases cache locality. | 30 | * touched, increases cache locality. |
diff --git a/kernel/sched_idletask.c b/kernel/sched_idletask.c index a8a6d8a50947..9fa0f402c87c 100644 --- a/kernel/sched_idletask.c +++ b/kernel/sched_idletask.c | |||
@@ -6,7 +6,8 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifdef CONFIG_SMP | 8 | #ifdef CONFIG_SMP |
9 | static int select_task_rq_idle(struct task_struct *p, int sd_flag, int flags) | 9 | static int |
10 | select_task_rq_idle(struct rq *rq, struct task_struct *p, int sd_flag, int flags) | ||
10 | { | 11 | { |
11 | return task_cpu(p); /* IDLE tasks as never migrated */ | 12 | return task_cpu(p); /* IDLE tasks as never migrated */ |
12 | } | 13 | } |
@@ -22,8 +23,7 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl | |||
22 | static struct task_struct *pick_next_task_idle(struct rq *rq) | 23 | static struct task_struct *pick_next_task_idle(struct rq *rq) |
23 | { | 24 | { |
24 | schedstat_inc(rq, sched_goidle); | 25 | schedstat_inc(rq, sched_goidle); |
25 | /* adjust the active tasks as we might go into a long sleep */ | 26 | calc_load_account_idle(rq); |
26 | calc_load_account_active(rq); | ||
27 | return rq->idle; | 27 | return rq->idle; |
28 | } | 28 | } |
29 | 29 | ||
@@ -32,7 +32,7 @@ static struct task_struct *pick_next_task_idle(struct rq *rq) | |||
32 | * message if some code attempts to do it: | 32 | * message if some code attempts to do it: |
33 | */ | 33 | */ |
34 | static void | 34 | static void |
35 | dequeue_task_idle(struct rq *rq, struct task_struct *p, int sleep) | 35 | dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags) |
36 | { | 36 | { |
37 | raw_spin_unlock_irq(&rq->lock); | 37 | raw_spin_unlock_irq(&rq->lock); |
38 | printk(KERN_ERR "bad: scheduling from the idle thread!\n"); | 38 | printk(KERN_ERR "bad: scheduling from the idle thread!\n"); |
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c index b5b920ae2ea7..8afb953e31c6 100644 --- a/kernel/sched_rt.c +++ b/kernel/sched_rt.c | |||
@@ -613,7 +613,7 @@ static void update_curr_rt(struct rq *rq) | |||
613 | if (unlikely((s64)delta_exec < 0)) | 613 | if (unlikely((s64)delta_exec < 0)) |
614 | delta_exec = 0; | 614 | delta_exec = 0; |
615 | 615 | ||
616 | schedstat_set(curr->se.exec_max, max(curr->se.exec_max, delta_exec)); | 616 | schedstat_set(curr->se.statistics.exec_max, max(curr->se.statistics.exec_max, delta_exec)); |
617 | 617 | ||
618 | curr->se.sum_exec_runtime += delta_exec; | 618 | curr->se.sum_exec_runtime += delta_exec; |
619 | account_group_exec_runtime(curr, delta_exec); | 619 | account_group_exec_runtime(curr, delta_exec); |
@@ -888,20 +888,20 @@ static void dequeue_rt_entity(struct sched_rt_entity *rt_se) | |||
888 | * Adding/removing a task to/from a priority array: | 888 | * Adding/removing a task to/from a priority array: |
889 | */ | 889 | */ |
890 | static void | 890 | static void |
891 | enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup, bool head) | 891 | enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) |
892 | { | 892 | { |
893 | struct sched_rt_entity *rt_se = &p->rt; | 893 | struct sched_rt_entity *rt_se = &p->rt; |
894 | 894 | ||
895 | if (wakeup) | 895 | if (flags & ENQUEUE_WAKEUP) |
896 | rt_se->timeout = 0; | 896 | rt_se->timeout = 0; |
897 | 897 | ||
898 | enqueue_rt_entity(rt_se, head); | 898 | enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD); |
899 | 899 | ||
900 | if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1) | 900 | if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1) |
901 | enqueue_pushable_task(rq, p); | 901 | enqueue_pushable_task(rq, p); |
902 | } | 902 | } |
903 | 903 | ||
904 | static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep) | 904 | static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) |
905 | { | 905 | { |
906 | struct sched_rt_entity *rt_se = &p->rt; | 906 | struct sched_rt_entity *rt_se = &p->rt; |
907 | 907 | ||
@@ -948,10 +948,9 @@ static void yield_task_rt(struct rq *rq) | |||
948 | #ifdef CONFIG_SMP | 948 | #ifdef CONFIG_SMP |
949 | static int find_lowest_rq(struct task_struct *task); | 949 | static int find_lowest_rq(struct task_struct *task); |
950 | 950 | ||
951 | static int select_task_rq_rt(struct task_struct *p, int sd_flag, int flags) | 951 | static int |
952 | select_task_rq_rt(struct rq *rq, struct task_struct *p, int sd_flag, int flags) | ||
952 | { | 953 | { |
953 | struct rq *rq = task_rq(p); | ||
954 | |||
955 | if (sd_flag != SD_BALANCE_WAKE) | 954 | if (sd_flag != SD_BALANCE_WAKE) |
956 | return smp_processor_id(); | 955 | return smp_processor_id(); |
957 | 956 | ||
diff --git a/kernel/softirq.c b/kernel/softirq.c index 7c1a67ef0274..0db913a5c60f 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
@@ -716,7 +716,7 @@ static int run_ksoftirqd(void * __bind_cpu) | |||
716 | preempt_enable_no_resched(); | 716 | preempt_enable_no_resched(); |
717 | cond_resched(); | 717 | cond_resched(); |
718 | preempt_disable(); | 718 | preempt_disable(); |
719 | rcu_sched_qs((long)__bind_cpu); | 719 | rcu_note_context_switch((long)__bind_cpu); |
720 | } | 720 | } |
721 | preempt_enable(); | 721 | preempt_enable(); |
722 | set_current_state(TASK_INTERRUPTIBLE); | 722 | set_current_state(TASK_INTERRUPTIBLE); |
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 9bb9fb1bd79c..b4e7431e7c78 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c | |||
@@ -1,17 +1,384 @@ | |||
1 | /* Copyright 2008, 2005 Rusty Russell rusty@rustcorp.com.au IBM Corporation. | 1 | /* |
2 | * GPL v2 and any later version. | 2 | * kernel/stop_machine.c |
3 | * | ||
4 | * Copyright (C) 2008, 2005 IBM Corporation. | ||
5 | * Copyright (C) 2008, 2005 Rusty Russell rusty@rustcorp.com.au | ||
6 | * Copyright (C) 2010 SUSE Linux Products GmbH | ||
7 | * Copyright (C) 2010 Tejun Heo <tj@kernel.org> | ||
8 | * | ||
9 | * This file is released under the GPLv2 and any later version. | ||
3 | */ | 10 | */ |
11 | #include <linux/completion.h> | ||
4 | #include <linux/cpu.h> | 12 | #include <linux/cpu.h> |
5 | #include <linux/err.h> | 13 | #include <linux/init.h> |
6 | #include <linux/kthread.h> | 14 | #include <linux/kthread.h> |
7 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/percpu.h> | ||
8 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
9 | #include <linux/stop_machine.h> | 18 | #include <linux/stop_machine.h> |
10 | #include <linux/syscalls.h> | ||
11 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | #include <linux/kallsyms.h> | ||
12 | 21 | ||
13 | #include <asm/atomic.h> | 22 | #include <asm/atomic.h> |
14 | #include <asm/uaccess.h> | 23 | |
24 | /* | ||
25 | * Structure to determine completion condition and record errors. May | ||
26 | * be shared by works on different cpus. | ||
27 | */ | ||
28 | struct cpu_stop_done { | ||
29 | atomic_t nr_todo; /* nr left to execute */ | ||
30 | bool executed; /* actually executed? */ | ||
31 | int ret; /* collected return value */ | ||
32 | struct completion completion; /* fired if nr_todo reaches 0 */ | ||
33 | }; | ||
34 | |||
35 | /* the actual stopper, one per every possible cpu, enabled on online cpus */ | ||
36 | struct cpu_stopper { | ||
37 | spinlock_t lock; | ||
38 | struct list_head works; /* list of pending works */ | ||
39 | struct task_struct *thread; /* stopper thread */ | ||
40 | bool enabled; /* is this stopper enabled? */ | ||
41 | }; | ||
42 | |||
43 | static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper); | ||
44 | |||
45 | static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo) | ||
46 | { | ||
47 | memset(done, 0, sizeof(*done)); | ||
48 | atomic_set(&done->nr_todo, nr_todo); | ||
49 | init_completion(&done->completion); | ||
50 | } | ||
51 | |||
52 | /* signal completion unless @done is NULL */ | ||
53 | static void cpu_stop_signal_done(struct cpu_stop_done *done, bool executed) | ||
54 | { | ||
55 | if (done) { | ||
56 | if (executed) | ||
57 | done->executed = true; | ||
58 | if (atomic_dec_and_test(&done->nr_todo)) | ||
59 | complete(&done->completion); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | /* queue @work to @stopper. if offline, @work is completed immediately */ | ||
64 | static void cpu_stop_queue_work(struct cpu_stopper *stopper, | ||
65 | struct cpu_stop_work *work) | ||
66 | { | ||
67 | unsigned long flags; | ||
68 | |||
69 | spin_lock_irqsave(&stopper->lock, flags); | ||
70 | |||
71 | if (stopper->enabled) { | ||
72 | list_add_tail(&work->list, &stopper->works); | ||
73 | wake_up_process(stopper->thread); | ||
74 | } else | ||
75 | cpu_stop_signal_done(work->done, false); | ||
76 | |||
77 | spin_unlock_irqrestore(&stopper->lock, flags); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * stop_one_cpu - stop a cpu | ||
82 | * @cpu: cpu to stop | ||
83 | * @fn: function to execute | ||
84 | * @arg: argument to @fn | ||
85 | * | ||
86 | * Execute @fn(@arg) on @cpu. @fn is run in a process context with | ||
87 | * the highest priority preempting any task on the cpu and | ||
88 | * monopolizing it. This function returns after the execution is | ||
89 | * complete. | ||
90 | * | ||
91 | * This function doesn't guarantee @cpu stays online till @fn | ||
92 | * completes. If @cpu goes down in the middle, execution may happen | ||
93 | * partially or fully on different cpus. @fn should either be ready | ||
94 | * for that or the caller should ensure that @cpu stays online until | ||
95 | * this function completes. | ||
96 | * | ||
97 | * CONTEXT: | ||
98 | * Might sleep. | ||
99 | * | ||
100 | * RETURNS: | ||
101 | * -ENOENT if @fn(@arg) was not executed because @cpu was offline; | ||
102 | * otherwise, the return value of @fn. | ||
103 | */ | ||
104 | int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg) | ||
105 | { | ||
106 | struct cpu_stop_done done; | ||
107 | struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = &done }; | ||
108 | |||
109 | cpu_stop_init_done(&done, 1); | ||
110 | cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), &work); | ||
111 | wait_for_completion(&done.completion); | ||
112 | return done.executed ? done.ret : -ENOENT; | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * stop_one_cpu_nowait - stop a cpu but don't wait for completion | ||
117 | * @cpu: cpu to stop | ||
118 | * @fn: function to execute | ||
119 | * @arg: argument to @fn | ||
120 | * | ||
121 | * Similar to stop_one_cpu() but doesn't wait for completion. The | ||
122 | * caller is responsible for ensuring @work_buf is currently unused | ||
123 | * and will remain untouched until stopper starts executing @fn. | ||
124 | * | ||
125 | * CONTEXT: | ||
126 | * Don't care. | ||
127 | */ | ||
128 | void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg, | ||
129 | struct cpu_stop_work *work_buf) | ||
130 | { | ||
131 | *work_buf = (struct cpu_stop_work){ .fn = fn, .arg = arg, }; | ||
132 | cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), work_buf); | ||
133 | } | ||
134 | |||
135 | /* static data for stop_cpus */ | ||
136 | static DEFINE_MUTEX(stop_cpus_mutex); | ||
137 | static DEFINE_PER_CPU(struct cpu_stop_work, stop_cpus_work); | ||
138 | |||
139 | int __stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg) | ||
140 | { | ||
141 | struct cpu_stop_work *work; | ||
142 | struct cpu_stop_done done; | ||
143 | unsigned int cpu; | ||
144 | |||
145 | /* initialize works and done */ | ||
146 | for_each_cpu(cpu, cpumask) { | ||
147 | work = &per_cpu(stop_cpus_work, cpu); | ||
148 | work->fn = fn; | ||
149 | work->arg = arg; | ||
150 | work->done = &done; | ||
151 | } | ||
152 | cpu_stop_init_done(&done, cpumask_weight(cpumask)); | ||
153 | |||
154 | /* | ||
155 | * Disable preemption while queueing to avoid getting | ||
156 | * preempted by a stopper which might wait for other stoppers | ||
157 | * to enter @fn which can lead to deadlock. | ||
158 | */ | ||
159 | preempt_disable(); | ||
160 | for_each_cpu(cpu, cpumask) | ||
161 | cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), | ||
162 | &per_cpu(stop_cpus_work, cpu)); | ||
163 | preempt_enable(); | ||
164 | |||
165 | wait_for_completion(&done.completion); | ||
166 | return done.executed ? done.ret : -ENOENT; | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * stop_cpus - stop multiple cpus | ||
171 | * @cpumask: cpus to stop | ||
172 | * @fn: function to execute | ||
173 | * @arg: argument to @fn | ||
174 | * | ||
175 | * Execute @fn(@arg) on online cpus in @cpumask. On each target cpu, | ||
176 | * @fn is run in a process context with the highest priority | ||
177 | * preempting any task on the cpu and monopolizing it. This function | ||
178 | * returns after all executions are complete. | ||
179 | * | ||
180 | * This function doesn't guarantee the cpus in @cpumask stay online | ||
181 | * till @fn completes. If some cpus go down in the middle, execution | ||
182 | * on the cpu may happen partially or fully on different cpus. @fn | ||
183 | * should either be ready for that or the caller should ensure that | ||
184 | * the cpus stay online until this function completes. | ||
185 | * | ||
186 | * All stop_cpus() calls are serialized making it safe for @fn to wait | ||
187 | * for all cpus to start executing it. | ||
188 | * | ||
189 | * CONTEXT: | ||
190 | * Might sleep. | ||
191 | * | ||
192 | * RETURNS: | ||
193 | * -ENOENT if @fn(@arg) was not executed at all because all cpus in | ||
194 | * @cpumask were offline; otherwise, 0 if all executions of @fn | ||
195 | * returned 0, any non zero return value if any returned non zero. | ||
196 | */ | ||
197 | int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg) | ||
198 | { | ||
199 | int ret; | ||
200 | |||
201 | /* static works are used, process one request at a time */ | ||
202 | mutex_lock(&stop_cpus_mutex); | ||
203 | ret = __stop_cpus(cpumask, fn, arg); | ||
204 | mutex_unlock(&stop_cpus_mutex); | ||
205 | return ret; | ||
206 | } | ||
207 | |||
208 | /** | ||
209 | * try_stop_cpus - try to stop multiple cpus | ||
210 | * @cpumask: cpus to stop | ||
211 | * @fn: function to execute | ||
212 | * @arg: argument to @fn | ||
213 | * | ||
214 | * Identical to stop_cpus() except that it fails with -EAGAIN if | ||
215 | * someone else is already using the facility. | ||
216 | * | ||
217 | * CONTEXT: | ||
218 | * Might sleep. | ||
219 | * | ||
220 | * RETURNS: | ||
221 | * -EAGAIN if someone else is already stopping cpus, -ENOENT if | ||
222 | * @fn(@arg) was not executed at all because all cpus in @cpumask were | ||
223 | * offline; otherwise, 0 if all executions of @fn returned 0, any non | ||
224 | * zero return value if any returned non zero. | ||
225 | */ | ||
226 | int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg) | ||
227 | { | ||
228 | int ret; | ||
229 | |||
230 | /* static works are used, process one request at a time */ | ||
231 | if (!mutex_trylock(&stop_cpus_mutex)) | ||
232 | return -EAGAIN; | ||
233 | ret = __stop_cpus(cpumask, fn, arg); | ||
234 | mutex_unlock(&stop_cpus_mutex); | ||
235 | return ret; | ||
236 | } | ||
237 | |||
238 | static int cpu_stopper_thread(void *data) | ||
239 | { | ||
240 | struct cpu_stopper *stopper = data; | ||
241 | struct cpu_stop_work *work; | ||
242 | int ret; | ||
243 | |||
244 | repeat: | ||
245 | set_current_state(TASK_INTERRUPTIBLE); /* mb paired w/ kthread_stop */ | ||
246 | |||
247 | if (kthread_should_stop()) { | ||
248 | __set_current_state(TASK_RUNNING); | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | work = NULL; | ||
253 | spin_lock_irq(&stopper->lock); | ||
254 | if (!list_empty(&stopper->works)) { | ||
255 | work = list_first_entry(&stopper->works, | ||
256 | struct cpu_stop_work, list); | ||
257 | list_del_init(&work->list); | ||
258 | } | ||
259 | spin_unlock_irq(&stopper->lock); | ||
260 | |||
261 | if (work) { | ||
262 | cpu_stop_fn_t fn = work->fn; | ||
263 | void *arg = work->arg; | ||
264 | struct cpu_stop_done *done = work->done; | ||
265 | char ksym_buf[KSYM_NAME_LEN]; | ||
266 | |||
267 | __set_current_state(TASK_RUNNING); | ||
268 | |||
269 | /* cpu stop callbacks are not allowed to sleep */ | ||
270 | preempt_disable(); | ||
271 | |||
272 | ret = fn(arg); | ||
273 | if (ret) | ||
274 | done->ret = ret; | ||
275 | |||
276 | /* restore preemption and check it's still balanced */ | ||
277 | preempt_enable(); | ||
278 | WARN_ONCE(preempt_count(), | ||
279 | "cpu_stop: %s(%p) leaked preempt count\n", | ||
280 | kallsyms_lookup((unsigned long)fn, NULL, NULL, NULL, | ||
281 | ksym_buf), arg); | ||
282 | |||
283 | cpu_stop_signal_done(done, true); | ||
284 | } else | ||
285 | schedule(); | ||
286 | |||
287 | goto repeat; | ||
288 | } | ||
289 | |||
290 | /* manage stopper for a cpu, mostly lifted from sched migration thread mgmt */ | ||
291 | static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb, | ||
292 | unsigned long action, void *hcpu) | ||
293 | { | ||
294 | struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 }; | ||
295 | unsigned int cpu = (unsigned long)hcpu; | ||
296 | struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu); | ||
297 | struct task_struct *p; | ||
298 | |||
299 | switch (action & ~CPU_TASKS_FROZEN) { | ||
300 | case CPU_UP_PREPARE: | ||
301 | BUG_ON(stopper->thread || stopper->enabled || | ||
302 | !list_empty(&stopper->works)); | ||
303 | p = kthread_create(cpu_stopper_thread, stopper, "migration/%d", | ||
304 | cpu); | ||
305 | if (IS_ERR(p)) | ||
306 | return NOTIFY_BAD; | ||
307 | sched_setscheduler_nocheck(p, SCHED_FIFO, ¶m); | ||
308 | get_task_struct(p); | ||
309 | stopper->thread = p; | ||
310 | break; | ||
311 | |||
312 | case CPU_ONLINE: | ||
313 | kthread_bind(stopper->thread, cpu); | ||
314 | /* strictly unnecessary, as first user will wake it */ | ||
315 | wake_up_process(stopper->thread); | ||
316 | /* mark enabled */ | ||
317 | spin_lock_irq(&stopper->lock); | ||
318 | stopper->enabled = true; | ||
319 | spin_unlock_irq(&stopper->lock); | ||
320 | break; | ||
321 | |||
322 | #ifdef CONFIG_HOTPLUG_CPU | ||
323 | case CPU_UP_CANCELED: | ||
324 | case CPU_DEAD: | ||
325 | { | ||
326 | struct cpu_stop_work *work; | ||
327 | |||
328 | /* kill the stopper */ | ||
329 | kthread_stop(stopper->thread); | ||
330 | /* drain remaining works */ | ||
331 | spin_lock_irq(&stopper->lock); | ||
332 | list_for_each_entry(work, &stopper->works, list) | ||
333 | cpu_stop_signal_done(work->done, false); | ||
334 | stopper->enabled = false; | ||
335 | spin_unlock_irq(&stopper->lock); | ||
336 | /* release the stopper */ | ||
337 | put_task_struct(stopper->thread); | ||
338 | stopper->thread = NULL; | ||
339 | break; | ||
340 | } | ||
341 | #endif | ||
342 | } | ||
343 | |||
344 | return NOTIFY_OK; | ||
345 | } | ||
346 | |||
347 | /* | ||
348 | * Give it a higher priority so that cpu stopper is available to other | ||
349 | * cpu notifiers. It currently shares the same priority as sched | ||
350 | * migration_notifier. | ||
351 | */ | ||
352 | static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = { | ||
353 | .notifier_call = cpu_stop_cpu_callback, | ||
354 | .priority = 10, | ||
355 | }; | ||
356 | |||
357 | static int __init cpu_stop_init(void) | ||
358 | { | ||
359 | void *bcpu = (void *)(long)smp_processor_id(); | ||
360 | unsigned int cpu; | ||
361 | int err; | ||
362 | |||
363 | for_each_possible_cpu(cpu) { | ||
364 | struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu); | ||
365 | |||
366 | spin_lock_init(&stopper->lock); | ||
367 | INIT_LIST_HEAD(&stopper->works); | ||
368 | } | ||
369 | |||
370 | /* start one for the boot cpu */ | ||
371 | err = cpu_stop_cpu_callback(&cpu_stop_cpu_notifier, CPU_UP_PREPARE, | ||
372 | bcpu); | ||
373 | BUG_ON(err == NOTIFY_BAD); | ||
374 | cpu_stop_cpu_callback(&cpu_stop_cpu_notifier, CPU_ONLINE, bcpu); | ||
375 | register_cpu_notifier(&cpu_stop_cpu_notifier); | ||
376 | |||
377 | return 0; | ||
378 | } | ||
379 | early_initcall(cpu_stop_init); | ||
380 | |||
381 | #ifdef CONFIG_STOP_MACHINE | ||
15 | 382 | ||
16 | /* This controls the threads on each CPU. */ | 383 | /* This controls the threads on each CPU. */ |
17 | enum stopmachine_state { | 384 | enum stopmachine_state { |
@@ -26,174 +393,94 @@ enum stopmachine_state { | |||
26 | /* Exit */ | 393 | /* Exit */ |
27 | STOPMACHINE_EXIT, | 394 | STOPMACHINE_EXIT, |
28 | }; | 395 | }; |
29 | static enum stopmachine_state state; | ||
30 | 396 | ||
31 | struct stop_machine_data { | 397 | struct stop_machine_data { |
32 | int (*fn)(void *); | 398 | int (*fn)(void *); |
33 | void *data; | 399 | void *data; |
34 | int fnret; | 400 | /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */ |
401 | unsigned int num_threads; | ||
402 | const struct cpumask *active_cpus; | ||
403 | |||
404 | enum stopmachine_state state; | ||
405 | atomic_t thread_ack; | ||
35 | }; | 406 | }; |
36 | 407 | ||
37 | /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */ | 408 | static void set_state(struct stop_machine_data *smdata, |
38 | static unsigned int num_threads; | 409 | enum stopmachine_state newstate) |
39 | static atomic_t thread_ack; | ||
40 | static DEFINE_MUTEX(lock); | ||
41 | /* setup_lock protects refcount, stop_machine_wq and stop_machine_work. */ | ||
42 | static DEFINE_MUTEX(setup_lock); | ||
43 | /* Users of stop_machine. */ | ||
44 | static int refcount; | ||
45 | static struct workqueue_struct *stop_machine_wq; | ||
46 | static struct stop_machine_data active, idle; | ||
47 | static const struct cpumask *active_cpus; | ||
48 | static void __percpu *stop_machine_work; | ||
49 | |||
50 | static void set_state(enum stopmachine_state newstate) | ||
51 | { | 410 | { |
52 | /* Reset ack counter. */ | 411 | /* Reset ack counter. */ |
53 | atomic_set(&thread_ack, num_threads); | 412 | atomic_set(&smdata->thread_ack, smdata->num_threads); |
54 | smp_wmb(); | 413 | smp_wmb(); |
55 | state = newstate; | 414 | smdata->state = newstate; |
56 | } | 415 | } |
57 | 416 | ||
58 | /* Last one to ack a state moves to the next state. */ | 417 | /* Last one to ack a state moves to the next state. */ |
59 | static void ack_state(void) | 418 | static void ack_state(struct stop_machine_data *smdata) |
60 | { | 419 | { |
61 | if (atomic_dec_and_test(&thread_ack)) | 420 | if (atomic_dec_and_test(&smdata->thread_ack)) |
62 | set_state(state + 1); | 421 | set_state(smdata, smdata->state + 1); |
63 | } | 422 | } |
64 | 423 | ||
65 | /* This is the actual function which stops the CPU. It runs | 424 | /* This is the cpu_stop function which stops the CPU. */ |
66 | * in the context of a dedicated stopmachine workqueue. */ | 425 | static int stop_machine_cpu_stop(void *data) |
67 | static void stop_cpu(struct work_struct *unused) | ||
68 | { | 426 | { |
427 | struct stop_machine_data *smdata = data; | ||
69 | enum stopmachine_state curstate = STOPMACHINE_NONE; | 428 | enum stopmachine_state curstate = STOPMACHINE_NONE; |
70 | struct stop_machine_data *smdata = &idle; | 429 | int cpu = smp_processor_id(), err = 0; |
71 | int cpu = smp_processor_id(); | 430 | bool is_active; |
72 | int err; | 431 | |
432 | if (!smdata->active_cpus) | ||
433 | is_active = cpu == cpumask_first(cpu_online_mask); | ||
434 | else | ||
435 | is_active = cpumask_test_cpu(cpu, smdata->active_cpus); | ||
73 | 436 | ||
74 | if (!active_cpus) { | ||
75 | if (cpu == cpumask_first(cpu_online_mask)) | ||
76 | smdata = &active; | ||
77 | } else { | ||
78 | if (cpumask_test_cpu(cpu, active_cpus)) | ||
79 | smdata = &active; | ||
80 | } | ||
81 | /* Simple state machine */ | 437 | /* Simple state machine */ |
82 | do { | 438 | do { |
83 | /* Chill out and ensure we re-read stopmachine_state. */ | 439 | /* Chill out and ensure we re-read stopmachine_state. */ |
84 | cpu_relax(); | 440 | cpu_relax(); |
85 | if (state != curstate) { | 441 | if (smdata->state != curstate) { |
86 | curstate = state; | 442 | curstate = smdata->state; |
87 | switch (curstate) { | 443 | switch (curstate) { |
88 | case STOPMACHINE_DISABLE_IRQ: | 444 | case STOPMACHINE_DISABLE_IRQ: |
89 | local_irq_disable(); | 445 | local_irq_disable(); |
90 | hard_irq_disable(); | 446 | hard_irq_disable(); |
91 | break; | 447 | break; |
92 | case STOPMACHINE_RUN: | 448 | case STOPMACHINE_RUN: |
93 | /* On multiple CPUs only a single error code | 449 | if (is_active) |
94 | * is needed to tell that something failed. */ | 450 | err = smdata->fn(smdata->data); |
95 | err = smdata->fn(smdata->data); | ||
96 | if (err) | ||
97 | smdata->fnret = err; | ||
98 | break; | 451 | break; |
99 | default: | 452 | default: |
100 | break; | 453 | break; |
101 | } | 454 | } |
102 | ack_state(); | 455 | ack_state(smdata); |
103 | } | 456 | } |
104 | } while (curstate != STOPMACHINE_EXIT); | 457 | } while (curstate != STOPMACHINE_EXIT); |
105 | 458 | ||
106 | local_irq_enable(); | 459 | local_irq_enable(); |
460 | return err; | ||
107 | } | 461 | } |
108 | 462 | ||
109 | /* Callback for CPUs which aren't supposed to do anything. */ | ||
110 | static int chill(void *unused) | ||
111 | { | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | int stop_machine_create(void) | ||
116 | { | ||
117 | mutex_lock(&setup_lock); | ||
118 | if (refcount) | ||
119 | goto done; | ||
120 | stop_machine_wq = create_rt_workqueue("kstop"); | ||
121 | if (!stop_machine_wq) | ||
122 | goto err_out; | ||
123 | stop_machine_work = alloc_percpu(struct work_struct); | ||
124 | if (!stop_machine_work) | ||
125 | goto err_out; | ||
126 | done: | ||
127 | refcount++; | ||
128 | mutex_unlock(&setup_lock); | ||
129 | return 0; | ||
130 | |||
131 | err_out: | ||
132 | if (stop_machine_wq) | ||
133 | destroy_workqueue(stop_machine_wq); | ||
134 | mutex_unlock(&setup_lock); | ||
135 | return -ENOMEM; | ||
136 | } | ||
137 | EXPORT_SYMBOL_GPL(stop_machine_create); | ||
138 | |||
139 | void stop_machine_destroy(void) | ||
140 | { | ||
141 | mutex_lock(&setup_lock); | ||
142 | refcount--; | ||
143 | if (refcount) | ||
144 | goto done; | ||
145 | destroy_workqueue(stop_machine_wq); | ||
146 | free_percpu(stop_machine_work); | ||
147 | done: | ||
148 | mutex_unlock(&setup_lock); | ||
149 | } | ||
150 | EXPORT_SYMBOL_GPL(stop_machine_destroy); | ||
151 | |||
152 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus) | 463 | int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus) |
153 | { | 464 | { |
154 | struct work_struct *sm_work; | 465 | struct stop_machine_data smdata = { .fn = fn, .data = data, |
155 | int i, ret; | 466 | .num_threads = num_online_cpus(), |
156 | 467 | .active_cpus = cpus }; | |
157 | /* Set up initial state. */ | 468 | |
158 | mutex_lock(&lock); | 469 | /* Set the initial state and stop all online cpus. */ |
159 | num_threads = num_online_cpus(); | 470 | set_state(&smdata, STOPMACHINE_PREPARE); |
160 | active_cpus = cpus; | 471 | return stop_cpus(cpu_online_mask, stop_machine_cpu_stop, &smdata); |
161 | active.fn = fn; | ||
162 | active.data = data; | ||
163 | active.fnret = 0; | ||
164 | idle.fn = chill; | ||
165 | idle.data = NULL; | ||
166 | |||
167 | set_state(STOPMACHINE_PREPARE); | ||
168 | |||
169 | /* Schedule the stop_cpu work on all cpus: hold this CPU so one | ||
170 | * doesn't hit this CPU until we're ready. */ | ||
171 | get_cpu(); | ||
172 | for_each_online_cpu(i) { | ||
173 | sm_work = per_cpu_ptr(stop_machine_work, i); | ||
174 | INIT_WORK(sm_work, stop_cpu); | ||
175 | queue_work_on(i, stop_machine_wq, sm_work); | ||
176 | } | ||
177 | /* This will release the thread on our CPU. */ | ||
178 | put_cpu(); | ||
179 | flush_workqueue(stop_machine_wq); | ||
180 | ret = active.fnret; | ||
181 | mutex_unlock(&lock); | ||
182 | return ret; | ||
183 | } | 472 | } |
184 | 473 | ||
185 | int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus) | 474 | int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus) |
186 | { | 475 | { |
187 | int ret; | 476 | int ret; |
188 | 477 | ||
189 | ret = stop_machine_create(); | ||
190 | if (ret) | ||
191 | return ret; | ||
192 | /* No CPUs can come up or down during this. */ | 478 | /* No CPUs can come up or down during this. */ |
193 | get_online_cpus(); | 479 | get_online_cpus(); |
194 | ret = __stop_machine(fn, data, cpus); | 480 | ret = __stop_machine(fn, data, cpus); |
195 | put_online_cpus(); | 481 | put_online_cpus(); |
196 | stop_machine_destroy(); | ||
197 | return ret; | 482 | return ret; |
198 | } | 483 | } |
199 | EXPORT_SYMBOL_GPL(stop_machine); | 484 | EXPORT_SYMBOL_GPL(stop_machine); |
485 | |||
486 | #endif /* CONFIG_STOP_MACHINE */ | ||
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index f992762d7f51..1d7b9bc1c034 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c | |||
@@ -150,14 +150,32 @@ static void tick_nohz_update_jiffies(ktime_t now) | |||
150 | touch_softlockup_watchdog(); | 150 | touch_softlockup_watchdog(); |
151 | } | 151 | } |
152 | 152 | ||
153 | /* | ||
154 | * Updates the per cpu time idle statistics counters | ||
155 | */ | ||
156 | static void | ||
157 | update_ts_time_stats(struct tick_sched *ts, ktime_t now, u64 *last_update_time) | ||
158 | { | ||
159 | ktime_t delta; | ||
160 | |||
161 | if (ts->idle_active) { | ||
162 | delta = ktime_sub(now, ts->idle_entrytime); | ||
163 | ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); | ||
164 | if (nr_iowait_cpu() > 0) | ||
165 | ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); | ||
166 | ts->idle_entrytime = now; | ||
167 | } | ||
168 | |||
169 | if (last_update_time) | ||
170 | *last_update_time = ktime_to_us(now); | ||
171 | |||
172 | } | ||
173 | |||
153 | static void tick_nohz_stop_idle(int cpu, ktime_t now) | 174 | static void tick_nohz_stop_idle(int cpu, ktime_t now) |
154 | { | 175 | { |
155 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 176 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
156 | ktime_t delta; | ||
157 | 177 | ||
158 | delta = ktime_sub(now, ts->idle_entrytime); | 178 | update_ts_time_stats(ts, now, NULL); |
159 | ts->idle_lastupdate = now; | ||
160 | ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); | ||
161 | ts->idle_active = 0; | 179 | ts->idle_active = 0; |
162 | 180 | ||
163 | sched_clock_idle_wakeup_event(0); | 181 | sched_clock_idle_wakeup_event(0); |
@@ -165,20 +183,32 @@ static void tick_nohz_stop_idle(int cpu, ktime_t now) | |||
165 | 183 | ||
166 | static ktime_t tick_nohz_start_idle(struct tick_sched *ts) | 184 | static ktime_t tick_nohz_start_idle(struct tick_sched *ts) |
167 | { | 185 | { |
168 | ktime_t now, delta; | 186 | ktime_t now; |
169 | 187 | ||
170 | now = ktime_get(); | 188 | now = ktime_get(); |
171 | if (ts->idle_active) { | 189 | |
172 | delta = ktime_sub(now, ts->idle_entrytime); | 190 | update_ts_time_stats(ts, now, NULL); |
173 | ts->idle_lastupdate = now; | 191 | |
174 | ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); | ||
175 | } | ||
176 | ts->idle_entrytime = now; | 192 | ts->idle_entrytime = now; |
177 | ts->idle_active = 1; | 193 | ts->idle_active = 1; |
178 | sched_clock_idle_sleep_event(); | 194 | sched_clock_idle_sleep_event(); |
179 | return now; | 195 | return now; |
180 | } | 196 | } |
181 | 197 | ||
198 | /** | ||
199 | * get_cpu_idle_time_us - get the total idle time of a cpu | ||
200 | * @cpu: CPU number to query | ||
201 | * @last_update_time: variable to store update time in | ||
202 | * | ||
203 | * Return the cummulative idle time (since boot) for a given | ||
204 | * CPU, in microseconds. The idle time returned includes | ||
205 | * the iowait time (unlike what "top" and co report). | ||
206 | * | ||
207 | * This time is measured via accounting rather than sampling, | ||
208 | * and is as accurate as ktime_get() is. | ||
209 | * | ||
210 | * This function returns -1 if NOHZ is not enabled. | ||
211 | */ | ||
182 | u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) | 212 | u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) |
183 | { | 213 | { |
184 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | 214 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); |
@@ -186,15 +216,38 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) | |||
186 | if (!tick_nohz_enabled) | 216 | if (!tick_nohz_enabled) |
187 | return -1; | 217 | return -1; |
188 | 218 | ||
189 | if (ts->idle_active) | 219 | update_ts_time_stats(ts, ktime_get(), last_update_time); |
190 | *last_update_time = ktime_to_us(ts->idle_lastupdate); | ||
191 | else | ||
192 | *last_update_time = ktime_to_us(ktime_get()); | ||
193 | 220 | ||
194 | return ktime_to_us(ts->idle_sleeptime); | 221 | return ktime_to_us(ts->idle_sleeptime); |
195 | } | 222 | } |
196 | EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); | 223 | EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); |
197 | 224 | ||
225 | /* | ||
226 | * get_cpu_iowait_time_us - get the total iowait time of a cpu | ||
227 | * @cpu: CPU number to query | ||
228 | * @last_update_time: variable to store update time in | ||
229 | * | ||
230 | * Return the cummulative iowait time (since boot) for a given | ||
231 | * CPU, in microseconds. | ||
232 | * | ||
233 | * This time is measured via accounting rather than sampling, | ||
234 | * and is as accurate as ktime_get() is. | ||
235 | * | ||
236 | * This function returns -1 if NOHZ is not enabled. | ||
237 | */ | ||
238 | u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time) | ||
239 | { | ||
240 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | ||
241 | |||
242 | if (!tick_nohz_enabled) | ||
243 | return -1; | ||
244 | |||
245 | update_ts_time_stats(ts, ktime_get(), last_update_time); | ||
246 | |||
247 | return ktime_to_us(ts->iowait_sleeptime); | ||
248 | } | ||
249 | EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us); | ||
250 | |||
198 | /** | 251 | /** |
199 | * tick_nohz_stop_sched_tick - stop the idle tick from the idle task | 252 | * tick_nohz_stop_sched_tick - stop the idle tick from the idle task |
200 | * | 253 | * |
@@ -262,6 +315,9 @@ void tick_nohz_stop_sched_tick(int inidle) | |||
262 | goto end; | 315 | goto end; |
263 | } | 316 | } |
264 | 317 | ||
318 | if (nohz_ratelimit(cpu)) | ||
319 | goto end; | ||
320 | |||
265 | ts->idle_calls++; | 321 | ts->idle_calls++; |
266 | /* Read jiffies and the time when jiffies were updated last */ | 322 | /* Read jiffies and the time when jiffies were updated last */ |
267 | do { | 323 | do { |
diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c index 1a4a7dd78777..ab8f5e33fa92 100644 --- a/kernel/time/timer_list.c +++ b/kernel/time/timer_list.c | |||
@@ -176,6 +176,7 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now) | |||
176 | P_ns(idle_waketime); | 176 | P_ns(idle_waketime); |
177 | P_ns(idle_exittime); | 177 | P_ns(idle_exittime); |
178 | P_ns(idle_sleeptime); | 178 | P_ns(idle_sleeptime); |
179 | P_ns(iowait_sleeptime); | ||
179 | P(last_jiffies); | 180 | P(last_jiffies); |
180 | P(next_jiffies); | 181 | P(next_jiffies); |
181 | P_ns(idle_expires); | 182 | P_ns(idle_expires); |
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 13e13d428cd3..8b1797c4545b 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig | |||
@@ -44,9 +44,6 @@ config HAVE_FTRACE_MCOUNT_RECORD | |||
44 | help | 44 | help |
45 | See Documentation/trace/ftrace-design.txt | 45 | See Documentation/trace/ftrace-design.txt |
46 | 46 | ||
47 | config HAVE_HW_BRANCH_TRACER | ||
48 | bool | ||
49 | |||
50 | config HAVE_SYSCALL_TRACEPOINTS | 47 | config HAVE_SYSCALL_TRACEPOINTS |
51 | bool | 48 | bool |
52 | help | 49 | help |
@@ -374,14 +371,6 @@ config STACK_TRACER | |||
374 | 371 | ||
375 | Say N if unsure. | 372 | Say N if unsure. |
376 | 373 | ||
377 | config HW_BRANCH_TRACER | ||
378 | depends on HAVE_HW_BRANCH_TRACER | ||
379 | bool "Trace hw branches" | ||
380 | select GENERIC_TRACER | ||
381 | help | ||
382 | This tracer records all branches on the system in a circular | ||
383 | buffer, giving access to the last N branches for each cpu. | ||
384 | |||
385 | config KMEMTRACE | 374 | config KMEMTRACE |
386 | bool "Trace SLAB allocations" | 375 | bool "Trace SLAB allocations" |
387 | select GENERIC_TRACER | 376 | select GENERIC_TRACER |
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 78edc6490038..ffb1a5b0550e 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
@@ -41,7 +41,6 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o | |||
41 | obj-$(CONFIG_BOOT_TRACER) += trace_boot.o | 41 | obj-$(CONFIG_BOOT_TRACER) += trace_boot.o |
42 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o | 42 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o |
43 | obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o | 43 | obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o |
44 | obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o | ||
45 | obj-$(CONFIG_KMEMTRACE) += kmemtrace.o | 44 | obj-$(CONFIG_KMEMTRACE) += kmemtrace.o |
46 | obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o | 45 | obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o |
47 | obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o | 46 | obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o |
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 2404b59b3097..32837e19e3bd 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -264,6 +264,7 @@ struct ftrace_profile { | |||
264 | unsigned long counter; | 264 | unsigned long counter; |
265 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 265 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
266 | unsigned long long time; | 266 | unsigned long long time; |
267 | unsigned long long time_squared; | ||
267 | #endif | 268 | #endif |
268 | }; | 269 | }; |
269 | 270 | ||
@@ -366,9 +367,9 @@ static int function_stat_headers(struct seq_file *m) | |||
366 | { | 367 | { |
367 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 368 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
368 | seq_printf(m, " Function " | 369 | seq_printf(m, " Function " |
369 | "Hit Time Avg\n" | 370 | "Hit Time Avg s^2\n" |
370 | " -------- " | 371 | " -------- " |
371 | "--- ---- ---\n"); | 372 | "--- ---- --- ---\n"); |
372 | #else | 373 | #else |
373 | seq_printf(m, " Function Hit\n" | 374 | seq_printf(m, " Function Hit\n" |
374 | " -------- ---\n"); | 375 | " -------- ---\n"); |
@@ -384,6 +385,7 @@ static int function_stat_show(struct seq_file *m, void *v) | |||
384 | static DEFINE_MUTEX(mutex); | 385 | static DEFINE_MUTEX(mutex); |
385 | static struct trace_seq s; | 386 | static struct trace_seq s; |
386 | unsigned long long avg; | 387 | unsigned long long avg; |
388 | unsigned long long stddev; | ||
387 | #endif | 389 | #endif |
388 | 390 | ||
389 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); | 391 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
@@ -394,11 +396,25 @@ static int function_stat_show(struct seq_file *m, void *v) | |||
394 | avg = rec->time; | 396 | avg = rec->time; |
395 | do_div(avg, rec->counter); | 397 | do_div(avg, rec->counter); |
396 | 398 | ||
399 | /* Sample standard deviation (s^2) */ | ||
400 | if (rec->counter <= 1) | ||
401 | stddev = 0; | ||
402 | else { | ||
403 | stddev = rec->time_squared - rec->counter * avg * avg; | ||
404 | /* | ||
405 | * Divide only 1000 for ns^2 -> us^2 conversion. | ||
406 | * trace_print_graph_duration will divide 1000 again. | ||
407 | */ | ||
408 | do_div(stddev, (rec->counter - 1) * 1000); | ||
409 | } | ||
410 | |||
397 | mutex_lock(&mutex); | 411 | mutex_lock(&mutex); |
398 | trace_seq_init(&s); | 412 | trace_seq_init(&s); |
399 | trace_print_graph_duration(rec->time, &s); | 413 | trace_print_graph_duration(rec->time, &s); |
400 | trace_seq_puts(&s, " "); | 414 | trace_seq_puts(&s, " "); |
401 | trace_print_graph_duration(avg, &s); | 415 | trace_print_graph_duration(avg, &s); |
416 | trace_seq_puts(&s, " "); | ||
417 | trace_print_graph_duration(stddev, &s); | ||
402 | trace_print_seq(m, &s); | 418 | trace_print_seq(m, &s); |
403 | mutex_unlock(&mutex); | 419 | mutex_unlock(&mutex); |
404 | #endif | 420 | #endif |
@@ -650,6 +666,10 @@ static void profile_graph_return(struct ftrace_graph_ret *trace) | |||
650 | if (!stat->hash || !ftrace_profile_enabled) | 666 | if (!stat->hash || !ftrace_profile_enabled) |
651 | goto out; | 667 | goto out; |
652 | 668 | ||
669 | /* If the calltime was zero'd ignore it */ | ||
670 | if (!trace->calltime) | ||
671 | goto out; | ||
672 | |||
653 | calltime = trace->rettime - trace->calltime; | 673 | calltime = trace->rettime - trace->calltime; |
654 | 674 | ||
655 | if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) { | 675 | if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) { |
@@ -668,8 +688,10 @@ static void profile_graph_return(struct ftrace_graph_ret *trace) | |||
668 | } | 688 | } |
669 | 689 | ||
670 | rec = ftrace_find_profiled_func(stat, trace->func); | 690 | rec = ftrace_find_profiled_func(stat, trace->func); |
671 | if (rec) | 691 | if (rec) { |
672 | rec->time += calltime; | 692 | rec->time += calltime; |
693 | rec->time_squared += calltime * calltime; | ||
694 | } | ||
673 | 695 | ||
674 | out: | 696 | out: |
675 | local_irq_restore(flags); | 697 | local_irq_restore(flags); |
@@ -3212,8 +3234,7 @@ free: | |||
3212 | } | 3234 | } |
3213 | 3235 | ||
3214 | static void | 3236 | static void |
3215 | ftrace_graph_probe_sched_switch(struct rq *__rq, struct task_struct *prev, | 3237 | ftrace_graph_probe_sched_switch(struct task_struct *prev, struct task_struct *next) |
3216 | struct task_struct *next) | ||
3217 | { | 3238 | { |
3218 | unsigned long long timestamp; | 3239 | unsigned long long timestamp; |
3219 | int index; | 3240 | int index; |
@@ -3339,11 +3360,11 @@ void unregister_ftrace_graph(void) | |||
3339 | goto out; | 3360 | goto out; |
3340 | 3361 | ||
3341 | ftrace_graph_active--; | 3362 | ftrace_graph_active--; |
3342 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); | ||
3343 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; | 3363 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
3344 | ftrace_graph_entry = ftrace_graph_entry_stub; | 3364 | ftrace_graph_entry = ftrace_graph_entry_stub; |
3345 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); | 3365 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
3346 | unregister_pm_notifier(&ftrace_suspend_notifier); | 3366 | unregister_pm_notifier(&ftrace_suspend_notifier); |
3367 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); | ||
3347 | 3368 | ||
3348 | out: | 3369 | out: |
3349 | mutex_unlock(&ftrace_lock); | 3370 | mutex_unlock(&ftrace_lock); |
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 41ca394feb22..7f6059c5aa94 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
@@ -319,6 +319,11 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_data); | |||
319 | #define TS_MASK ((1ULL << TS_SHIFT) - 1) | 319 | #define TS_MASK ((1ULL << TS_SHIFT) - 1) |
320 | #define TS_DELTA_TEST (~TS_MASK) | 320 | #define TS_DELTA_TEST (~TS_MASK) |
321 | 321 | ||
322 | /* Flag when events were overwritten */ | ||
323 | #define RB_MISSED_EVENTS (1 << 31) | ||
324 | /* Missed count stored at end */ | ||
325 | #define RB_MISSED_STORED (1 << 30) | ||
326 | |||
322 | struct buffer_data_page { | 327 | struct buffer_data_page { |
323 | u64 time_stamp; /* page time stamp */ | 328 | u64 time_stamp; /* page time stamp */ |
324 | local_t commit; /* write committed index */ | 329 | local_t commit; /* write committed index */ |
@@ -338,6 +343,7 @@ struct buffer_page { | |||
338 | local_t write; /* index for next write */ | 343 | local_t write; /* index for next write */ |
339 | unsigned read; /* index for next read */ | 344 | unsigned read; /* index for next read */ |
340 | local_t entries; /* entries on this page */ | 345 | local_t entries; /* entries on this page */ |
346 | unsigned long real_end; /* real end of data */ | ||
341 | struct buffer_data_page *page; /* Actual data page */ | 347 | struct buffer_data_page *page; /* Actual data page */ |
342 | }; | 348 | }; |
343 | 349 | ||
@@ -417,6 +423,12 @@ int ring_buffer_print_page_header(struct trace_seq *s) | |||
417 | (unsigned int)sizeof(field.commit), | 423 | (unsigned int)sizeof(field.commit), |
418 | (unsigned int)is_signed_type(long)); | 424 | (unsigned int)is_signed_type(long)); |
419 | 425 | ||
426 | ret = trace_seq_printf(s, "\tfield: int overwrite;\t" | ||
427 | "offset:%u;\tsize:%u;\tsigned:%u;\n", | ||
428 | (unsigned int)offsetof(typeof(field), commit), | ||
429 | 1, | ||
430 | (unsigned int)is_signed_type(long)); | ||
431 | |||
420 | ret = trace_seq_printf(s, "\tfield: char data;\t" | 432 | ret = trace_seq_printf(s, "\tfield: char data;\t" |
421 | "offset:%u;\tsize:%u;\tsigned:%u;\n", | 433 | "offset:%u;\tsize:%u;\tsigned:%u;\n", |
422 | (unsigned int)offsetof(typeof(field), data), | 434 | (unsigned int)offsetof(typeof(field), data), |
@@ -440,6 +452,8 @@ struct ring_buffer_per_cpu { | |||
440 | struct buffer_page *tail_page; /* write to tail */ | 452 | struct buffer_page *tail_page; /* write to tail */ |
441 | struct buffer_page *commit_page; /* committed pages */ | 453 | struct buffer_page *commit_page; /* committed pages */ |
442 | struct buffer_page *reader_page; | 454 | struct buffer_page *reader_page; |
455 | unsigned long lost_events; | ||
456 | unsigned long last_overrun; | ||
443 | local_t commit_overrun; | 457 | local_t commit_overrun; |
444 | local_t overrun; | 458 | local_t overrun; |
445 | local_t entries; | 459 | local_t entries; |
@@ -1762,6 +1776,13 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer, | |||
1762 | kmemcheck_annotate_bitfield(event, bitfield); | 1776 | kmemcheck_annotate_bitfield(event, bitfield); |
1763 | 1777 | ||
1764 | /* | 1778 | /* |
1779 | * Save the original length to the meta data. | ||
1780 | * This will be used by the reader to add lost event | ||
1781 | * counter. | ||
1782 | */ | ||
1783 | tail_page->real_end = tail; | ||
1784 | |||
1785 | /* | ||
1765 | * If this event is bigger than the minimum size, then | 1786 | * If this event is bigger than the minimum size, then |
1766 | * we need to be careful that we don't subtract the | 1787 | * we need to be careful that we don't subtract the |
1767 | * write counter enough to allow another writer to slip | 1788 | * write counter enough to allow another writer to slip |
@@ -1979,17 +2000,13 @@ rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer, | |||
1979 | u64 *ts, u64 *delta) | 2000 | u64 *ts, u64 *delta) |
1980 | { | 2001 | { |
1981 | struct ring_buffer_event *event; | 2002 | struct ring_buffer_event *event; |
1982 | static int once; | ||
1983 | int ret; | 2003 | int ret; |
1984 | 2004 | ||
1985 | if (unlikely(*delta > (1ULL << 59) && !once++)) { | 2005 | WARN_ONCE(*delta > (1ULL << 59), |
1986 | printk(KERN_WARNING "Delta way too big! %llu" | 2006 | KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n", |
1987 | " ts=%llu write stamp = %llu\n", | 2007 | (unsigned long long)*delta, |
1988 | (unsigned long long)*delta, | 2008 | (unsigned long long)*ts, |
1989 | (unsigned long long)*ts, | 2009 | (unsigned long long)cpu_buffer->write_stamp); |
1990 | (unsigned long long)cpu_buffer->write_stamp); | ||
1991 | WARN_ON(1); | ||
1992 | } | ||
1993 | 2010 | ||
1994 | /* | 2011 | /* |
1995 | * The delta is too big, we to add a | 2012 | * The delta is too big, we to add a |
@@ -2838,6 +2855,7 @@ static struct buffer_page * | |||
2838 | rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | 2855 | rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) |
2839 | { | 2856 | { |
2840 | struct buffer_page *reader = NULL; | 2857 | struct buffer_page *reader = NULL; |
2858 | unsigned long overwrite; | ||
2841 | unsigned long flags; | 2859 | unsigned long flags; |
2842 | int nr_loops = 0; | 2860 | int nr_loops = 0; |
2843 | int ret; | 2861 | int ret; |
@@ -2879,6 +2897,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | |||
2879 | local_set(&cpu_buffer->reader_page->write, 0); | 2897 | local_set(&cpu_buffer->reader_page->write, 0); |
2880 | local_set(&cpu_buffer->reader_page->entries, 0); | 2898 | local_set(&cpu_buffer->reader_page->entries, 0); |
2881 | local_set(&cpu_buffer->reader_page->page->commit, 0); | 2899 | local_set(&cpu_buffer->reader_page->page->commit, 0); |
2900 | cpu_buffer->reader_page->real_end = 0; | ||
2882 | 2901 | ||
2883 | spin: | 2902 | spin: |
2884 | /* | 2903 | /* |
@@ -2899,6 +2918,18 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | |||
2899 | rb_set_list_to_head(cpu_buffer, &cpu_buffer->reader_page->list); | 2918 | rb_set_list_to_head(cpu_buffer, &cpu_buffer->reader_page->list); |
2900 | 2919 | ||
2901 | /* | 2920 | /* |
2921 | * We want to make sure we read the overruns after we set up our | ||
2922 | * pointers to the next object. The writer side does a | ||
2923 | * cmpxchg to cross pages which acts as the mb on the writer | ||
2924 | * side. Note, the reader will constantly fail the swap | ||
2925 | * while the writer is updating the pointers, so this | ||
2926 | * guarantees that the overwrite recorded here is the one we | ||
2927 | * want to compare with the last_overrun. | ||
2928 | */ | ||
2929 | smp_mb(); | ||
2930 | overwrite = local_read(&(cpu_buffer->overrun)); | ||
2931 | |||
2932 | /* | ||
2902 | * Here's the tricky part. | 2933 | * Here's the tricky part. |
2903 | * | 2934 | * |
2904 | * We need to move the pointer past the header page. | 2935 | * We need to move the pointer past the header page. |
@@ -2929,6 +2960,11 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer) | |||
2929 | cpu_buffer->reader_page = reader; | 2960 | cpu_buffer->reader_page = reader; |
2930 | rb_reset_reader_page(cpu_buffer); | 2961 | rb_reset_reader_page(cpu_buffer); |
2931 | 2962 | ||
2963 | if (overwrite != cpu_buffer->last_overrun) { | ||
2964 | cpu_buffer->lost_events = overwrite - cpu_buffer->last_overrun; | ||
2965 | cpu_buffer->last_overrun = overwrite; | ||
2966 | } | ||
2967 | |||
2932 | goto again; | 2968 | goto again; |
2933 | 2969 | ||
2934 | out: | 2970 | out: |
@@ -3005,8 +3041,14 @@ static void rb_advance_iter(struct ring_buffer_iter *iter) | |||
3005 | rb_advance_iter(iter); | 3041 | rb_advance_iter(iter); |
3006 | } | 3042 | } |
3007 | 3043 | ||
3044 | static int rb_lost_events(struct ring_buffer_per_cpu *cpu_buffer) | ||
3045 | { | ||
3046 | return cpu_buffer->lost_events; | ||
3047 | } | ||
3048 | |||
3008 | static struct ring_buffer_event * | 3049 | static struct ring_buffer_event * |
3009 | rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts) | 3050 | rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts, |
3051 | unsigned long *lost_events) | ||
3010 | { | 3052 | { |
3011 | struct ring_buffer_event *event; | 3053 | struct ring_buffer_event *event; |
3012 | struct buffer_page *reader; | 3054 | struct buffer_page *reader; |
@@ -3058,6 +3100,8 @@ rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts) | |||
3058 | ring_buffer_normalize_time_stamp(cpu_buffer->buffer, | 3100 | ring_buffer_normalize_time_stamp(cpu_buffer->buffer, |
3059 | cpu_buffer->cpu, ts); | 3101 | cpu_buffer->cpu, ts); |
3060 | } | 3102 | } |
3103 | if (lost_events) | ||
3104 | *lost_events = rb_lost_events(cpu_buffer); | ||
3061 | return event; | 3105 | return event; |
3062 | 3106 | ||
3063 | default: | 3107 | default: |
@@ -3168,12 +3212,14 @@ static inline int rb_ok_to_lock(void) | |||
3168 | * @buffer: The ring buffer to read | 3212 | * @buffer: The ring buffer to read |
3169 | * @cpu: The cpu to peak at | 3213 | * @cpu: The cpu to peak at |
3170 | * @ts: The timestamp counter of this event. | 3214 | * @ts: The timestamp counter of this event. |
3215 | * @lost_events: a variable to store if events were lost (may be NULL) | ||
3171 | * | 3216 | * |
3172 | * This will return the event that will be read next, but does | 3217 | * This will return the event that will be read next, but does |
3173 | * not consume the data. | 3218 | * not consume the data. |
3174 | */ | 3219 | */ |
3175 | struct ring_buffer_event * | 3220 | struct ring_buffer_event * |
3176 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | 3221 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts, |
3222 | unsigned long *lost_events) | ||
3177 | { | 3223 | { |
3178 | struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; | 3224 | struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; |
3179 | struct ring_buffer_event *event; | 3225 | struct ring_buffer_event *event; |
@@ -3188,7 +3234,7 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
3188 | local_irq_save(flags); | 3234 | local_irq_save(flags); |
3189 | if (dolock) | 3235 | if (dolock) |
3190 | spin_lock(&cpu_buffer->reader_lock); | 3236 | spin_lock(&cpu_buffer->reader_lock); |
3191 | event = rb_buffer_peek(cpu_buffer, ts); | 3237 | event = rb_buffer_peek(cpu_buffer, ts, lost_events); |
3192 | if (event && event->type_len == RINGBUF_TYPE_PADDING) | 3238 | if (event && event->type_len == RINGBUF_TYPE_PADDING) |
3193 | rb_advance_reader(cpu_buffer); | 3239 | rb_advance_reader(cpu_buffer); |
3194 | if (dolock) | 3240 | if (dolock) |
@@ -3230,13 +3276,17 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts) | |||
3230 | /** | 3276 | /** |
3231 | * ring_buffer_consume - return an event and consume it | 3277 | * ring_buffer_consume - return an event and consume it |
3232 | * @buffer: The ring buffer to get the next event from | 3278 | * @buffer: The ring buffer to get the next event from |
3279 | * @cpu: the cpu to read the buffer from | ||
3280 | * @ts: a variable to store the timestamp (may be NULL) | ||
3281 | * @lost_events: a variable to store if events were lost (may be NULL) | ||
3233 | * | 3282 | * |
3234 | * Returns the next event in the ring buffer, and that event is consumed. | 3283 | * Returns the next event in the ring buffer, and that event is consumed. |
3235 | * Meaning, that sequential reads will keep returning a different event, | 3284 | * Meaning, that sequential reads will keep returning a different event, |
3236 | * and eventually empty the ring buffer if the producer is slower. | 3285 | * and eventually empty the ring buffer if the producer is slower. |
3237 | */ | 3286 | */ |
3238 | struct ring_buffer_event * | 3287 | struct ring_buffer_event * |
3239 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | 3288 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts, |
3289 | unsigned long *lost_events) | ||
3240 | { | 3290 | { |
3241 | struct ring_buffer_per_cpu *cpu_buffer; | 3291 | struct ring_buffer_per_cpu *cpu_buffer; |
3242 | struct ring_buffer_event *event = NULL; | 3292 | struct ring_buffer_event *event = NULL; |
@@ -3257,9 +3307,11 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
3257 | if (dolock) | 3307 | if (dolock) |
3258 | spin_lock(&cpu_buffer->reader_lock); | 3308 | spin_lock(&cpu_buffer->reader_lock); |
3259 | 3309 | ||
3260 | event = rb_buffer_peek(cpu_buffer, ts); | 3310 | event = rb_buffer_peek(cpu_buffer, ts, lost_events); |
3261 | if (event) | 3311 | if (event) { |
3312 | cpu_buffer->lost_events = 0; | ||
3262 | rb_advance_reader(cpu_buffer); | 3313 | rb_advance_reader(cpu_buffer); |
3314 | } | ||
3263 | 3315 | ||
3264 | if (dolock) | 3316 | if (dolock) |
3265 | spin_unlock(&cpu_buffer->reader_lock); | 3317 | spin_unlock(&cpu_buffer->reader_lock); |
@@ -3276,23 +3328,30 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts) | |||
3276 | EXPORT_SYMBOL_GPL(ring_buffer_consume); | 3328 | EXPORT_SYMBOL_GPL(ring_buffer_consume); |
3277 | 3329 | ||
3278 | /** | 3330 | /** |
3279 | * ring_buffer_read_start - start a non consuming read of the buffer | 3331 | * ring_buffer_read_prepare - Prepare for a non consuming read of the buffer |
3280 | * @buffer: The ring buffer to read from | 3332 | * @buffer: The ring buffer to read from |
3281 | * @cpu: The cpu buffer to iterate over | 3333 | * @cpu: The cpu buffer to iterate over |
3282 | * | 3334 | * |
3283 | * This starts up an iteration through the buffer. It also disables | 3335 | * This performs the initial preparations necessary to iterate |
3284 | * the recording to the buffer until the reading is finished. | 3336 | * through the buffer. Memory is allocated, buffer recording |
3285 | * This prevents the reading from being corrupted. This is not | 3337 | * is disabled, and the iterator pointer is returned to the caller. |
3286 | * a consuming read, so a producer is not expected. | ||
3287 | * | 3338 | * |
3288 | * Must be paired with ring_buffer_finish. | 3339 | * Disabling buffer recordng prevents the reading from being |
3340 | * corrupted. This is not a consuming read, so a producer is not | ||
3341 | * expected. | ||
3342 | * | ||
3343 | * After a sequence of ring_buffer_read_prepare calls, the user is | ||
3344 | * expected to make at least one call to ring_buffer_prepare_sync. | ||
3345 | * Afterwards, ring_buffer_read_start is invoked to get things going | ||
3346 | * for real. | ||
3347 | * | ||
3348 | * This overall must be paired with ring_buffer_finish. | ||
3289 | */ | 3349 | */ |
3290 | struct ring_buffer_iter * | 3350 | struct ring_buffer_iter * |
3291 | ring_buffer_read_start(struct ring_buffer *buffer, int cpu) | 3351 | ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu) |
3292 | { | 3352 | { |
3293 | struct ring_buffer_per_cpu *cpu_buffer; | 3353 | struct ring_buffer_per_cpu *cpu_buffer; |
3294 | struct ring_buffer_iter *iter; | 3354 | struct ring_buffer_iter *iter; |
3295 | unsigned long flags; | ||
3296 | 3355 | ||
3297 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | 3356 | if (!cpumask_test_cpu(cpu, buffer->cpumask)) |
3298 | return NULL; | 3357 | return NULL; |
@@ -3306,15 +3365,52 @@ ring_buffer_read_start(struct ring_buffer *buffer, int cpu) | |||
3306 | iter->cpu_buffer = cpu_buffer; | 3365 | iter->cpu_buffer = cpu_buffer; |
3307 | 3366 | ||
3308 | atomic_inc(&cpu_buffer->record_disabled); | 3367 | atomic_inc(&cpu_buffer->record_disabled); |
3368 | |||
3369 | return iter; | ||
3370 | } | ||
3371 | EXPORT_SYMBOL_GPL(ring_buffer_read_prepare); | ||
3372 | |||
3373 | /** | ||
3374 | * ring_buffer_read_prepare_sync - Synchronize a set of prepare calls | ||
3375 | * | ||
3376 | * All previously invoked ring_buffer_read_prepare calls to prepare | ||
3377 | * iterators will be synchronized. Afterwards, read_buffer_read_start | ||
3378 | * calls on those iterators are allowed. | ||
3379 | */ | ||
3380 | void | ||
3381 | ring_buffer_read_prepare_sync(void) | ||
3382 | { | ||
3309 | synchronize_sched(); | 3383 | synchronize_sched(); |
3384 | } | ||
3385 | EXPORT_SYMBOL_GPL(ring_buffer_read_prepare_sync); | ||
3386 | |||
3387 | /** | ||
3388 | * ring_buffer_read_start - start a non consuming read of the buffer | ||
3389 | * @iter: The iterator returned by ring_buffer_read_prepare | ||
3390 | * | ||
3391 | * This finalizes the startup of an iteration through the buffer. | ||
3392 | * The iterator comes from a call to ring_buffer_read_prepare and | ||
3393 | * an intervening ring_buffer_read_prepare_sync must have been | ||
3394 | * performed. | ||
3395 | * | ||
3396 | * Must be paired with ring_buffer_finish. | ||
3397 | */ | ||
3398 | void | ||
3399 | ring_buffer_read_start(struct ring_buffer_iter *iter) | ||
3400 | { | ||
3401 | struct ring_buffer_per_cpu *cpu_buffer; | ||
3402 | unsigned long flags; | ||
3403 | |||
3404 | if (!iter) | ||
3405 | return; | ||
3406 | |||
3407 | cpu_buffer = iter->cpu_buffer; | ||
3310 | 3408 | ||
3311 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); | 3409 | spin_lock_irqsave(&cpu_buffer->reader_lock, flags); |
3312 | arch_spin_lock(&cpu_buffer->lock); | 3410 | arch_spin_lock(&cpu_buffer->lock); |
3313 | rb_iter_reset(iter); | 3411 | rb_iter_reset(iter); |
3314 | arch_spin_unlock(&cpu_buffer->lock); | 3412 | arch_spin_unlock(&cpu_buffer->lock); |
3315 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 3413 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
3316 | |||
3317 | return iter; | ||
3318 | } | 3414 | } |
3319 | EXPORT_SYMBOL_GPL(ring_buffer_read_start); | 3415 | EXPORT_SYMBOL_GPL(ring_buffer_read_start); |
3320 | 3416 | ||
@@ -3408,6 +3504,9 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer) | |||
3408 | cpu_buffer->write_stamp = 0; | 3504 | cpu_buffer->write_stamp = 0; |
3409 | cpu_buffer->read_stamp = 0; | 3505 | cpu_buffer->read_stamp = 0; |
3410 | 3506 | ||
3507 | cpu_buffer->lost_events = 0; | ||
3508 | cpu_buffer->last_overrun = 0; | ||
3509 | |||
3411 | rb_head_page_activate(cpu_buffer); | 3510 | rb_head_page_activate(cpu_buffer); |
3412 | } | 3511 | } |
3413 | 3512 | ||
@@ -3683,6 +3782,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer, | |||
3683 | struct ring_buffer_event *event; | 3782 | struct ring_buffer_event *event; |
3684 | struct buffer_data_page *bpage; | 3783 | struct buffer_data_page *bpage; |
3685 | struct buffer_page *reader; | 3784 | struct buffer_page *reader; |
3785 | unsigned long missed_events; | ||
3686 | unsigned long flags; | 3786 | unsigned long flags; |
3687 | unsigned int commit; | 3787 | unsigned int commit; |
3688 | unsigned int read; | 3788 | unsigned int read; |
@@ -3719,6 +3819,9 @@ int ring_buffer_read_page(struct ring_buffer *buffer, | |||
3719 | read = reader->read; | 3819 | read = reader->read; |
3720 | commit = rb_page_commit(reader); | 3820 | commit = rb_page_commit(reader); |
3721 | 3821 | ||
3822 | /* Check if any events were dropped */ | ||
3823 | missed_events = cpu_buffer->lost_events; | ||
3824 | |||
3722 | /* | 3825 | /* |
3723 | * If this page has been partially read or | 3826 | * If this page has been partially read or |
3724 | * if len is not big enough to read the rest of the page or | 3827 | * if len is not big enough to read the rest of the page or |
@@ -3779,9 +3882,35 @@ int ring_buffer_read_page(struct ring_buffer *buffer, | |||
3779 | local_set(&reader->entries, 0); | 3882 | local_set(&reader->entries, 0); |
3780 | reader->read = 0; | 3883 | reader->read = 0; |
3781 | *data_page = bpage; | 3884 | *data_page = bpage; |
3885 | |||
3886 | /* | ||
3887 | * Use the real_end for the data size, | ||
3888 | * This gives us a chance to store the lost events | ||
3889 | * on the page. | ||
3890 | */ | ||
3891 | if (reader->real_end) | ||
3892 | local_set(&bpage->commit, reader->real_end); | ||
3782 | } | 3893 | } |
3783 | ret = read; | 3894 | ret = read; |
3784 | 3895 | ||
3896 | cpu_buffer->lost_events = 0; | ||
3897 | /* | ||
3898 | * Set a flag in the commit field if we lost events | ||
3899 | */ | ||
3900 | if (missed_events) { | ||
3901 | commit = local_read(&bpage->commit); | ||
3902 | |||
3903 | /* If there is room at the end of the page to save the | ||
3904 | * missed events, then record it there. | ||
3905 | */ | ||
3906 | if (BUF_PAGE_SIZE - commit >= sizeof(missed_events)) { | ||
3907 | memcpy(&bpage->data[commit], &missed_events, | ||
3908 | sizeof(missed_events)); | ||
3909 | local_add(RB_MISSED_STORED, &bpage->commit); | ||
3910 | } | ||
3911 | local_add(RB_MISSED_EVENTS, &bpage->commit); | ||
3912 | } | ||
3913 | |||
3785 | out_unlock: | 3914 | out_unlock: |
3786 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); | 3915 | spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); |
3787 | 3916 | ||
diff --git a/kernel/trace/ring_buffer_benchmark.c b/kernel/trace/ring_buffer_benchmark.c index df74c7982255..302f8a614635 100644 --- a/kernel/trace/ring_buffer_benchmark.c +++ b/kernel/trace/ring_buffer_benchmark.c | |||
@@ -81,7 +81,7 @@ static enum event_status read_event(int cpu) | |||
81 | int *entry; | 81 | int *entry; |
82 | u64 ts; | 82 | u64 ts; |
83 | 83 | ||
84 | event = ring_buffer_consume(buffer, cpu, &ts); | 84 | event = ring_buffer_consume(buffer, cpu, &ts, NULL); |
85 | if (!event) | 85 | if (!event) |
86 | return EVENT_DROPPED; | 86 | return EVENT_DROPPED; |
87 | 87 | ||
@@ -113,7 +113,8 @@ static enum event_status read_page(int cpu) | |||
113 | ret = ring_buffer_read_page(buffer, &bpage, PAGE_SIZE, cpu, 1); | 113 | ret = ring_buffer_read_page(buffer, &bpage, PAGE_SIZE, cpu, 1); |
114 | if (ret >= 0) { | 114 | if (ret >= 0) { |
115 | rpage = bpage; | 115 | rpage = bpage; |
116 | commit = local_read(&rpage->commit); | 116 | /* The commit may have missed event flags set, clear them */ |
117 | commit = local_read(&rpage->commit) & 0xfffff; | ||
117 | for (i = 0; i < commit && !kill_test; i += inc) { | 118 | for (i = 0; i < commit && !kill_test; i += inc) { |
118 | 119 | ||
119 | if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) { | 120 | if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) { |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 44f916a04065..756d7283318b 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -117,9 +117,12 @@ static cpumask_var_t __read_mostly tracing_buffer_mask; | |||
117 | * | 117 | * |
118 | * It is default off, but you can enable it with either specifying | 118 | * It is default off, but you can enable it with either specifying |
119 | * "ftrace_dump_on_oops" in the kernel command line, or setting | 119 | * "ftrace_dump_on_oops" in the kernel command line, or setting |
120 | * /proc/sys/kernel/ftrace_dump_on_oops to true. | 120 | * /proc/sys/kernel/ftrace_dump_on_oops |
121 | * Set 1 if you want to dump buffers of all CPUs | ||
122 | * Set 2 if you want to dump the buffer of the CPU that triggered oops | ||
121 | */ | 123 | */ |
122 | int ftrace_dump_on_oops; | 124 | |
125 | enum ftrace_dump_mode ftrace_dump_on_oops; | ||
123 | 126 | ||
124 | static int tracing_set_tracer(const char *buf); | 127 | static int tracing_set_tracer(const char *buf); |
125 | 128 | ||
@@ -139,8 +142,17 @@ __setup("ftrace=", set_cmdline_ftrace); | |||
139 | 142 | ||
140 | static int __init set_ftrace_dump_on_oops(char *str) | 143 | static int __init set_ftrace_dump_on_oops(char *str) |
141 | { | 144 | { |
142 | ftrace_dump_on_oops = 1; | 145 | if (*str++ != '=' || !*str) { |
143 | return 1; | 146 | ftrace_dump_on_oops = DUMP_ALL; |
147 | return 1; | ||
148 | } | ||
149 | |||
150 | if (!strcmp("orig_cpu", str)) { | ||
151 | ftrace_dump_on_oops = DUMP_ORIG; | ||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | return 0; | ||
144 | } | 156 | } |
145 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); | 157 | __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); |
146 | 158 | ||
@@ -1545,7 +1557,8 @@ static void trace_iterator_increment(struct trace_iterator *iter) | |||
1545 | } | 1557 | } |
1546 | 1558 | ||
1547 | static struct trace_entry * | 1559 | static struct trace_entry * |
1548 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | 1560 | peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts, |
1561 | unsigned long *lost_events) | ||
1549 | { | 1562 | { |
1550 | struct ring_buffer_event *event; | 1563 | struct ring_buffer_event *event; |
1551 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; | 1564 | struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu]; |
@@ -1556,7 +1569,8 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | |||
1556 | if (buf_iter) | 1569 | if (buf_iter) |
1557 | event = ring_buffer_iter_peek(buf_iter, ts); | 1570 | event = ring_buffer_iter_peek(buf_iter, ts); |
1558 | else | 1571 | else |
1559 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts); | 1572 | event = ring_buffer_peek(iter->tr->buffer, cpu, ts, |
1573 | lost_events); | ||
1560 | 1574 | ||
1561 | ftrace_enable_cpu(); | 1575 | ftrace_enable_cpu(); |
1562 | 1576 | ||
@@ -1564,10 +1578,12 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts) | |||
1564 | } | 1578 | } |
1565 | 1579 | ||
1566 | static struct trace_entry * | 1580 | static struct trace_entry * |
1567 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | 1581 | __find_next_entry(struct trace_iterator *iter, int *ent_cpu, |
1582 | unsigned long *missing_events, u64 *ent_ts) | ||
1568 | { | 1583 | { |
1569 | struct ring_buffer *buffer = iter->tr->buffer; | 1584 | struct ring_buffer *buffer = iter->tr->buffer; |
1570 | struct trace_entry *ent, *next = NULL; | 1585 | struct trace_entry *ent, *next = NULL; |
1586 | unsigned long lost_events = 0, next_lost = 0; | ||
1571 | int cpu_file = iter->cpu_file; | 1587 | int cpu_file = iter->cpu_file; |
1572 | u64 next_ts = 0, ts; | 1588 | u64 next_ts = 0, ts; |
1573 | int next_cpu = -1; | 1589 | int next_cpu = -1; |
@@ -1580,7 +1596,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1580 | if (cpu_file > TRACE_PIPE_ALL_CPU) { | 1596 | if (cpu_file > TRACE_PIPE_ALL_CPU) { |
1581 | if (ring_buffer_empty_cpu(buffer, cpu_file)) | 1597 | if (ring_buffer_empty_cpu(buffer, cpu_file)) |
1582 | return NULL; | 1598 | return NULL; |
1583 | ent = peek_next_entry(iter, cpu_file, ent_ts); | 1599 | ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events); |
1584 | if (ent_cpu) | 1600 | if (ent_cpu) |
1585 | *ent_cpu = cpu_file; | 1601 | *ent_cpu = cpu_file; |
1586 | 1602 | ||
@@ -1592,7 +1608,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1592 | if (ring_buffer_empty_cpu(buffer, cpu)) | 1608 | if (ring_buffer_empty_cpu(buffer, cpu)) |
1593 | continue; | 1609 | continue; |
1594 | 1610 | ||
1595 | ent = peek_next_entry(iter, cpu, &ts); | 1611 | ent = peek_next_entry(iter, cpu, &ts, &lost_events); |
1596 | 1612 | ||
1597 | /* | 1613 | /* |
1598 | * Pick the entry with the smallest timestamp: | 1614 | * Pick the entry with the smallest timestamp: |
@@ -1601,6 +1617,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1601 | next = ent; | 1617 | next = ent; |
1602 | next_cpu = cpu; | 1618 | next_cpu = cpu; |
1603 | next_ts = ts; | 1619 | next_ts = ts; |
1620 | next_lost = lost_events; | ||
1604 | } | 1621 | } |
1605 | } | 1622 | } |
1606 | 1623 | ||
@@ -1610,6 +1627,9 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1610 | if (ent_ts) | 1627 | if (ent_ts) |
1611 | *ent_ts = next_ts; | 1628 | *ent_ts = next_ts; |
1612 | 1629 | ||
1630 | if (missing_events) | ||
1631 | *missing_events = next_lost; | ||
1632 | |||
1613 | return next; | 1633 | return next; |
1614 | } | 1634 | } |
1615 | 1635 | ||
@@ -1617,13 +1637,14 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts) | |||
1617 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | 1637 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
1618 | int *ent_cpu, u64 *ent_ts) | 1638 | int *ent_cpu, u64 *ent_ts) |
1619 | { | 1639 | { |
1620 | return __find_next_entry(iter, ent_cpu, ent_ts); | 1640 | return __find_next_entry(iter, ent_cpu, NULL, ent_ts); |
1621 | } | 1641 | } |
1622 | 1642 | ||
1623 | /* Find the next real entry, and increment the iterator to the next entry */ | 1643 | /* Find the next real entry, and increment the iterator to the next entry */ |
1624 | static void *find_next_entry_inc(struct trace_iterator *iter) | 1644 | static void *find_next_entry_inc(struct trace_iterator *iter) |
1625 | { | 1645 | { |
1626 | iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts); | 1646 | iter->ent = __find_next_entry(iter, &iter->cpu, |
1647 | &iter->lost_events, &iter->ts); | ||
1627 | 1648 | ||
1628 | if (iter->ent) | 1649 | if (iter->ent) |
1629 | trace_iterator_increment(iter); | 1650 | trace_iterator_increment(iter); |
@@ -1635,7 +1656,8 @@ static void trace_consume(struct trace_iterator *iter) | |||
1635 | { | 1656 | { |
1636 | /* Don't allow ftrace to trace into the ring buffers */ | 1657 | /* Don't allow ftrace to trace into the ring buffers */ |
1637 | ftrace_disable_cpu(); | 1658 | ftrace_disable_cpu(); |
1638 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts); | 1659 | ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts, |
1660 | &iter->lost_events); | ||
1639 | ftrace_enable_cpu(); | 1661 | ftrace_enable_cpu(); |
1640 | } | 1662 | } |
1641 | 1663 | ||
@@ -1786,7 +1808,7 @@ static void print_func_help_header(struct seq_file *m) | |||
1786 | } | 1808 | } |
1787 | 1809 | ||
1788 | 1810 | ||
1789 | static void | 1811 | void |
1790 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) | 1812 | print_trace_header(struct seq_file *m, struct trace_iterator *iter) |
1791 | { | 1813 | { |
1792 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 1814 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
@@ -1995,7 +2017,7 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter) | |||
1995 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; | 2017 | return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED; |
1996 | } | 2018 | } |
1997 | 2019 | ||
1998 | static int trace_empty(struct trace_iterator *iter) | 2020 | int trace_empty(struct trace_iterator *iter) |
1999 | { | 2021 | { |
2000 | int cpu; | 2022 | int cpu; |
2001 | 2023 | ||
@@ -2030,6 +2052,10 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
2030 | { | 2052 | { |
2031 | enum print_line_t ret; | 2053 | enum print_line_t ret; |
2032 | 2054 | ||
2055 | if (iter->lost_events) | ||
2056 | trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", | ||
2057 | iter->cpu, iter->lost_events); | ||
2058 | |||
2033 | if (iter->trace && iter->trace->print_line) { | 2059 | if (iter->trace && iter->trace->print_line) { |
2034 | ret = iter->trace->print_line(iter); | 2060 | ret = iter->trace->print_line(iter); |
2035 | if (ret != TRACE_TYPE_UNHANDLED) | 2061 | if (ret != TRACE_TYPE_UNHANDLED) |
@@ -2058,6 +2084,23 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter) | |||
2058 | return print_trace_fmt(iter); | 2084 | return print_trace_fmt(iter); |
2059 | } | 2085 | } |
2060 | 2086 | ||
2087 | void trace_default_header(struct seq_file *m) | ||
2088 | { | ||
2089 | struct trace_iterator *iter = m->private; | ||
2090 | |||
2091 | if (iter->iter_flags & TRACE_FILE_LAT_FMT) { | ||
2092 | /* print nothing if the buffers are empty */ | ||
2093 | if (trace_empty(iter)) | ||
2094 | return; | ||
2095 | print_trace_header(m, iter); | ||
2096 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2097 | print_lat_help_header(m); | ||
2098 | } else { | ||
2099 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2100 | print_func_help_header(m); | ||
2101 | } | ||
2102 | } | ||
2103 | |||
2061 | static int s_show(struct seq_file *m, void *v) | 2104 | static int s_show(struct seq_file *m, void *v) |
2062 | { | 2105 | { |
2063 | struct trace_iterator *iter = v; | 2106 | struct trace_iterator *iter = v; |
@@ -2070,17 +2113,9 @@ static int s_show(struct seq_file *m, void *v) | |||
2070 | } | 2113 | } |
2071 | if (iter->trace && iter->trace->print_header) | 2114 | if (iter->trace && iter->trace->print_header) |
2072 | iter->trace->print_header(m); | 2115 | iter->trace->print_header(m); |
2073 | else if (iter->iter_flags & TRACE_FILE_LAT_FMT) { | 2116 | else |
2074 | /* print nothing if the buffers are empty */ | 2117 | trace_default_header(m); |
2075 | if (trace_empty(iter)) | 2118 | |
2076 | return 0; | ||
2077 | print_trace_header(m, iter); | ||
2078 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2079 | print_lat_help_header(m); | ||
2080 | } else { | ||
2081 | if (!(trace_flags & TRACE_ITER_VERBOSE)) | ||
2082 | print_func_help_header(m); | ||
2083 | } | ||
2084 | } else if (iter->leftover) { | 2119 | } else if (iter->leftover) { |
2085 | /* | 2120 | /* |
2086 | * If we filled the seq_file buffer earlier, we | 2121 | * If we filled the seq_file buffer earlier, we |
@@ -2166,15 +2201,20 @@ __tracing_open(struct inode *inode, struct file *file) | |||
2166 | 2201 | ||
2167 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { | 2202 | if (iter->cpu_file == TRACE_PIPE_ALL_CPU) { |
2168 | for_each_tracing_cpu(cpu) { | 2203 | for_each_tracing_cpu(cpu) { |
2169 | |||
2170 | iter->buffer_iter[cpu] = | 2204 | iter->buffer_iter[cpu] = |
2171 | ring_buffer_read_start(iter->tr->buffer, cpu); | 2205 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2206 | } | ||
2207 | ring_buffer_read_prepare_sync(); | ||
2208 | for_each_tracing_cpu(cpu) { | ||
2209 | ring_buffer_read_start(iter->buffer_iter[cpu]); | ||
2172 | tracing_iter_reset(iter, cpu); | 2210 | tracing_iter_reset(iter, cpu); |
2173 | } | 2211 | } |
2174 | } else { | 2212 | } else { |
2175 | cpu = iter->cpu_file; | 2213 | cpu = iter->cpu_file; |
2176 | iter->buffer_iter[cpu] = | 2214 | iter->buffer_iter[cpu] = |
2177 | ring_buffer_read_start(iter->tr->buffer, cpu); | 2215 | ring_buffer_read_prepare(iter->tr->buffer, cpu); |
2216 | ring_buffer_read_prepare_sync(); | ||
2217 | ring_buffer_read_start(iter->buffer_iter[cpu]); | ||
2178 | tracing_iter_reset(iter, cpu); | 2218 | tracing_iter_reset(iter, cpu); |
2179 | } | 2219 | } |
2180 | 2220 | ||
@@ -4324,7 +4364,7 @@ static int trace_panic_handler(struct notifier_block *this, | |||
4324 | unsigned long event, void *unused) | 4364 | unsigned long event, void *unused) |
4325 | { | 4365 | { |
4326 | if (ftrace_dump_on_oops) | 4366 | if (ftrace_dump_on_oops) |
4327 | ftrace_dump(); | 4367 | ftrace_dump(ftrace_dump_on_oops); |
4328 | return NOTIFY_OK; | 4368 | return NOTIFY_OK; |
4329 | } | 4369 | } |
4330 | 4370 | ||
@@ -4341,7 +4381,7 @@ static int trace_die_handler(struct notifier_block *self, | |||
4341 | switch (val) { | 4381 | switch (val) { |
4342 | case DIE_OOPS: | 4382 | case DIE_OOPS: |
4343 | if (ftrace_dump_on_oops) | 4383 | if (ftrace_dump_on_oops) |
4344 | ftrace_dump(); | 4384 | ftrace_dump(ftrace_dump_on_oops); |
4345 | break; | 4385 | break; |
4346 | default: | 4386 | default: |
4347 | break; | 4387 | break; |
@@ -4382,7 +4422,8 @@ trace_printk_seq(struct trace_seq *s) | |||
4382 | trace_seq_init(s); | 4422 | trace_seq_init(s); |
4383 | } | 4423 | } |
4384 | 4424 | ||
4385 | static void __ftrace_dump(bool disable_tracing) | 4425 | static void |
4426 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | ||
4386 | { | 4427 | { |
4387 | static arch_spinlock_t ftrace_dump_lock = | 4428 | static arch_spinlock_t ftrace_dump_lock = |
4388 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; | 4429 | (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; |
@@ -4415,12 +4456,25 @@ static void __ftrace_dump(bool disable_tracing) | |||
4415 | /* don't look at user memory in panic mode */ | 4456 | /* don't look at user memory in panic mode */ |
4416 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | 4457 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; |
4417 | 4458 | ||
4418 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); | ||
4419 | |||
4420 | /* Simulate the iterator */ | 4459 | /* Simulate the iterator */ |
4421 | iter.tr = &global_trace; | 4460 | iter.tr = &global_trace; |
4422 | iter.trace = current_trace; | 4461 | iter.trace = current_trace; |
4423 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | 4462 | |
4463 | switch (oops_dump_mode) { | ||
4464 | case DUMP_ALL: | ||
4465 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | ||
4466 | break; | ||
4467 | case DUMP_ORIG: | ||
4468 | iter.cpu_file = raw_smp_processor_id(); | ||
4469 | break; | ||
4470 | case DUMP_NONE: | ||
4471 | goto out_enable; | ||
4472 | default: | ||
4473 | printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n"); | ||
4474 | iter.cpu_file = TRACE_PIPE_ALL_CPU; | ||
4475 | } | ||
4476 | |||
4477 | printk(KERN_TRACE "Dumping ftrace buffer:\n"); | ||
4424 | 4478 | ||
4425 | /* | 4479 | /* |
4426 | * We need to stop all tracing on all CPUS to read the | 4480 | * We need to stop all tracing on all CPUS to read the |
@@ -4459,6 +4513,7 @@ static void __ftrace_dump(bool disable_tracing) | |||
4459 | else | 4513 | else |
4460 | printk(KERN_TRACE "---------------------------------\n"); | 4514 | printk(KERN_TRACE "---------------------------------\n"); |
4461 | 4515 | ||
4516 | out_enable: | ||
4462 | /* Re-enable tracing if requested */ | 4517 | /* Re-enable tracing if requested */ |
4463 | if (!disable_tracing) { | 4518 | if (!disable_tracing) { |
4464 | trace_flags |= old_userobj; | 4519 | trace_flags |= old_userobj; |
@@ -4475,9 +4530,9 @@ static void __ftrace_dump(bool disable_tracing) | |||
4475 | } | 4530 | } |
4476 | 4531 | ||
4477 | /* By default: disable tracing after the dump */ | 4532 | /* By default: disable tracing after the dump */ |
4478 | void ftrace_dump(void) | 4533 | void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) |
4479 | { | 4534 | { |
4480 | __ftrace_dump(true); | 4535 | __ftrace_dump(true, oops_dump_mode); |
4481 | } | 4536 | } |
4482 | 4537 | ||
4483 | __init static int tracer_alloc_buffers(void) | 4538 | __init static int tracer_alloc_buffers(void) |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 2825ef2c0b15..d1ce0bec1b3f 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
@@ -34,7 +34,6 @@ enum trace_type { | |||
34 | TRACE_GRAPH_RET, | 34 | TRACE_GRAPH_RET, |
35 | TRACE_GRAPH_ENT, | 35 | TRACE_GRAPH_ENT, |
36 | TRACE_USER_STACK, | 36 | TRACE_USER_STACK, |
37 | TRACE_HW_BRANCHES, | ||
38 | TRACE_KMEM_ALLOC, | 37 | TRACE_KMEM_ALLOC, |
39 | TRACE_KMEM_FREE, | 38 | TRACE_KMEM_FREE, |
40 | TRACE_BLK, | 39 | TRACE_BLK, |
@@ -103,29 +102,17 @@ struct syscall_trace_exit { | |||
103 | long ret; | 102 | long ret; |
104 | }; | 103 | }; |
105 | 104 | ||
106 | struct kprobe_trace_entry { | 105 | struct kprobe_trace_entry_head { |
107 | struct trace_entry ent; | 106 | struct trace_entry ent; |
108 | unsigned long ip; | 107 | unsigned long ip; |
109 | int nargs; | ||
110 | unsigned long args[]; | ||
111 | }; | 108 | }; |
112 | 109 | ||
113 | #define SIZEOF_KPROBE_TRACE_ENTRY(n) \ | 110 | struct kretprobe_trace_entry_head { |
114 | (offsetof(struct kprobe_trace_entry, args) + \ | ||
115 | (sizeof(unsigned long) * (n))) | ||
116 | |||
117 | struct kretprobe_trace_entry { | ||
118 | struct trace_entry ent; | 111 | struct trace_entry ent; |
119 | unsigned long func; | 112 | unsigned long func; |
120 | unsigned long ret_ip; | 113 | unsigned long ret_ip; |
121 | int nargs; | ||
122 | unsigned long args[]; | ||
123 | }; | 114 | }; |
124 | 115 | ||
125 | #define SIZEOF_KRETPROBE_TRACE_ENTRY(n) \ | ||
126 | (offsetof(struct kretprobe_trace_entry, args) + \ | ||
127 | (sizeof(unsigned long) * (n))) | ||
128 | |||
129 | /* | 116 | /* |
130 | * trace_flag_type is an enumeration that holds different | 117 | * trace_flag_type is an enumeration that holds different |
131 | * states when a trace occurs. These are: | 118 | * states when a trace occurs. These are: |
@@ -229,7 +216,6 @@ extern void __ftrace_bad_type(void); | |||
229 | TRACE_GRAPH_ENT); \ | 216 | TRACE_GRAPH_ENT); \ |
230 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ | 217 | IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \ |
231 | TRACE_GRAPH_RET); \ | 218 | TRACE_GRAPH_RET); \ |
232 | IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\ | ||
233 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ | 219 | IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry, \ |
234 | TRACE_KMEM_ALLOC); \ | 220 | TRACE_KMEM_ALLOC); \ |
235 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ | 221 | IF_ASSIGN(var, ent, struct kmemtrace_free_entry, \ |
@@ -378,6 +364,9 @@ void trace_function(struct trace_array *tr, | |||
378 | unsigned long ip, | 364 | unsigned long ip, |
379 | unsigned long parent_ip, | 365 | unsigned long parent_ip, |
380 | unsigned long flags, int pc); | 366 | unsigned long flags, int pc); |
367 | void trace_default_header(struct seq_file *m); | ||
368 | void print_trace_header(struct seq_file *m, struct trace_iterator *iter); | ||
369 | int trace_empty(struct trace_iterator *iter); | ||
381 | 370 | ||
382 | void trace_graph_return(struct ftrace_graph_ret *trace); | 371 | void trace_graph_return(struct ftrace_graph_ret *trace); |
383 | int trace_graph_entry(struct ftrace_graph_ent *trace); | 372 | int trace_graph_entry(struct ftrace_graph_ent *trace); |
@@ -467,8 +456,6 @@ extern int trace_selftest_startup_sysprof(struct tracer *trace, | |||
467 | struct trace_array *tr); | 456 | struct trace_array *tr); |
468 | extern int trace_selftest_startup_branch(struct tracer *trace, | 457 | extern int trace_selftest_startup_branch(struct tracer *trace, |
469 | struct trace_array *tr); | 458 | struct trace_array *tr); |
470 | extern int trace_selftest_startup_hw_branches(struct tracer *trace, | ||
471 | struct trace_array *tr); | ||
472 | extern int trace_selftest_startup_ksym(struct tracer *trace, | 459 | extern int trace_selftest_startup_ksym(struct tracer *trace, |
473 | struct trace_array *tr); | 460 | struct trace_array *tr); |
474 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ | 461 | #endif /* CONFIG_FTRACE_STARTUP_TEST */ |
@@ -491,9 +478,29 @@ extern int trace_clock_id; | |||
491 | 478 | ||
492 | /* Standard output formatting function used for function return traces */ | 479 | /* Standard output formatting function used for function return traces */ |
493 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 480 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
494 | extern enum print_line_t print_graph_function(struct trace_iterator *iter); | 481 | |
482 | /* Flag options */ | ||
483 | #define TRACE_GRAPH_PRINT_OVERRUN 0x1 | ||
484 | #define TRACE_GRAPH_PRINT_CPU 0x2 | ||
485 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 | ||
486 | #define TRACE_GRAPH_PRINT_PROC 0x8 | ||
487 | #define TRACE_GRAPH_PRINT_DURATION 0x10 | ||
488 | #define TRACE_GRAPH_PRINT_ABS_TIME 0x20 | ||
489 | |||
490 | extern enum print_line_t | ||
491 | print_graph_function_flags(struct trace_iterator *iter, u32 flags); | ||
492 | extern void print_graph_headers_flags(struct seq_file *s, u32 flags); | ||
495 | extern enum print_line_t | 493 | extern enum print_line_t |
496 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); | 494 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s); |
495 | extern void graph_trace_open(struct trace_iterator *iter); | ||
496 | extern void graph_trace_close(struct trace_iterator *iter); | ||
497 | extern int __trace_graph_entry(struct trace_array *tr, | ||
498 | struct ftrace_graph_ent *trace, | ||
499 | unsigned long flags, int pc); | ||
500 | extern void __trace_graph_return(struct trace_array *tr, | ||
501 | struct ftrace_graph_ret *trace, | ||
502 | unsigned long flags, int pc); | ||
503 | |||
497 | 504 | ||
498 | #ifdef CONFIG_DYNAMIC_FTRACE | 505 | #ifdef CONFIG_DYNAMIC_FTRACE |
499 | /* TODO: make this variable */ | 506 | /* TODO: make this variable */ |
@@ -524,7 +531,7 @@ static inline int ftrace_graph_addr(unsigned long addr) | |||
524 | #endif /* CONFIG_DYNAMIC_FTRACE */ | 531 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
525 | #else /* CONFIG_FUNCTION_GRAPH_TRACER */ | 532 | #else /* CONFIG_FUNCTION_GRAPH_TRACER */ |
526 | static inline enum print_line_t | 533 | static inline enum print_line_t |
527 | print_graph_function(struct trace_iterator *iter) | 534 | print_graph_function_flags(struct trace_iterator *iter, u32 flags) |
528 | { | 535 | { |
529 | return TRACE_TYPE_UNHANDLED; | 536 | return TRACE_TYPE_UNHANDLED; |
530 | } | 537 | } |
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index c16a08f399df..dc008c1240da 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h | |||
@@ -318,18 +318,6 @@ FTRACE_ENTRY(branch, trace_branch, | |||
318 | __entry->func, __entry->file, __entry->correct) | 318 | __entry->func, __entry->file, __entry->correct) |
319 | ); | 319 | ); |
320 | 320 | ||
321 | FTRACE_ENTRY(hw_branch, hw_branch_entry, | ||
322 | |||
323 | TRACE_HW_BRANCHES, | ||
324 | |||
325 | F_STRUCT( | ||
326 | __field( u64, from ) | ||
327 | __field( u64, to ) | ||
328 | ), | ||
329 | |||
330 | F_printk("from: %llx to: %llx", __entry->from, __entry->to) | ||
331 | ); | ||
332 | |||
333 | FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry, | 321 | FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry, |
334 | 322 | ||
335 | TRACE_KMEM_ALLOC, | 323 | TRACE_KMEM_ALLOC, |
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c index 88c0b6dbd7fe..58092d844a1f 100644 --- a/kernel/trace/trace_events_filter.c +++ b/kernel/trace/trace_events_filter.c | |||
@@ -1398,7 +1398,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id, | |||
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | err = -EINVAL; | 1400 | err = -EINVAL; |
1401 | if (!call) | 1401 | if (&call->list == &ftrace_events) |
1402 | goto out_unlock; | 1402 | goto out_unlock; |
1403 | 1403 | ||
1404 | err = -EEXIST; | 1404 | err = -EEXIST; |
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c index 9aed1a5cf553..dd11c830eb84 100644 --- a/kernel/trace/trace_functions_graph.c +++ b/kernel/trace/trace_functions_graph.c | |||
@@ -40,7 +40,7 @@ struct fgraph_data { | |||
40 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 | 40 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 |
41 | #define TRACE_GRAPH_PRINT_PROC 0x8 | 41 | #define TRACE_GRAPH_PRINT_PROC 0x8 |
42 | #define TRACE_GRAPH_PRINT_DURATION 0x10 | 42 | #define TRACE_GRAPH_PRINT_DURATION 0x10 |
43 | #define TRACE_GRAPH_PRINT_ABS_TIME 0X20 | 43 | #define TRACE_GRAPH_PRINT_ABS_TIME 0x20 |
44 | 44 | ||
45 | static struct tracer_opt trace_opts[] = { | 45 | static struct tracer_opt trace_opts[] = { |
46 | /* Display overruns? (for self-debug purpose) */ | 46 | /* Display overruns? (for self-debug purpose) */ |
@@ -179,7 +179,7 @@ unsigned long ftrace_return_to_handler(unsigned long frame_pointer) | |||
179 | return ret; | 179 | return ret; |
180 | } | 180 | } |
181 | 181 | ||
182 | static int __trace_graph_entry(struct trace_array *tr, | 182 | int __trace_graph_entry(struct trace_array *tr, |
183 | struct ftrace_graph_ent *trace, | 183 | struct ftrace_graph_ent *trace, |
184 | unsigned long flags, | 184 | unsigned long flags, |
185 | int pc) | 185 | int pc) |
@@ -246,7 +246,7 @@ int trace_graph_thresh_entry(struct ftrace_graph_ent *trace) | |||
246 | return trace_graph_entry(trace); | 246 | return trace_graph_entry(trace); |
247 | } | 247 | } |
248 | 248 | ||
249 | static void __trace_graph_return(struct trace_array *tr, | 249 | void __trace_graph_return(struct trace_array *tr, |
250 | struct ftrace_graph_ret *trace, | 250 | struct ftrace_graph_ret *trace, |
251 | unsigned long flags, | 251 | unsigned long flags, |
252 | int pc) | 252 | int pc) |
@@ -490,9 +490,10 @@ get_return_for_leaf(struct trace_iterator *iter, | |||
490 | * We need to consume the current entry to see | 490 | * We need to consume the current entry to see |
491 | * the next one. | 491 | * the next one. |
492 | */ | 492 | */ |
493 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); | 493 | ring_buffer_consume(iter->tr->buffer, iter->cpu, |
494 | NULL, NULL); | ||
494 | event = ring_buffer_peek(iter->tr->buffer, iter->cpu, | 495 | event = ring_buffer_peek(iter->tr->buffer, iter->cpu, |
495 | NULL); | 496 | NULL, NULL); |
496 | } | 497 | } |
497 | 498 | ||
498 | if (!event) | 499 | if (!event) |
@@ -526,17 +527,18 @@ get_return_for_leaf(struct trace_iterator *iter, | |||
526 | 527 | ||
527 | /* Signal a overhead of time execution to the output */ | 528 | /* Signal a overhead of time execution to the output */ |
528 | static int | 529 | static int |
529 | print_graph_overhead(unsigned long long duration, struct trace_seq *s) | 530 | print_graph_overhead(unsigned long long duration, struct trace_seq *s, |
531 | u32 flags) | ||
530 | { | 532 | { |
531 | /* If duration disappear, we don't need anything */ | 533 | /* If duration disappear, we don't need anything */ |
532 | if (!(tracer_flags.val & TRACE_GRAPH_PRINT_DURATION)) | 534 | if (!(flags & TRACE_GRAPH_PRINT_DURATION)) |
533 | return 1; | 535 | return 1; |
534 | 536 | ||
535 | /* Non nested entry or return */ | 537 | /* Non nested entry or return */ |
536 | if (duration == -1) | 538 | if (duration == -1) |
537 | return trace_seq_printf(s, " "); | 539 | return trace_seq_printf(s, " "); |
538 | 540 | ||
539 | if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERHEAD) { | 541 | if (flags & TRACE_GRAPH_PRINT_OVERHEAD) { |
540 | /* Duration exceeded 100 msecs */ | 542 | /* Duration exceeded 100 msecs */ |
541 | if (duration > 100000ULL) | 543 | if (duration > 100000ULL) |
542 | return trace_seq_printf(s, "! "); | 544 | return trace_seq_printf(s, "! "); |
@@ -562,7 +564,7 @@ static int print_graph_abs_time(u64 t, struct trace_seq *s) | |||
562 | 564 | ||
563 | static enum print_line_t | 565 | static enum print_line_t |
564 | print_graph_irq(struct trace_iterator *iter, unsigned long addr, | 566 | print_graph_irq(struct trace_iterator *iter, unsigned long addr, |
565 | enum trace_type type, int cpu, pid_t pid) | 567 | enum trace_type type, int cpu, pid_t pid, u32 flags) |
566 | { | 568 | { |
567 | int ret; | 569 | int ret; |
568 | struct trace_seq *s = &iter->seq; | 570 | struct trace_seq *s = &iter->seq; |
@@ -572,21 +574,21 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr, | |||
572 | return TRACE_TYPE_UNHANDLED; | 574 | return TRACE_TYPE_UNHANDLED; |
573 | 575 | ||
574 | /* Absolute time */ | 576 | /* Absolute time */ |
575 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { | 577 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) { |
576 | ret = print_graph_abs_time(iter->ts, s); | 578 | ret = print_graph_abs_time(iter->ts, s); |
577 | if (!ret) | 579 | if (!ret) |
578 | return TRACE_TYPE_PARTIAL_LINE; | 580 | return TRACE_TYPE_PARTIAL_LINE; |
579 | } | 581 | } |
580 | 582 | ||
581 | /* Cpu */ | 583 | /* Cpu */ |
582 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { | 584 | if (flags & TRACE_GRAPH_PRINT_CPU) { |
583 | ret = print_graph_cpu(s, cpu); | 585 | ret = print_graph_cpu(s, cpu); |
584 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 586 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
585 | return TRACE_TYPE_PARTIAL_LINE; | 587 | return TRACE_TYPE_PARTIAL_LINE; |
586 | } | 588 | } |
587 | 589 | ||
588 | /* Proc */ | 590 | /* Proc */ |
589 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { | 591 | if (flags & TRACE_GRAPH_PRINT_PROC) { |
590 | ret = print_graph_proc(s, pid); | 592 | ret = print_graph_proc(s, pid); |
591 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 593 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
592 | return TRACE_TYPE_PARTIAL_LINE; | 594 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -596,7 +598,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr, | |||
596 | } | 598 | } |
597 | 599 | ||
598 | /* No overhead */ | 600 | /* No overhead */ |
599 | ret = print_graph_overhead(-1, s); | 601 | ret = print_graph_overhead(-1, s, flags); |
600 | if (!ret) | 602 | if (!ret) |
601 | return TRACE_TYPE_PARTIAL_LINE; | 603 | return TRACE_TYPE_PARTIAL_LINE; |
602 | 604 | ||
@@ -609,7 +611,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr, | |||
609 | return TRACE_TYPE_PARTIAL_LINE; | 611 | return TRACE_TYPE_PARTIAL_LINE; |
610 | 612 | ||
611 | /* Don't close the duration column if haven't one */ | 613 | /* Don't close the duration column if haven't one */ |
612 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) | 614 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
613 | trace_seq_printf(s, " |"); | 615 | trace_seq_printf(s, " |"); |
614 | ret = trace_seq_printf(s, "\n"); | 616 | ret = trace_seq_printf(s, "\n"); |
615 | 617 | ||
@@ -679,7 +681,8 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s) | |||
679 | static enum print_line_t | 681 | static enum print_line_t |
680 | print_graph_entry_leaf(struct trace_iterator *iter, | 682 | print_graph_entry_leaf(struct trace_iterator *iter, |
681 | struct ftrace_graph_ent_entry *entry, | 683 | struct ftrace_graph_ent_entry *entry, |
682 | struct ftrace_graph_ret_entry *ret_entry, struct trace_seq *s) | 684 | struct ftrace_graph_ret_entry *ret_entry, |
685 | struct trace_seq *s, u32 flags) | ||
683 | { | 686 | { |
684 | struct fgraph_data *data = iter->private; | 687 | struct fgraph_data *data = iter->private; |
685 | struct ftrace_graph_ret *graph_ret; | 688 | struct ftrace_graph_ret *graph_ret; |
@@ -711,12 +714,12 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
711 | } | 714 | } |
712 | 715 | ||
713 | /* Overhead */ | 716 | /* Overhead */ |
714 | ret = print_graph_overhead(duration, s); | 717 | ret = print_graph_overhead(duration, s, flags); |
715 | if (!ret) | 718 | if (!ret) |
716 | return TRACE_TYPE_PARTIAL_LINE; | 719 | return TRACE_TYPE_PARTIAL_LINE; |
717 | 720 | ||
718 | /* Duration */ | 721 | /* Duration */ |
719 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { | 722 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
720 | ret = print_graph_duration(duration, s); | 723 | ret = print_graph_duration(duration, s); |
721 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 724 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
722 | return TRACE_TYPE_PARTIAL_LINE; | 725 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -739,7 +742,7 @@ print_graph_entry_leaf(struct trace_iterator *iter, | |||
739 | static enum print_line_t | 742 | static enum print_line_t |
740 | print_graph_entry_nested(struct trace_iterator *iter, | 743 | print_graph_entry_nested(struct trace_iterator *iter, |
741 | struct ftrace_graph_ent_entry *entry, | 744 | struct ftrace_graph_ent_entry *entry, |
742 | struct trace_seq *s, int cpu) | 745 | struct trace_seq *s, int cpu, u32 flags) |
743 | { | 746 | { |
744 | struct ftrace_graph_ent *call = &entry->graph_ent; | 747 | struct ftrace_graph_ent *call = &entry->graph_ent; |
745 | struct fgraph_data *data = iter->private; | 748 | struct fgraph_data *data = iter->private; |
@@ -759,12 +762,12 @@ print_graph_entry_nested(struct trace_iterator *iter, | |||
759 | } | 762 | } |
760 | 763 | ||
761 | /* No overhead */ | 764 | /* No overhead */ |
762 | ret = print_graph_overhead(-1, s); | 765 | ret = print_graph_overhead(-1, s, flags); |
763 | if (!ret) | 766 | if (!ret) |
764 | return TRACE_TYPE_PARTIAL_LINE; | 767 | return TRACE_TYPE_PARTIAL_LINE; |
765 | 768 | ||
766 | /* No time */ | 769 | /* No time */ |
767 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { | 770 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
768 | ret = trace_seq_printf(s, " | "); | 771 | ret = trace_seq_printf(s, " | "); |
769 | if (!ret) | 772 | if (!ret) |
770 | return TRACE_TYPE_PARTIAL_LINE; | 773 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -790,7 +793,7 @@ print_graph_entry_nested(struct trace_iterator *iter, | |||
790 | 793 | ||
791 | static enum print_line_t | 794 | static enum print_line_t |
792 | print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, | 795 | print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, |
793 | int type, unsigned long addr) | 796 | int type, unsigned long addr, u32 flags) |
794 | { | 797 | { |
795 | struct fgraph_data *data = iter->private; | 798 | struct fgraph_data *data = iter->private; |
796 | struct trace_entry *ent = iter->ent; | 799 | struct trace_entry *ent = iter->ent; |
@@ -803,27 +806,27 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, | |||
803 | 806 | ||
804 | if (type) { | 807 | if (type) { |
805 | /* Interrupt */ | 808 | /* Interrupt */ |
806 | ret = print_graph_irq(iter, addr, type, cpu, ent->pid); | 809 | ret = print_graph_irq(iter, addr, type, cpu, ent->pid, flags); |
807 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 810 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
808 | return TRACE_TYPE_PARTIAL_LINE; | 811 | return TRACE_TYPE_PARTIAL_LINE; |
809 | } | 812 | } |
810 | 813 | ||
811 | /* Absolute time */ | 814 | /* Absolute time */ |
812 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { | 815 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) { |
813 | ret = print_graph_abs_time(iter->ts, s); | 816 | ret = print_graph_abs_time(iter->ts, s); |
814 | if (!ret) | 817 | if (!ret) |
815 | return TRACE_TYPE_PARTIAL_LINE; | 818 | return TRACE_TYPE_PARTIAL_LINE; |
816 | } | 819 | } |
817 | 820 | ||
818 | /* Cpu */ | 821 | /* Cpu */ |
819 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { | 822 | if (flags & TRACE_GRAPH_PRINT_CPU) { |
820 | ret = print_graph_cpu(s, cpu); | 823 | ret = print_graph_cpu(s, cpu); |
821 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 824 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
822 | return TRACE_TYPE_PARTIAL_LINE; | 825 | return TRACE_TYPE_PARTIAL_LINE; |
823 | } | 826 | } |
824 | 827 | ||
825 | /* Proc */ | 828 | /* Proc */ |
826 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { | 829 | if (flags & TRACE_GRAPH_PRINT_PROC) { |
827 | ret = print_graph_proc(s, ent->pid); | 830 | ret = print_graph_proc(s, ent->pid); |
828 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 831 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
829 | return TRACE_TYPE_PARTIAL_LINE; | 832 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -845,7 +848,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, | |||
845 | 848 | ||
846 | static enum print_line_t | 849 | static enum print_line_t |
847 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | 850 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, |
848 | struct trace_iterator *iter) | 851 | struct trace_iterator *iter, u32 flags) |
849 | { | 852 | { |
850 | struct fgraph_data *data = iter->private; | 853 | struct fgraph_data *data = iter->private; |
851 | struct ftrace_graph_ent *call = &field->graph_ent; | 854 | struct ftrace_graph_ent *call = &field->graph_ent; |
@@ -853,14 +856,14 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | |||
853 | static enum print_line_t ret; | 856 | static enum print_line_t ret; |
854 | int cpu = iter->cpu; | 857 | int cpu = iter->cpu; |
855 | 858 | ||
856 | if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func)) | 859 | if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags)) |
857 | return TRACE_TYPE_PARTIAL_LINE; | 860 | return TRACE_TYPE_PARTIAL_LINE; |
858 | 861 | ||
859 | leaf_ret = get_return_for_leaf(iter, field); | 862 | leaf_ret = get_return_for_leaf(iter, field); |
860 | if (leaf_ret) | 863 | if (leaf_ret) |
861 | ret = print_graph_entry_leaf(iter, field, leaf_ret, s); | 864 | ret = print_graph_entry_leaf(iter, field, leaf_ret, s, flags); |
862 | else | 865 | else |
863 | ret = print_graph_entry_nested(iter, field, s, cpu); | 866 | ret = print_graph_entry_nested(iter, field, s, cpu, flags); |
864 | 867 | ||
865 | if (data) { | 868 | if (data) { |
866 | /* | 869 | /* |
@@ -879,7 +882,8 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, | |||
879 | 882 | ||
880 | static enum print_line_t | 883 | static enum print_line_t |
881 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | 884 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, |
882 | struct trace_entry *ent, struct trace_iterator *iter) | 885 | struct trace_entry *ent, struct trace_iterator *iter, |
886 | u32 flags) | ||
883 | { | 887 | { |
884 | unsigned long long duration = trace->rettime - trace->calltime; | 888 | unsigned long long duration = trace->rettime - trace->calltime; |
885 | struct fgraph_data *data = iter->private; | 889 | struct fgraph_data *data = iter->private; |
@@ -909,16 +913,16 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | |||
909 | } | 913 | } |
910 | } | 914 | } |
911 | 915 | ||
912 | if (print_graph_prologue(iter, s, 0, 0)) | 916 | if (print_graph_prologue(iter, s, 0, 0, flags)) |
913 | return TRACE_TYPE_PARTIAL_LINE; | 917 | return TRACE_TYPE_PARTIAL_LINE; |
914 | 918 | ||
915 | /* Overhead */ | 919 | /* Overhead */ |
916 | ret = print_graph_overhead(duration, s); | 920 | ret = print_graph_overhead(duration, s, flags); |
917 | if (!ret) | 921 | if (!ret) |
918 | return TRACE_TYPE_PARTIAL_LINE; | 922 | return TRACE_TYPE_PARTIAL_LINE; |
919 | 923 | ||
920 | /* Duration */ | 924 | /* Duration */ |
921 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { | 925 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
922 | ret = print_graph_duration(duration, s); | 926 | ret = print_graph_duration(duration, s); |
923 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 927 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
924 | return TRACE_TYPE_PARTIAL_LINE; | 928 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -948,14 +952,15 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | |||
948 | } | 952 | } |
949 | 953 | ||
950 | /* Overrun */ | 954 | /* Overrun */ |
951 | if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERRUN) { | 955 | if (flags & TRACE_GRAPH_PRINT_OVERRUN) { |
952 | ret = trace_seq_printf(s, " (Overruns: %lu)\n", | 956 | ret = trace_seq_printf(s, " (Overruns: %lu)\n", |
953 | trace->overrun); | 957 | trace->overrun); |
954 | if (!ret) | 958 | if (!ret) |
955 | return TRACE_TYPE_PARTIAL_LINE; | 959 | return TRACE_TYPE_PARTIAL_LINE; |
956 | } | 960 | } |
957 | 961 | ||
958 | ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET, cpu, pid); | 962 | ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET, |
963 | cpu, pid, flags); | ||
959 | if (ret == TRACE_TYPE_PARTIAL_LINE) | 964 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
960 | return TRACE_TYPE_PARTIAL_LINE; | 965 | return TRACE_TYPE_PARTIAL_LINE; |
961 | 966 | ||
@@ -963,8 +968,8 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, | |||
963 | } | 968 | } |
964 | 969 | ||
965 | static enum print_line_t | 970 | static enum print_line_t |
966 | print_graph_comment(struct trace_seq *s, struct trace_entry *ent, | 971 | print_graph_comment(struct trace_seq *s, struct trace_entry *ent, |
967 | struct trace_iterator *iter) | 972 | struct trace_iterator *iter, u32 flags) |
968 | { | 973 | { |
969 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); | 974 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
970 | struct fgraph_data *data = iter->private; | 975 | struct fgraph_data *data = iter->private; |
@@ -976,16 +981,16 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent, | |||
976 | if (data) | 981 | if (data) |
977 | depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth; | 982 | depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth; |
978 | 983 | ||
979 | if (print_graph_prologue(iter, s, 0, 0)) | 984 | if (print_graph_prologue(iter, s, 0, 0, flags)) |
980 | return TRACE_TYPE_PARTIAL_LINE; | 985 | return TRACE_TYPE_PARTIAL_LINE; |
981 | 986 | ||
982 | /* No overhead */ | 987 | /* No overhead */ |
983 | ret = print_graph_overhead(-1, s); | 988 | ret = print_graph_overhead(-1, s, flags); |
984 | if (!ret) | 989 | if (!ret) |
985 | return TRACE_TYPE_PARTIAL_LINE; | 990 | return TRACE_TYPE_PARTIAL_LINE; |
986 | 991 | ||
987 | /* No time */ | 992 | /* No time */ |
988 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { | 993 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
989 | ret = trace_seq_printf(s, " | "); | 994 | ret = trace_seq_printf(s, " | "); |
990 | if (!ret) | 995 | if (!ret) |
991 | return TRACE_TYPE_PARTIAL_LINE; | 996 | return TRACE_TYPE_PARTIAL_LINE; |
@@ -1040,7 +1045,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent, | |||
1040 | 1045 | ||
1041 | 1046 | ||
1042 | enum print_line_t | 1047 | enum print_line_t |
1043 | print_graph_function(struct trace_iterator *iter) | 1048 | print_graph_function_flags(struct trace_iterator *iter, u32 flags) |
1044 | { | 1049 | { |
1045 | struct ftrace_graph_ent_entry *field; | 1050 | struct ftrace_graph_ent_entry *field; |
1046 | struct fgraph_data *data = iter->private; | 1051 | struct fgraph_data *data = iter->private; |
@@ -1061,7 +1066,7 @@ print_graph_function(struct trace_iterator *iter) | |||
1061 | if (data && data->failed) { | 1066 | if (data && data->failed) { |
1062 | field = &data->ent; | 1067 | field = &data->ent; |
1063 | iter->cpu = data->cpu; | 1068 | iter->cpu = data->cpu; |
1064 | ret = print_graph_entry(field, s, iter); | 1069 | ret = print_graph_entry(field, s, iter, flags); |
1065 | if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) { | 1070 | if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) { |
1066 | per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1; | 1071 | per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1; |
1067 | ret = TRACE_TYPE_NO_CONSUME; | 1072 | ret = TRACE_TYPE_NO_CONSUME; |
@@ -1081,32 +1086,49 @@ print_graph_function(struct trace_iterator *iter) | |||
1081 | struct ftrace_graph_ent_entry saved; | 1086 | struct ftrace_graph_ent_entry saved; |
1082 | trace_assign_type(field, entry); | 1087 | trace_assign_type(field, entry); |
1083 | saved = *field; | 1088 | saved = *field; |
1084 | return print_graph_entry(&saved, s, iter); | 1089 | return print_graph_entry(&saved, s, iter, flags); |
1085 | } | 1090 | } |
1086 | case TRACE_GRAPH_RET: { | 1091 | case TRACE_GRAPH_RET: { |
1087 | struct ftrace_graph_ret_entry *field; | 1092 | struct ftrace_graph_ret_entry *field; |
1088 | trace_assign_type(field, entry); | 1093 | trace_assign_type(field, entry); |
1089 | return print_graph_return(&field->ret, s, entry, iter); | 1094 | return print_graph_return(&field->ret, s, entry, iter, flags); |
1090 | } | 1095 | } |
1096 | case TRACE_STACK: | ||
1097 | case TRACE_FN: | ||
1098 | /* dont trace stack and functions as comments */ | ||
1099 | return TRACE_TYPE_UNHANDLED; | ||
1100 | |||
1091 | default: | 1101 | default: |
1092 | return print_graph_comment(s, entry, iter); | 1102 | return print_graph_comment(s, entry, iter, flags); |
1093 | } | 1103 | } |
1094 | 1104 | ||
1095 | return TRACE_TYPE_HANDLED; | 1105 | return TRACE_TYPE_HANDLED; |
1096 | } | 1106 | } |
1097 | 1107 | ||
1098 | static void print_lat_header(struct seq_file *s) | 1108 | static enum print_line_t |
1109 | print_graph_function(struct trace_iterator *iter) | ||
1110 | { | ||
1111 | return print_graph_function_flags(iter, tracer_flags.val); | ||
1112 | } | ||
1113 | |||
1114 | static enum print_line_t | ||
1115 | print_graph_function_event(struct trace_iterator *iter, int flags) | ||
1116 | { | ||
1117 | return print_graph_function(iter); | ||
1118 | } | ||
1119 | |||
1120 | static void print_lat_header(struct seq_file *s, u32 flags) | ||
1099 | { | 1121 | { |
1100 | static const char spaces[] = " " /* 16 spaces */ | 1122 | static const char spaces[] = " " /* 16 spaces */ |
1101 | " " /* 4 spaces */ | 1123 | " " /* 4 spaces */ |
1102 | " "; /* 17 spaces */ | 1124 | " "; /* 17 spaces */ |
1103 | int size = 0; | 1125 | int size = 0; |
1104 | 1126 | ||
1105 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) | 1127 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
1106 | size += 16; | 1128 | size += 16; |
1107 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) | 1129 | if (flags & TRACE_GRAPH_PRINT_CPU) |
1108 | size += 4; | 1130 | size += 4; |
1109 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) | 1131 | if (flags & TRACE_GRAPH_PRINT_PROC) |
1110 | size += 17; | 1132 | size += 17; |
1111 | 1133 | ||
1112 | seq_printf(s, "#%.*s _-----=> irqs-off \n", size, spaces); | 1134 | seq_printf(s, "#%.*s _-----=> irqs-off \n", size, spaces); |
@@ -1117,43 +1139,48 @@ static void print_lat_header(struct seq_file *s) | |||
1117 | seq_printf(s, "#%.*s|||| / \n", size, spaces); | 1139 | seq_printf(s, "#%.*s|||| / \n", size, spaces); |
1118 | } | 1140 | } |
1119 | 1141 | ||
1120 | static void print_graph_headers(struct seq_file *s) | 1142 | void print_graph_headers_flags(struct seq_file *s, u32 flags) |
1121 | { | 1143 | { |
1122 | int lat = trace_flags & TRACE_ITER_LATENCY_FMT; | 1144 | int lat = trace_flags & TRACE_ITER_LATENCY_FMT; |
1123 | 1145 | ||
1124 | if (lat) | 1146 | if (lat) |
1125 | print_lat_header(s); | 1147 | print_lat_header(s, flags); |
1126 | 1148 | ||
1127 | /* 1st line */ | 1149 | /* 1st line */ |
1128 | seq_printf(s, "#"); | 1150 | seq_printf(s, "#"); |
1129 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) | 1151 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
1130 | seq_printf(s, " TIME "); | 1152 | seq_printf(s, " TIME "); |
1131 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) | 1153 | if (flags & TRACE_GRAPH_PRINT_CPU) |
1132 | seq_printf(s, " CPU"); | 1154 | seq_printf(s, " CPU"); |
1133 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) | 1155 | if (flags & TRACE_GRAPH_PRINT_PROC) |
1134 | seq_printf(s, " TASK/PID "); | 1156 | seq_printf(s, " TASK/PID "); |
1135 | if (lat) | 1157 | if (lat) |
1136 | seq_printf(s, "|||||"); | 1158 | seq_printf(s, "|||||"); |
1137 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) | 1159 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
1138 | seq_printf(s, " DURATION "); | 1160 | seq_printf(s, " DURATION "); |
1139 | seq_printf(s, " FUNCTION CALLS\n"); | 1161 | seq_printf(s, " FUNCTION CALLS\n"); |
1140 | 1162 | ||
1141 | /* 2nd line */ | 1163 | /* 2nd line */ |
1142 | seq_printf(s, "#"); | 1164 | seq_printf(s, "#"); |
1143 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) | 1165 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
1144 | seq_printf(s, " | "); | 1166 | seq_printf(s, " | "); |
1145 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) | 1167 | if (flags & TRACE_GRAPH_PRINT_CPU) |
1146 | seq_printf(s, " | "); | 1168 | seq_printf(s, " | "); |
1147 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) | 1169 | if (flags & TRACE_GRAPH_PRINT_PROC) |
1148 | seq_printf(s, " | | "); | 1170 | seq_printf(s, " | | "); |
1149 | if (lat) | 1171 | if (lat) |
1150 | seq_printf(s, "|||||"); | 1172 | seq_printf(s, "|||||"); |
1151 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) | 1173 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
1152 | seq_printf(s, " | | "); | 1174 | seq_printf(s, " | | "); |
1153 | seq_printf(s, " | | | |\n"); | 1175 | seq_printf(s, " | | | |\n"); |
1154 | } | 1176 | } |
1155 | 1177 | ||
1156 | static void graph_trace_open(struct trace_iterator *iter) | 1178 | void print_graph_headers(struct seq_file *s) |
1179 | { | ||
1180 | print_graph_headers_flags(s, tracer_flags.val); | ||
1181 | } | ||
1182 | |||
1183 | void graph_trace_open(struct trace_iterator *iter) | ||
1157 | { | 1184 | { |
1158 | /* pid and depth on the last trace processed */ | 1185 | /* pid and depth on the last trace processed */ |
1159 | struct fgraph_data *data; | 1186 | struct fgraph_data *data; |
@@ -1188,7 +1215,7 @@ static void graph_trace_open(struct trace_iterator *iter) | |||
1188 | pr_warning("function graph tracer: not enough memory\n"); | 1215 | pr_warning("function graph tracer: not enough memory\n"); |
1189 | } | 1216 | } |
1190 | 1217 | ||
1191 | static void graph_trace_close(struct trace_iterator *iter) | 1218 | void graph_trace_close(struct trace_iterator *iter) |
1192 | { | 1219 | { |
1193 | struct fgraph_data *data = iter->private; | 1220 | struct fgraph_data *data = iter->private; |
1194 | 1221 | ||
@@ -1198,6 +1225,16 @@ static void graph_trace_close(struct trace_iterator *iter) | |||
1198 | } | 1225 | } |
1199 | } | 1226 | } |
1200 | 1227 | ||
1228 | static struct trace_event graph_trace_entry_event = { | ||
1229 | .type = TRACE_GRAPH_ENT, | ||
1230 | .trace = print_graph_function_event, | ||
1231 | }; | ||
1232 | |||
1233 | static struct trace_event graph_trace_ret_event = { | ||
1234 | .type = TRACE_GRAPH_RET, | ||
1235 | .trace = print_graph_function_event, | ||
1236 | }; | ||
1237 | |||
1201 | static struct tracer graph_trace __read_mostly = { | 1238 | static struct tracer graph_trace __read_mostly = { |
1202 | .name = "function_graph", | 1239 | .name = "function_graph", |
1203 | .open = graph_trace_open, | 1240 | .open = graph_trace_open, |
@@ -1219,6 +1256,16 @@ static __init int init_graph_trace(void) | |||
1219 | { | 1256 | { |
1220 | max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1); | 1257 | max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1); |
1221 | 1258 | ||
1259 | if (!register_ftrace_event(&graph_trace_entry_event)) { | ||
1260 | pr_warning("Warning: could not register graph trace events\n"); | ||
1261 | return 1; | ||
1262 | } | ||
1263 | |||
1264 | if (!register_ftrace_event(&graph_trace_ret_event)) { | ||
1265 | pr_warning("Warning: could not register graph trace events\n"); | ||
1266 | return 1; | ||
1267 | } | ||
1268 | |||
1222 | return register_tracer(&graph_trace); | 1269 | return register_tracer(&graph_trace); |
1223 | } | 1270 | } |
1224 | 1271 | ||
diff --git a/kernel/trace/trace_hw_branches.c b/kernel/trace/trace_hw_branches.c deleted file mode 100644 index 7b97000745f5..000000000000 --- a/kernel/trace/trace_hw_branches.c +++ /dev/null | |||
@@ -1,312 +0,0 @@ | |||
1 | /* | ||
2 | * h/w branch tracer for x86 based on BTS | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Intel Corporation. | ||
5 | * Markus Metzger <markus.t.metzger@gmail.com>, 2008-2009 | ||
6 | */ | ||
7 | #include <linux/kallsyms.h> | ||
8 | #include <linux/debugfs.h> | ||
9 | #include <linux/ftrace.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/cpu.h> | ||
12 | #include <linux/smp.h> | ||
13 | #include <linux/fs.h> | ||
14 | |||
15 | #include <asm/ds.h> | ||
16 | |||
17 | #include "trace_output.h" | ||
18 | #include "trace.h" | ||
19 | |||
20 | |||
21 | #define BTS_BUFFER_SIZE (1 << 13) | ||
22 | |||
23 | static DEFINE_PER_CPU(struct bts_tracer *, hwb_tracer); | ||
24 | static DEFINE_PER_CPU(unsigned char[BTS_BUFFER_SIZE], hwb_buffer); | ||
25 | |||
26 | #define this_tracer per_cpu(hwb_tracer, smp_processor_id()) | ||
27 | |||
28 | static int trace_hw_branches_enabled __read_mostly; | ||
29 | static int trace_hw_branches_suspended __read_mostly; | ||
30 | static struct trace_array *hw_branch_trace __read_mostly; | ||
31 | |||
32 | |||
33 | static void bts_trace_init_cpu(int cpu) | ||
34 | { | ||
35 | per_cpu(hwb_tracer, cpu) = | ||
36 | ds_request_bts_cpu(cpu, per_cpu(hwb_buffer, cpu), | ||
37 | BTS_BUFFER_SIZE, NULL, (size_t)-1, | ||
38 | BTS_KERNEL); | ||
39 | |||
40 | if (IS_ERR(per_cpu(hwb_tracer, cpu))) | ||
41 | per_cpu(hwb_tracer, cpu) = NULL; | ||
42 | } | ||
43 | |||
44 | static int bts_trace_init(struct trace_array *tr) | ||
45 | { | ||
46 | int cpu; | ||
47 | |||
48 | hw_branch_trace = tr; | ||
49 | trace_hw_branches_enabled = 0; | ||
50 | |||
51 | get_online_cpus(); | ||
52 | for_each_online_cpu(cpu) { | ||
53 | bts_trace_init_cpu(cpu); | ||
54 | |||
55 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
56 | trace_hw_branches_enabled = 1; | ||
57 | } | ||
58 | trace_hw_branches_suspended = 0; | ||
59 | put_online_cpus(); | ||
60 | |||
61 | /* If we could not enable tracing on a single cpu, we fail. */ | ||
62 | return trace_hw_branches_enabled ? 0 : -EOPNOTSUPP; | ||
63 | } | ||
64 | |||
65 | static void bts_trace_reset(struct trace_array *tr) | ||
66 | { | ||
67 | int cpu; | ||
68 | |||
69 | get_online_cpus(); | ||
70 | for_each_online_cpu(cpu) { | ||
71 | if (likely(per_cpu(hwb_tracer, cpu))) { | ||
72 | ds_release_bts(per_cpu(hwb_tracer, cpu)); | ||
73 | per_cpu(hwb_tracer, cpu) = NULL; | ||
74 | } | ||
75 | } | ||
76 | trace_hw_branches_enabled = 0; | ||
77 | trace_hw_branches_suspended = 0; | ||
78 | put_online_cpus(); | ||
79 | } | ||
80 | |||
81 | static void bts_trace_start(struct trace_array *tr) | ||
82 | { | ||
83 | int cpu; | ||
84 | |||
85 | get_online_cpus(); | ||
86 | for_each_online_cpu(cpu) | ||
87 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
88 | ds_resume_bts(per_cpu(hwb_tracer, cpu)); | ||
89 | trace_hw_branches_suspended = 0; | ||
90 | put_online_cpus(); | ||
91 | } | ||
92 | |||
93 | static void bts_trace_stop(struct trace_array *tr) | ||
94 | { | ||
95 | int cpu; | ||
96 | |||
97 | get_online_cpus(); | ||
98 | for_each_online_cpu(cpu) | ||
99 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
100 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
101 | trace_hw_branches_suspended = 1; | ||
102 | put_online_cpus(); | ||
103 | } | ||
104 | |||
105 | static int __cpuinit bts_hotcpu_handler(struct notifier_block *nfb, | ||
106 | unsigned long action, void *hcpu) | ||
107 | { | ||
108 | int cpu = (long)hcpu; | ||
109 | |||
110 | switch (action) { | ||
111 | case CPU_ONLINE: | ||
112 | case CPU_DOWN_FAILED: | ||
113 | /* The notification is sent with interrupts enabled. */ | ||
114 | if (trace_hw_branches_enabled) { | ||
115 | bts_trace_init_cpu(cpu); | ||
116 | |||
117 | if (trace_hw_branches_suspended && | ||
118 | likely(per_cpu(hwb_tracer, cpu))) | ||
119 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
120 | } | ||
121 | break; | ||
122 | |||
123 | case CPU_DOWN_PREPARE: | ||
124 | /* The notification is sent with interrupts enabled. */ | ||
125 | if (likely(per_cpu(hwb_tracer, cpu))) { | ||
126 | ds_release_bts(per_cpu(hwb_tracer, cpu)); | ||
127 | per_cpu(hwb_tracer, cpu) = NULL; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return NOTIFY_DONE; | ||
132 | } | ||
133 | |||
134 | static struct notifier_block bts_hotcpu_notifier __cpuinitdata = { | ||
135 | .notifier_call = bts_hotcpu_handler | ||
136 | }; | ||
137 | |||
138 | static void bts_trace_print_header(struct seq_file *m) | ||
139 | { | ||
140 | seq_puts(m, "# CPU# TO <- FROM\n"); | ||
141 | } | ||
142 | |||
143 | static enum print_line_t bts_trace_print_line(struct trace_iterator *iter) | ||
144 | { | ||
145 | unsigned long symflags = TRACE_ITER_SYM_OFFSET; | ||
146 | struct trace_entry *entry = iter->ent; | ||
147 | struct trace_seq *seq = &iter->seq; | ||
148 | struct hw_branch_entry *it; | ||
149 | |||
150 | trace_assign_type(it, entry); | ||
151 | |||
152 | if (entry->type == TRACE_HW_BRANCHES) { | ||
153 | if (trace_seq_printf(seq, "%4d ", iter->cpu) && | ||
154 | seq_print_ip_sym(seq, it->to, symflags) && | ||
155 | trace_seq_printf(seq, "\t <- ") && | ||
156 | seq_print_ip_sym(seq, it->from, symflags) && | ||
157 | trace_seq_printf(seq, "\n")) | ||
158 | return TRACE_TYPE_HANDLED; | ||
159 | return TRACE_TYPE_PARTIAL_LINE; | ||
160 | } | ||
161 | return TRACE_TYPE_UNHANDLED; | ||
162 | } | ||
163 | |||
164 | void trace_hw_branch(u64 from, u64 to) | ||
165 | { | ||
166 | struct ftrace_event_call *call = &event_hw_branch; | ||
167 | struct trace_array *tr = hw_branch_trace; | ||
168 | struct ring_buffer_event *event; | ||
169 | struct ring_buffer *buf; | ||
170 | struct hw_branch_entry *entry; | ||
171 | unsigned long irq1; | ||
172 | int cpu; | ||
173 | |||
174 | if (unlikely(!tr)) | ||
175 | return; | ||
176 | |||
177 | if (unlikely(!trace_hw_branches_enabled)) | ||
178 | return; | ||
179 | |||
180 | local_irq_save(irq1); | ||
181 | cpu = raw_smp_processor_id(); | ||
182 | if (atomic_inc_return(&tr->data[cpu]->disabled) != 1) | ||
183 | goto out; | ||
184 | |||
185 | buf = tr->buffer; | ||
186 | event = trace_buffer_lock_reserve(buf, TRACE_HW_BRANCHES, | ||
187 | sizeof(*entry), 0, 0); | ||
188 | if (!event) | ||
189 | goto out; | ||
190 | entry = ring_buffer_event_data(event); | ||
191 | tracing_generic_entry_update(&entry->ent, 0, from); | ||
192 | entry->ent.type = TRACE_HW_BRANCHES; | ||
193 | entry->from = from; | ||
194 | entry->to = to; | ||
195 | if (!filter_check_discard(call, entry, buf, event)) | ||
196 | trace_buffer_unlock_commit(buf, event, 0, 0); | ||
197 | |||
198 | out: | ||
199 | atomic_dec(&tr->data[cpu]->disabled); | ||
200 | local_irq_restore(irq1); | ||
201 | } | ||
202 | |||
203 | static void trace_bts_at(const struct bts_trace *trace, void *at) | ||
204 | { | ||
205 | struct bts_struct bts; | ||
206 | int err = 0; | ||
207 | |||
208 | WARN_ON_ONCE(!trace->read); | ||
209 | if (!trace->read) | ||
210 | return; | ||
211 | |||
212 | err = trace->read(this_tracer, at, &bts); | ||
213 | if (err < 0) | ||
214 | return; | ||
215 | |||
216 | switch (bts.qualifier) { | ||
217 | case BTS_BRANCH: | ||
218 | trace_hw_branch(bts.variant.lbr.from, bts.variant.lbr.to); | ||
219 | break; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * Collect the trace on the current cpu and write it into the ftrace buffer. | ||
225 | * | ||
226 | * pre: tracing must be suspended on the current cpu | ||
227 | */ | ||
228 | static void trace_bts_cpu(void *arg) | ||
229 | { | ||
230 | struct trace_array *tr = (struct trace_array *)arg; | ||
231 | const struct bts_trace *trace; | ||
232 | unsigned char *at; | ||
233 | |||
234 | if (unlikely(!tr)) | ||
235 | return; | ||
236 | |||
237 | if (unlikely(atomic_read(&tr->data[raw_smp_processor_id()]->disabled))) | ||
238 | return; | ||
239 | |||
240 | if (unlikely(!this_tracer)) | ||
241 | return; | ||
242 | |||
243 | trace = ds_read_bts(this_tracer); | ||
244 | if (!trace) | ||
245 | return; | ||
246 | |||
247 | for (at = trace->ds.top; (void *)at < trace->ds.end; | ||
248 | at += trace->ds.size) | ||
249 | trace_bts_at(trace, at); | ||
250 | |||
251 | for (at = trace->ds.begin; (void *)at < trace->ds.top; | ||
252 | at += trace->ds.size) | ||
253 | trace_bts_at(trace, at); | ||
254 | } | ||
255 | |||
256 | static void trace_bts_prepare(struct trace_iterator *iter) | ||
257 | { | ||
258 | int cpu; | ||
259 | |||
260 | get_online_cpus(); | ||
261 | for_each_online_cpu(cpu) | ||
262 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
263 | ds_suspend_bts(per_cpu(hwb_tracer, cpu)); | ||
264 | /* | ||
265 | * We need to collect the trace on the respective cpu since ftrace | ||
266 | * implicitly adds the record for the current cpu. | ||
267 | * Once that is more flexible, we could collect the data from any cpu. | ||
268 | */ | ||
269 | on_each_cpu(trace_bts_cpu, iter->tr, 1); | ||
270 | |||
271 | for_each_online_cpu(cpu) | ||
272 | if (likely(per_cpu(hwb_tracer, cpu))) | ||
273 | ds_resume_bts(per_cpu(hwb_tracer, cpu)); | ||
274 | put_online_cpus(); | ||
275 | } | ||
276 | |||
277 | static void trace_bts_close(struct trace_iterator *iter) | ||
278 | { | ||
279 | tracing_reset_online_cpus(iter->tr); | ||
280 | } | ||
281 | |||
282 | void trace_hw_branch_oops(void) | ||
283 | { | ||
284 | if (this_tracer) { | ||
285 | ds_suspend_bts_noirq(this_tracer); | ||
286 | trace_bts_cpu(hw_branch_trace); | ||
287 | ds_resume_bts_noirq(this_tracer); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | struct tracer bts_tracer __read_mostly = | ||
292 | { | ||
293 | .name = "hw-branch-tracer", | ||
294 | .init = bts_trace_init, | ||
295 | .reset = bts_trace_reset, | ||
296 | .print_header = bts_trace_print_header, | ||
297 | .print_line = bts_trace_print_line, | ||
298 | .start = bts_trace_start, | ||
299 | .stop = bts_trace_stop, | ||
300 | .open = trace_bts_prepare, | ||
301 | .close = trace_bts_close, | ||
302 | #ifdef CONFIG_FTRACE_SELFTEST | ||
303 | .selftest = trace_selftest_startup_hw_branches, | ||
304 | #endif /* CONFIG_FTRACE_SELFTEST */ | ||
305 | }; | ||
306 | |||
307 | __init static int init_bts_trace(void) | ||
308 | { | ||
309 | register_hotcpu_notifier(&bts_hotcpu_notifier); | ||
310 | return register_tracer(&bts_tracer); | ||
311 | } | ||
312 | device_initcall(init_bts_trace); | ||
diff --git a/kernel/trace/trace_irqsoff.c b/kernel/trace/trace_irqsoff.c index 2974bc7538c7..6fd486e0cef4 100644 --- a/kernel/trace/trace_irqsoff.c +++ b/kernel/trace/trace_irqsoff.c | |||
@@ -34,6 +34,9 @@ static int trace_type __read_mostly; | |||
34 | 34 | ||
35 | static int save_lat_flag; | 35 | static int save_lat_flag; |
36 | 36 | ||
37 | static void stop_irqsoff_tracer(struct trace_array *tr, int graph); | ||
38 | static int start_irqsoff_tracer(struct trace_array *tr, int graph); | ||
39 | |||
37 | #ifdef CONFIG_PREEMPT_TRACER | 40 | #ifdef CONFIG_PREEMPT_TRACER |
38 | static inline int | 41 | static inline int |
39 | preempt_trace(void) | 42 | preempt_trace(void) |
@@ -55,6 +58,23 @@ irq_trace(void) | |||
55 | # define irq_trace() (0) | 58 | # define irq_trace() (0) |
56 | #endif | 59 | #endif |
57 | 60 | ||
61 | #define TRACE_DISPLAY_GRAPH 1 | ||
62 | |||
63 | static struct tracer_opt trace_opts[] = { | ||
64 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
65 | /* display latency trace as call graph */ | ||
66 | { TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) }, | ||
67 | #endif | ||
68 | { } /* Empty entry */ | ||
69 | }; | ||
70 | |||
71 | static struct tracer_flags tracer_flags = { | ||
72 | .val = 0, | ||
73 | .opts = trace_opts, | ||
74 | }; | ||
75 | |||
76 | #define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH) | ||
77 | |||
58 | /* | 78 | /* |
59 | * Sequence count - we record it when starting a measurement and | 79 | * Sequence count - we record it when starting a measurement and |
60 | * skip the latency if the sequence has changed - some other section | 80 | * skip the latency if the sequence has changed - some other section |
@@ -108,6 +128,202 @@ static struct ftrace_ops trace_ops __read_mostly = | |||
108 | }; | 128 | }; |
109 | #endif /* CONFIG_FUNCTION_TRACER */ | 129 | #endif /* CONFIG_FUNCTION_TRACER */ |
110 | 130 | ||
131 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | ||
132 | static int irqsoff_set_flag(u32 old_flags, u32 bit, int set) | ||
133 | { | ||
134 | int cpu; | ||
135 | |||
136 | if (!(bit & TRACE_DISPLAY_GRAPH)) | ||
137 | return -EINVAL; | ||
138 | |||
139 | if (!(is_graph() ^ set)) | ||
140 | return 0; | ||
141 | |||
142 | stop_irqsoff_tracer(irqsoff_trace, !set); | ||
143 | |||
144 | for_each_possible_cpu(cpu) | ||
145 | per_cpu(tracing_cpu, cpu) = 0; | ||
146 | |||
147 | tracing_max_latency = 0; | ||
148 | tracing_reset_online_cpus(irqsoff_trace); | ||
149 | |||
150 | return start_irqsoff_tracer(irqsoff_trace, set); | ||
151 | } | ||
152 | |||
153 | static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) | ||
154 | { | ||
155 | struct trace_array *tr = irqsoff_trace; | ||
156 | struct trace_array_cpu *data; | ||
157 | unsigned long flags; | ||
158 | long disabled; | ||
159 | int ret; | ||
160 | int cpu; | ||
161 | int pc; | ||
162 | |||
163 | cpu = raw_smp_processor_id(); | ||
164 | if (likely(!per_cpu(tracing_cpu, cpu))) | ||
165 | return 0; | ||
166 | |||
167 | local_save_flags(flags); | ||
168 | /* slight chance to get a false positive on tracing_cpu */ | ||
169 | if (!irqs_disabled_flags(flags)) | ||
170 | return 0; | ||
171 | |||
172 | data = tr->data[cpu]; | ||
173 | disabled = atomic_inc_return(&data->disabled); | ||
174 | |||
175 | if (likely(disabled == 1)) { | ||
176 | pc = preempt_count(); | ||
177 | ret = __trace_graph_entry(tr, trace, flags, pc); | ||
178 | } else | ||
179 | ret = 0; | ||
180 | |||
181 | atomic_dec(&data->disabled); | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | static void irqsoff_graph_return(struct ftrace_graph_ret *trace) | ||
186 | { | ||
187 | struct trace_array *tr = irqsoff_trace; | ||
188 | struct trace_array_cpu *data; | ||
189 | unsigned long flags; | ||
190 | long disabled; | ||
191 | int cpu; | ||
192 | int pc; | ||
193 | |||
194 | cpu = raw_smp_processor_id(); | ||
195 | if (likely(!per_cpu(tracing_cpu, cpu))) | ||
196 | return; | ||
197 | |||
198 | local_save_flags(flags); | ||
199 | /* slight chance to get a false positive on tracing_cpu */ | ||
200 | if (!irqs_disabled_flags(flags)) | ||
201 | return; | ||
202 | |||
203 | data = tr->data[cpu]; | ||
204 | disabled = atomic_inc_return(&data->disabled); | ||
205 | |||
206 | if (likely(disabled == 1)) { | ||
207 | pc = preempt_count(); | ||
208 | __trace_graph_return(tr, trace, flags, pc); | ||
209 | } | ||
210 | |||
211 | atomic_dec(&data->disabled); | ||
212 | } | ||
213 | |||
214 | static void irqsoff_trace_open(struct trace_iterator *iter) | ||
215 | { | ||
216 | if (is_graph()) | ||
217 | graph_trace_open(iter); | ||
218 | |||
219 | } | ||
220 | |||
221 | static void irqsoff_trace_close(struct trace_iterator *iter) | ||
222 | { | ||
223 | if (iter->private) | ||
224 | graph_trace_close(iter); | ||
225 | } | ||
226 | |||
227 | #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \ | ||
228 | TRACE_GRAPH_PRINT_PROC) | ||
229 | |||
230 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) | ||
231 | { | ||
232 | u32 flags = GRAPH_TRACER_FLAGS; | ||
233 | |||
234 | if (trace_flags & TRACE_ITER_LATENCY_FMT) | ||
235 | flags |= TRACE_GRAPH_PRINT_DURATION; | ||
236 | else | ||
237 | flags |= TRACE_GRAPH_PRINT_ABS_TIME; | ||
238 | |||
239 | /* | ||
240 | * In graph mode call the graph tracer output function, | ||
241 | * otherwise go with the TRACE_FN event handler | ||
242 | */ | ||
243 | if (is_graph()) | ||
244 | return print_graph_function_flags(iter, flags); | ||
245 | |||
246 | return TRACE_TYPE_UNHANDLED; | ||
247 | } | ||
248 | |||
249 | static void irqsoff_print_header(struct seq_file *s) | ||
250 | { | ||
251 | if (is_graph()) { | ||
252 | struct trace_iterator *iter = s->private; | ||
253 | u32 flags = GRAPH_TRACER_FLAGS; | ||
254 | |||
255 | if (trace_flags & TRACE_ITER_LATENCY_FMT) { | ||
256 | /* print nothing if the buffers are empty */ | ||
257 | if (trace_empty(iter)) | ||
258 | return; | ||
259 | |||
260 | print_trace_header(s, iter); | ||
261 | flags |= TRACE_GRAPH_PRINT_DURATION; | ||
262 | } else | ||
263 | flags |= TRACE_GRAPH_PRINT_ABS_TIME; | ||
264 | |||
265 | print_graph_headers_flags(s, flags); | ||
266 | } else | ||
267 | trace_default_header(s); | ||
268 | } | ||
269 | |||
270 | static void | ||
271 | trace_graph_function(struct trace_array *tr, | ||
272 | unsigned long ip, unsigned long flags, int pc) | ||
273 | { | ||
274 | u64 time = trace_clock_local(); | ||
275 | struct ftrace_graph_ent ent = { | ||
276 | .func = ip, | ||
277 | .depth = 0, | ||
278 | }; | ||
279 | struct ftrace_graph_ret ret = { | ||
280 | .func = ip, | ||
281 | .depth = 0, | ||
282 | .calltime = time, | ||
283 | .rettime = time, | ||
284 | }; | ||
285 | |||
286 | __trace_graph_entry(tr, &ent, flags, pc); | ||
287 | __trace_graph_return(tr, &ret, flags, pc); | ||
288 | } | ||
289 | |||
290 | static void | ||
291 | __trace_function(struct trace_array *tr, | ||
292 | unsigned long ip, unsigned long parent_ip, | ||
293 | unsigned long flags, int pc) | ||
294 | { | ||
295 | if (!is_graph()) | ||
296 | trace_function(tr, ip, parent_ip, flags, pc); | ||
297 | else { | ||
298 | trace_graph_function(tr, parent_ip, flags, pc); | ||
299 | trace_graph_function(tr, ip, flags, pc); | ||
300 | } | ||
301 | } | ||
302 | |||
303 | #else | ||
304 | #define __trace_function trace_function | ||
305 | |||
306 | static int irqsoff_set_flag(u32 old_flags, u32 bit, int set) | ||
307 | { | ||
308 | return -EINVAL; | ||
309 | } | ||
310 | |||
311 | static int irqsoff_graph_entry(struct ftrace_graph_ent *trace) | ||
312 | { | ||
313 | return -1; | ||
314 | } | ||
315 | |||
316 | static enum print_line_t irqsoff_print_line(struct trace_iterator *iter) | ||
317 | { | ||
318 | return TRACE_TYPE_UNHANDLED; | ||
319 | } | ||
320 | |||
321 | static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { } | ||
322 | static void irqsoff_print_header(struct seq_file *s) { } | ||
323 | static void irqsoff_trace_open(struct trace_iterator *iter) { } | ||
324 | static void irqsoff_trace_close(struct trace_iterator *iter) { } | ||
325 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | ||
326 | |||
111 | /* | 327 | /* |
112 | * Should this new latency be reported/recorded? | 328 | * Should this new latency be reported/recorded? |
113 | */ | 329 | */ |
@@ -150,7 +366,7 @@ check_critical_timing(struct trace_array *tr, | |||
150 | if (!report_latency(delta)) | 366 | if (!report_latency(delta)) |
151 | goto out_unlock; | 367 | goto out_unlock; |
152 | 368 | ||
153 | trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); | 369 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
154 | /* Skip 5 functions to get to the irq/preempt enable function */ | 370 | /* Skip 5 functions to get to the irq/preempt enable function */ |
155 | __trace_stack(tr, flags, 5, pc); | 371 | __trace_stack(tr, flags, 5, pc); |
156 | 372 | ||
@@ -172,7 +388,7 @@ out_unlock: | |||
172 | out: | 388 | out: |
173 | data->critical_sequence = max_sequence; | 389 | data->critical_sequence = max_sequence; |
174 | data->preempt_timestamp = ftrace_now(cpu); | 390 | data->preempt_timestamp = ftrace_now(cpu); |
175 | trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); | 391 | __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc); |
176 | } | 392 | } |
177 | 393 | ||
178 | static inline void | 394 | static inline void |
@@ -204,7 +420,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip) | |||
204 | 420 | ||
205 | local_save_flags(flags); | 421 | local_save_flags(flags); |
206 | 422 | ||
207 | trace_function(tr, ip, parent_ip, flags, preempt_count()); | 423 | __trace_function(tr, ip, parent_ip, flags, preempt_count()); |
208 | 424 | ||
209 | per_cpu(tracing_cpu, cpu) = 1; | 425 | per_cpu(tracing_cpu, cpu) = 1; |
210 | 426 | ||
@@ -238,7 +454,7 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip) | |||
238 | atomic_inc(&data->disabled); | 454 | atomic_inc(&data->disabled); |
239 | 455 | ||
240 | local_save_flags(flags); | 456 | local_save_flags(flags); |
241 | trace_function(tr, ip, parent_ip, flags, preempt_count()); | 457 | __trace_function(tr, ip, parent_ip, flags, preempt_count()); |
242 | check_critical_timing(tr, data, parent_ip ? : ip, cpu); | 458 | check_critical_timing(tr, data, parent_ip ? : ip, cpu); |
243 | data->critical_start = 0; | 459 | data->critical_start = 0; |
244 | atomic_dec(&data->disabled); | 460 | atomic_dec(&data->disabled); |
@@ -347,19 +563,32 @@ void trace_preempt_off(unsigned long a0, unsigned long a1) | |||
347 | } | 563 | } |
348 | #endif /* CONFIG_PREEMPT_TRACER */ | 564 | #endif /* CONFIG_PREEMPT_TRACER */ |
349 | 565 | ||
350 | static void start_irqsoff_tracer(struct trace_array *tr) | 566 | static int start_irqsoff_tracer(struct trace_array *tr, int graph) |
351 | { | 567 | { |
352 | register_ftrace_function(&trace_ops); | 568 | int ret = 0; |
353 | if (tracing_is_enabled()) | 569 | |
570 | if (!graph) | ||
571 | ret = register_ftrace_function(&trace_ops); | ||
572 | else | ||
573 | ret = register_ftrace_graph(&irqsoff_graph_return, | ||
574 | &irqsoff_graph_entry); | ||
575 | |||
576 | if (!ret && tracing_is_enabled()) | ||
354 | tracer_enabled = 1; | 577 | tracer_enabled = 1; |
355 | else | 578 | else |
356 | tracer_enabled = 0; | 579 | tracer_enabled = 0; |
580 | |||
581 | return ret; | ||
357 | } | 582 | } |
358 | 583 | ||
359 | static void stop_irqsoff_tracer(struct trace_array *tr) | 584 | static void stop_irqsoff_tracer(struct trace_array *tr, int graph) |
360 | { | 585 | { |
361 | tracer_enabled = 0; | 586 | tracer_enabled = 0; |
362 | unregister_ftrace_function(&trace_ops); | 587 | |
588 | if (!graph) | ||
589 | unregister_ftrace_function(&trace_ops); | ||
590 | else | ||
591 | unregister_ftrace_graph(); | ||
363 | } | 592 | } |
364 | 593 | ||
365 | static void __irqsoff_tracer_init(struct trace_array *tr) | 594 | static void __irqsoff_tracer_init(struct trace_array *tr) |
@@ -372,12 +601,14 @@ static void __irqsoff_tracer_init(struct trace_array *tr) | |||
372 | /* make sure that the tracer is visible */ | 601 | /* make sure that the tracer is visible */ |
373 | smp_wmb(); | 602 | smp_wmb(); |
374 | tracing_reset_online_cpus(tr); | 603 | tracing_reset_online_cpus(tr); |
375 | start_irqsoff_tracer(tr); | 604 | |
605 | if (start_irqsoff_tracer(tr, is_graph())) | ||
606 | printk(KERN_ERR "failed to start irqsoff tracer\n"); | ||
376 | } | 607 | } |
377 | 608 | ||
378 | static void irqsoff_tracer_reset(struct trace_array *tr) | 609 | static void irqsoff_tracer_reset(struct trace_array *tr) |
379 | { | 610 | { |
380 | stop_irqsoff_tracer(tr); | 611 | stop_irqsoff_tracer(tr, is_graph()); |
381 | 612 | ||
382 | if (!save_lat_flag) | 613 | if (!save_lat_flag) |
383 | trace_flags &= ~TRACE_ITER_LATENCY_FMT; | 614 | trace_flags &= ~TRACE_ITER_LATENCY_FMT; |
@@ -409,9 +640,15 @@ static struct tracer irqsoff_tracer __read_mostly = | |||
409 | .start = irqsoff_tracer_start, | 640 | .start = irqsoff_tracer_start, |
410 | .stop = irqsoff_tracer_stop, | 641 | .stop = irqsoff_tracer_stop, |
411 | .print_max = 1, | 642 | .print_max = 1, |
643 | .print_header = irqsoff_print_header, | ||
644 | .print_line = irqsoff_print_line, | ||
645 | .flags = &tracer_flags, | ||
646 | .set_flag = irqsoff_set_flag, | ||
412 | #ifdef CONFIG_FTRACE_SELFTEST | 647 | #ifdef CONFIG_FTRACE_SELFTEST |
413 | .selftest = trace_selftest_startup_irqsoff, | 648 | .selftest = trace_selftest_startup_irqsoff, |
414 | #endif | 649 | #endif |
650 | .open = irqsoff_trace_open, | ||
651 | .close = irqsoff_trace_close, | ||
415 | }; | 652 | }; |
416 | # define register_irqsoff(trace) register_tracer(&trace) | 653 | # define register_irqsoff(trace) register_tracer(&trace) |
417 | #else | 654 | #else |
@@ -435,9 +672,15 @@ static struct tracer preemptoff_tracer __read_mostly = | |||
435 | .start = irqsoff_tracer_start, | 672 | .start = irqsoff_tracer_start, |
436 | .stop = irqsoff_tracer_stop, | 673 | .stop = irqsoff_tracer_stop, |
437 | .print_max = 1, | 674 | .print_max = 1, |
675 | .print_header = irqsoff_print_header, | ||
676 | .print_line = irqsoff_print_line, | ||
677 | .flags = &tracer_flags, | ||
678 | .set_flag = irqsoff_set_flag, | ||
438 | #ifdef CONFIG_FTRACE_SELFTEST | 679 | #ifdef CONFIG_FTRACE_SELFTEST |
439 | .selftest = trace_selftest_startup_preemptoff, | 680 | .selftest = trace_selftest_startup_preemptoff, |
440 | #endif | 681 | #endif |
682 | .open = irqsoff_trace_open, | ||
683 | .close = irqsoff_trace_close, | ||
441 | }; | 684 | }; |
442 | # define register_preemptoff(trace) register_tracer(&trace) | 685 | # define register_preemptoff(trace) register_tracer(&trace) |
443 | #else | 686 | #else |
@@ -463,9 +706,15 @@ static struct tracer preemptirqsoff_tracer __read_mostly = | |||
463 | .start = irqsoff_tracer_start, | 706 | .start = irqsoff_tracer_start, |
464 | .stop = irqsoff_tracer_stop, | 707 | .stop = irqsoff_tracer_stop, |
465 | .print_max = 1, | 708 | .print_max = 1, |
709 | .print_header = irqsoff_print_header, | ||
710 | .print_line = irqsoff_print_line, | ||
711 | .flags = &tracer_flags, | ||
712 | .set_flag = irqsoff_set_flag, | ||
466 | #ifdef CONFIG_FTRACE_SELFTEST | 713 | #ifdef CONFIG_FTRACE_SELFTEST |
467 | .selftest = trace_selftest_startup_preemptirqsoff, | 714 | .selftest = trace_selftest_startup_preemptirqsoff, |
468 | #endif | 715 | #endif |
716 | .open = irqsoff_trace_open, | ||
717 | .close = irqsoff_trace_close, | ||
469 | }; | 718 | }; |
470 | 719 | ||
471 | # define register_preemptirqsoff(trace) register_tracer(&trace) | 720 | # define register_preemptirqsoff(trace) register_tracer(&trace) |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 1251e367bae9..a7514326052b 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <linux/ctype.h> | 29 | #include <linux/ctype.h> |
30 | #include <linux/ptrace.h> | 30 | #include <linux/ptrace.h> |
31 | #include <linux/perf_event.h> | 31 | #include <linux/perf_event.h> |
32 | #include <linux/stringify.h> | ||
33 | #include <asm/bitsperlong.h> | ||
32 | 34 | ||
33 | #include "trace.h" | 35 | #include "trace.h" |
34 | #include "trace_output.h" | 36 | #include "trace_output.h" |
@@ -40,7 +42,6 @@ | |||
40 | 42 | ||
41 | /* Reserved field names */ | 43 | /* Reserved field names */ |
42 | #define FIELD_STRING_IP "__probe_ip" | 44 | #define FIELD_STRING_IP "__probe_ip" |
43 | #define FIELD_STRING_NARGS "__probe_nargs" | ||
44 | #define FIELD_STRING_RETIP "__probe_ret_ip" | 45 | #define FIELD_STRING_RETIP "__probe_ret_ip" |
45 | #define FIELD_STRING_FUNC "__probe_func" | 46 | #define FIELD_STRING_FUNC "__probe_func" |
46 | 47 | ||
@@ -52,56 +53,102 @@ const char *reserved_field_names[] = { | |||
52 | "common_tgid", | 53 | "common_tgid", |
53 | "common_lock_depth", | 54 | "common_lock_depth", |
54 | FIELD_STRING_IP, | 55 | FIELD_STRING_IP, |
55 | FIELD_STRING_NARGS, | ||
56 | FIELD_STRING_RETIP, | 56 | FIELD_STRING_RETIP, |
57 | FIELD_STRING_FUNC, | 57 | FIELD_STRING_FUNC, |
58 | }; | 58 | }; |
59 | 59 | ||
60 | struct fetch_func { | 60 | /* Printing function type */ |
61 | unsigned long (*func)(struct pt_regs *, void *); | 61 | typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *); |
62 | #define PRINT_TYPE_FUNC_NAME(type) print_type_##type | ||
63 | #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type | ||
64 | |||
65 | /* Printing in basic type function template */ | ||
66 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast) \ | ||
67 | static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \ | ||
68 | const char *name, void *data)\ | ||
69 | { \ | ||
70 | return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\ | ||
71 | } \ | ||
72 | static const char PRINT_TYPE_FMT_NAME(type)[] = fmt; | ||
73 | |||
74 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8, "%x", unsigned int) | ||
75 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "%x", unsigned int) | ||
76 | DEFINE_BASIC_PRINT_TYPE_FUNC(u32, "%lx", unsigned long) | ||
77 | DEFINE_BASIC_PRINT_TYPE_FUNC(u64, "%llx", unsigned long long) | ||
78 | DEFINE_BASIC_PRINT_TYPE_FUNC(s8, "%d", int) | ||
79 | DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d", int) | ||
80 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%ld", long) | ||
81 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%lld", long long) | ||
82 | |||
83 | /* Data fetch function type */ | ||
84 | typedef void (*fetch_func_t)(struct pt_regs *, void *, void *); | ||
85 | |||
86 | struct fetch_param { | ||
87 | fetch_func_t fn; | ||
62 | void *data; | 88 | void *data; |
63 | }; | 89 | }; |
64 | 90 | ||
65 | static __kprobes unsigned long call_fetch(struct fetch_func *f, | 91 | static __kprobes void call_fetch(struct fetch_param *fprm, |
66 | struct pt_regs *regs) | 92 | struct pt_regs *regs, void *dest) |
67 | { | 93 | { |
68 | return f->func(regs, f->data); | 94 | return fprm->fn(regs, fprm->data, dest); |
69 | } | 95 | } |
70 | 96 | ||
71 | /* fetch handlers */ | 97 | #define FETCH_FUNC_NAME(kind, type) fetch_##kind##_##type |
72 | static __kprobes unsigned long fetch_register(struct pt_regs *regs, | 98 | /* |
73 | void *offset) | 99 | * Define macro for basic types - we don't need to define s* types, because |
74 | { | 100 | * we have to care only about bitwidth at recording time. |
75 | return regs_get_register(regs, (unsigned int)((unsigned long)offset)); | 101 | */ |
102 | #define DEFINE_BASIC_FETCH_FUNCS(kind) \ | ||
103 | DEFINE_FETCH_##kind(u8) \ | ||
104 | DEFINE_FETCH_##kind(u16) \ | ||
105 | DEFINE_FETCH_##kind(u32) \ | ||
106 | DEFINE_FETCH_##kind(u64) | ||
107 | |||
108 | #define CHECK_BASIC_FETCH_FUNCS(kind, fn) \ | ||
109 | ((FETCH_FUNC_NAME(kind, u8) == fn) || \ | ||
110 | (FETCH_FUNC_NAME(kind, u16) == fn) || \ | ||
111 | (FETCH_FUNC_NAME(kind, u32) == fn) || \ | ||
112 | (FETCH_FUNC_NAME(kind, u64) == fn)) | ||
113 | |||
114 | /* Data fetch function templates */ | ||
115 | #define DEFINE_FETCH_reg(type) \ | ||
116 | static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \ | ||
117 | void *offset, void *dest) \ | ||
118 | { \ | ||
119 | *(type *)dest = (type)regs_get_register(regs, \ | ||
120 | (unsigned int)((unsigned long)offset)); \ | ||
76 | } | 121 | } |
77 | 122 | DEFINE_BASIC_FETCH_FUNCS(reg) | |
78 | static __kprobes unsigned long fetch_stack(struct pt_regs *regs, | 123 | |
79 | void *num) | 124 | #define DEFINE_FETCH_stack(type) \ |
80 | { | 125 | static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\ |
81 | return regs_get_kernel_stack_nth(regs, | 126 | void *offset, void *dest) \ |
82 | (unsigned int)((unsigned long)num)); | 127 | { \ |
128 | *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ | ||
129 | (unsigned int)((unsigned long)offset)); \ | ||
83 | } | 130 | } |
131 | DEFINE_BASIC_FETCH_FUNCS(stack) | ||
84 | 132 | ||
85 | static __kprobes unsigned long fetch_memory(struct pt_regs *regs, void *addr) | 133 | #define DEFINE_FETCH_retval(type) \ |
86 | { | 134 | static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\ |
87 | unsigned long retval; | 135 | void *dummy, void *dest) \ |
88 | 136 | { \ | |
89 | if (probe_kernel_address(addr, retval)) | 137 | *(type *)dest = (type)regs_return_value(regs); \ |
90 | return 0; | ||
91 | return retval; | ||
92 | } | 138 | } |
93 | 139 | DEFINE_BASIC_FETCH_FUNCS(retval) | |
94 | static __kprobes unsigned long fetch_retvalue(struct pt_regs *regs, | 140 | |
95 | void *dummy) | 141 | #define DEFINE_FETCH_memory(type) \ |
96 | { | 142 | static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\ |
97 | return regs_return_value(regs); | 143 | void *addr, void *dest) \ |
98 | } | 144 | { \ |
99 | 145 | type retval; \ | |
100 | static __kprobes unsigned long fetch_stack_address(struct pt_regs *regs, | 146 | if (probe_kernel_address(addr, retval)) \ |
101 | void *dummy) | 147 | *(type *)dest = 0; \ |
102 | { | 148 | else \ |
103 | return kernel_stack_pointer(regs); | 149 | *(type *)dest = retval; \ |
104 | } | 150 | } |
151 | DEFINE_BASIC_FETCH_FUNCS(memory) | ||
105 | 152 | ||
106 | /* Memory fetching by symbol */ | 153 | /* Memory fetching by symbol */ |
107 | struct symbol_cache { | 154 | struct symbol_cache { |
@@ -145,51 +192,126 @@ static struct symbol_cache *alloc_symbol_cache(const char *sym, long offset) | |||
145 | return sc; | 192 | return sc; |
146 | } | 193 | } |
147 | 194 | ||
148 | static __kprobes unsigned long fetch_symbol(struct pt_regs *regs, void *data) | 195 | #define DEFINE_FETCH_symbol(type) \ |
149 | { | 196 | static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\ |
150 | struct symbol_cache *sc = data; | 197 | void *data, void *dest) \ |
151 | 198 | { \ | |
152 | if (sc->addr) | 199 | struct symbol_cache *sc = data; \ |
153 | return fetch_memory(regs, (void *)sc->addr); | 200 | if (sc->addr) \ |
154 | else | 201 | fetch_memory_##type(regs, (void *)sc->addr, dest); \ |
155 | return 0; | 202 | else \ |
203 | *(type *)dest = 0; \ | ||
156 | } | 204 | } |
205 | DEFINE_BASIC_FETCH_FUNCS(symbol) | ||
157 | 206 | ||
158 | /* Special indirect memory access interface */ | 207 | /* Dereference memory access function */ |
159 | struct indirect_fetch_data { | 208 | struct deref_fetch_param { |
160 | struct fetch_func orig; | 209 | struct fetch_param orig; |
161 | long offset; | 210 | long offset; |
162 | }; | 211 | }; |
163 | 212 | ||
164 | static __kprobes unsigned long fetch_indirect(struct pt_regs *regs, void *data) | 213 | #define DEFINE_FETCH_deref(type) \ |
165 | { | 214 | static __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs,\ |
166 | struct indirect_fetch_data *ind = data; | 215 | void *data, void *dest) \ |
167 | unsigned long addr; | 216 | { \ |
168 | 217 | struct deref_fetch_param *dprm = data; \ | |
169 | addr = call_fetch(&ind->orig, regs); | 218 | unsigned long addr; \ |
170 | if (addr) { | 219 | call_fetch(&dprm->orig, regs, &addr); \ |
171 | addr += ind->offset; | 220 | if (addr) { \ |
172 | return fetch_memory(regs, (void *)addr); | 221 | addr += dprm->offset; \ |
173 | } else | 222 | fetch_memory_##type(regs, (void *)addr, dest); \ |
174 | return 0; | 223 | } else \ |
224 | *(type *)dest = 0; \ | ||
175 | } | 225 | } |
226 | DEFINE_BASIC_FETCH_FUNCS(deref) | ||
176 | 227 | ||
177 | static __kprobes void free_indirect_fetch_data(struct indirect_fetch_data *data) | 228 | static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) |
178 | { | 229 | { |
179 | if (data->orig.func == fetch_indirect) | 230 | if (CHECK_BASIC_FETCH_FUNCS(deref, data->orig.fn)) |
180 | free_indirect_fetch_data(data->orig.data); | 231 | free_deref_fetch_param(data->orig.data); |
181 | else if (data->orig.func == fetch_symbol) | 232 | else if (CHECK_BASIC_FETCH_FUNCS(symbol, data->orig.fn)) |
182 | free_symbol_cache(data->orig.data); | 233 | free_symbol_cache(data->orig.data); |
183 | kfree(data); | 234 | kfree(data); |
184 | } | 235 | } |
185 | 236 | ||
237 | /* Default (unsigned long) fetch type */ | ||
238 | #define __DEFAULT_FETCH_TYPE(t) u##t | ||
239 | #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) | ||
240 | #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG) | ||
241 | #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) | ||
242 | |||
243 | #define ASSIGN_FETCH_FUNC(kind, type) \ | ||
244 | .kind = FETCH_FUNC_NAME(kind, type) | ||
245 | |||
246 | #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \ | ||
247 | {.name = #ptype, \ | ||
248 | .size = sizeof(ftype), \ | ||
249 | .is_signed = sign, \ | ||
250 | .print = PRINT_TYPE_FUNC_NAME(ptype), \ | ||
251 | .fmt = PRINT_TYPE_FMT_NAME(ptype), \ | ||
252 | ASSIGN_FETCH_FUNC(reg, ftype), \ | ||
253 | ASSIGN_FETCH_FUNC(stack, ftype), \ | ||
254 | ASSIGN_FETCH_FUNC(retval, ftype), \ | ||
255 | ASSIGN_FETCH_FUNC(memory, ftype), \ | ||
256 | ASSIGN_FETCH_FUNC(symbol, ftype), \ | ||
257 | ASSIGN_FETCH_FUNC(deref, ftype), \ | ||
258 | } | ||
259 | |||
260 | /* Fetch type information table */ | ||
261 | static const struct fetch_type { | ||
262 | const char *name; /* Name of type */ | ||
263 | size_t size; /* Byte size of type */ | ||
264 | int is_signed; /* Signed flag */ | ||
265 | print_type_func_t print; /* Print functions */ | ||
266 | const char *fmt; /* Fromat string */ | ||
267 | /* Fetch functions */ | ||
268 | fetch_func_t reg; | ||
269 | fetch_func_t stack; | ||
270 | fetch_func_t retval; | ||
271 | fetch_func_t memory; | ||
272 | fetch_func_t symbol; | ||
273 | fetch_func_t deref; | ||
274 | } fetch_type_table[] = { | ||
275 | ASSIGN_FETCH_TYPE(u8, u8, 0), | ||
276 | ASSIGN_FETCH_TYPE(u16, u16, 0), | ||
277 | ASSIGN_FETCH_TYPE(u32, u32, 0), | ||
278 | ASSIGN_FETCH_TYPE(u64, u64, 0), | ||
279 | ASSIGN_FETCH_TYPE(s8, u8, 1), | ||
280 | ASSIGN_FETCH_TYPE(s16, u16, 1), | ||
281 | ASSIGN_FETCH_TYPE(s32, u32, 1), | ||
282 | ASSIGN_FETCH_TYPE(s64, u64, 1), | ||
283 | }; | ||
284 | |||
285 | static const struct fetch_type *find_fetch_type(const char *type) | ||
286 | { | ||
287 | int i; | ||
288 | |||
289 | if (!type) | ||
290 | type = DEFAULT_FETCH_TYPE_STR; | ||
291 | |||
292 | for (i = 0; i < ARRAY_SIZE(fetch_type_table); i++) | ||
293 | if (strcmp(type, fetch_type_table[i].name) == 0) | ||
294 | return &fetch_type_table[i]; | ||
295 | return NULL; | ||
296 | } | ||
297 | |||
298 | /* Special function : only accept unsigned long */ | ||
299 | static __kprobes void fetch_stack_address(struct pt_regs *regs, | ||
300 | void *dummy, void *dest) | ||
301 | { | ||
302 | *(unsigned long *)dest = kernel_stack_pointer(regs); | ||
303 | } | ||
304 | |||
186 | /** | 305 | /** |
187 | * Kprobe event core functions | 306 | * Kprobe event core functions |
188 | */ | 307 | */ |
189 | 308 | ||
190 | struct probe_arg { | 309 | struct probe_arg { |
191 | struct fetch_func fetch; | 310 | struct fetch_param fetch; |
192 | const char *name; | 311 | unsigned int offset; /* Offset from argument entry */ |
312 | const char *name; /* Name of this argument */ | ||
313 | const char *comm; /* Command of this argument */ | ||
314 | const struct fetch_type *type; /* Type of this argument */ | ||
193 | }; | 315 | }; |
194 | 316 | ||
195 | /* Flags for trace_probe */ | 317 | /* Flags for trace_probe */ |
@@ -204,6 +326,7 @@ struct trace_probe { | |||
204 | const char *symbol; /* symbol name */ | 326 | const char *symbol; /* symbol name */ |
205 | struct ftrace_event_call call; | 327 | struct ftrace_event_call call; |
206 | struct trace_event event; | 328 | struct trace_event event; |
329 | ssize_t size; /* trace entry size */ | ||
207 | unsigned int nr_args; | 330 | unsigned int nr_args; |
208 | struct probe_arg args[]; | 331 | struct probe_arg args[]; |
209 | }; | 332 | }; |
@@ -212,6 +335,7 @@ struct trace_probe { | |||
212 | (offsetof(struct trace_probe, args) + \ | 335 | (offsetof(struct trace_probe, args) + \ |
213 | (sizeof(struct probe_arg) * (n))) | 336 | (sizeof(struct probe_arg) * (n))) |
214 | 337 | ||
338 | |||
215 | static __kprobes int probe_is_return(struct trace_probe *tp) | 339 | static __kprobes int probe_is_return(struct trace_probe *tp) |
216 | { | 340 | { |
217 | return tp->rp.handler != NULL; | 341 | return tp->rp.handler != NULL; |
@@ -222,49 +346,6 @@ static __kprobes const char *probe_symbol(struct trace_probe *tp) | |||
222 | return tp->symbol ? tp->symbol : "unknown"; | 346 | return tp->symbol ? tp->symbol : "unknown"; |
223 | } | 347 | } |
224 | 348 | ||
225 | static int probe_arg_string(char *buf, size_t n, struct fetch_func *ff) | ||
226 | { | ||
227 | int ret = -EINVAL; | ||
228 | |||
229 | if (ff->func == fetch_register) { | ||
230 | const char *name; | ||
231 | name = regs_query_register_name((unsigned int)((long)ff->data)); | ||
232 | ret = snprintf(buf, n, "%%%s", name); | ||
233 | } else if (ff->func == fetch_stack) | ||
234 | ret = snprintf(buf, n, "$stack%lu", (unsigned long)ff->data); | ||
235 | else if (ff->func == fetch_memory) | ||
236 | ret = snprintf(buf, n, "@0x%p", ff->data); | ||
237 | else if (ff->func == fetch_symbol) { | ||
238 | struct symbol_cache *sc = ff->data; | ||
239 | if (sc->offset) | ||
240 | ret = snprintf(buf, n, "@%s%+ld", sc->symbol, | ||
241 | sc->offset); | ||
242 | else | ||
243 | ret = snprintf(buf, n, "@%s", sc->symbol); | ||
244 | } else if (ff->func == fetch_retvalue) | ||
245 | ret = snprintf(buf, n, "$retval"); | ||
246 | else if (ff->func == fetch_stack_address) | ||
247 | ret = snprintf(buf, n, "$stack"); | ||
248 | else if (ff->func == fetch_indirect) { | ||
249 | struct indirect_fetch_data *id = ff->data; | ||
250 | size_t l = 0; | ||
251 | ret = snprintf(buf, n, "%+ld(", id->offset); | ||
252 | if (ret >= n) | ||
253 | goto end; | ||
254 | l += ret; | ||
255 | ret = probe_arg_string(buf + l, n - l, &id->orig); | ||
256 | if (ret < 0) | ||
257 | goto end; | ||
258 | l += ret; | ||
259 | ret = snprintf(buf + l, n - l, ")"); | ||
260 | ret += l; | ||
261 | } | ||
262 | end: | ||
263 | if (ret >= n) | ||
264 | return -ENOSPC; | ||
265 | return ret; | ||
266 | } | ||
267 | |||
268 | static int register_probe_event(struct trace_probe *tp); | 349 | static int register_probe_event(struct trace_probe *tp); |
269 | static void unregister_probe_event(struct trace_probe *tp); | 350 | static void unregister_probe_event(struct trace_probe *tp); |
270 | 351 | ||
@@ -347,11 +428,12 @@ error: | |||
347 | 428 | ||
348 | static void free_probe_arg(struct probe_arg *arg) | 429 | static void free_probe_arg(struct probe_arg *arg) |
349 | { | 430 | { |
350 | if (arg->fetch.func == fetch_symbol) | 431 | if (CHECK_BASIC_FETCH_FUNCS(deref, arg->fetch.fn)) |
432 | free_deref_fetch_param(arg->fetch.data); | ||
433 | else if (CHECK_BASIC_FETCH_FUNCS(symbol, arg->fetch.fn)) | ||
351 | free_symbol_cache(arg->fetch.data); | 434 | free_symbol_cache(arg->fetch.data); |
352 | else if (arg->fetch.func == fetch_indirect) | ||
353 | free_indirect_fetch_data(arg->fetch.data); | ||
354 | kfree(arg->name); | 435 | kfree(arg->name); |
436 | kfree(arg->comm); | ||
355 | } | 437 | } |
356 | 438 | ||
357 | static void free_trace_probe(struct trace_probe *tp) | 439 | static void free_trace_probe(struct trace_probe *tp) |
@@ -457,28 +539,30 @@ static int split_symbol_offset(char *symbol, unsigned long *offset) | |||
457 | #define PARAM_MAX_ARGS 16 | 539 | #define PARAM_MAX_ARGS 16 |
458 | #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) | 540 | #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) |
459 | 541 | ||
460 | static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return) | 542 | static int parse_probe_vars(char *arg, const struct fetch_type *t, |
543 | struct fetch_param *f, int is_return) | ||
461 | { | 544 | { |
462 | int ret = 0; | 545 | int ret = 0; |
463 | unsigned long param; | 546 | unsigned long param; |
464 | 547 | ||
465 | if (strcmp(arg, "retval") == 0) { | 548 | if (strcmp(arg, "retval") == 0) { |
466 | if (is_return) { | 549 | if (is_return) |
467 | ff->func = fetch_retvalue; | 550 | f->fn = t->retval; |
468 | ff->data = NULL; | 551 | else |
469 | } else | ||
470 | ret = -EINVAL; | 552 | ret = -EINVAL; |
471 | } else if (strncmp(arg, "stack", 5) == 0) { | 553 | } else if (strncmp(arg, "stack", 5) == 0) { |
472 | if (arg[5] == '\0') { | 554 | if (arg[5] == '\0') { |
473 | ff->func = fetch_stack_address; | 555 | if (strcmp(t->name, DEFAULT_FETCH_TYPE_STR) == 0) |
474 | ff->data = NULL; | 556 | f->fn = fetch_stack_address; |
557 | else | ||
558 | ret = -EINVAL; | ||
475 | } else if (isdigit(arg[5])) { | 559 | } else if (isdigit(arg[5])) { |
476 | ret = strict_strtoul(arg + 5, 10, ¶m); | 560 | ret = strict_strtoul(arg + 5, 10, ¶m); |
477 | if (ret || param > PARAM_MAX_STACK) | 561 | if (ret || param > PARAM_MAX_STACK) |
478 | ret = -EINVAL; | 562 | ret = -EINVAL; |
479 | else { | 563 | else { |
480 | ff->func = fetch_stack; | 564 | f->fn = t->stack; |
481 | ff->data = (void *)param; | 565 | f->data = (void *)param; |
482 | } | 566 | } |
483 | } else | 567 | } else |
484 | ret = -EINVAL; | 568 | ret = -EINVAL; |
@@ -488,7 +572,8 @@ static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return) | |||
488 | } | 572 | } |
489 | 573 | ||
490 | /* Recursive argument parser */ | 574 | /* Recursive argument parser */ |
491 | static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | 575 | static int __parse_probe_arg(char *arg, const struct fetch_type *t, |
576 | struct fetch_param *f, int is_return) | ||
492 | { | 577 | { |
493 | int ret = 0; | 578 | int ret = 0; |
494 | unsigned long param; | 579 | unsigned long param; |
@@ -497,13 +582,13 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | |||
497 | 582 | ||
498 | switch (arg[0]) { | 583 | switch (arg[0]) { |
499 | case '$': | 584 | case '$': |
500 | ret = parse_probe_vars(arg + 1, ff, is_return); | 585 | ret = parse_probe_vars(arg + 1, t, f, is_return); |
501 | break; | 586 | break; |
502 | case '%': /* named register */ | 587 | case '%': /* named register */ |
503 | ret = regs_query_register_offset(arg + 1); | 588 | ret = regs_query_register_offset(arg + 1); |
504 | if (ret >= 0) { | 589 | if (ret >= 0) { |
505 | ff->func = fetch_register; | 590 | f->fn = t->reg; |
506 | ff->data = (void *)(unsigned long)ret; | 591 | f->data = (void *)(unsigned long)ret; |
507 | ret = 0; | 592 | ret = 0; |
508 | } | 593 | } |
509 | break; | 594 | break; |
@@ -512,26 +597,22 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | |||
512 | ret = strict_strtoul(arg + 1, 0, ¶m); | 597 | ret = strict_strtoul(arg + 1, 0, ¶m); |
513 | if (ret) | 598 | if (ret) |
514 | break; | 599 | break; |
515 | ff->func = fetch_memory; | 600 | f->fn = t->memory; |
516 | ff->data = (void *)param; | 601 | f->data = (void *)param; |
517 | } else { | 602 | } else { |
518 | ret = split_symbol_offset(arg + 1, &offset); | 603 | ret = split_symbol_offset(arg + 1, &offset); |
519 | if (ret) | 604 | if (ret) |
520 | break; | 605 | break; |
521 | ff->data = alloc_symbol_cache(arg + 1, offset); | 606 | f->data = alloc_symbol_cache(arg + 1, offset); |
522 | if (ff->data) | 607 | if (f->data) |
523 | ff->func = fetch_symbol; | 608 | f->fn = t->symbol; |
524 | else | ||
525 | ret = -EINVAL; | ||
526 | } | 609 | } |
527 | break; | 610 | break; |
528 | case '+': /* indirect memory */ | 611 | case '+': /* deref memory */ |
529 | case '-': | 612 | case '-': |
530 | tmp = strchr(arg, '('); | 613 | tmp = strchr(arg, '('); |
531 | if (!tmp) { | 614 | if (!tmp) |
532 | ret = -EINVAL; | ||
533 | break; | 615 | break; |
534 | } | ||
535 | *tmp = '\0'; | 616 | *tmp = '\0'; |
536 | ret = strict_strtol(arg + 1, 0, &offset); | 617 | ret = strict_strtol(arg + 1, 0, &offset); |
537 | if (ret) | 618 | if (ret) |
@@ -541,38 +622,58 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | |||
541 | arg = tmp + 1; | 622 | arg = tmp + 1; |
542 | tmp = strrchr(arg, ')'); | 623 | tmp = strrchr(arg, ')'); |
543 | if (tmp) { | 624 | if (tmp) { |
544 | struct indirect_fetch_data *id; | 625 | struct deref_fetch_param *dprm; |
626 | const struct fetch_type *t2 = find_fetch_type(NULL); | ||
545 | *tmp = '\0'; | 627 | *tmp = '\0'; |
546 | id = kzalloc(sizeof(struct indirect_fetch_data), | 628 | dprm = kzalloc(sizeof(struct deref_fetch_param), |
547 | GFP_KERNEL); | 629 | GFP_KERNEL); |
548 | if (!id) | 630 | if (!dprm) |
549 | return -ENOMEM; | 631 | return -ENOMEM; |
550 | id->offset = offset; | 632 | dprm->offset = offset; |
551 | ret = __parse_probe_arg(arg, &id->orig, is_return); | 633 | ret = __parse_probe_arg(arg, t2, &dprm->orig, |
634 | is_return); | ||
552 | if (ret) | 635 | if (ret) |
553 | kfree(id); | 636 | kfree(dprm); |
554 | else { | 637 | else { |
555 | ff->func = fetch_indirect; | 638 | f->fn = t->deref; |
556 | ff->data = (void *)id; | 639 | f->data = (void *)dprm; |
557 | } | 640 | } |
558 | } else | 641 | } |
559 | ret = -EINVAL; | ||
560 | break; | 642 | break; |
561 | default: | ||
562 | /* TODO: support custom handler */ | ||
563 | ret = -EINVAL; | ||
564 | } | 643 | } |
644 | if (!ret && !f->fn) | ||
645 | ret = -EINVAL; | ||
565 | return ret; | 646 | return ret; |
566 | } | 647 | } |
567 | 648 | ||
568 | /* String length checking wrapper */ | 649 | /* String length checking wrapper */ |
569 | static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return) | 650 | static int parse_probe_arg(char *arg, struct trace_probe *tp, |
651 | struct probe_arg *parg, int is_return) | ||
570 | { | 652 | { |
653 | const char *t; | ||
654 | |||
571 | if (strlen(arg) > MAX_ARGSTR_LEN) { | 655 | if (strlen(arg) > MAX_ARGSTR_LEN) { |
572 | pr_info("Argument is too long.: %s\n", arg); | 656 | pr_info("Argument is too long.: %s\n", arg); |
573 | return -ENOSPC; | 657 | return -ENOSPC; |
574 | } | 658 | } |
575 | return __parse_probe_arg(arg, ff, is_return); | 659 | parg->comm = kstrdup(arg, GFP_KERNEL); |
660 | if (!parg->comm) { | ||
661 | pr_info("Failed to allocate memory for command '%s'.\n", arg); | ||
662 | return -ENOMEM; | ||
663 | } | ||
664 | t = strchr(parg->comm, ':'); | ||
665 | if (t) { | ||
666 | arg[t - parg->comm] = '\0'; | ||
667 | t++; | ||
668 | } | ||
669 | parg->type = find_fetch_type(t); | ||
670 | if (!parg->type) { | ||
671 | pr_info("Unsupported type: %s\n", t); | ||
672 | return -EINVAL; | ||
673 | } | ||
674 | parg->offset = tp->size; | ||
675 | tp->size += parg->type->size; | ||
676 | return __parse_probe_arg(arg, parg->type, &parg->fetch, is_return); | ||
576 | } | 677 | } |
577 | 678 | ||
578 | /* Return 1 if name is reserved or already used by another argument */ | 679 | /* Return 1 if name is reserved or already used by another argument */ |
@@ -602,15 +703,18 @@ static int create_trace_probe(int argc, char **argv) | |||
602 | * @ADDR : fetch memory at ADDR (ADDR should be in kernel) | 703 | * @ADDR : fetch memory at ADDR (ADDR should be in kernel) |
603 | * @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol) | 704 | * @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol) |
604 | * %REG : fetch register REG | 705 | * %REG : fetch register REG |
605 | * Indirect memory fetch: | 706 | * Dereferencing memory fetch: |
606 | * +|-offs(ARG) : fetch memory at ARG +|- offs address. | 707 | * +|-offs(ARG) : fetch memory at ARG +|- offs address. |
607 | * Alias name of args: | 708 | * Alias name of args: |
608 | * NAME=FETCHARG : set NAME as alias of FETCHARG. | 709 | * NAME=FETCHARG : set NAME as alias of FETCHARG. |
710 | * Type of args: | ||
711 | * FETCHARG:TYPE : use TYPE instead of unsigned long. | ||
609 | */ | 712 | */ |
610 | struct trace_probe *tp; | 713 | struct trace_probe *tp; |
611 | int i, ret = 0; | 714 | int i, ret = 0; |
612 | int is_return = 0, is_delete = 0; | 715 | int is_return = 0, is_delete = 0; |
613 | char *symbol = NULL, *event = NULL, *arg = NULL, *group = NULL; | 716 | char *symbol = NULL, *event = NULL, *group = NULL; |
717 | char *arg, *tmp; | ||
614 | unsigned long offset = 0; | 718 | unsigned long offset = 0; |
615 | void *addr = NULL; | 719 | void *addr = NULL; |
616 | char buf[MAX_EVENT_NAME_LEN]; | 720 | char buf[MAX_EVENT_NAME_LEN]; |
@@ -723,13 +827,6 @@ static int create_trace_probe(int argc, char **argv) | |||
723 | else | 827 | else |
724 | arg = argv[i]; | 828 | arg = argv[i]; |
725 | 829 | ||
726 | if (conflict_field_name(argv[i], tp->args, i)) { | ||
727 | pr_info("Argument%d name '%s' conflicts with " | ||
728 | "another field.\n", i, argv[i]); | ||
729 | ret = -EINVAL; | ||
730 | goto error; | ||
731 | } | ||
732 | |||
733 | tp->args[i].name = kstrdup(argv[i], GFP_KERNEL); | 830 | tp->args[i].name = kstrdup(argv[i], GFP_KERNEL); |
734 | if (!tp->args[i].name) { | 831 | if (!tp->args[i].name) { |
735 | pr_info("Failed to allocate argument%d name '%s'.\n", | 832 | pr_info("Failed to allocate argument%d name '%s'.\n", |
@@ -737,9 +834,19 @@ static int create_trace_probe(int argc, char **argv) | |||
737 | ret = -ENOMEM; | 834 | ret = -ENOMEM; |
738 | goto error; | 835 | goto error; |
739 | } | 836 | } |
837 | tmp = strchr(tp->args[i].name, ':'); | ||
838 | if (tmp) | ||
839 | *tmp = '_'; /* convert : to _ */ | ||
840 | |||
841 | if (conflict_field_name(tp->args[i].name, tp->args, i)) { | ||
842 | pr_info("Argument%d name '%s' conflicts with " | ||
843 | "another field.\n", i, argv[i]); | ||
844 | ret = -EINVAL; | ||
845 | goto error; | ||
846 | } | ||
740 | 847 | ||
741 | /* Parse fetch argument */ | 848 | /* Parse fetch argument */ |
742 | ret = parse_probe_arg(arg, &tp->args[i].fetch, is_return); | 849 | ret = parse_probe_arg(arg, tp, &tp->args[i], is_return); |
743 | if (ret) { | 850 | if (ret) { |
744 | pr_info("Parse error at argument%d. (%d)\n", i, ret); | 851 | pr_info("Parse error at argument%d. (%d)\n", i, ret); |
745 | kfree(tp->args[i].name); | 852 | kfree(tp->args[i].name); |
@@ -794,8 +901,7 @@ static void probes_seq_stop(struct seq_file *m, void *v) | |||
794 | static int probes_seq_show(struct seq_file *m, void *v) | 901 | static int probes_seq_show(struct seq_file *m, void *v) |
795 | { | 902 | { |
796 | struct trace_probe *tp = v; | 903 | struct trace_probe *tp = v; |
797 | int i, ret; | 904 | int i; |
798 | char buf[MAX_ARGSTR_LEN + 1]; | ||
799 | 905 | ||
800 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); | 906 | seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); |
801 | seq_printf(m, ":%s/%s", tp->call.system, tp->call.name); | 907 | seq_printf(m, ":%s/%s", tp->call.system, tp->call.name); |
@@ -807,15 +913,10 @@ static int probes_seq_show(struct seq_file *m, void *v) | |||
807 | else | 913 | else |
808 | seq_printf(m, " %s", probe_symbol(tp)); | 914 | seq_printf(m, " %s", probe_symbol(tp)); |
809 | 915 | ||
810 | for (i = 0; i < tp->nr_args; i++) { | 916 | for (i = 0; i < tp->nr_args; i++) |
811 | ret = probe_arg_string(buf, MAX_ARGSTR_LEN, &tp->args[i].fetch); | 917 | seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm); |
812 | if (ret < 0) { | ||
813 | pr_warning("Argument%d decoding error(%d).\n", i, ret); | ||
814 | return ret; | ||
815 | } | ||
816 | seq_printf(m, " %s=%s", tp->args[i].name, buf); | ||
817 | } | ||
818 | seq_printf(m, "\n"); | 918 | seq_printf(m, "\n"); |
919 | |||
819 | return 0; | 920 | return 0; |
820 | } | 921 | } |
821 | 922 | ||
@@ -945,9 +1046,10 @@ static const struct file_operations kprobe_profile_ops = { | |||
945 | static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | 1046 | static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) |
946 | { | 1047 | { |
947 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); | 1048 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); |
948 | struct kprobe_trace_entry *entry; | 1049 | struct kprobe_trace_entry_head *entry; |
949 | struct ring_buffer_event *event; | 1050 | struct ring_buffer_event *event; |
950 | struct ring_buffer *buffer; | 1051 | struct ring_buffer *buffer; |
1052 | u8 *data; | ||
951 | int size, i, pc; | 1053 | int size, i, pc; |
952 | unsigned long irq_flags; | 1054 | unsigned long irq_flags; |
953 | struct ftrace_event_call *call = &tp->call; | 1055 | struct ftrace_event_call *call = &tp->call; |
@@ -957,7 +1059,7 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
957 | local_save_flags(irq_flags); | 1059 | local_save_flags(irq_flags); |
958 | pc = preempt_count(); | 1060 | pc = preempt_count(); |
959 | 1061 | ||
960 | size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args); | 1062 | size = sizeof(*entry) + tp->size; |
961 | 1063 | ||
962 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1064 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, |
963 | irq_flags, pc); | 1065 | irq_flags, pc); |
@@ -965,10 +1067,10 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs) | |||
965 | return; | 1067 | return; |
966 | 1068 | ||
967 | entry = ring_buffer_event_data(event); | 1069 | entry = ring_buffer_event_data(event); |
968 | entry->nargs = tp->nr_args; | ||
969 | entry->ip = (unsigned long)kp->addr; | 1070 | entry->ip = (unsigned long)kp->addr; |
1071 | data = (u8 *)&entry[1]; | ||
970 | for (i = 0; i < tp->nr_args; i++) | 1072 | for (i = 0; i < tp->nr_args; i++) |
971 | entry->args[i] = call_fetch(&tp->args[i].fetch, regs); | 1073 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
972 | 1074 | ||
973 | if (!filter_current_check_discard(buffer, call, entry, event)) | 1075 | if (!filter_current_check_discard(buffer, call, entry, event)) |
974 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); | 1076 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); |
@@ -979,9 +1081,10 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
979 | struct pt_regs *regs) | 1081 | struct pt_regs *regs) |
980 | { | 1082 | { |
981 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); | 1083 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); |
982 | struct kretprobe_trace_entry *entry; | 1084 | struct kretprobe_trace_entry_head *entry; |
983 | struct ring_buffer_event *event; | 1085 | struct ring_buffer_event *event; |
984 | struct ring_buffer *buffer; | 1086 | struct ring_buffer *buffer; |
1087 | u8 *data; | ||
985 | int size, i, pc; | 1088 | int size, i, pc; |
986 | unsigned long irq_flags; | 1089 | unsigned long irq_flags; |
987 | struct ftrace_event_call *call = &tp->call; | 1090 | struct ftrace_event_call *call = &tp->call; |
@@ -989,7 +1092,7 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
989 | local_save_flags(irq_flags); | 1092 | local_save_flags(irq_flags); |
990 | pc = preempt_count(); | 1093 | pc = preempt_count(); |
991 | 1094 | ||
992 | size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args); | 1095 | size = sizeof(*entry) + tp->size; |
993 | 1096 | ||
994 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, | 1097 | event = trace_current_buffer_lock_reserve(&buffer, call->id, size, |
995 | irq_flags, pc); | 1098 | irq_flags, pc); |
@@ -997,11 +1100,11 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
997 | return; | 1100 | return; |
998 | 1101 | ||
999 | entry = ring_buffer_event_data(event); | 1102 | entry = ring_buffer_event_data(event); |
1000 | entry->nargs = tp->nr_args; | ||
1001 | entry->func = (unsigned long)tp->rp.kp.addr; | 1103 | entry->func = (unsigned long)tp->rp.kp.addr; |
1002 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1104 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1105 | data = (u8 *)&entry[1]; | ||
1003 | for (i = 0; i < tp->nr_args; i++) | 1106 | for (i = 0; i < tp->nr_args; i++) |
1004 | entry->args[i] = call_fetch(&tp->args[i].fetch, regs); | 1107 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1005 | 1108 | ||
1006 | if (!filter_current_check_discard(buffer, call, entry, event)) | 1109 | if (!filter_current_check_discard(buffer, call, entry, event)) |
1007 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); | 1110 | trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); |
@@ -1011,13 +1114,14 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri, | |||
1011 | enum print_line_t | 1114 | enum print_line_t |
1012 | print_kprobe_event(struct trace_iterator *iter, int flags) | 1115 | print_kprobe_event(struct trace_iterator *iter, int flags) |
1013 | { | 1116 | { |
1014 | struct kprobe_trace_entry *field; | 1117 | struct kprobe_trace_entry_head *field; |
1015 | struct trace_seq *s = &iter->seq; | 1118 | struct trace_seq *s = &iter->seq; |
1016 | struct trace_event *event; | 1119 | struct trace_event *event; |
1017 | struct trace_probe *tp; | 1120 | struct trace_probe *tp; |
1121 | u8 *data; | ||
1018 | int i; | 1122 | int i; |
1019 | 1123 | ||
1020 | field = (struct kprobe_trace_entry *)iter->ent; | 1124 | field = (struct kprobe_trace_entry_head *)iter->ent; |
1021 | event = ftrace_find_event(field->ent.type); | 1125 | event = ftrace_find_event(field->ent.type); |
1022 | tp = container_of(event, struct trace_probe, event); | 1126 | tp = container_of(event, struct trace_probe, event); |
1023 | 1127 | ||
@@ -1030,9 +1134,10 @@ print_kprobe_event(struct trace_iterator *iter, int flags) | |||
1030 | if (!trace_seq_puts(s, ")")) | 1134 | if (!trace_seq_puts(s, ")")) |
1031 | goto partial; | 1135 | goto partial; |
1032 | 1136 | ||
1033 | for (i = 0; i < field->nargs; i++) | 1137 | data = (u8 *)&field[1]; |
1034 | if (!trace_seq_printf(s, " %s=%lx", | 1138 | for (i = 0; i < tp->nr_args; i++) |
1035 | tp->args[i].name, field->args[i])) | 1139 | if (!tp->args[i].type->print(s, tp->args[i].name, |
1140 | data + tp->args[i].offset)) | ||
1036 | goto partial; | 1141 | goto partial; |
1037 | 1142 | ||
1038 | if (!trace_seq_puts(s, "\n")) | 1143 | if (!trace_seq_puts(s, "\n")) |
@@ -1046,13 +1151,14 @@ partial: | |||
1046 | enum print_line_t | 1151 | enum print_line_t |
1047 | print_kretprobe_event(struct trace_iterator *iter, int flags) | 1152 | print_kretprobe_event(struct trace_iterator *iter, int flags) |
1048 | { | 1153 | { |
1049 | struct kretprobe_trace_entry *field; | 1154 | struct kretprobe_trace_entry_head *field; |
1050 | struct trace_seq *s = &iter->seq; | 1155 | struct trace_seq *s = &iter->seq; |
1051 | struct trace_event *event; | 1156 | struct trace_event *event; |
1052 | struct trace_probe *tp; | 1157 | struct trace_probe *tp; |
1158 | u8 *data; | ||
1053 | int i; | 1159 | int i; |
1054 | 1160 | ||
1055 | field = (struct kretprobe_trace_entry *)iter->ent; | 1161 | field = (struct kretprobe_trace_entry_head *)iter->ent; |
1056 | event = ftrace_find_event(field->ent.type); | 1162 | event = ftrace_find_event(field->ent.type); |
1057 | tp = container_of(event, struct trace_probe, event); | 1163 | tp = container_of(event, struct trace_probe, event); |
1058 | 1164 | ||
@@ -1071,9 +1177,10 @@ print_kretprobe_event(struct trace_iterator *iter, int flags) | |||
1071 | if (!trace_seq_puts(s, ")")) | 1177 | if (!trace_seq_puts(s, ")")) |
1072 | goto partial; | 1178 | goto partial; |
1073 | 1179 | ||
1074 | for (i = 0; i < field->nargs; i++) | 1180 | data = (u8 *)&field[1]; |
1075 | if (!trace_seq_printf(s, " %s=%lx", | 1181 | for (i = 0; i < tp->nr_args; i++) |
1076 | tp->args[i].name, field->args[i])) | 1182 | if (!tp->args[i].type->print(s, tp->args[i].name, |
1183 | data + tp->args[i].offset)) | ||
1077 | goto partial; | 1184 | goto partial; |
1078 | 1185 | ||
1079 | if (!trace_seq_puts(s, "\n")) | 1186 | if (!trace_seq_puts(s, "\n")) |
@@ -1129,29 +1236,43 @@ static int probe_event_raw_init(struct ftrace_event_call *event_call) | |||
1129 | static int kprobe_event_define_fields(struct ftrace_event_call *event_call) | 1236 | static int kprobe_event_define_fields(struct ftrace_event_call *event_call) |
1130 | { | 1237 | { |
1131 | int ret, i; | 1238 | int ret, i; |
1132 | struct kprobe_trace_entry field; | 1239 | struct kprobe_trace_entry_head field; |
1133 | struct trace_probe *tp = (struct trace_probe *)event_call->data; | 1240 | struct trace_probe *tp = (struct trace_probe *)event_call->data; |
1134 | 1241 | ||
1135 | DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); | 1242 | DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); |
1136 | DEFINE_FIELD(int, nargs, FIELD_STRING_NARGS, 1); | ||
1137 | /* Set argument names as fields */ | 1243 | /* Set argument names as fields */ |
1138 | for (i = 0; i < tp->nr_args; i++) | 1244 | for (i = 0; i < tp->nr_args; i++) { |
1139 | DEFINE_FIELD(unsigned long, args[i], tp->args[i].name, 0); | 1245 | ret = trace_define_field(event_call, tp->args[i].type->name, |
1246 | tp->args[i].name, | ||
1247 | sizeof(field) + tp->args[i].offset, | ||
1248 | tp->args[i].type->size, | ||
1249 | tp->args[i].type->is_signed, | ||
1250 | FILTER_OTHER); | ||
1251 | if (ret) | ||
1252 | return ret; | ||
1253 | } | ||
1140 | return 0; | 1254 | return 0; |
1141 | } | 1255 | } |
1142 | 1256 | ||
1143 | static int kretprobe_event_define_fields(struct ftrace_event_call *event_call) | 1257 | static int kretprobe_event_define_fields(struct ftrace_event_call *event_call) |
1144 | { | 1258 | { |
1145 | int ret, i; | 1259 | int ret, i; |
1146 | struct kretprobe_trace_entry field; | 1260 | struct kretprobe_trace_entry_head field; |
1147 | struct trace_probe *tp = (struct trace_probe *)event_call->data; | 1261 | struct trace_probe *tp = (struct trace_probe *)event_call->data; |
1148 | 1262 | ||
1149 | DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0); | 1263 | DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0); |
1150 | DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); | 1264 | DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); |
1151 | DEFINE_FIELD(int, nargs, FIELD_STRING_NARGS, 1); | ||
1152 | /* Set argument names as fields */ | 1265 | /* Set argument names as fields */ |
1153 | for (i = 0; i < tp->nr_args; i++) | 1266 | for (i = 0; i < tp->nr_args; i++) { |
1154 | DEFINE_FIELD(unsigned long, args[i], tp->args[i].name, 0); | 1267 | ret = trace_define_field(event_call, tp->args[i].type->name, |
1268 | tp->args[i].name, | ||
1269 | sizeof(field) + tp->args[i].offset, | ||
1270 | tp->args[i].type->size, | ||
1271 | tp->args[i].type->is_signed, | ||
1272 | FILTER_OTHER); | ||
1273 | if (ret) | ||
1274 | return ret; | ||
1275 | } | ||
1155 | return 0; | 1276 | return 0; |
1156 | } | 1277 | } |
1157 | 1278 | ||
@@ -1176,8 +1297,8 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len) | |||
1176 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); | 1297 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); |
1177 | 1298 | ||
1178 | for (i = 0; i < tp->nr_args; i++) { | 1299 | for (i = 0; i < tp->nr_args; i++) { |
1179 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%%lx", | 1300 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", |
1180 | tp->args[i].name); | 1301 | tp->args[i].name, tp->args[i].type->fmt); |
1181 | } | 1302 | } |
1182 | 1303 | ||
1183 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); | 1304 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); |
@@ -1219,12 +1340,13 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1219 | { | 1340 | { |
1220 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); | 1341 | struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp); |
1221 | struct ftrace_event_call *call = &tp->call; | 1342 | struct ftrace_event_call *call = &tp->call; |
1222 | struct kprobe_trace_entry *entry; | 1343 | struct kprobe_trace_entry_head *entry; |
1344 | u8 *data; | ||
1223 | int size, __size, i; | 1345 | int size, __size, i; |
1224 | unsigned long irq_flags; | 1346 | unsigned long irq_flags; |
1225 | int rctx; | 1347 | int rctx; |
1226 | 1348 | ||
1227 | __size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args); | 1349 | __size = sizeof(*entry) + tp->size; |
1228 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1350 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
1229 | size -= sizeof(u32); | 1351 | size -= sizeof(u32); |
1230 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, | 1352 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
@@ -1235,10 +1357,10 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1235 | if (!entry) | 1357 | if (!entry) |
1236 | return; | 1358 | return; |
1237 | 1359 | ||
1238 | entry->nargs = tp->nr_args; | ||
1239 | entry->ip = (unsigned long)kp->addr; | 1360 | entry->ip = (unsigned long)kp->addr; |
1361 | data = (u8 *)&entry[1]; | ||
1240 | for (i = 0; i < tp->nr_args; i++) | 1362 | for (i = 0; i < tp->nr_args; i++) |
1241 | entry->args[i] = call_fetch(&tp->args[i].fetch, regs); | 1363 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1242 | 1364 | ||
1243 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs); | 1365 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs); |
1244 | } | 1366 | } |
@@ -1249,12 +1371,13 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1249 | { | 1371 | { |
1250 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); | 1372 | struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp); |
1251 | struct ftrace_event_call *call = &tp->call; | 1373 | struct ftrace_event_call *call = &tp->call; |
1252 | struct kretprobe_trace_entry *entry; | 1374 | struct kretprobe_trace_entry_head *entry; |
1375 | u8 *data; | ||
1253 | int size, __size, i; | 1376 | int size, __size, i; |
1254 | unsigned long irq_flags; | 1377 | unsigned long irq_flags; |
1255 | int rctx; | 1378 | int rctx; |
1256 | 1379 | ||
1257 | __size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args); | 1380 | __size = sizeof(*entry) + tp->size; |
1258 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); | 1381 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
1259 | size -= sizeof(u32); | 1382 | size -= sizeof(u32); |
1260 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, | 1383 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
@@ -1265,11 +1388,11 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1265 | if (!entry) | 1388 | if (!entry) |
1266 | return; | 1389 | return; |
1267 | 1390 | ||
1268 | entry->nargs = tp->nr_args; | ||
1269 | entry->func = (unsigned long)tp->rp.kp.addr; | 1391 | entry->func = (unsigned long)tp->rp.kp.addr; |
1270 | entry->ret_ip = (unsigned long)ri->ret_addr; | 1392 | entry->ret_ip = (unsigned long)ri->ret_addr; |
1393 | data = (u8 *)&entry[1]; | ||
1271 | for (i = 0; i < tp->nr_args; i++) | 1394 | for (i = 0; i < tp->nr_args; i++) |
1272 | entry->args[i] = call_fetch(&tp->args[i].fetch, regs); | 1395 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1273 | 1396 | ||
1274 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, | 1397 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, |
1275 | irq_flags, regs); | 1398 | irq_flags, regs); |
diff --git a/kernel/trace/trace_ksym.c b/kernel/trace/trace_ksym.c index d59cd6879477..8eaf00749b65 100644 --- a/kernel/trace/trace_ksym.c +++ b/kernel/trace/trace_ksym.c | |||
@@ -34,12 +34,6 @@ | |||
34 | 34 | ||
35 | #include <asm/atomic.h> | 35 | #include <asm/atomic.h> |
36 | 36 | ||
37 | /* | ||
38 | * For now, let us restrict the no. of symbols traced simultaneously to number | ||
39 | * of available hardware breakpoint registers. | ||
40 | */ | ||
41 | #define KSYM_TRACER_MAX HBP_NUM | ||
42 | |||
43 | #define KSYM_TRACER_OP_LEN 3 /* rw- */ | 37 | #define KSYM_TRACER_OP_LEN 3 /* rw- */ |
44 | 38 | ||
45 | struct trace_ksym { | 39 | struct trace_ksym { |
@@ -53,7 +47,6 @@ struct trace_ksym { | |||
53 | 47 | ||
54 | static struct trace_array *ksym_trace_array; | 48 | static struct trace_array *ksym_trace_array; |
55 | 49 | ||
56 | static unsigned int ksym_filter_entry_count; | ||
57 | static unsigned int ksym_tracing_enabled; | 50 | static unsigned int ksym_tracing_enabled; |
58 | 51 | ||
59 | static HLIST_HEAD(ksym_filter_head); | 52 | static HLIST_HEAD(ksym_filter_head); |
@@ -181,13 +174,6 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr) | |||
181 | struct trace_ksym *entry; | 174 | struct trace_ksym *entry; |
182 | int ret = -ENOMEM; | 175 | int ret = -ENOMEM; |
183 | 176 | ||
184 | if (ksym_filter_entry_count >= KSYM_TRACER_MAX) { | ||
185 | printk(KERN_ERR "ksym_tracer: Maximum limit:(%d) reached. No" | ||
186 | " new requests for tracing can be accepted now.\n", | ||
187 | KSYM_TRACER_MAX); | ||
188 | return -ENOSPC; | ||
189 | } | ||
190 | |||
191 | entry = kzalloc(sizeof(struct trace_ksym), GFP_KERNEL); | 177 | entry = kzalloc(sizeof(struct trace_ksym), GFP_KERNEL); |
192 | if (!entry) | 178 | if (!entry) |
193 | return -ENOMEM; | 179 | return -ENOMEM; |
@@ -203,13 +189,17 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr) | |||
203 | 189 | ||
204 | if (IS_ERR(entry->ksym_hbp)) { | 190 | if (IS_ERR(entry->ksym_hbp)) { |
205 | ret = PTR_ERR(entry->ksym_hbp); | 191 | ret = PTR_ERR(entry->ksym_hbp); |
206 | printk(KERN_INFO "ksym_tracer request failed. Try again" | 192 | if (ret == -ENOSPC) { |
207 | " later!!\n"); | 193 | printk(KERN_ERR "ksym_tracer: Maximum limit reached." |
194 | " No new requests for tracing can be accepted now.\n"); | ||
195 | } else { | ||
196 | printk(KERN_INFO "ksym_tracer request failed. Try again" | ||
197 | " later!!\n"); | ||
198 | } | ||
208 | goto err; | 199 | goto err; |
209 | } | 200 | } |
210 | 201 | ||
211 | hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head); | 202 | hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head); |
212 | ksym_filter_entry_count++; | ||
213 | 203 | ||
214 | return 0; | 204 | return 0; |
215 | 205 | ||
@@ -265,7 +255,6 @@ static void __ksym_trace_reset(void) | |||
265 | hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head, | 255 | hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head, |
266 | ksym_hlist) { | 256 | ksym_hlist) { |
267 | unregister_wide_hw_breakpoint(entry->ksym_hbp); | 257 | unregister_wide_hw_breakpoint(entry->ksym_hbp); |
268 | ksym_filter_entry_count--; | ||
269 | hlist_del_rcu(&(entry->ksym_hlist)); | 258 | hlist_del_rcu(&(entry->ksym_hlist)); |
270 | synchronize_rcu(); | 259 | synchronize_rcu(); |
271 | kfree(entry); | 260 | kfree(entry); |
@@ -338,7 +327,6 @@ static ssize_t ksym_trace_filter_write(struct file *file, | |||
338 | goto out_unlock; | 327 | goto out_unlock; |
339 | } | 328 | } |
340 | /* Error or "symbol:---" case: drop it */ | 329 | /* Error or "symbol:---" case: drop it */ |
341 | ksym_filter_entry_count--; | ||
342 | hlist_del_rcu(&(entry->ksym_hlist)); | 330 | hlist_del_rcu(&(entry->ksym_hlist)); |
343 | synchronize_rcu(); | 331 | synchronize_rcu(); |
344 | kfree(entry); | 332 | kfree(entry); |
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 8e46b3323cdc..2404c129a8c9 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
@@ -253,7 +253,7 @@ void *trace_seq_reserve(struct trace_seq *s, size_t len) | |||
253 | void *ret; | 253 | void *ret; |
254 | 254 | ||
255 | if (s->full) | 255 | if (s->full) |
256 | return 0; | 256 | return NULL; |
257 | 257 | ||
258 | if (len > ((PAGE_SIZE - 1) - s->len)) { | 258 | if (len > ((PAGE_SIZE - 1) - s->len)) { |
259 | s->full = 1; | 259 | s->full = 1; |
diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c index 5fca0f51fde4..a55fccfede5d 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c | |||
@@ -50,8 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr, | |||
50 | } | 50 | } |
51 | 51 | ||
52 | static void | 52 | static void |
53 | probe_sched_switch(struct rq *__rq, struct task_struct *prev, | 53 | probe_sched_switch(struct task_struct *prev, struct task_struct *next) |
54 | struct task_struct *next) | ||
55 | { | 54 | { |
56 | struct trace_array_cpu *data; | 55 | struct trace_array_cpu *data; |
57 | unsigned long flags; | 56 | unsigned long flags; |
@@ -109,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr, | |||
109 | } | 108 | } |
110 | 109 | ||
111 | static void | 110 | static void |
112 | probe_sched_wakeup(struct rq *__rq, struct task_struct *wakee, int success) | 111 | probe_sched_wakeup(struct task_struct *wakee, int success) |
113 | { | 112 | { |
114 | struct trace_array_cpu *data; | 113 | struct trace_array_cpu *data; |
115 | unsigned long flags; | 114 | unsigned long flags; |
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c index 0271742abb8d..8052446ceeaa 100644 --- a/kernel/trace/trace_sched_wakeup.c +++ b/kernel/trace/trace_sched_wakeup.c | |||
@@ -107,8 +107,7 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) | |||
107 | } | 107 | } |
108 | 108 | ||
109 | static void notrace | 109 | static void notrace |
110 | probe_wakeup_sched_switch(struct rq *rq, struct task_struct *prev, | 110 | probe_wakeup_sched_switch(struct task_struct *prev, struct task_struct *next) |
111 | struct task_struct *next) | ||
112 | { | 111 | { |
113 | struct trace_array_cpu *data; | 112 | struct trace_array_cpu *data; |
114 | cycle_t T0, T1, delta; | 113 | cycle_t T0, T1, delta; |
@@ -200,7 +199,7 @@ static void wakeup_reset(struct trace_array *tr) | |||
200 | } | 199 | } |
201 | 200 | ||
202 | static void | 201 | static void |
203 | probe_wakeup(struct rq *rq, struct task_struct *p, int success) | 202 | probe_wakeup(struct task_struct *p, int success) |
204 | { | 203 | { |
205 | struct trace_array_cpu *data; | 204 | struct trace_array_cpu *data; |
206 | int cpu = smp_processor_id(); | 205 | int cpu = smp_processor_id(); |
diff --git a/kernel/trace/trace_selftest.c b/kernel/trace/trace_selftest.c index 81003b4d617f..250e7f9bd2f0 100644 --- a/kernel/trace/trace_selftest.c +++ b/kernel/trace/trace_selftest.c | |||
@@ -17,7 +17,6 @@ static inline int trace_valid_entry(struct trace_entry *entry) | |||
17 | case TRACE_BRANCH: | 17 | case TRACE_BRANCH: |
18 | case TRACE_GRAPH_ENT: | 18 | case TRACE_GRAPH_ENT: |
19 | case TRACE_GRAPH_RET: | 19 | case TRACE_GRAPH_RET: |
20 | case TRACE_HW_BRANCHES: | ||
21 | case TRACE_KSYM: | 20 | case TRACE_KSYM: |
22 | return 1; | 21 | return 1; |
23 | } | 22 | } |
@@ -30,7 +29,7 @@ static int trace_test_buffer_cpu(struct trace_array *tr, int cpu) | |||
30 | struct trace_entry *entry; | 29 | struct trace_entry *entry; |
31 | unsigned int loops = 0; | 30 | unsigned int loops = 0; |
32 | 31 | ||
33 | while ((event = ring_buffer_consume(tr->buffer, cpu, NULL))) { | 32 | while ((event = ring_buffer_consume(tr->buffer, cpu, NULL, NULL))) { |
34 | entry = ring_buffer_event_data(event); | 33 | entry = ring_buffer_event_data(event); |
35 | 34 | ||
36 | /* | 35 | /* |
@@ -256,7 +255,8 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr) | |||
256 | /* Maximum number of functions to trace before diagnosing a hang */ | 255 | /* Maximum number of functions to trace before diagnosing a hang */ |
257 | #define GRAPH_MAX_FUNC_TEST 100000000 | 256 | #define GRAPH_MAX_FUNC_TEST 100000000 |
258 | 257 | ||
259 | static void __ftrace_dump(bool disable_tracing); | 258 | static void |
259 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode); | ||
260 | static unsigned int graph_hang_thresh; | 260 | static unsigned int graph_hang_thresh; |
261 | 261 | ||
262 | /* Wrap the real function entry probe to avoid possible hanging */ | 262 | /* Wrap the real function entry probe to avoid possible hanging */ |
@@ -267,7 +267,7 @@ static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace) | |||
267 | ftrace_graph_stop(); | 267 | ftrace_graph_stop(); |
268 | printk(KERN_WARNING "BUG: Function graph tracer hang!\n"); | 268 | printk(KERN_WARNING "BUG: Function graph tracer hang!\n"); |
269 | if (ftrace_dump_on_oops) | 269 | if (ftrace_dump_on_oops) |
270 | __ftrace_dump(false); | 270 | __ftrace_dump(false, DUMP_ALL); |
271 | return 0; | 271 | return 0; |
272 | } | 272 | } |
273 | 273 | ||
@@ -755,62 +755,6 @@ trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr) | |||
755 | } | 755 | } |
756 | #endif /* CONFIG_BRANCH_TRACER */ | 756 | #endif /* CONFIG_BRANCH_TRACER */ |
757 | 757 | ||
758 | #ifdef CONFIG_HW_BRANCH_TRACER | ||
759 | int | ||
760 | trace_selftest_startup_hw_branches(struct tracer *trace, | ||
761 | struct trace_array *tr) | ||
762 | { | ||
763 | struct trace_iterator *iter; | ||
764 | struct tracer tracer; | ||
765 | unsigned long count; | ||
766 | int ret; | ||
767 | |||
768 | if (!trace->open) { | ||
769 | printk(KERN_CONT "missing open function..."); | ||
770 | return -1; | ||
771 | } | ||
772 | |||
773 | ret = tracer_init(trace, tr); | ||
774 | if (ret) { | ||
775 | warn_failed_init_tracer(trace, ret); | ||
776 | return ret; | ||
777 | } | ||
778 | |||
779 | /* | ||
780 | * The hw-branch tracer needs to collect the trace from the various | ||
781 | * cpu trace buffers - before tracing is stopped. | ||
782 | */ | ||
783 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); | ||
784 | if (!iter) | ||
785 | return -ENOMEM; | ||
786 | |||
787 | memcpy(&tracer, trace, sizeof(tracer)); | ||
788 | |||
789 | iter->trace = &tracer; | ||
790 | iter->tr = tr; | ||
791 | iter->pos = -1; | ||
792 | mutex_init(&iter->mutex); | ||
793 | |||
794 | trace->open(iter); | ||
795 | |||
796 | mutex_destroy(&iter->mutex); | ||
797 | kfree(iter); | ||
798 | |||
799 | tracing_stop(); | ||
800 | |||
801 | ret = trace_test_buffer(tr, &count); | ||
802 | trace->reset(tr); | ||
803 | tracing_start(); | ||
804 | |||
805 | if (!ret && !count) { | ||
806 | printk(KERN_CONT "no entries found.."); | ||
807 | ret = -1; | ||
808 | } | ||
809 | |||
810 | return ret; | ||
811 | } | ||
812 | #endif /* CONFIG_HW_BRANCH_TRACER */ | ||
813 | |||
814 | #ifdef CONFIG_KSYM_TRACER | 758 | #ifdef CONFIG_KSYM_TRACER |
815 | static int ksym_selftest_dummy; | 759 | static int ksym_selftest_dummy; |
816 | 760 | ||
diff --git a/kernel/user.c b/kernel/user.c index 766467b3bcb7..7e72614b736d 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/user_namespace.h> | 18 | #include <linux/user_namespace.h> |
19 | #include "cred-internals.h" | ||
20 | 19 | ||
21 | struct user_namespace init_user_ns = { | 20 | struct user_namespace init_user_ns = { |
22 | .kref = { | 21 | .kref = { |
@@ -137,9 +136,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid) | |||
137 | struct hlist_head *hashent = uidhashentry(ns, uid); | 136 | struct hlist_head *hashent = uidhashentry(ns, uid); |
138 | struct user_struct *up, *new; | 137 | struct user_struct *up, *new; |
139 | 138 | ||
140 | /* Make uid_hash_find() + uids_user_create() + uid_hash_insert() | ||
141 | * atomic. | ||
142 | */ | ||
143 | spin_lock_irq(&uidhash_lock); | 139 | spin_lock_irq(&uidhash_lock); |
144 | up = uid_hash_find(uid, hashent); | 140 | up = uid_hash_find(uid, hashent); |
145 | spin_unlock_irq(&uidhash_lock); | 141 | spin_unlock_irq(&uidhash_lock); |
@@ -161,11 +157,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid) | |||
161 | spin_lock_irq(&uidhash_lock); | 157 | spin_lock_irq(&uidhash_lock); |
162 | up = uid_hash_find(uid, hashent); | 158 | up = uid_hash_find(uid, hashent); |
163 | if (up) { | 159 | if (up) { |
164 | /* This case is not possible when CONFIG_USER_SCHED | ||
165 | * is defined, since we serialize alloc_uid() using | ||
166 | * uids_mutex. Hence no need to call | ||
167 | * sched_destroy_user() or remove_user_sysfs_dir(). | ||
168 | */ | ||
169 | key_put(new->uid_keyring); | 160 | key_put(new->uid_keyring); |
170 | key_put(new->session_keyring); | 161 | key_put(new->session_keyring); |
171 | kmem_cache_free(uid_cachep, new); | 162 | kmem_cache_free(uid_cachep, new); |
@@ -178,8 +169,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid) | |||
178 | 169 | ||
179 | return up; | 170 | return up; |
180 | 171 | ||
181 | put_user_ns(new->user_ns); | ||
182 | kmem_cache_free(uid_cachep, new); | ||
183 | out_unlock: | 172 | out_unlock: |
184 | return NULL; | 173 | return NULL; |
185 | } | 174 | } |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 935248bdbc47..d85be90d5888 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -512,6 +512,18 @@ config PROVE_RCU | |||
512 | 512 | ||
513 | Say N if you are unsure. | 513 | Say N if you are unsure. |
514 | 514 | ||
515 | config PROVE_RCU_REPEATEDLY | ||
516 | bool "RCU debugging: don't disable PROVE_RCU on first splat" | ||
517 | depends on PROVE_RCU | ||
518 | default n | ||
519 | help | ||
520 | By itself, PROVE_RCU will disable checking upon issuing the | ||
521 | first warning (or "splat"). This feature prevents such | ||
522 | disabling, allowing multiple RCU-lockdep warnings to be printed | ||
523 | on a single reboot. | ||
524 | |||
525 | Say N if you are unsure. | ||
526 | |||
515 | config LOCKDEP | 527 | config LOCKDEP |
516 | bool | 528 | bool |
517 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT | 529 | depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT |
@@ -793,7 +805,7 @@ config RCU_CPU_STALL_DETECTOR | |||
793 | config RCU_CPU_STALL_VERBOSE | 805 | config RCU_CPU_STALL_VERBOSE |
794 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" | 806 | bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR" |
795 | depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU | 807 | depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU |
796 | default n | 808 | default y |
797 | help | 809 | help |
798 | This option causes RCU to printk detailed per-task information | 810 | This option causes RCU to printk detailed per-task information |
799 | for any tasks that are stalling the current RCU grace period. | 811 | for any tasks that are stalling the current RCU grace period. |
@@ -1086,6 +1098,13 @@ config DMA_API_DEBUG | |||
1086 | This option causes a performance degredation. Use only if you want | 1098 | This option causes a performance degredation. Use only if you want |
1087 | to debug device drivers. If unsure, say N. | 1099 | to debug device drivers. If unsure, say N. |
1088 | 1100 | ||
1101 | config ATOMIC64_SELFTEST | ||
1102 | bool "Perform an atomic64_t self-test at boot" | ||
1103 | help | ||
1104 | Enable this option to test the atomic64_t functions at boot. | ||
1105 | |||
1106 | If unsure, say N. | ||
1107 | |||
1089 | source "samples/Kconfig" | 1108 | source "samples/Kconfig" |
1090 | 1109 | ||
1091 | source "lib/Kconfig.kgdb" | 1110 | source "lib/Kconfig.kgdb" |
diff --git a/lib/Makefile b/lib/Makefile index 0d4015205c64..9e6d3c29d73a 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -39,7 +39,10 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o | |||
39 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o | 39 | lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o |
40 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o | 40 | lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o |
41 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o | 41 | obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o |
42 | |||
43 | CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS)) | ||
42 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o | 44 | obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o |
45 | |||
43 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o | 46 | obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o |
44 | obj-$(CONFIG_BTREE) += btree.o | 47 | obj-$(CONFIG_BTREE) += btree.o |
45 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o | 48 | obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o |
@@ -101,6 +104,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o | |||
101 | 104 | ||
102 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o | 105 | obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o |
103 | 106 | ||
107 | obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o | ||
108 | |||
104 | hostprogs-y := gen_crc32table | 109 | hostprogs-y := gen_crc32table |
105 | clean-files := crc32table.h | 110 | clean-files := crc32table.h |
106 | 111 | ||
diff --git a/lib/atomic64.c b/lib/atomic64.c index 8bee16ec7524..a21c12bc727c 100644 --- a/lib/atomic64.c +++ b/lib/atomic64.c | |||
@@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u) | |||
162 | { | 162 | { |
163 | unsigned long flags; | 163 | unsigned long flags; |
164 | spinlock_t *lock = lock_addr(v); | 164 | spinlock_t *lock = lock_addr(v); |
165 | int ret = 1; | 165 | int ret = 0; |
166 | 166 | ||
167 | spin_lock_irqsave(lock, flags); | 167 | spin_lock_irqsave(lock, flags); |
168 | if (v->counter != u) { | 168 | if (v->counter != u) { |
169 | v->counter += a; | 169 | v->counter += a; |
170 | ret = 0; | 170 | ret = 1; |
171 | } | 171 | } |
172 | spin_unlock_irqrestore(lock, flags); | 172 | spin_unlock_irqrestore(lock, flags); |
173 | return ret; | 173 | return ret; |
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c new file mode 100644 index 000000000000..65e482caf5e9 --- /dev/null +++ b/lib/atomic64_test.c | |||
@@ -0,0 +1,164 @@ | |||
1 | /* | ||
2 | * Testsuite for atomic64_t functions | ||
3 | * | ||
4 | * Copyright © 2010 Luca Barbieri | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | #include <linux/init.h> | ||
12 | #include <asm/atomic.h> | ||
13 | |||
14 | #define INIT(c) do { atomic64_set(&v, c); r = c; } while (0) | ||
15 | static __init int test_atomic64(void) | ||
16 | { | ||
17 | long long v0 = 0xaaa31337c001d00dLL; | ||
18 | long long v1 = 0xdeadbeefdeafcafeLL; | ||
19 | long long v2 = 0xfaceabadf00df001LL; | ||
20 | long long onestwos = 0x1111111122222222LL; | ||
21 | long long one = 1LL; | ||
22 | |||
23 | atomic64_t v = ATOMIC64_INIT(v0); | ||
24 | long long r = v0; | ||
25 | BUG_ON(v.counter != r); | ||
26 | |||
27 | atomic64_set(&v, v1); | ||
28 | r = v1; | ||
29 | BUG_ON(v.counter != r); | ||
30 | BUG_ON(atomic64_read(&v) != r); | ||
31 | |||
32 | INIT(v0); | ||
33 | atomic64_add(onestwos, &v); | ||
34 | r += onestwos; | ||
35 | BUG_ON(v.counter != r); | ||
36 | |||
37 | INIT(v0); | ||
38 | atomic64_add(-one, &v); | ||
39 | r += -one; | ||
40 | BUG_ON(v.counter != r); | ||
41 | |||
42 | INIT(v0); | ||
43 | r += onestwos; | ||
44 | BUG_ON(atomic64_add_return(onestwos, &v) != r); | ||
45 | BUG_ON(v.counter != r); | ||
46 | |||
47 | INIT(v0); | ||
48 | r += -one; | ||
49 | BUG_ON(atomic64_add_return(-one, &v) != r); | ||
50 | BUG_ON(v.counter != r); | ||
51 | |||
52 | INIT(v0); | ||
53 | atomic64_sub(onestwos, &v); | ||
54 | r -= onestwos; | ||
55 | BUG_ON(v.counter != r); | ||
56 | |||
57 | INIT(v0); | ||
58 | atomic64_sub(-one, &v); | ||
59 | r -= -one; | ||
60 | BUG_ON(v.counter != r); | ||
61 | |||
62 | INIT(v0); | ||
63 | r -= onestwos; | ||
64 | BUG_ON(atomic64_sub_return(onestwos, &v) != r); | ||
65 | BUG_ON(v.counter != r); | ||
66 | |||
67 | INIT(v0); | ||
68 | r -= -one; | ||
69 | BUG_ON(atomic64_sub_return(-one, &v) != r); | ||
70 | BUG_ON(v.counter != r); | ||
71 | |||
72 | INIT(v0); | ||
73 | atomic64_inc(&v); | ||
74 | r += one; | ||
75 | BUG_ON(v.counter != r); | ||
76 | |||
77 | INIT(v0); | ||
78 | r += one; | ||
79 | BUG_ON(atomic64_inc_return(&v) != r); | ||
80 | BUG_ON(v.counter != r); | ||
81 | |||
82 | INIT(v0); | ||
83 | atomic64_dec(&v); | ||
84 | r -= one; | ||
85 | BUG_ON(v.counter != r); | ||
86 | |||
87 | INIT(v0); | ||
88 | r -= one; | ||
89 | BUG_ON(atomic64_dec_return(&v) != r); | ||
90 | BUG_ON(v.counter != r); | ||
91 | |||
92 | INIT(v0); | ||
93 | BUG_ON(atomic64_xchg(&v, v1) != v0); | ||
94 | r = v1; | ||
95 | BUG_ON(v.counter != r); | ||
96 | |||
97 | INIT(v0); | ||
98 | BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0); | ||
99 | r = v1; | ||
100 | BUG_ON(v.counter != r); | ||
101 | |||
102 | INIT(v0); | ||
103 | BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0); | ||
104 | BUG_ON(v.counter != r); | ||
105 | |||
106 | INIT(v0); | ||
107 | BUG_ON(atomic64_add_unless(&v, one, v0)); | ||
108 | BUG_ON(v.counter != r); | ||
109 | |||
110 | INIT(v0); | ||
111 | BUG_ON(!atomic64_add_unless(&v, one, v1)); | ||
112 | r += one; | ||
113 | BUG_ON(v.counter != r); | ||
114 | |||
115 | #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(_ASM_GENERIC_ATOMIC64_H) | ||
116 | INIT(onestwos); | ||
117 | BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1)); | ||
118 | r -= one; | ||
119 | BUG_ON(v.counter != r); | ||
120 | |||
121 | INIT(0); | ||
122 | BUG_ON(atomic64_dec_if_positive(&v) != -one); | ||
123 | BUG_ON(v.counter != r); | ||
124 | |||
125 | INIT(-one); | ||
126 | BUG_ON(atomic64_dec_if_positive(&v) != (-one - one)); | ||
127 | BUG_ON(v.counter != r); | ||
128 | #else | ||
129 | #warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above | ||
130 | #endif | ||
131 | |||
132 | INIT(onestwos); | ||
133 | BUG_ON(!atomic64_inc_not_zero(&v)); | ||
134 | r += one; | ||
135 | BUG_ON(v.counter != r); | ||
136 | |||
137 | INIT(0); | ||
138 | BUG_ON(atomic64_inc_not_zero(&v)); | ||
139 | BUG_ON(v.counter != r); | ||
140 | |||
141 | INIT(-one); | ||
142 | BUG_ON(!atomic64_inc_not_zero(&v)); | ||
143 | r += one; | ||
144 | BUG_ON(v.counter != r); | ||
145 | |||
146 | #ifdef CONFIG_X86 | ||
147 | printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n", | ||
148 | #ifdef CONFIG_X86_64 | ||
149 | "x86-64", | ||
150 | #elif defined(CONFIG_X86_CMPXCHG64) | ||
151 | "i586+", | ||
152 | #else | ||
153 | "i386+", | ||
154 | #endif | ||
155 | boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without", | ||
156 | boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without"); | ||
157 | #else | ||
158 | printk(KERN_INFO "atomic64 test passed\n"); | ||
159 | #endif | ||
160 | |||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | core_initcall(test_atomic64); | ||
diff --git a/lib/btree.c b/lib/btree.c index 41859a820218..c9c6f0351526 100644 --- a/lib/btree.c +++ b/lib/btree.c | |||
@@ -95,7 +95,8 @@ static unsigned long *btree_node_alloc(struct btree_head *head, gfp_t gfp) | |||
95 | unsigned long *node; | 95 | unsigned long *node; |
96 | 96 | ||
97 | node = mempool_alloc(head->mempool, gfp); | 97 | node = mempool_alloc(head->mempool, gfp); |
98 | memset(node, 0, NODESIZE); | 98 | if (likely(node)) |
99 | memset(node, 0, NODESIZE); | ||
99 | return node; | 100 | return node; |
100 | } | 101 | } |
101 | 102 | ||
diff --git a/lib/debugobjects.c b/lib/debugobjects.c index b862b30369ff..deebcc57d4e6 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c | |||
@@ -141,6 +141,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr) | |||
141 | obj->object = addr; | 141 | obj->object = addr; |
142 | obj->descr = descr; | 142 | obj->descr = descr; |
143 | obj->state = ODEBUG_STATE_NONE; | 143 | obj->state = ODEBUG_STATE_NONE; |
144 | obj->astate = 0; | ||
144 | hlist_del(&obj->node); | 145 | hlist_del(&obj->node); |
145 | 146 | ||
146 | hlist_add_head(&obj->node, &b->list); | 147 | hlist_add_head(&obj->node, &b->list); |
@@ -252,8 +253,10 @@ static void debug_print_object(struct debug_obj *obj, char *msg) | |||
252 | 253 | ||
253 | if (limit < 5 && obj->descr != descr_test) { | 254 | if (limit < 5 && obj->descr != descr_test) { |
254 | limit++; | 255 | limit++; |
255 | WARN(1, KERN_ERR "ODEBUG: %s %s object type: %s\n", msg, | 256 | WARN(1, KERN_ERR "ODEBUG: %s %s (active state %u) " |
256 | obj_states[obj->state], obj->descr->name); | 257 | "object type: %s\n", |
258 | msg, obj_states[obj->state], obj->astate, | ||
259 | obj->descr->name); | ||
257 | } | 260 | } |
258 | debug_objects_warnings++; | 261 | debug_objects_warnings++; |
259 | } | 262 | } |
@@ -447,7 +450,10 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr) | |||
447 | case ODEBUG_STATE_INIT: | 450 | case ODEBUG_STATE_INIT: |
448 | case ODEBUG_STATE_INACTIVE: | 451 | case ODEBUG_STATE_INACTIVE: |
449 | case ODEBUG_STATE_ACTIVE: | 452 | case ODEBUG_STATE_ACTIVE: |
450 | obj->state = ODEBUG_STATE_INACTIVE; | 453 | if (!obj->astate) |
454 | obj->state = ODEBUG_STATE_INACTIVE; | ||
455 | else | ||
456 | debug_print_object(obj, "deactivate"); | ||
451 | break; | 457 | break; |
452 | 458 | ||
453 | case ODEBUG_STATE_DESTROYED: | 459 | case ODEBUG_STATE_DESTROYED: |
@@ -553,6 +559,53 @@ out_unlock: | |||
553 | raw_spin_unlock_irqrestore(&db->lock, flags); | 559 | raw_spin_unlock_irqrestore(&db->lock, flags); |
554 | } | 560 | } |
555 | 561 | ||
562 | /** | ||
563 | * debug_object_active_state - debug checks object usage state machine | ||
564 | * @addr: address of the object | ||
565 | * @descr: pointer to an object specific debug description structure | ||
566 | * @expect: expected state | ||
567 | * @next: state to move to if expected state is found | ||
568 | */ | ||
569 | void | ||
570 | debug_object_active_state(void *addr, struct debug_obj_descr *descr, | ||
571 | unsigned int expect, unsigned int next) | ||
572 | { | ||
573 | struct debug_bucket *db; | ||
574 | struct debug_obj *obj; | ||
575 | unsigned long flags; | ||
576 | |||
577 | if (!debug_objects_enabled) | ||
578 | return; | ||
579 | |||
580 | db = get_bucket((unsigned long) addr); | ||
581 | |||
582 | raw_spin_lock_irqsave(&db->lock, flags); | ||
583 | |||
584 | obj = lookup_object(addr, db); | ||
585 | if (obj) { | ||
586 | switch (obj->state) { | ||
587 | case ODEBUG_STATE_ACTIVE: | ||
588 | if (obj->astate == expect) | ||
589 | obj->astate = next; | ||
590 | else | ||
591 | debug_print_object(obj, "active_state"); | ||
592 | break; | ||
593 | |||
594 | default: | ||
595 | debug_print_object(obj, "active_state"); | ||
596 | break; | ||
597 | } | ||
598 | } else { | ||
599 | struct debug_obj o = { .object = addr, | ||
600 | .state = ODEBUG_STATE_NOTAVAILABLE, | ||
601 | .descr = descr }; | ||
602 | |||
603 | debug_print_object(&o, "active_state"); | ||
604 | } | ||
605 | |||
606 | raw_spin_unlock_irqrestore(&db->lock, flags); | ||
607 | } | ||
608 | |||
556 | #ifdef CONFIG_DEBUG_OBJECTS_FREE | 609 | #ifdef CONFIG_DEBUG_OBJECTS_FREE |
557 | static void __debug_check_no_obj_freed(const void *address, unsigned long size) | 610 | static void __debug_check_no_obj_freed(const void *address, unsigned long size) |
558 | { | 611 | { |
@@ -774,7 +827,7 @@ static int __init fixup_free(void *addr, enum debug_obj_state state) | |||
774 | } | 827 | } |
775 | } | 828 | } |
776 | 829 | ||
777 | static int | 830 | static int __init |
778 | check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) | 831 | check_results(void *addr, enum debug_obj_state state, int fixups, int warnings) |
779 | { | 832 | { |
780 | struct debug_bucket *db; | 833 | struct debug_bucket *db; |
@@ -917,7 +970,7 @@ void __init debug_objects_early_init(void) | |||
917 | /* | 970 | /* |
918 | * Convert the statically allocated objects to dynamic ones: | 971 | * Convert the statically allocated objects to dynamic ones: |
919 | */ | 972 | */ |
920 | static int debug_objects_replace_static_objects(void) | 973 | static int __init debug_objects_replace_static_objects(void) |
921 | { | 974 | { |
922 | struct debug_bucket *db = obj_hash; | 975 | struct debug_bucket *db = obj_hash; |
923 | struct hlist_node *node, *tmp; | 976 | struct hlist_node *node, *tmp; |
diff --git a/lib/hweight.c b/lib/hweight.c index 63ee4eb1228d..3c79d50814cf 100644 --- a/lib/hweight.c +++ b/lib/hweight.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * The Hamming Weight of a number is the total number of bits set in it. | 9 | * The Hamming Weight of a number is the total number of bits set in it. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | unsigned int hweight32(unsigned int w) | 12 | unsigned int __sw_hweight32(unsigned int w) |
13 | { | 13 | { |
14 | #ifdef ARCH_HAS_FAST_MULTIPLIER | 14 | #ifdef ARCH_HAS_FAST_MULTIPLIER |
15 | w -= (w >> 1) & 0x55555555; | 15 | w -= (w >> 1) & 0x55555555; |
@@ -24,29 +24,30 @@ unsigned int hweight32(unsigned int w) | |||
24 | return (res + (res >> 16)) & 0x000000FF; | 24 | return (res + (res >> 16)) & 0x000000FF; |
25 | #endif | 25 | #endif |
26 | } | 26 | } |
27 | EXPORT_SYMBOL(hweight32); | 27 | EXPORT_SYMBOL(__sw_hweight32); |
28 | 28 | ||
29 | unsigned int hweight16(unsigned int w) | 29 | unsigned int __sw_hweight16(unsigned int w) |
30 | { | 30 | { |
31 | unsigned int res = w - ((w >> 1) & 0x5555); | 31 | unsigned int res = w - ((w >> 1) & 0x5555); |
32 | res = (res & 0x3333) + ((res >> 2) & 0x3333); | 32 | res = (res & 0x3333) + ((res >> 2) & 0x3333); |
33 | res = (res + (res >> 4)) & 0x0F0F; | 33 | res = (res + (res >> 4)) & 0x0F0F; |
34 | return (res + (res >> 8)) & 0x00FF; | 34 | return (res + (res >> 8)) & 0x00FF; |
35 | } | 35 | } |
36 | EXPORT_SYMBOL(hweight16); | 36 | EXPORT_SYMBOL(__sw_hweight16); |
37 | 37 | ||
38 | unsigned int hweight8(unsigned int w) | 38 | unsigned int __sw_hweight8(unsigned int w) |
39 | { | 39 | { |
40 | unsigned int res = w - ((w >> 1) & 0x55); | 40 | unsigned int res = w - ((w >> 1) & 0x55); |
41 | res = (res & 0x33) + ((res >> 2) & 0x33); | 41 | res = (res & 0x33) + ((res >> 2) & 0x33); |
42 | return (res + (res >> 4)) & 0x0F; | 42 | return (res + (res >> 4)) & 0x0F; |
43 | } | 43 | } |
44 | EXPORT_SYMBOL(hweight8); | 44 | EXPORT_SYMBOL(__sw_hweight8); |
45 | 45 | ||
46 | unsigned long hweight64(__u64 w) | 46 | unsigned long __sw_hweight64(__u64 w) |
47 | { | 47 | { |
48 | #if BITS_PER_LONG == 32 | 48 | #if BITS_PER_LONG == 32 |
49 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | 49 | return __sw_hweight32((unsigned int)(w >> 32)) + |
50 | __sw_hweight32((unsigned int)w); | ||
50 | #elif BITS_PER_LONG == 64 | 51 | #elif BITS_PER_LONG == 64 |
51 | #ifdef ARCH_HAS_FAST_MULTIPLIER | 52 | #ifdef ARCH_HAS_FAST_MULTIPLIER |
52 | w -= (w >> 1) & 0x5555555555555555ul; | 53 | w -= (w >> 1) & 0x5555555555555555ul; |
@@ -63,4 +64,4 @@ unsigned long hweight64(__u64 w) | |||
63 | #endif | 64 | #endif |
64 | #endif | 65 | #endif |
65 | } | 66 | } |
66 | EXPORT_SYMBOL(hweight64); | 67 | EXPORT_SYMBOL(__sw_hweight64); |
diff --git a/lib/rbtree.c b/lib/rbtree.c index e2aa3be29858..15e10b1afdd2 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -44,6 +44,11 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) | |||
44 | else | 44 | else |
45 | root->rb_node = right; | 45 | root->rb_node = right; |
46 | rb_set_parent(node, right); | 46 | rb_set_parent(node, right); |
47 | |||
48 | if (root->augment_cb) { | ||
49 | root->augment_cb(node); | ||
50 | root->augment_cb(right); | ||
51 | } | ||
47 | } | 52 | } |
48 | 53 | ||
49 | static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) | 54 | static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) |
@@ -67,12 +72,20 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) | |||
67 | else | 72 | else |
68 | root->rb_node = left; | 73 | root->rb_node = left; |
69 | rb_set_parent(node, left); | 74 | rb_set_parent(node, left); |
75 | |||
76 | if (root->augment_cb) { | ||
77 | root->augment_cb(node); | ||
78 | root->augment_cb(left); | ||
79 | } | ||
70 | } | 80 | } |
71 | 81 | ||
72 | void rb_insert_color(struct rb_node *node, struct rb_root *root) | 82 | void rb_insert_color(struct rb_node *node, struct rb_root *root) |
73 | { | 83 | { |
74 | struct rb_node *parent, *gparent; | 84 | struct rb_node *parent, *gparent; |
75 | 85 | ||
86 | if (root->augment_cb) | ||
87 | root->augment_cb(node); | ||
88 | |||
76 | while ((parent = rb_parent(node)) && rb_is_red(parent)) | 89 | while ((parent = rb_parent(node)) && rb_is_red(parent)) |
77 | { | 90 | { |
78 | gparent = rb_parent(parent); | 91 | gparent = rb_parent(parent); |
@@ -227,12 +240,15 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
227 | else | 240 | else |
228 | { | 241 | { |
229 | struct rb_node *old = node, *left; | 242 | struct rb_node *old = node, *left; |
243 | int old_parent_cb = 0; | ||
244 | int successor_parent_cb = 0; | ||
230 | 245 | ||
231 | node = node->rb_right; | 246 | node = node->rb_right; |
232 | while ((left = node->rb_left) != NULL) | 247 | while ((left = node->rb_left) != NULL) |
233 | node = left; | 248 | node = left; |
234 | 249 | ||
235 | if (rb_parent(old)) { | 250 | if (rb_parent(old)) { |
251 | old_parent_cb = 1; | ||
236 | if (rb_parent(old)->rb_left == old) | 252 | if (rb_parent(old)->rb_left == old) |
237 | rb_parent(old)->rb_left = node; | 253 | rb_parent(old)->rb_left = node; |
238 | else | 254 | else |
@@ -247,8 +263,10 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
247 | if (parent == old) { | 263 | if (parent == old) { |
248 | parent = node; | 264 | parent = node; |
249 | } else { | 265 | } else { |
266 | successor_parent_cb = 1; | ||
250 | if (child) | 267 | if (child) |
251 | rb_set_parent(child, parent); | 268 | rb_set_parent(child, parent); |
269 | |||
252 | parent->rb_left = child; | 270 | parent->rb_left = child; |
253 | 271 | ||
254 | node->rb_right = old->rb_right; | 272 | node->rb_right = old->rb_right; |
@@ -259,6 +277,24 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
259 | node->rb_left = old->rb_left; | 277 | node->rb_left = old->rb_left; |
260 | rb_set_parent(old->rb_left, node); | 278 | rb_set_parent(old->rb_left, node); |
261 | 279 | ||
280 | if (root->augment_cb) { | ||
281 | /* | ||
282 | * Here, three different nodes can have new children. | ||
283 | * The parent of the successor node that was selected | ||
284 | * to replace the node to be erased. | ||
285 | * The node that is getting erased and is now replaced | ||
286 | * by its successor. | ||
287 | * The parent of the node getting erased-replaced. | ||
288 | */ | ||
289 | if (successor_parent_cb) | ||
290 | root->augment_cb(parent); | ||
291 | |||
292 | root->augment_cb(node); | ||
293 | |||
294 | if (old_parent_cb) | ||
295 | root->augment_cb(rb_parent(old)); | ||
296 | } | ||
297 | |||
262 | goto color; | 298 | goto color; |
263 | } | 299 | } |
264 | 300 | ||
@@ -267,15 +303,19 @@ void rb_erase(struct rb_node *node, struct rb_root *root) | |||
267 | 303 | ||
268 | if (child) | 304 | if (child) |
269 | rb_set_parent(child, parent); | 305 | rb_set_parent(child, parent); |
270 | if (parent) | 306 | |
271 | { | 307 | if (parent) { |
272 | if (parent->rb_left == node) | 308 | if (parent->rb_left == node) |
273 | parent->rb_left = child; | 309 | parent->rb_left = child; |
274 | else | 310 | else |
275 | parent->rb_right = child; | 311 | parent->rb_right = child; |
276 | } | 312 | |
277 | else | 313 | if (root->augment_cb) |
314 | root->augment_cb(parent); | ||
315 | |||
316 | } else { | ||
278 | root->rb_node = child; | 317 | root->rb_node = child; |
318 | } | ||
279 | 319 | ||
280 | color: | 320 | color: |
281 | if (color == RB_BLACK) | 321 | if (color == RB_BLACK) |
diff --git a/lib/rwsem.c b/lib/rwsem.c index 3e3365e5665e..ceba8e28807a 100644 --- a/lib/rwsem.c +++ b/lib/rwsem.c | |||
@@ -136,9 +136,10 @@ __rwsem_do_wake(struct rw_semaphore *sem, int downgrading) | |||
136 | out: | 136 | out: |
137 | return sem; | 137 | return sem; |
138 | 138 | ||
139 | /* undo the change to count, but check for a transition 1->0 */ | 139 | /* undo the change to the active count, but check for a transition |
140 | * 1->0 */ | ||
140 | undo: | 141 | undo: |
141 | if (rwsem_atomic_update(-RWSEM_ACTIVE_BIAS, sem) != 0) | 142 | if (rwsem_atomic_update(-RWSEM_ACTIVE_BIAS, sem) & RWSEM_ACTIVE_MASK) |
142 | goto out; | 143 | goto out; |
143 | goto try_again; | 144 | goto try_again; |
144 | } | 145 | } |
diff --git a/mm/mlock.c b/mm/mlock.c index 8f4e2dfceec1..3f82720e0515 100644 --- a/mm/mlock.c +++ b/mm/mlock.c | |||
@@ -607,44 +607,3 @@ void user_shm_unlock(size_t size, struct user_struct *user) | |||
607 | spin_unlock(&shmlock_user_lock); | 607 | spin_unlock(&shmlock_user_lock); |
608 | free_uid(user); | 608 | free_uid(user); |
609 | } | 609 | } |
610 | |||
611 | int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim, | ||
612 | size_t size) | ||
613 | { | ||
614 | unsigned long lim, vm, pgsz; | ||
615 | int error = -ENOMEM; | ||
616 | |||
617 | pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT; | ||
618 | |||
619 | down_write(&mm->mmap_sem); | ||
620 | |||
621 | lim = ACCESS_ONCE(rlim[RLIMIT_AS].rlim_cur) >> PAGE_SHIFT; | ||
622 | vm = mm->total_vm + pgsz; | ||
623 | if (lim < vm) | ||
624 | goto out; | ||
625 | |||
626 | lim = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur) >> PAGE_SHIFT; | ||
627 | vm = mm->locked_vm + pgsz; | ||
628 | if (lim < vm) | ||
629 | goto out; | ||
630 | |||
631 | mm->total_vm += pgsz; | ||
632 | mm->locked_vm += pgsz; | ||
633 | |||
634 | error = 0; | ||
635 | out: | ||
636 | up_write(&mm->mmap_sem); | ||
637 | return error; | ||
638 | } | ||
639 | |||
640 | void refund_locked_memory(struct mm_struct *mm, size_t size) | ||
641 | { | ||
642 | unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT; | ||
643 | |||
644 | down_write(&mm->mmap_sem); | ||
645 | |||
646 | mm->total_vm -= pgsz; | ||
647 | mm->locked_vm -= pgsz; | ||
648 | |||
649 | up_write(&mm->mmap_sem); | ||
650 | } | ||
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index f9bdf264473d..cbcd654215e6 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -245,3 +245,7 @@ quiet_cmd_lzo = LZO $@ | |||
245 | cmd_lzo = (cat $(filter-out FORCE,$^) | \ | 245 | cmd_lzo = (cat $(filter-out FORCE,$^) | \ |
246 | lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ | 246 | lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ |
247 | (rm -f $@ ; false) | 247 | (rm -f $@ ; false) |
248 | |||
249 | # misc stuff | ||
250 | # --------------------------------------------------------------------------- | ||
251 | quote:=" | ||
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 36a60a853173..9cf2400580a7 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
@@ -818,6 +818,16 @@ static int do_mdio_entry(const char *filename, | |||
818 | return 1; | 818 | return 1; |
819 | } | 819 | } |
820 | 820 | ||
821 | /* Looks like: zorro:iN. */ | ||
822 | static int do_zorro_entry(const char *filename, struct zorro_device_id *id, | ||
823 | char *alias) | ||
824 | { | ||
825 | id->id = TO_NATIVE(id->id); | ||
826 | strcpy(alias, "zorro:"); | ||
827 | ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id); | ||
828 | return 1; | ||
829 | } | ||
830 | |||
821 | /* Ignore any prefix, eg. some architectures prepend _ */ | 831 | /* Ignore any prefix, eg. some architectures prepend _ */ |
822 | static inline int sym_is(const char *symbol, const char *name) | 832 | static inline int sym_is(const char *symbol, const char *name) |
823 | { | 833 | { |
@@ -969,6 +979,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, | |||
969 | do_table(symval, sym->st_size, | 979 | do_table(symval, sym->st_size, |
970 | sizeof(struct mdio_device_id), "mdio", | 980 | sizeof(struct mdio_device_id), "mdio", |
971 | do_mdio_entry, mod); | 981 | do_mdio_entry, mod); |
982 | else if (sym_is(symname, "__mod_zorro_device_table")) | ||
983 | do_table(symval, sym->st_size, | ||
984 | sizeof(struct zorro_device_id), "zorro", | ||
985 | do_zorro_entry, mod); | ||
972 | free(zeros); | 986 | free(zeros); |
973 | } | 987 | } |
974 | 988 | ||
diff --git a/security/min_addr.c b/security/min_addr.c index e86f297522bf..f728728f193b 100644 --- a/security/min_addr.c +++ b/security/min_addr.c | |||
@@ -33,7 +33,7 @@ int mmap_min_addr_handler(struct ctl_table *table, int write, | |||
33 | { | 33 | { |
34 | int ret; | 34 | int ret; |
35 | 35 | ||
36 | if (!capable(CAP_SYS_RAWIO)) | 36 | if (write && !capable(CAP_SYS_RAWIO)) |
37 | return -EPERM; | 37 | return -EPERM; |
38 | 38 | ||
39 | ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos); | 39 | ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos); |
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 872887624030..20b5982c996b 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c | |||
@@ -36,6 +36,9 @@ | |||
36 | #include <sound/timer.h> | 36 | #include <sound/timer.h> |
37 | #include <sound/minors.h> | 37 | #include <sound/minors.h> |
38 | #include <asm/io.h> | 38 | #include <asm/io.h> |
39 | #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) | ||
40 | #include <dma-coherence.h> | ||
41 | #endif | ||
39 | 42 | ||
40 | /* | 43 | /* |
41 | * Compatibility | 44 | * Compatibility |
@@ -3184,6 +3187,10 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream, | |||
3184 | substream->runtime->dma_area, | 3187 | substream->runtime->dma_area, |
3185 | substream->runtime->dma_addr, | 3188 | substream->runtime->dma_addr, |
3186 | area->vm_end - area->vm_start); | 3189 | area->vm_end - area->vm_start); |
3190 | #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) | ||
3191 | if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV && | ||
3192 | !plat_device_is_coherent(substream->dma_buffer.dev.dev)) | ||
3193 | area->vm_page_prot = pgprot_noncached(area->vm_page_prot); | ||
3187 | #endif /* ARCH_HAS_DMA_MMAP_COHERENT */ | 3194 | #endif /* ARCH_HAS_DMA_MMAP_COHERENT */ |
3188 | /* mmap with fault handler */ | 3195 | /* mmap with fault handler */ |
3189 | area->vm_ops = &snd_pcm_vm_ops_data_fault; | 3196 | area->vm_ops = &snd_pcm_vm_ops_data_fault; |
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h index 1e123077923d..4ff6c8cc5077 100644 --- a/sound/drivers/pcsp/pcsp.h +++ b/sound/drivers/pcsp/pcsp.h | |||
@@ -16,7 +16,7 @@ | |||
16 | #include <asm/i8253.h> | 16 | #include <asm/i8253.h> |
17 | #else | 17 | #else |
18 | #include <asm/8253pit.h> | 18 | #include <asm/8253pit.h> |
19 | static DEFINE_SPINLOCK(i8253_lock); | 19 | static DEFINE_RAW_SPINLOCK(i8253_lock); |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */ | 22 | #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */ |
diff --git a/sound/drivers/pcsp/pcsp_input.c b/sound/drivers/pcsp/pcsp_input.c index 0444cdeb4bec..b5e2b54c2604 100644 --- a/sound/drivers/pcsp/pcsp_input.c +++ b/sound/drivers/pcsp/pcsp_input.c | |||
@@ -21,7 +21,7 @@ static void pcspkr_do_sound(unsigned int count) | |||
21 | { | 21 | { |
22 | unsigned long flags; | 22 | unsigned long flags; |
23 | 23 | ||
24 | spin_lock_irqsave(&i8253_lock, flags); | 24 | raw_spin_lock_irqsave(&i8253_lock, flags); |
25 | 25 | ||
26 | if (count) { | 26 | if (count) { |
27 | /* set command for counter 2, 2 byte write */ | 27 | /* set command for counter 2, 2 byte write */ |
@@ -36,7 +36,7 @@ static void pcspkr_do_sound(unsigned int count) | |||
36 | outb(inb_p(0x61) & 0xFC, 0x61); | 36 | outb(inb_p(0x61) & 0xFC, 0x61); |
37 | } | 37 | } |
38 | 38 | ||
39 | spin_unlock_irqrestore(&i8253_lock, flags); | 39 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
40 | } | 40 | } |
41 | 41 | ||
42 | void pcspkr_stop_sound(void) | 42 | void pcspkr_stop_sound(void) |
diff --git a/sound/drivers/pcsp/pcsp_lib.c b/sound/drivers/pcsp/pcsp_lib.c index d77ffa9a9387..ce9e7d170c0d 100644 --- a/sound/drivers/pcsp/pcsp_lib.c +++ b/sound/drivers/pcsp/pcsp_lib.c | |||
@@ -66,7 +66,7 @@ static u64 pcsp_timer_update(struct snd_pcsp *chip) | |||
66 | timer_cnt = val * CUR_DIV() / 256; | 66 | timer_cnt = val * CUR_DIV() / 256; |
67 | 67 | ||
68 | if (timer_cnt && chip->enable) { | 68 | if (timer_cnt && chip->enable) { |
69 | spin_lock_irqsave(&i8253_lock, flags); | 69 | raw_spin_lock_irqsave(&i8253_lock, flags); |
70 | if (!nforce_wa) { | 70 | if (!nforce_wa) { |
71 | outb_p(chip->val61, 0x61); | 71 | outb_p(chip->val61, 0x61); |
72 | outb_p(timer_cnt, 0x42); | 72 | outb_p(timer_cnt, 0x42); |
@@ -75,7 +75,7 @@ static u64 pcsp_timer_update(struct snd_pcsp *chip) | |||
75 | outb(chip->val61 ^ 2, 0x61); | 75 | outb(chip->val61 ^ 2, 0x61); |
76 | chip->thalf = 1; | 76 | chip->thalf = 1; |
77 | } | 77 | } |
78 | spin_unlock_irqrestore(&i8253_lock, flags); | 78 | raw_spin_unlock_irqrestore(&i8253_lock, flags); |
79 | } | 79 | } |
80 | 80 | ||
81 | chip->ns_rem = PCSP_PERIOD_NS(); | 81 | chip->ns_rem = PCSP_PERIOD_NS(); |
@@ -159,10 +159,10 @@ static int pcsp_start_playing(struct snd_pcsp *chip) | |||
159 | return -EIO; | 159 | return -EIO; |
160 | } | 160 | } |
161 | 161 | ||
162 | spin_lock(&i8253_lock); | 162 | raw_spin_lock(&i8253_lock); |
163 | chip->val61 = inb(0x61) | 0x03; | 163 | chip->val61 = inb(0x61) | 0x03; |
164 | outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */ | 164 | outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */ |
165 | spin_unlock(&i8253_lock); | 165 | raw_spin_unlock(&i8253_lock); |
166 | atomic_set(&chip->timer_active, 1); | 166 | atomic_set(&chip->timer_active, 1); |
167 | chip->thalf = 0; | 167 | chip->thalf = 0; |
168 | 168 | ||
@@ -179,11 +179,11 @@ static void pcsp_stop_playing(struct snd_pcsp *chip) | |||
179 | return; | 179 | return; |
180 | 180 | ||
181 | atomic_set(&chip->timer_active, 0); | 181 | atomic_set(&chip->timer_active, 0); |
182 | spin_lock(&i8253_lock); | 182 | raw_spin_lock(&i8253_lock); |
183 | /* restore the timer */ | 183 | /* restore the timer */ |
184 | outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */ | 184 | outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */ |
185 | outb(chip->val61 & 0xFC, 0x61); | 185 | outb(chip->val61 & 0xFC, 0x61); |
186 | spin_unlock(&i8253_lock); | 186 | raw_spin_unlock(&i8253_lock); |
187 | } | 187 | } |
188 | 188 | ||
189 | /* | 189 | /* |
diff --git a/sound/oss/dmasound/dmasound_paula.c b/sound/oss/dmasound/dmasound_paula.c index bb14e4c67e89..87910e992133 100644 --- a/sound/oss/dmasound/dmasound_paula.c +++ b/sound/oss/dmasound/dmasound_paula.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/ioport.h> | 21 | #include <linux/ioport.h> |
22 | #include <linux/soundcard.h> | 22 | #include <linux/soundcard.h> |
23 | #include <linux/interrupt.h> | 23 | #include <linux/interrupt.h> |
24 | #include <linux/platform_device.h> | ||
24 | 25 | ||
25 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
26 | #include <asm/setup.h> | 27 | #include <asm/setup.h> |
@@ -710,31 +711,41 @@ static MACHINE machAmiga = { | |||
710 | /*** Config & Setup **********************************************************/ | 711 | /*** Config & Setup **********************************************************/ |
711 | 712 | ||
712 | 713 | ||
713 | static int __init dmasound_paula_init(void) | 714 | static int __init amiga_audio_probe(struct platform_device *pdev) |
714 | { | 715 | { |
715 | int err; | 716 | dmasound.mach = machAmiga; |
716 | 717 | dmasound.mach.default_hard = def_hard ; | |
717 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) { | 718 | dmasound.mach.default_soft = def_soft ; |
718 | if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40, | 719 | return dmasound_init(); |
719 | "dmasound [Paula]")) | ||
720 | return -EBUSY; | ||
721 | dmasound.mach = machAmiga; | ||
722 | dmasound.mach.default_hard = def_hard ; | ||
723 | dmasound.mach.default_soft = def_soft ; | ||
724 | err = dmasound_init(); | ||
725 | if (err) | ||
726 | release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40); | ||
727 | return err; | ||
728 | } else | ||
729 | return -ENODEV; | ||
730 | } | 720 | } |
731 | 721 | ||
732 | static void __exit dmasound_paula_cleanup(void) | 722 | static int __exit amiga_audio_remove(struct platform_device *pdev) |
733 | { | 723 | { |
734 | dmasound_deinit(); | 724 | dmasound_deinit(); |
735 | release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40); | 725 | return 0; |
726 | } | ||
727 | |||
728 | static struct platform_driver amiga_audio_driver = { | ||
729 | .remove = __exit_p(amiga_audio_remove), | ||
730 | .driver = { | ||
731 | .name = "amiga-audio", | ||
732 | .owner = THIS_MODULE, | ||
733 | }, | ||
734 | }; | ||
735 | |||
736 | static int __init amiga_audio_init(void) | ||
737 | { | ||
738 | return platform_driver_probe(&amiga_audio_driver, amiga_audio_probe); | ||
736 | } | 739 | } |
737 | 740 | ||
738 | module_init(dmasound_paula_init); | 741 | module_init(amiga_audio_init); |
739 | module_exit(dmasound_paula_cleanup); | 742 | |
743 | static void __exit amiga_audio_exit(void) | ||
744 | { | ||
745 | platform_driver_unregister(&amiga_audio_driver); | ||
746 | } | ||
747 | |||
748 | module_exit(amiga_audio_exit); | ||
749 | |||
740 | MODULE_LICENSE("GPL"); | 750 | MODULE_LICENSE("GPL"); |
751 | MODULE_ALIAS("platform:amiga-audio"); | ||
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index d8213e2231a6..feabb44c7ca4 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c | |||
@@ -1197,9 +1197,10 @@ static int patch_cxt5045(struct hda_codec *codec) | |||
1197 | case 0x103c: | 1197 | case 0x103c: |
1198 | case 0x1631: | 1198 | case 0x1631: |
1199 | case 0x1734: | 1199 | case 0x1734: |
1200 | /* HP, Packard Bell, & Fujitsu-Siemens laptops have really bad | 1200 | case 0x17aa: |
1201 | * sound over 0dB on NID 0x17. Fix max PCM level to 0 dB | 1201 | /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have |
1202 | * (originally it has 0x2b steps with 0dB offset 0x14) | 1202 | * really bad sound over 0dB on NID 0x17. Fix max PCM level to |
1203 | * 0 dB (originally it has 0x2b steps with 0dB offset 0x14) | ||
1203 | */ | 1204 | */ |
1204 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, | 1205 | snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT, |
1205 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | | 1206 | (0x14 << AC_AMPCAP_OFFSET_SHIFT) | |
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 12825aa03106..a0e06d82da1f 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c | |||
@@ -104,6 +104,7 @@ enum { | |||
104 | STAC_DELL_M4_2, | 104 | STAC_DELL_M4_2, |
105 | STAC_DELL_M4_3, | 105 | STAC_DELL_M4_3, |
106 | STAC_HP_M4, | 106 | STAC_HP_M4, |
107 | STAC_HP_DV4, | ||
107 | STAC_HP_DV5, | 108 | STAC_HP_DV5, |
108 | STAC_HP_HDX, | 109 | STAC_HP_HDX, |
109 | STAC_HP_DV4_1222NR, | 110 | STAC_HP_DV4_1222NR, |
@@ -1691,6 +1692,7 @@ static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { | |||
1691 | [STAC_DELL_M4_2] = dell_m4_2_pin_configs, | 1692 | [STAC_DELL_M4_2] = dell_m4_2_pin_configs, |
1692 | [STAC_DELL_M4_3] = dell_m4_3_pin_configs, | 1693 | [STAC_DELL_M4_3] = dell_m4_3_pin_configs, |
1693 | [STAC_HP_M4] = NULL, | 1694 | [STAC_HP_M4] = NULL, |
1695 | [STAC_HP_DV4] = NULL, | ||
1694 | [STAC_HP_DV5] = NULL, | 1696 | [STAC_HP_DV5] = NULL, |
1695 | [STAC_HP_HDX] = NULL, | 1697 | [STAC_HP_HDX] = NULL, |
1696 | [STAC_HP_DV4_1222NR] = NULL, | 1698 | [STAC_HP_DV4_1222NR] = NULL, |
@@ -1703,6 +1705,7 @@ static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { | |||
1703 | [STAC_DELL_M4_2] = "dell-m4-2", | 1705 | [STAC_DELL_M4_2] = "dell-m4-2", |
1704 | [STAC_DELL_M4_3] = "dell-m4-3", | 1706 | [STAC_DELL_M4_3] = "dell-m4-3", |
1705 | [STAC_HP_M4] = "hp-m4", | 1707 | [STAC_HP_M4] = "hp-m4", |
1708 | [STAC_HP_DV4] = "hp-dv4", | ||
1706 | [STAC_HP_DV5] = "hp-dv5", | 1709 | [STAC_HP_DV5] = "hp-dv5", |
1707 | [STAC_HP_HDX] = "hp-hdx", | 1710 | [STAC_HP_HDX] = "hp-hdx", |
1708 | [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr", | 1711 | [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr", |
@@ -1721,7 +1724,7 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { | |||
1721 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080, | 1724 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080, |
1722 | "HP", STAC_HP_DV5), | 1725 | "HP", STAC_HP_DV5), |
1723 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0, | 1726 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0, |
1724 | "HP dv4-7", STAC_HP_DV5), | 1727 | "HP dv4-7", STAC_HP_DV4), |
1725 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600, | 1728 | SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600, |
1726 | "HP dv4-7", STAC_HP_DV5), | 1729 | "HP dv4-7", STAC_HP_DV5), |
1727 | SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610, | 1730 | SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610, |
@@ -4766,6 +4769,9 @@ static void set_hp_led_gpio(struct hda_codec *codec) | |||
4766 | struct sigmatel_spec *spec = codec->spec; | 4769 | struct sigmatel_spec *spec = codec->spec; |
4767 | unsigned int gpio; | 4770 | unsigned int gpio; |
4768 | 4771 | ||
4772 | if (spec->gpio_led) | ||
4773 | return; | ||
4774 | |||
4769 | gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); | 4775 | gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP); |
4770 | gpio &= AC_GPIO_IO_COUNT; | 4776 | gpio &= AC_GPIO_IO_COUNT; |
4771 | if (gpio > 3) | 4777 | if (gpio > 3) |
@@ -5675,6 +5681,9 @@ again: | |||
5675 | spec->num_smuxes = 1; | 5681 | spec->num_smuxes = 1; |
5676 | spec->num_dmuxes = 1; | 5682 | spec->num_dmuxes = 1; |
5677 | /* fallthrough */ | 5683 | /* fallthrough */ |
5684 | case STAC_HP_DV4: | ||
5685 | spec->gpio_led = 0x01; | ||
5686 | /* fallthrough */ | ||
5678 | case STAC_HP_DV5: | 5687 | case STAC_HP_DV5: |
5679 | snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010); | 5688 | snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010); |
5680 | stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN); | 5689 | stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN); |
@@ -5688,6 +5697,7 @@ again: | |||
5688 | spec->num_dmics = 1; | 5697 | spec->num_dmics = 1; |
5689 | spec->num_dmuxes = 1; | 5698 | spec->num_dmuxes = 1; |
5690 | spec->num_smuxes = 1; | 5699 | spec->num_smuxes = 1; |
5700 | spec->gpio_led = 0x08; | ||
5691 | break; | 5701 | break; |
5692 | } | 5702 | } |
5693 | 5703 | ||
@@ -5744,7 +5754,8 @@ again: | |||
5744 | } | 5754 | } |
5745 | 5755 | ||
5746 | /* enable bass on HP dv7 */ | 5756 | /* enable bass on HP dv7 */ |
5747 | if (spec->board_config == STAC_HP_DV5) { | 5757 | if (spec->board_config == STAC_HP_DV4 || |
5758 | spec->board_config == STAC_HP_DV5) { | ||
5748 | unsigned int cap; | 5759 | unsigned int cap; |
5749 | cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP); | 5760 | cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP); |
5750 | cap &= AC_GPIO_IO_COUNT; | 5761 | cap &= AC_GPIO_IO_COUNT; |
diff --git a/sound/pci/ice1712/maya44.c b/sound/pci/ice1712/maya44.c index 3e1c20ae2f1c..726fd4b92e19 100644 --- a/sound/pci/ice1712/maya44.c +++ b/sound/pci/ice1712/maya44.c | |||
@@ -347,7 +347,7 @@ static int maya_gpio_sw_put(struct snd_kcontrol *kcontrol, | |||
347 | 347 | ||
348 | /* known working input slots (0-4) */ | 348 | /* known working input slots (0-4) */ |
349 | #define MAYA_LINE_IN 1 /* in-2 */ | 349 | #define MAYA_LINE_IN 1 /* in-2 */ |
350 | #define MAYA_MIC_IN 4 /* in-5 */ | 350 | #define MAYA_MIC_IN 3 /* in-4 */ |
351 | 351 | ||
352 | static void wm8776_select_input(struct snd_maya44 *chip, int idx, int line) | 352 | static void wm8776_select_input(struct snd_maya44 *chip, int idx, int line) |
353 | { | 353 | { |
@@ -393,8 +393,8 @@ static int maya_rec_src_put(struct snd_kcontrol *kcontrol, | |||
393 | int changed; | 393 | int changed; |
394 | 394 | ||
395 | mutex_lock(&chip->mutex); | 395 | mutex_lock(&chip->mutex); |
396 | changed = maya_set_gpio_bits(chip->ice, GPIO_MIC_RELAY, | 396 | changed = maya_set_gpio_bits(chip->ice, 1 << GPIO_MIC_RELAY, |
397 | sel ? GPIO_MIC_RELAY : 0); | 397 | sel ? (1 << GPIO_MIC_RELAY) : 0); |
398 | wm8776_select_input(chip, 0, sel ? MAYA_MIC_IN : MAYA_LINE_IN); | 398 | wm8776_select_input(chip, 0, sel ? MAYA_MIC_IN : MAYA_LINE_IN); |
399 | mutex_unlock(&chip->mutex); | 399 | mutex_unlock(&chip->mutex); |
400 | return changed; | 400 | return changed; |
diff --git a/sound/pci/oxygen/xonar_cs43xx.c b/sound/pci/oxygen/xonar_cs43xx.c index 16c226bfcd2b..7c4986b27f2b 100644 --- a/sound/pci/oxygen/xonar_cs43xx.c +++ b/sound/pci/oxygen/xonar_cs43xx.c | |||
@@ -56,6 +56,7 @@ | |||
56 | #include <sound/pcm_params.h> | 56 | #include <sound/pcm_params.h> |
57 | #include <sound/tlv.h> | 57 | #include <sound/tlv.h> |
58 | #include "xonar.h" | 58 | #include "xonar.h" |
59 | #include "cm9780.h" | ||
59 | #include "cs4398.h" | 60 | #include "cs4398.h" |
60 | #include "cs4362a.h" | 61 | #include "cs4362a.h" |
61 | 62 | ||
@@ -172,6 +173,8 @@ static void xonar_d1_init(struct oxygen *chip) | |||
172 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, | 173 | oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, |
173 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); | 174 | GPIO_D1_FRONT_PANEL | GPIO_D1_INPUT_ROUTE); |
174 | 175 | ||
176 | oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC); | ||
177 | |||
175 | xonar_init_cs53x1(chip); | 178 | xonar_init_cs53x1(chip); |
176 | xonar_enable_output(chip); | 179 | xonar_enable_output(chip); |
177 | 180 | ||
diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt index c9dcade06831..5164a655c39f 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-annotate(1) | 1 | perf-annotate(1) |
2 | ============== | 2 | ================ |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
diff --git a/tools/perf/Documentation/perf-bench.txt b/tools/perf/Documentation/perf-bench.txt index ae525ac5a2ce..a3dbadb26ef5 100644 --- a/tools/perf/Documentation/perf-bench.txt +++ b/tools/perf/Documentation/perf-bench.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-bench(1) | 1 | perf-bench(1) |
2 | ============ | 2 | ============= |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
@@ -19,12 +19,12 @@ COMMON OPTIONS | |||
19 | -f:: | 19 | -f:: |
20 | --format=:: | 20 | --format=:: |
21 | Specify format style. | 21 | Specify format style. |
22 | Current available format styles are, | 22 | Current available format styles are: |
23 | 23 | ||
24 | 'default':: | 24 | 'default':: |
25 | Default style. This is mainly for human reading. | 25 | Default style. This is mainly for human reading. |
26 | --------------------- | 26 | --------------------- |
27 | % perf bench sched pipe # with no style specify | 27 | % perf bench sched pipe # with no style specified |
28 | (executing 1000000 pipe operations between two tasks) | 28 | (executing 1000000 pipe operations between two tasks) |
29 | Total time:5.855 sec | 29 | Total time:5.855 sec |
30 | 5.855061 usecs/op | 30 | 5.855061 usecs/op |
@@ -79,7 +79,7 @@ options (20 sender and receiver processes per group) | |||
79 | 79 | ||
80 | Total time:0.308 sec | 80 | Total time:0.308 sec |
81 | 81 | ||
82 | % perf bench sched messaging -t -g 20 # be multi-thread,with 20 groups | 82 | % perf bench sched messaging -t -g 20 # be multi-thread, with 20 groups |
83 | (20 sender and receiver threads per group) | 83 | (20 sender and receiver threads per group) |
84 | (20 groups == 800 threads run) | 84 | (20 groups == 800 threads run) |
85 | 85 | ||
diff --git a/tools/perf/Documentation/perf-buildid-cache.txt b/tools/perf/Documentation/perf-buildid-cache.txt index 88bc3b519746..5d1a9500277f 100644 --- a/tools/perf/Documentation/perf-buildid-cache.txt +++ b/tools/perf/Documentation/perf-buildid-cache.txt | |||
@@ -8,7 +8,7 @@ perf-buildid-cache - Manage build-id cache. | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf buildid-list <options>' | 11 | 'perf buildid-cache <options>' |
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
@@ -30,4 +30,4 @@ OPTIONS | |||
30 | 30 | ||
31 | SEE ALSO | 31 | SEE ALSO |
32 | -------- | 32 | -------- |
33 | linkperf:perf-record[1], linkperf:perf-report[1] | 33 | linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-buildid-list[1] |
diff --git a/tools/perf/Documentation/perf-diff.txt b/tools/perf/Documentation/perf-diff.txt index 8974e208cba6..20d97d84ea1c 100644 --- a/tools/perf/Documentation/perf-diff.txt +++ b/tools/perf/Documentation/perf-diff.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-diff(1) | 1 | perf-diff(1) |
2 | ============== | 2 | ============ |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt new file mode 100644 index 000000000000..025630d43cd2 --- /dev/null +++ b/tools/perf/Documentation/perf-inject.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | perf-inject(1) | ||
2 | ============== | ||
3 | |||
4 | NAME | ||
5 | ---- | ||
6 | perf-inject - Filter to augment the events stream with additional information | ||
7 | |||
8 | SYNOPSIS | ||
9 | -------- | ||
10 | [verse] | ||
11 | 'perf inject <options>' | ||
12 | |||
13 | DESCRIPTION | ||
14 | ----------- | ||
15 | perf-inject reads a perf-record event stream and repipes it to stdout. At any | ||
16 | point the processing code can inject other events into the event stream - in | ||
17 | this case build-ids (-b option) are read and injected as needed into the event | ||
18 | stream. | ||
19 | |||
20 | Build-ids are just the first user of perf-inject - potentially anything that | ||
21 | needs userspace processing to augment the events stream with additional | ||
22 | information could make use of this facility. | ||
23 | |||
24 | OPTIONS | ||
25 | ------- | ||
26 | -b:: | ||
27 | --build-ids=:: | ||
28 | Inject build-ids into the output stream | ||
29 | -v:: | ||
30 | --verbose:: | ||
31 | Be more verbose. | ||
32 | |||
33 | SEE ALSO | ||
34 | -------- | ||
35 | linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1] | ||
diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt index eac4d852e7cd..a52fcde894c7 100644 --- a/tools/perf/Documentation/perf-kmem.txt +++ b/tools/perf/Documentation/perf-kmem.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-kmem(1) | 1 | perf-kmem(1) |
2 | ============== | 2 | ============ |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt new file mode 100644 index 000000000000..d004e19fe6d6 --- /dev/null +++ b/tools/perf/Documentation/perf-kvm.txt | |||
@@ -0,0 +1,68 @@ | |||
1 | perf-kvm(1) | ||
2 | =========== | ||
3 | |||
4 | NAME | ||
5 | ---- | ||
6 | perf-kvm - Tool to trace/measure kvm guest os | ||
7 | |||
8 | SYNOPSIS | ||
9 | -------- | ||
10 | [verse] | ||
11 | 'perf kvm' [--host] [--guest] [--guestmount=<path> | ||
12 | [--guestkallsyms=<path> --guestmodules=<path> | --guestvmlinux=<path>]] | ||
13 | {top|record|report|diff|buildid-list} | ||
14 | 'perf kvm' [--host] [--guest] [--guestkallsyms=<path> --guestmodules=<path> | ||
15 | | --guestvmlinux=<path>] {top|record|report|diff|buildid-list} | ||
16 | |||
17 | DESCRIPTION | ||
18 | ----------- | ||
19 | There are a couple of variants of perf kvm: | ||
20 | |||
21 | 'perf kvm [options] top <command>' to generates and displays | ||
22 | a performance counter profile of guest os in realtime | ||
23 | of an arbitrary workload. | ||
24 | |||
25 | 'perf kvm record <command>' to record the performance couinter profile | ||
26 | of an arbitrary workload and save it into a perf data file. If both | ||
27 | --host and --guest are input, the perf data file name is perf.data.kvm. | ||
28 | If there is no --host but --guest, the file name is perf.data.guest. | ||
29 | If there is no --guest but --host, the file name is perf.data.host. | ||
30 | |||
31 | 'perf kvm report' to display the performance counter profile information | ||
32 | recorded via perf kvm record. | ||
33 | |||
34 | 'perf kvm diff' to displays the performance difference amongst two perf.data | ||
35 | files captured via perf record. | ||
36 | |||
37 | 'perf kvm buildid-list' to display the buildids found in a perf data file, | ||
38 | so that other tools can be used to fetch packages with matching symbol tables | ||
39 | for use by perf report. | ||
40 | |||
41 | OPTIONS | ||
42 | ------- | ||
43 | --host=:: | ||
44 | Collect host side performance profile. | ||
45 | --guest=:: | ||
46 | Collect guest side performance profile. | ||
47 | --guestmount=<path>:: | ||
48 | Guest os root file system mount directory. Users mounts guest os | ||
49 | root directories under <path> by a specific filesystem access method, | ||
50 | typically, sshfs. For example, start 2 guest os. The one's pid is 8888 | ||
51 | and the other's is 9999. | ||
52 | #mkdir ~/guestmount; cd ~/guestmount | ||
53 | #sshfs -o allow_other,direct_io -p 5551 localhost:/ 8888/ | ||
54 | #sshfs -o allow_other,direct_io -p 5552 localhost:/ 9999/ | ||
55 | #perf kvm --host --guest --guestmount=~/guestmount top | ||
56 | --guestkallsyms=<path>:: | ||
57 | Guest os /proc/kallsyms file copy. 'perf' kvm' reads it to get guest | ||
58 | kernel symbols. Users copy it out from guest os. | ||
59 | --guestmodules=<path>:: | ||
60 | Guest os /proc/modules file copy. 'perf' kvm' reads it to get guest | ||
61 | kernel module information. Users copy it out from guest os. | ||
62 | --guestvmlinux=<path>:: | ||
63 | Guest os kernel vmlinux. | ||
64 | |||
65 | SEE ALSO | ||
66 | -------- | ||
67 | linkperf:perf-top[1], linkperf:perf-record[1], linkperf:perf-report[1], | ||
68 | linkperf:perf-diff[1], linkperf:perf-buildid-list[1] | ||
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt index 8290b9422668..43e3dd284b90 100644 --- a/tools/perf/Documentation/perf-list.txt +++ b/tools/perf/Documentation/perf-list.txt | |||
@@ -15,6 +15,35 @@ DESCRIPTION | |||
15 | This command displays the symbolic event types which can be selected in the | 15 | This command displays the symbolic event types which can be selected in the |
16 | various perf commands with the -e option. | 16 | various perf commands with the -e option. |
17 | 17 | ||
18 | RAW HARDWARE EVENT DESCRIPTOR | ||
19 | ----------------------------- | ||
20 | Even when an event is not available in a symbolic form within perf right now, | ||
21 | it can be encoded in a per processor specific way. | ||
22 | |||
23 | For instance For x86 CPUs NNN represents the raw register encoding with the | ||
24 | layout of IA32_PERFEVTSELx MSRs (see [Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide] Figure 30-1 Layout | ||
25 | of IA32_PERFEVTSELx MSRs) or AMD's PerfEvtSeln (see [AMD64 Architecture Programmer’s Manual Volume 2: System Programming], Page 344, | ||
26 | Figure 13-7 Performance Event-Select Register (PerfEvtSeln)). | ||
27 | |||
28 | Example: | ||
29 | |||
30 | If the Intel docs for a QM720 Core i7 describe an event as: | ||
31 | |||
32 | Event Umask Event Mask | ||
33 | Num. Value Mnemonic Description Comment | ||
34 | |||
35 | A8H 01H LSD.UOPS Counts the number of micro-ops Use cmask=1 and | ||
36 | delivered by loop stream detector invert to count | ||
37 | cycles | ||
38 | |||
39 | raw encoding of 0x1A8 can be used: | ||
40 | |||
41 | perf stat -e r1a8 -a sleep 1 | ||
42 | perf record -e r1a8 ... | ||
43 | |||
44 | You should refer to the processor specific documentation for getting these | ||
45 | details. Some of them are referenced in the SEE ALSO section below. | ||
46 | |||
18 | OPTIONS | 47 | OPTIONS |
19 | ------- | 48 | ------- |
20 | None | 49 | None |
@@ -22,4 +51,6 @@ None | |||
22 | SEE ALSO | 51 | SEE ALSO |
23 | -------- | 52 | -------- |
24 | linkperf:perf-stat[1], linkperf:perf-top[1], | 53 | linkperf:perf-stat[1], linkperf:perf-top[1], |
25 | linkperf:perf-record[1] | 54 | linkperf:perf-record[1], |
55 | http://www.intel.com/Assets/PDF/manual/253669.pdf[Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide], | ||
56 | http://support.amd.com/us/Processor_TechDocs/24593.pdf[AMD64 Architecture Programmer’s Manual Volume 2: System Programming] | ||
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt index 34202b1be0bb..94a258c96a44 100644 --- a/tools/perf/Documentation/perf-probe.txt +++ b/tools/perf/Documentation/perf-probe.txt | |||
@@ -57,6 +57,14 @@ OPTIONS | |||
57 | --force:: | 57 | --force:: |
58 | Forcibly add events with existing name. | 58 | Forcibly add events with existing name. |
59 | 59 | ||
60 | -n:: | ||
61 | --dry-run:: | ||
62 | Dry run. With this option, --add and --del doesn't execute actual | ||
63 | adding and removal operations. | ||
64 | |||
65 | --max-probes:: | ||
66 | Set the maximum number of probe points for an event. Default is 128. | ||
67 | |||
60 | PROBE SYNTAX | 68 | PROBE SYNTAX |
61 | ------------ | 69 | ------------ |
62 | Probe points are defined by following syntax. | 70 | Probe points are defined by following syntax. |
@@ -74,13 +82,22 @@ Probe points are defined by following syntax. | |||
74 | 'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'. | 82 | 'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'. |
75 | 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition. In addition, '@SRC' specifies a source file which has that function. | 83 | 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition. In addition, '@SRC' specifies a source file which has that function. |
76 | It is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern. | 84 | It is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern. |
77 | 'ARG' specifies the arguments of this probe point. You can use the name of local variable, or kprobe-tracer argument format (e.g. $retval, %ax, etc). | 85 | 'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT). |
86 | |||
87 | PROBE ARGUMENT | ||
88 | -------------- | ||
89 | Each probe argument follows below syntax. | ||
90 | |||
91 | [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE] | ||
92 | |||
93 | 'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) | ||
94 | 'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. | ||
78 | 95 | ||
79 | LINE SYNTAX | 96 | LINE SYNTAX |
80 | ----------- | 97 | ----------- |
81 | Line range is descripted by following syntax. | 98 | Line range is descripted by following syntax. |
82 | 99 | ||
83 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]" | 100 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]" |
84 | 101 | ||
85 | FUNC specifies the function name of showing lines. 'RLN' is the start line | 102 | FUNC specifies the function name of showing lines. 'RLN' is the start line |
86 | number from function entry line, and 'RLN2' is the end line number. As same as | 103 | number from function entry line, and 'RLN2' is the end line number. As same as |
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index fc46c0b40f6e..34e255fc3e2f 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt | |||
@@ -58,7 +58,7 @@ OPTIONS | |||
58 | 58 | ||
59 | -f:: | 59 | -f:: |
60 | --force:: | 60 | --force:: |
61 | Overwrite existing data file. | 61 | Overwrite existing data file. (deprecated) |
62 | 62 | ||
63 | -c:: | 63 | -c:: |
64 | --count=:: | 64 | --count=:: |
@@ -69,8 +69,8 @@ OPTIONS | |||
69 | Output file name. | 69 | Output file name. |
70 | 70 | ||
71 | -i:: | 71 | -i:: |
72 | --inherit:: | 72 | --no-inherit:: |
73 | Child tasks inherit counters. | 73 | Child tasks do not inherit counters. |
74 | -F:: | 74 | -F:: |
75 | --freq=:: | 75 | --freq=:: |
76 | Profile at this frequency. | 76 | Profile at this frequency. |
@@ -101,7 +101,7 @@ OPTIONS | |||
101 | 101 | ||
102 | -R:: | 102 | -R:: |
103 | --raw-samples:: | 103 | --raw-samples:: |
104 | Collect raw sample records from all opened counters (typically for tracepoint counters). | 104 | Collect raw sample records from all opened counters (default for tracepoint counters). |
105 | 105 | ||
106 | SEE ALSO | 106 | SEE ALSO |
107 | -------- | 107 | -------- |
diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt index 1ce79198997b..8417644a6166 100644 --- a/tools/perf/Documentation/perf-sched.txt +++ b/tools/perf/Documentation/perf-sched.txt | |||
@@ -12,7 +12,7 @@ SYNOPSIS | |||
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
15 | There's four variants of perf sched: | 15 | There are four variants of perf sched: |
16 | 16 | ||
17 | 'perf sched record <command>' to record the scheduling events | 17 | 'perf sched record <command>' to record the scheduling events |
18 | of an arbitrary workload. | 18 | of an arbitrary workload. |
@@ -27,7 +27,7 @@ There's four variants of perf sched: | |||
27 | via perf sched record. (this is done by starting up mockup threads | 27 | via perf sched record. (this is done by starting up mockup threads |
28 | that mimic the workload based on the events in the trace. These | 28 | that mimic the workload based on the events in the trace. These |
29 | threads can then replay the timings (CPU runtime and sleep patterns) | 29 | threads can then replay the timings (CPU runtime and sleep patterns) |
30 | of the workload as it occured when it was recorded - and can repeat | 30 | of the workload as it occurred when it was recorded - and can repeat |
31 | it a number of times, measuring its performance.) | 31 | it a number of times, measuring its performance.) |
32 | 32 | ||
33 | OPTIONS | 33 | OPTIONS |
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 484080dd5b6f..2cab8e8c33d0 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt | |||
@@ -31,8 +31,8 @@ OPTIONS | |||
31 | hexadecimal event descriptor. | 31 | hexadecimal event descriptor. |
32 | 32 | ||
33 | -i:: | 33 | -i:: |
34 | --inherit:: | 34 | --no-inherit:: |
35 | child tasks inherit counters | 35 | child tasks do not inherit counters |
36 | -p:: | 36 | -p:: |
37 | --pid=<pid>:: | 37 | --pid=<pid>:: |
38 | stat events on existing pid | 38 | stat events on existing pid |
diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt new file mode 100644 index 000000000000..1c4b5f5b7f71 --- /dev/null +++ b/tools/perf/Documentation/perf-test.txt | |||
@@ -0,0 +1,22 @@ | |||
1 | perf-test(1) | ||
2 | ============ | ||
3 | |||
4 | NAME | ||
5 | ---- | ||
6 | perf-test - Runs sanity tests. | ||
7 | |||
8 | SYNOPSIS | ||
9 | -------- | ||
10 | [verse] | ||
11 | 'perf test <options>' | ||
12 | |||
13 | DESCRIPTION | ||
14 | ----------- | ||
15 | This command does assorted sanity tests, initially thru linked routines but | ||
16 | also will look for a directory with more tests in the form of scripts. | ||
17 | |||
18 | OPTIONS | ||
19 | ------- | ||
20 | -v:: | ||
21 | --verbose:: | ||
22 | Be more verbose. | ||
diff --git a/tools/perf/Documentation/perf-trace-perl.txt b/tools/perf/Documentation/perf-trace-perl.txt index d729cee8d987..ee6525ee6d69 100644 --- a/tools/perf/Documentation/perf-trace-perl.txt +++ b/tools/perf/Documentation/perf-trace-perl.txt | |||
@@ -49,12 +49,10 @@ available as calls back into the perf executable (see below). | |||
49 | As an example, the following perf record command can be used to record | 49 | As an example, the following perf record command can be used to record |
50 | all sched_wakeup events in the system: | 50 | all sched_wakeup events in the system: |
51 | 51 | ||
52 | # perf record -c 1 -f -a -M -R -e sched:sched_wakeup | 52 | # perf record -a -e sched:sched_wakeup |
53 | 53 | ||
54 | Traces meant to be processed using a script should be recorded with | 54 | Traces meant to be processed using a script should be recorded with |
55 | the above options: -c 1 says to sample every event, -a to enable | 55 | the above option: -a to enable system-wide collection. |
56 | system-wide collection, -M to multiplex the output, and -R to collect | ||
57 | raw samples. | ||
58 | 56 | ||
59 | The format file for the sched_wakep event defines the following fields | 57 | The format file for the sched_wakep event defines the following fields |
60 | (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format): | 58 | (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format): |
diff --git a/tools/perf/Documentation/perf-trace-python.txt b/tools/perf/Documentation/perf-trace-python.txt index a241aca77184..693be804dd3d 100644 --- a/tools/perf/Documentation/perf-trace-python.txt +++ b/tools/perf/Documentation/perf-trace-python.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-trace-python(1) | 1 | perf-trace-python(1) |
2 | ================== | 2 | ==================== |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
@@ -93,7 +93,7 @@ don't care how it exited, so we'll use 'perf record' to record only | |||
93 | the sys_enter events: | 93 | the sys_enter events: |
94 | 94 | ||
95 | ---- | 95 | ---- |
96 | # perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter | 96 | # perf record -a -e raw_syscalls:sys_enter |
97 | 97 | ||
98 | ^C[ perf record: Woken up 1 times to write data ] | 98 | ^C[ perf record: Woken up 1 times to write data ] |
99 | [ perf record: Captured and wrote 56.545 MB perf.data (~2470503 samples) ] | 99 | [ perf record: Captured and wrote 56.545 MB perf.data (~2470503 samples) ] |
@@ -182,7 +182,7 @@ mean either that the record step recorded event types that it wasn't | |||
182 | really interested in, or the script was run against a trace file that | 182 | really interested in, or the script was run against a trace file that |
183 | doesn't correspond to the script. | 183 | doesn't correspond to the script. |
184 | 184 | ||
185 | The script generated by -g option option simply prints a line for each | 185 | The script generated by -g option simply prints a line for each |
186 | event found in the trace stream i.e. it basically just dumps the event | 186 | event found in the trace stream i.e. it basically just dumps the event |
187 | and its parameter values to stdout. The print_header() function is | 187 | and its parameter values to stdout. The print_header() function is |
188 | simply a utility function used for that purpose. Let's rename the | 188 | simply a utility function used for that purpose. Let's rename the |
@@ -359,7 +359,7 @@ your script: | |||
359 | # cat kernel-source/tools/perf/scripts/python/bin/syscall-counts-record | 359 | # cat kernel-source/tools/perf/scripts/python/bin/syscall-counts-record |
360 | 360 | ||
361 | #!/bin/bash | 361 | #!/bin/bash |
362 | perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter | 362 | perf record -a -e raw_syscalls:sys_enter |
363 | ---- | 363 | ---- |
364 | 364 | ||
365 | The 'report' script is also a shell script with the same base name as | 365 | The 'report' script is also a shell script with the same base name as |
@@ -449,12 +449,10 @@ available as calls back into the perf executable (see below). | |||
449 | As an example, the following perf record command can be used to record | 449 | As an example, the following perf record command can be used to record |
450 | all sched_wakeup events in the system: | 450 | all sched_wakeup events in the system: |
451 | 451 | ||
452 | # perf record -c 1 -f -a -M -R -e sched:sched_wakeup | 452 | # perf record -a -e sched:sched_wakeup |
453 | 453 | ||
454 | Traces meant to be processed using a script should be recorded with | 454 | Traces meant to be processed using a script should be recorded with |
455 | the above options: -c 1 says to sample every event, -a to enable | 455 | the above option: -a to enable system-wide collection. |
456 | system-wide collection, -M to multiplex the output, and -R to collect | ||
457 | raw samples. | ||
458 | 456 | ||
459 | The format file for the sched_wakep event defines the following fields | 457 | The format file for the sched_wakep event defines the following fields |
460 | (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format): | 458 | (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format): |
@@ -584,7 +582,7 @@ files: | |||
584 | flag_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the flag field field_name of event event_name | 582 | flag_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the flag field field_name of event event_name |
585 | symbol_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the symbolic field field_name of event event_name | 583 | symbol_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the symbolic field field_name of event event_name |
586 | 584 | ||
587 | The *autodict* function returns a special special kind of Python | 585 | The *autodict* function returns a special kind of Python |
588 | dictionary that implements Perl's 'autovivifying' hashes in Python | 586 | dictionary that implements Perl's 'autovivifying' hashes in Python |
589 | i.e. with autovivifying hashes, you can assign nested hash values | 587 | i.e. with autovivifying hashes, you can assign nested hash values |
590 | without having to go to the trouble of creating intermediate levels if | 588 | without having to go to the trouble of creating intermediate levels if |
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt index 8879299cd9df..122ec9dc4853 100644 --- a/tools/perf/Documentation/perf-trace.txt +++ b/tools/perf/Documentation/perf-trace.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | perf-trace(1) | 1 | perf-trace(1) |
2 | ============== | 2 | ============= |
3 | 3 | ||
4 | NAME | 4 | NAME |
5 | ---- | 5 | ---- |
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index bc0f670a8338..3d8f31ed771d 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -1,3 +1,7 @@ | |||
1 | ifeq ("$(origin O)", "command line") | ||
2 | OUTPUT := $(O)/ | ||
3 | endif | ||
4 | |||
1 | # The default target of this Makefile is... | 5 | # The default target of this Makefile is... |
2 | all:: | 6 | all:: |
3 | 7 | ||
@@ -150,10 +154,17 @@ all:: | |||
150 | # Define LDFLAGS=-static to build a static binary. | 154 | # Define LDFLAGS=-static to build a static binary. |
151 | # | 155 | # |
152 | # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. | 156 | # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. |
157 | # | ||
158 | # Define NO_DWARF if you do not want debug-info analysis feature at all. | ||
153 | 159 | ||
154 | PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE | 160 | $(shell sh -c 'mkdir -p $(OUTPUT)scripts/python/Perf-Trace-Util/' 2> /dev/null) |
155 | @$(SHELL_PATH) util/PERF-VERSION-GEN | 161 | $(shell sh -c 'mkdir -p $(OUTPUT)scripts/perl/Perf-Trace-Util/' 2> /dev/null) |
156 | -include PERF-VERSION-FILE | 162 | $(shell sh -c 'mkdir -p $(OUTPUT)util/scripting-engines/' 2> /dev/null) |
163 | $(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null) | ||
164 | |||
165 | $(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE | ||
166 | @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) | ||
167 | -include $(OUTPUT)PERF-VERSION-FILE | ||
157 | 168 | ||
158 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') | 169 | uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') |
159 | uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') | 170 | uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') |
@@ -162,6 +173,22 @@ uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') | |||
162 | uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not') | 173 | uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not') |
163 | uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not') | 174 | uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not') |
164 | 175 | ||
176 | ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ | ||
177 | -e s/arm.*/arm/ -e s/sa110/arm/ \ | ||
178 | -e s/s390x/s390/ -e s/parisc64/parisc/ \ | ||
179 | -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ | ||
180 | -e s/sh[234].*/sh/ ) | ||
181 | |||
182 | # Additional ARCH settings for x86 | ||
183 | ifeq ($(ARCH),i386) | ||
184 | ARCH := x86 | ||
185 | endif | ||
186 | ifeq ($(ARCH),x86_64) | ||
187 | ARCH := x86 | ||
188 | endif | ||
189 | |||
190 | $(shell sh -c 'mkdir -p $(OUTPUT)arch/$(ARCH)/util/' 2> /dev/null) | ||
191 | |||
165 | # CFLAGS and LDFLAGS are for the users to override from the command line. | 192 | # CFLAGS and LDFLAGS are for the users to override from the command line. |
166 | 193 | ||
167 | # | 194 | # |
@@ -274,7 +301,7 @@ endif | |||
274 | # Those must not be GNU-specific; they are shared with perl/ which may | 301 | # Those must not be GNU-specific; they are shared with perl/ which may |
275 | # be built by a different compiler. (Note that this is an artifact now | 302 | # be built by a different compiler. (Note that this is an artifact now |
276 | # but it still might be nice to keep that distinction.) | 303 | # but it still might be nice to keep that distinction.) |
277 | BASIC_CFLAGS = -Iutil/include | 304 | BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include |
278 | BASIC_LDFLAGS = | 305 | BASIC_LDFLAGS = |
279 | 306 | ||
280 | # Guard against environment variables | 307 | # Guard against environment variables |
@@ -308,7 +335,7 @@ PROGRAMS += $(EXTRA_PROGRAMS) | |||
308 | # | 335 | # |
309 | # Single 'perf' binary right now: | 336 | # Single 'perf' binary right now: |
310 | # | 337 | # |
311 | PROGRAMS += perf | 338 | PROGRAMS += $(OUTPUT)perf |
312 | 339 | ||
313 | # List built-in command $C whose implementation cmd_$C() is not in | 340 | # List built-in command $C whose implementation cmd_$C() is not in |
314 | # builtin-$C.o but is linked in as part of some other command. | 341 | # builtin-$C.o but is linked in as part of some other command. |
@@ -318,7 +345,7 @@ PROGRAMS += perf | |||
318 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) | 345 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) |
319 | 346 | ||
320 | # what 'all' will build but not install in perfexecdir | 347 | # what 'all' will build but not install in perfexecdir |
321 | OTHER_PROGRAMS = perf$X | 348 | OTHER_PROGRAMS = $(OUTPUT)perf$X |
322 | 349 | ||
323 | # Set paths to tools early so that they can be used for version tests. | 350 | # Set paths to tools early so that they can be used for version tests. |
324 | ifndef SHELL_PATH | 351 | ifndef SHELL_PATH |
@@ -330,7 +357,7 @@ endif | |||
330 | 357 | ||
331 | export PERL_PATH | 358 | export PERL_PATH |
332 | 359 | ||
333 | LIB_FILE=libperf.a | 360 | LIB_FILE=$(OUTPUT)libperf.a |
334 | 361 | ||
335 | LIB_H += ../../include/linux/perf_event.h | 362 | LIB_H += ../../include/linux/perf_event.h |
336 | LIB_H += ../../include/linux/rbtree.h | 363 | LIB_H += ../../include/linux/rbtree.h |
@@ -350,12 +377,13 @@ LIB_H += util/include/linux/rbtree.h | |||
350 | LIB_H += util/include/linux/string.h | 377 | LIB_H += util/include/linux/string.h |
351 | LIB_H += util/include/linux/types.h | 378 | LIB_H += util/include/linux/types.h |
352 | LIB_H += util/include/asm/asm-offsets.h | 379 | LIB_H += util/include/asm/asm-offsets.h |
353 | LIB_H += util/include/asm/bitops.h | ||
354 | LIB_H += util/include/asm/bug.h | 380 | LIB_H += util/include/asm/bug.h |
355 | LIB_H += util/include/asm/byteorder.h | 381 | LIB_H += util/include/asm/byteorder.h |
382 | LIB_H += util/include/asm/hweight.h | ||
356 | LIB_H += util/include/asm/swab.h | 383 | LIB_H += util/include/asm/swab.h |
357 | LIB_H += util/include/asm/system.h | 384 | LIB_H += util/include/asm/system.h |
358 | LIB_H += util/include/asm/uaccess.h | 385 | LIB_H += util/include/asm/uaccess.h |
386 | LIB_H += util/include/dwarf-regs.h | ||
359 | LIB_H += perf.h | 387 | LIB_H += perf.h |
360 | LIB_H += util/cache.h | 388 | LIB_H += util/cache.h |
361 | LIB_H += util/callchain.h | 389 | LIB_H += util/callchain.h |
@@ -375,7 +403,6 @@ LIB_H += util/header.h | |||
375 | LIB_H += util/help.h | 403 | LIB_H += util/help.h |
376 | LIB_H += util/session.h | 404 | LIB_H += util/session.h |
377 | LIB_H += util/strbuf.h | 405 | LIB_H += util/strbuf.h |
378 | LIB_H += util/string.h | ||
379 | LIB_H += util/strlist.h | 406 | LIB_H += util/strlist.h |
380 | LIB_H += util/svghelper.h | 407 | LIB_H += util/svghelper.h |
381 | LIB_H += util/run-command.h | 408 | LIB_H += util/run-command.h |
@@ -389,79 +416,83 @@ LIB_H += util/thread.h | |||
389 | LIB_H += util/trace-event.h | 416 | LIB_H += util/trace-event.h |
390 | LIB_H += util/probe-finder.h | 417 | LIB_H += util/probe-finder.h |
391 | LIB_H += util/probe-event.h | 418 | LIB_H += util/probe-event.h |
419 | LIB_H += util/pstack.h | ||
392 | LIB_H += util/cpumap.h | 420 | LIB_H += util/cpumap.h |
393 | 421 | ||
394 | LIB_OBJS += util/abspath.o | 422 | LIB_OBJS += $(OUTPUT)util/abspath.o |
395 | LIB_OBJS += util/alias.o | 423 | LIB_OBJS += $(OUTPUT)util/alias.o |
396 | LIB_OBJS += util/build-id.o | 424 | LIB_OBJS += $(OUTPUT)util/build-id.o |
397 | LIB_OBJS += util/config.o | 425 | LIB_OBJS += $(OUTPUT)util/config.o |
398 | LIB_OBJS += util/ctype.o | 426 | LIB_OBJS += $(OUTPUT)util/ctype.o |
399 | LIB_OBJS += util/debugfs.o | 427 | LIB_OBJS += $(OUTPUT)util/debugfs.o |
400 | LIB_OBJS += util/environment.o | 428 | LIB_OBJS += $(OUTPUT)util/environment.o |
401 | LIB_OBJS += util/event.o | 429 | LIB_OBJS += $(OUTPUT)util/event.o |
402 | LIB_OBJS += util/exec_cmd.o | 430 | LIB_OBJS += $(OUTPUT)util/exec_cmd.o |
403 | LIB_OBJS += util/help.o | 431 | LIB_OBJS += $(OUTPUT)util/help.o |
404 | LIB_OBJS += util/levenshtein.o | 432 | LIB_OBJS += $(OUTPUT)util/levenshtein.o |
405 | LIB_OBJS += util/parse-options.o | 433 | LIB_OBJS += $(OUTPUT)util/parse-options.o |
406 | LIB_OBJS += util/parse-events.o | 434 | LIB_OBJS += $(OUTPUT)util/parse-events.o |
407 | LIB_OBJS += util/path.o | 435 | LIB_OBJS += $(OUTPUT)util/path.o |
408 | LIB_OBJS += util/rbtree.o | 436 | LIB_OBJS += $(OUTPUT)util/rbtree.o |
409 | LIB_OBJS += util/bitmap.o | 437 | LIB_OBJS += $(OUTPUT)util/bitmap.o |
410 | LIB_OBJS += util/hweight.o | 438 | LIB_OBJS += $(OUTPUT)util/hweight.o |
411 | LIB_OBJS += util/find_next_bit.o | 439 | LIB_OBJS += $(OUTPUT)util/run-command.o |
412 | LIB_OBJS += util/run-command.o | 440 | LIB_OBJS += $(OUTPUT)util/quote.o |
413 | LIB_OBJS += util/quote.o | 441 | LIB_OBJS += $(OUTPUT)util/strbuf.o |
414 | LIB_OBJS += util/strbuf.o | 442 | LIB_OBJS += $(OUTPUT)util/string.o |
415 | LIB_OBJS += util/string.o | 443 | LIB_OBJS += $(OUTPUT)util/strlist.o |
416 | LIB_OBJS += util/strlist.o | 444 | LIB_OBJS += $(OUTPUT)util/usage.o |
417 | LIB_OBJS += util/usage.o | 445 | LIB_OBJS += $(OUTPUT)util/wrapper.o |
418 | LIB_OBJS += util/wrapper.o | 446 | LIB_OBJS += $(OUTPUT)util/sigchain.o |
419 | LIB_OBJS += util/sigchain.o | 447 | LIB_OBJS += $(OUTPUT)util/symbol.o |
420 | LIB_OBJS += util/symbol.o | 448 | LIB_OBJS += $(OUTPUT)util/color.o |
421 | LIB_OBJS += util/color.o | 449 | LIB_OBJS += $(OUTPUT)util/pager.o |
422 | LIB_OBJS += util/pager.o | 450 | LIB_OBJS += $(OUTPUT)util/header.o |
423 | LIB_OBJS += util/header.o | 451 | LIB_OBJS += $(OUTPUT)util/callchain.o |
424 | LIB_OBJS += util/callchain.o | 452 | LIB_OBJS += $(OUTPUT)util/values.o |
425 | LIB_OBJS += util/values.o | 453 | LIB_OBJS += $(OUTPUT)util/debug.o |
426 | LIB_OBJS += util/debug.o | 454 | LIB_OBJS += $(OUTPUT)util/map.o |
427 | LIB_OBJS += util/map.o | 455 | LIB_OBJS += $(OUTPUT)util/pstack.o |
428 | LIB_OBJS += util/session.o | 456 | LIB_OBJS += $(OUTPUT)util/session.o |
429 | LIB_OBJS += util/thread.o | 457 | LIB_OBJS += $(OUTPUT)util/thread.o |
430 | LIB_OBJS += util/trace-event-parse.o | 458 | LIB_OBJS += $(OUTPUT)util/trace-event-parse.o |
431 | LIB_OBJS += util/trace-event-read.o | 459 | LIB_OBJS += $(OUTPUT)util/trace-event-read.o |
432 | LIB_OBJS += util/trace-event-info.o | 460 | LIB_OBJS += $(OUTPUT)util/trace-event-info.o |
433 | LIB_OBJS += util/trace-event-scripting.o | 461 | LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o |
434 | LIB_OBJS += util/svghelper.o | 462 | LIB_OBJS += $(OUTPUT)util/svghelper.o |
435 | LIB_OBJS += util/sort.o | 463 | LIB_OBJS += $(OUTPUT)util/sort.o |
436 | LIB_OBJS += util/hist.o | 464 | LIB_OBJS += $(OUTPUT)util/hist.o |
437 | LIB_OBJS += util/probe-event.o | 465 | LIB_OBJS += $(OUTPUT)util/probe-event.o |
438 | LIB_OBJS += util/util.o | 466 | LIB_OBJS += $(OUTPUT)util/util.o |
439 | LIB_OBJS += util/cpumap.o | 467 | LIB_OBJS += $(OUTPUT)util/cpumap.o |
440 | 468 | ||
441 | BUILTIN_OBJS += builtin-annotate.o | 469 | BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o |
442 | 470 | ||
443 | BUILTIN_OBJS += builtin-bench.o | 471 | BUILTIN_OBJS += $(OUTPUT)builtin-bench.o |
444 | 472 | ||
445 | # Benchmark modules | 473 | # Benchmark modules |
446 | BUILTIN_OBJS += bench/sched-messaging.o | 474 | BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o |
447 | BUILTIN_OBJS += bench/sched-pipe.o | 475 | BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o |
448 | BUILTIN_OBJS += bench/mem-memcpy.o | 476 | BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o |
449 | 477 | ||
450 | BUILTIN_OBJS += builtin-diff.o | 478 | BUILTIN_OBJS += $(OUTPUT)builtin-diff.o |
451 | BUILTIN_OBJS += builtin-help.o | 479 | BUILTIN_OBJS += $(OUTPUT)builtin-help.o |
452 | BUILTIN_OBJS += builtin-sched.o | 480 | BUILTIN_OBJS += $(OUTPUT)builtin-sched.o |
453 | BUILTIN_OBJS += builtin-buildid-list.o | 481 | BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o |
454 | BUILTIN_OBJS += builtin-buildid-cache.o | 482 | BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o |
455 | BUILTIN_OBJS += builtin-list.o | 483 | BUILTIN_OBJS += $(OUTPUT)builtin-list.o |
456 | BUILTIN_OBJS += builtin-record.o | 484 | BUILTIN_OBJS += $(OUTPUT)builtin-record.o |
457 | BUILTIN_OBJS += builtin-report.o | 485 | BUILTIN_OBJS += $(OUTPUT)builtin-report.o |
458 | BUILTIN_OBJS += builtin-stat.o | 486 | BUILTIN_OBJS += $(OUTPUT)builtin-stat.o |
459 | BUILTIN_OBJS += builtin-timechart.o | 487 | BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o |
460 | BUILTIN_OBJS += builtin-top.o | 488 | BUILTIN_OBJS += $(OUTPUT)builtin-top.o |
461 | BUILTIN_OBJS += builtin-trace.o | 489 | BUILTIN_OBJS += $(OUTPUT)builtin-trace.o |
462 | BUILTIN_OBJS += builtin-probe.o | 490 | BUILTIN_OBJS += $(OUTPUT)builtin-probe.o |
463 | BUILTIN_OBJS += builtin-kmem.o | 491 | BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o |
464 | BUILTIN_OBJS += builtin-lock.o | 492 | BUILTIN_OBJS += $(OUTPUT)builtin-lock.o |
493 | BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o | ||
494 | BUILTIN_OBJS += $(OUTPUT)builtin-test.o | ||
495 | BUILTIN_OBJS += $(OUTPUT)builtin-inject.o | ||
465 | 496 | ||
466 | PERFLIBS = $(LIB_FILE) | 497 | PERFLIBS = $(LIB_FILE) |
467 | 498 | ||
@@ -476,6 +507,15 @@ PERFLIBS = $(LIB_FILE) | |||
476 | -include config.mak.autogen | 507 | -include config.mak.autogen |
477 | -include config.mak | 508 | -include config.mak |
478 | 509 | ||
510 | ifndef NO_DWARF | ||
511 | ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo '\#include <version.h>'; echo '\#ifndef _ELFUTILS_PREREQ'; echo '\#error'; echo '\#endif'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | ||
512 | msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev); | ||
513 | NO_DWARF := 1 | ||
514 | endif # Dwarf support | ||
515 | endif # NO_DWARF | ||
516 | |||
517 | -include arch/$(ARCH)/Makefile | ||
518 | |||
479 | ifeq ($(uname_S),Darwin) | 519 | ifeq ($(uname_S),Darwin) |
480 | ifndef NO_FINK | 520 | ifndef NO_FINK |
481 | ifeq ($(shell test -d /sw/lib && echo y),y) | 521 | ifeq ($(shell test -d /sw/lib && echo y),y) |
@@ -492,6 +532,10 @@ ifeq ($(uname_S),Darwin) | |||
492 | PTHREAD_LIBS = | 532 | PTHREAD_LIBS = |
493 | endif | 533 | endif |
494 | 534 | ||
535 | ifneq ($(OUTPUT),) | ||
536 | BASIC_CFLAGS += -I$(OUTPUT) | ||
537 | endif | ||
538 | |||
495 | ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 539 | ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) |
496 | ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 540 | ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) |
497 | msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); | 541 | msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); |
@@ -504,14 +548,29 @@ else | |||
504 | msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); | 548 | msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); |
505 | endif | 549 | endif |
506 | 550 | ||
507 | ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | 551 | ifndef NO_DWARF |
508 | msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev); | 552 | ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined) |
509 | BASIC_CFLAGS += -DNO_DWARF_SUPPORT | 553 | msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled); |
510 | else | 554 | else |
511 | BASIC_CFLAGS += -I/usr/include/elfutils | 555 | BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT |
512 | EXTLIBS += -lelf -ldw | 556 | EXTLIBS += -lelf -ldw |
513 | LIB_OBJS += util/probe-finder.o | 557 | LIB_OBJS += $(OUTPUT)util/probe-finder.o |
558 | endif # PERF_HAVE_DWARF_REGS | ||
559 | endif # NO_DWARF | ||
560 | |||
561 | ifdef NO_NEWT | ||
562 | BASIC_CFLAGS += -DNO_NEWT_SUPPORT | ||
563 | else | ||
564 | ifneq ($(shell sh -c "(echo '\#include <newt.h>'; echo 'int main(void) { newtInit(); newtCls(); return newtFinished(); }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -lnewt -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y) | ||
565 | msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev); | ||
566 | BASIC_CFLAGS += -DNO_NEWT_SUPPORT | ||
567 | else | ||
568 | # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h | ||
569 | BASIC_CFLAGS += -I/usr/include/slang | ||
570 | EXTLIBS += -lnewt -lslang | ||
571 | LIB_OBJS += $(OUTPUT)util/newt.o | ||
514 | endif | 572 | endif |
573 | endif # NO_NEWT | ||
515 | 574 | ||
516 | ifndef NO_LIBPERL | 575 | ifndef NO_LIBPERL |
517 | PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null` | 576 | PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null` |
@@ -522,8 +581,8 @@ ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; e | |||
522 | BASIC_CFLAGS += -DNO_LIBPERL | 581 | BASIC_CFLAGS += -DNO_LIBPERL |
523 | else | 582 | else |
524 | ALL_LDFLAGS += $(PERL_EMBED_LDOPTS) | 583 | ALL_LDFLAGS += $(PERL_EMBED_LDOPTS) |
525 | LIB_OBJS += util/scripting-engines/trace-event-perl.o | 584 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o |
526 | LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o | 585 | LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o |
527 | endif | 586 | endif |
528 | 587 | ||
529 | ifndef NO_LIBPYTHON | 588 | ifndef NO_LIBPYTHON |
@@ -531,16 +590,19 @@ PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null` | |||
531 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` | 590 | PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null` |
532 | endif | 591 | endif |
533 | 592 | ||
534 | ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o /dev/null $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y) | 593 | ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o $(BITBUCKET) $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y) |
535 | BASIC_CFLAGS += -DNO_LIBPYTHON | 594 | BASIC_CFLAGS += -DNO_LIBPYTHON |
536 | else | 595 | else |
537 | ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS) | 596 | ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS) |
538 | LIB_OBJS += util/scripting-engines/trace-event-python.o | 597 | LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o |
539 | LIB_OBJS += scripts/python/Perf-Trace-Util/Context.o | 598 | LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o |
540 | endif | 599 | endif |
541 | 600 | ||
542 | ifdef NO_DEMANGLE | 601 | ifdef NO_DEMANGLE |
543 | BASIC_CFLAGS += -DNO_DEMANGLE | 602 | BASIC_CFLAGS += -DNO_DEMANGLE |
603 | else ifdef HAVE_CPLUS_DEMANGLE | ||
604 | EXTLIBS += -liberty | ||
605 | BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE | ||
544 | else | 606 | else |
545 | has_bfd := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd "$(QUIET_STDERR)" && echo y") | 607 | has_bfd := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd "$(QUIET_STDERR)" && echo y") |
546 | 608 | ||
@@ -607,53 +669,53 @@ ifdef NO_C99_FORMAT | |||
607 | endif | 669 | endif |
608 | ifdef SNPRINTF_RETURNS_BOGUS | 670 | ifdef SNPRINTF_RETURNS_BOGUS |
609 | COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS | 671 | COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS |
610 | COMPAT_OBJS += compat/snprintf.o | 672 | COMPAT_OBJS += $(OUTPUT)compat/snprintf.o |
611 | endif | 673 | endif |
612 | ifdef FREAD_READS_DIRECTORIES | 674 | ifdef FREAD_READS_DIRECTORIES |
613 | COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES | 675 | COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES |
614 | COMPAT_OBJS += compat/fopen.o | 676 | COMPAT_OBJS += $(OUTPUT)compat/fopen.o |
615 | endif | 677 | endif |
616 | ifdef NO_SYMLINK_HEAD | 678 | ifdef NO_SYMLINK_HEAD |
617 | BASIC_CFLAGS += -DNO_SYMLINK_HEAD | 679 | BASIC_CFLAGS += -DNO_SYMLINK_HEAD |
618 | endif | 680 | endif |
619 | ifdef NO_STRCASESTR | 681 | ifdef NO_STRCASESTR |
620 | COMPAT_CFLAGS += -DNO_STRCASESTR | 682 | COMPAT_CFLAGS += -DNO_STRCASESTR |
621 | COMPAT_OBJS += compat/strcasestr.o | 683 | COMPAT_OBJS += $(OUTPUT)compat/strcasestr.o |
622 | endif | 684 | endif |
623 | ifdef NO_STRTOUMAX | 685 | ifdef NO_STRTOUMAX |
624 | COMPAT_CFLAGS += -DNO_STRTOUMAX | 686 | COMPAT_CFLAGS += -DNO_STRTOUMAX |
625 | COMPAT_OBJS += compat/strtoumax.o | 687 | COMPAT_OBJS += $(OUTPUT)compat/strtoumax.o |
626 | endif | 688 | endif |
627 | ifdef NO_STRTOULL | 689 | ifdef NO_STRTOULL |
628 | COMPAT_CFLAGS += -DNO_STRTOULL | 690 | COMPAT_CFLAGS += -DNO_STRTOULL |
629 | endif | 691 | endif |
630 | ifdef NO_SETENV | 692 | ifdef NO_SETENV |
631 | COMPAT_CFLAGS += -DNO_SETENV | 693 | COMPAT_CFLAGS += -DNO_SETENV |
632 | COMPAT_OBJS += compat/setenv.o | 694 | COMPAT_OBJS += $(OUTPUT)compat/setenv.o |
633 | endif | 695 | endif |
634 | ifdef NO_MKDTEMP | 696 | ifdef NO_MKDTEMP |
635 | COMPAT_CFLAGS += -DNO_MKDTEMP | 697 | COMPAT_CFLAGS += -DNO_MKDTEMP |
636 | COMPAT_OBJS += compat/mkdtemp.o | 698 | COMPAT_OBJS += $(OUTPUT)compat/mkdtemp.o |
637 | endif | 699 | endif |
638 | ifdef NO_UNSETENV | 700 | ifdef NO_UNSETENV |
639 | COMPAT_CFLAGS += -DNO_UNSETENV | 701 | COMPAT_CFLAGS += -DNO_UNSETENV |
640 | COMPAT_OBJS += compat/unsetenv.o | 702 | COMPAT_OBJS += $(OUTPUT)compat/unsetenv.o |
641 | endif | 703 | endif |
642 | ifdef NO_SYS_SELECT_H | 704 | ifdef NO_SYS_SELECT_H |
643 | BASIC_CFLAGS += -DNO_SYS_SELECT_H | 705 | BASIC_CFLAGS += -DNO_SYS_SELECT_H |
644 | endif | 706 | endif |
645 | ifdef NO_MMAP | 707 | ifdef NO_MMAP |
646 | COMPAT_CFLAGS += -DNO_MMAP | 708 | COMPAT_CFLAGS += -DNO_MMAP |
647 | COMPAT_OBJS += compat/mmap.o | 709 | COMPAT_OBJS += $(OUTPUT)compat/mmap.o |
648 | else | 710 | else |
649 | ifdef USE_WIN32_MMAP | 711 | ifdef USE_WIN32_MMAP |
650 | COMPAT_CFLAGS += -DUSE_WIN32_MMAP | 712 | COMPAT_CFLAGS += -DUSE_WIN32_MMAP |
651 | COMPAT_OBJS += compat/win32mmap.o | 713 | COMPAT_OBJS += $(OUTPUT)compat/win32mmap.o |
652 | endif | 714 | endif |
653 | endif | 715 | endif |
654 | ifdef NO_PREAD | 716 | ifdef NO_PREAD |
655 | COMPAT_CFLAGS += -DNO_PREAD | 717 | COMPAT_CFLAGS += -DNO_PREAD |
656 | COMPAT_OBJS += compat/pread.o | 718 | COMPAT_OBJS += $(OUTPUT)compat/pread.o |
657 | endif | 719 | endif |
658 | ifdef NO_FAST_WORKING_DIRECTORY | 720 | ifdef NO_FAST_WORKING_DIRECTORY |
659 | BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY | 721 | BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY |
@@ -675,10 +737,10 @@ else | |||
675 | endif | 737 | endif |
676 | endif | 738 | endif |
677 | ifdef NO_INET_NTOP | 739 | ifdef NO_INET_NTOP |
678 | LIB_OBJS += compat/inet_ntop.o | 740 | LIB_OBJS += $(OUTPUT)compat/inet_ntop.o |
679 | endif | 741 | endif |
680 | ifdef NO_INET_PTON | 742 | ifdef NO_INET_PTON |
681 | LIB_OBJS += compat/inet_pton.o | 743 | LIB_OBJS += $(OUTPUT)compat/inet_pton.o |
682 | endif | 744 | endif |
683 | 745 | ||
684 | ifdef NO_ICONV | 746 | ifdef NO_ICONV |
@@ -695,15 +757,15 @@ endif | |||
695 | 757 | ||
696 | ifdef PPC_SHA1 | 758 | ifdef PPC_SHA1 |
697 | SHA1_HEADER = "ppc/sha1.h" | 759 | SHA1_HEADER = "ppc/sha1.h" |
698 | LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o | 760 | LIB_OBJS += $(OUTPUT)ppc/sha1.o ppc/sha1ppc.o |
699 | else | 761 | else |
700 | ifdef ARM_SHA1 | 762 | ifdef ARM_SHA1 |
701 | SHA1_HEADER = "arm/sha1.h" | 763 | SHA1_HEADER = "arm/sha1.h" |
702 | LIB_OBJS += arm/sha1.o arm/sha1_arm.o | 764 | LIB_OBJS += $(OUTPUT)arm/sha1.o $(OUTPUT)arm/sha1_arm.o |
703 | else | 765 | else |
704 | ifdef MOZILLA_SHA1 | 766 | ifdef MOZILLA_SHA1 |
705 | SHA1_HEADER = "mozilla-sha1/sha1.h" | 767 | SHA1_HEADER = "mozilla-sha1/sha1.h" |
706 | LIB_OBJS += mozilla-sha1/sha1.o | 768 | LIB_OBJS += $(OUTPUT)mozilla-sha1/sha1.o |
707 | else | 769 | else |
708 | SHA1_HEADER = <openssl/sha.h> | 770 | SHA1_HEADER = <openssl/sha.h> |
709 | EXTLIBS += $(LIB_4_CRYPTO) | 771 | EXTLIBS += $(LIB_4_CRYPTO) |
@@ -715,15 +777,15 @@ ifdef NO_PERL_MAKEMAKER | |||
715 | endif | 777 | endif |
716 | ifdef NO_HSTRERROR | 778 | ifdef NO_HSTRERROR |
717 | COMPAT_CFLAGS += -DNO_HSTRERROR | 779 | COMPAT_CFLAGS += -DNO_HSTRERROR |
718 | COMPAT_OBJS += compat/hstrerror.o | 780 | COMPAT_OBJS += $(OUTPUT)compat/hstrerror.o |
719 | endif | 781 | endif |
720 | ifdef NO_MEMMEM | 782 | ifdef NO_MEMMEM |
721 | COMPAT_CFLAGS += -DNO_MEMMEM | 783 | COMPAT_CFLAGS += -DNO_MEMMEM |
722 | COMPAT_OBJS += compat/memmem.o | 784 | COMPAT_OBJS += $(OUTPUT)compat/memmem.o |
723 | endif | 785 | endif |
724 | ifdef INTERNAL_QSORT | 786 | ifdef INTERNAL_QSORT |
725 | COMPAT_CFLAGS += -DINTERNAL_QSORT | 787 | COMPAT_CFLAGS += -DINTERNAL_QSORT |
726 | COMPAT_OBJS += compat/qsort.o | 788 | COMPAT_OBJS += $(OUTPUT)compat/qsort.o |
727 | endif | 789 | endif |
728 | ifdef RUNTIME_PREFIX | 790 | ifdef RUNTIME_PREFIX |
729 | COMPAT_CFLAGS += -DRUNTIME_PREFIX | 791 | COMPAT_CFLAGS += -DRUNTIME_PREFIX |
@@ -803,7 +865,7 @@ export TAR INSTALL DESTDIR SHELL_PATH | |||
803 | 865 | ||
804 | SHELL = $(SHELL_PATH) | 866 | SHELL = $(SHELL_PATH) |
805 | 867 | ||
806 | all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) PERF-BUILD-OPTIONS | 868 | all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) $(OUTPUT)PERF-BUILD-OPTIONS |
807 | ifneq (,$X) | 869 | ifneq (,$X) |
808 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), test '$p' -ef '$p$X' || $(RM) '$p';) | 870 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), test '$p' -ef '$p$X' || $(RM) '$p';) |
809 | endif | 871 | endif |
@@ -815,39 +877,39 @@ please_set_SHELL_PATH_to_a_more_modern_shell: | |||
815 | 877 | ||
816 | shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell | 878 | shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell |
817 | 879 | ||
818 | strip: $(PROGRAMS) perf$X | 880 | strip: $(PROGRAMS) $(OUTPUT)perf$X |
819 | $(STRIP) $(STRIP_OPTS) $(PROGRAMS) perf$X | 881 | $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf$X |
820 | 882 | ||
821 | perf.o: perf.c common-cmds.h PERF-CFLAGS | 883 | $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
822 | $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \ | 884 | $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \ |
823 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 885 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
824 | $(ALL_CFLAGS) -c $(filter %.c,$^) | 886 | $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ |
825 | 887 | ||
826 | perf$X: perf.o $(BUILTIN_OBJS) $(PERFLIBS) | 888 | $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) |
827 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ perf.o \ | 889 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \ |
828 | $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) | 890 | $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) |
829 | 891 | ||
830 | builtin-help.o: builtin-help.c common-cmds.h PERF-CFLAGS | 892 | $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
831 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 893 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
832 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 894 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
833 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ | 895 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ |
834 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< | 896 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< |
835 | 897 | ||
836 | builtin-timechart.o: builtin-timechart.c common-cmds.h PERF-CFLAGS | 898 | $(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS |
837 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 899 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
838 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ | 900 | '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ |
839 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ | 901 | '-DPERF_MAN_PATH="$(mandir_SQ)"' \ |
840 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< | 902 | '-DPERF_INFO_PATH="$(infodir_SQ)"' $< |
841 | 903 | ||
842 | $(BUILT_INS): perf$X | 904 | $(BUILT_INS): $(OUTPUT)perf$X |
843 | $(QUIET_BUILT_IN)$(RM) $@ && \ | 905 | $(QUIET_BUILT_IN)$(RM) $@ && \ |
844 | ln perf$X $@ 2>/dev/null || \ | 906 | ln perf$X $@ 2>/dev/null || \ |
845 | ln -s perf$X $@ 2>/dev/null || \ | 907 | ln -s perf$X $@ 2>/dev/null || \ |
846 | cp perf$X $@ | 908 | cp perf$X $@ |
847 | 909 | ||
848 | common-cmds.h: util/generate-cmdlist.sh command-list.txt | 910 | $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt |
849 | 911 | ||
850 | common-cmds.h: $(wildcard Documentation/perf-*.txt) | 912 | $(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt) |
851 | $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ | 913 | $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ |
852 | 914 | ||
853 | $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh | 915 | $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh |
@@ -859,7 +921,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh | |||
859 | -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ | 921 | -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ |
860 | $@.sh >$@+ && \ | 922 | $@.sh >$@+ && \ |
861 | chmod +x $@+ && \ | 923 | chmod +x $@+ && \ |
862 | mv $@+ $@ | 924 | mv $@+ $(OUTPUT)$@ |
863 | 925 | ||
864 | configure: configure.ac | 926 | configure: configure.ac |
865 | $(QUIET_GEN)$(RM) $@ $<+ && \ | 927 | $(QUIET_GEN)$(RM) $@ $<+ && \ |
@@ -869,60 +931,50 @@ configure: configure.ac | |||
869 | $(RM) $<+ | 931 | $(RM) $<+ |
870 | 932 | ||
871 | # These can record PERF_VERSION | 933 | # These can record PERF_VERSION |
872 | perf.o perf.spec \ | 934 | $(OUTPUT)perf.o perf.spec \ |
873 | $(patsubst %.sh,%,$(SCRIPT_SH)) \ | 935 | $(patsubst %.sh,%,$(SCRIPT_SH)) \ |
874 | $(patsubst %.perl,%,$(SCRIPT_PERL)) \ | 936 | $(patsubst %.perl,%,$(SCRIPT_PERL)) \ |
875 | : PERF-VERSION-FILE | 937 | : $(OUTPUT)PERF-VERSION-FILE |
876 | 938 | ||
877 | %.o: %.c PERF-CFLAGS | 939 | $(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS |
878 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< | 940 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< |
879 | %.s: %.c PERF-CFLAGS | 941 | $(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS |
880 | $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< | 942 | $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< |
881 | %.o: %.S | 943 | $(OUTPUT)%.o: %.S |
882 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< | 944 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< |
883 | 945 | ||
884 | util/exec_cmd.o: util/exec_cmd.c PERF-CFLAGS | 946 | $(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS |
885 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \ | 947 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ |
886 | '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ | 948 | '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ |
887 | '-DBINDIR="$(bindir_relative_SQ)"' \ | 949 | '-DBINDIR="$(bindir_relative_SQ)"' \ |
888 | '-DPREFIX="$(prefix_SQ)"' \ | 950 | '-DPREFIX="$(prefix_SQ)"' \ |
889 | $< | 951 | $< |
890 | 952 | ||
891 | builtin-init-db.o: builtin-init-db.c PERF-CFLAGS | 953 | $(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS |
892 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $< | 954 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $< |
893 | |||
894 | util/config.o: util/config.c PERF-CFLAGS | ||
895 | $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
896 | |||
897 | util/rbtree.o: ../../lib/rbtree.c PERF-CFLAGS | ||
898 | $(QUIET_CC)$(CC) -o util/rbtree.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | ||
899 | |||
900 | # some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing | ||
901 | # from <string.h> that comes from kernel headers wrapping. | ||
902 | KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//` | ||
903 | 955 | ||
904 | util/bitmap.o: ../../lib/bitmap.c PERF-CFLAGS | 956 | $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS |
905 | $(QUIET_CC)$(CC) -o util/bitmap.o -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 957 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
906 | 958 | ||
907 | util/hweight.o: ../../lib/hweight.c PERF-CFLAGS | 959 | $(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS |
908 | $(QUIET_CC)$(CC) -o util/hweight.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 960 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< |
909 | 961 | ||
910 | util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS | 962 | $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS |
911 | $(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< | 963 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< |
912 | 964 | ||
913 | util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c PERF-CFLAGS | 965 | $(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS |
914 | $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 966 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
915 | 967 | ||
916 | scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS | 968 | $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS |
917 | $(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< | 969 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< |
918 | 970 | ||
919 | util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c PERF-CFLAGS | 971 | $(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS |
920 | $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-python.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< | 972 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< |
921 | 973 | ||
922 | scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c PERF-CFLAGS | 974 | $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS |
923 | $(QUIET_CC)$(CC) -o scripts/python/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< | 975 | $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< |
924 | 976 | ||
925 | perf-%$X: %.o $(PERFLIBS) | 977 | $(OUTPUT)perf-%$X: %.o $(PERFLIBS) |
926 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) | 978 | $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) |
927 | 979 | ||
928 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) | 980 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) |
@@ -963,17 +1015,17 @@ cscope: | |||
963 | TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ | 1015 | TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ |
964 | $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) | 1016 | $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) |
965 | 1017 | ||
966 | PERF-CFLAGS: .FORCE-PERF-CFLAGS | 1018 | $(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS |
967 | @FLAGS='$(TRACK_CFLAGS)'; \ | 1019 | @FLAGS='$(TRACK_CFLAGS)'; \ |
968 | if test x"$$FLAGS" != x"`cat PERF-CFLAGS 2>/dev/null`" ; then \ | 1020 | if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \ |
969 | echo 1>&2 " * new build flags or prefix"; \ | 1021 | echo 1>&2 " * new build flags or prefix"; \ |
970 | echo "$$FLAGS" >PERF-CFLAGS; \ | 1022 | echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \ |
971 | fi | 1023 | fi |
972 | 1024 | ||
973 | # We need to apply sq twice, once to protect from the shell | 1025 | # We need to apply sq twice, once to protect from the shell |
974 | # that runs PERF-BUILD-OPTIONS, and then again to protect it | 1026 | # that runs $(OUTPUT)PERF-BUILD-OPTIONS, and then again to protect it |
975 | # and the first level quoting from the shell that runs "echo". | 1027 | # and the first level quoting from the shell that runs "echo". |
976 | PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS | 1028 | $(OUTPUT)PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS |
977 | @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@ | 1029 | @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@ |
978 | @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@ | 1030 | @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@ |
979 | @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@ | 1031 | @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@ |
@@ -994,7 +1046,7 @@ all:: $(TEST_PROGRAMS) | |||
994 | 1046 | ||
995 | export NO_SVN_TESTS | 1047 | export NO_SVN_TESTS |
996 | 1048 | ||
997 | check: common-cmds.h | 1049 | check: $(OUTPUT)common-cmds.h |
998 | if sparse; \ | 1050 | if sparse; \ |
999 | then \ | 1051 | then \ |
1000 | for i in *.c */*.c; \ | 1052 | for i in *.c */*.c; \ |
@@ -1028,10 +1080,10 @@ export perfexec_instdir | |||
1028 | 1080 | ||
1029 | install: all | 1081 | install: all |
1030 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' | 1082 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' |
1031 | $(INSTALL) perf$X '$(DESTDIR_SQ)$(bindir_SQ)' | 1083 | $(INSTALL) $(OUTPUT)perf$X '$(DESTDIR_SQ)$(bindir_SQ)' |
1032 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' | 1084 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' |
1033 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' | 1085 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' |
1034 | $(INSTALL) perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1086 | $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1035 | $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' | 1087 | $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' |
1036 | $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl' | 1088 | $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl' |
1037 | $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' | 1089 | $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' |
@@ -1045,7 +1097,7 @@ ifdef BUILT_INS | |||
1045 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1097 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1046 | $(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 1098 | $(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
1047 | ifneq (,$X) | 1099 | ifneq (,$X) |
1048 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';) | 1100 | $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) $(OUTPUT)perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';) |
1049 | endif | 1101 | endif |
1050 | endif | 1102 | endif |
1051 | 1103 | ||
@@ -1129,14 +1181,14 @@ clean: | |||
1129 | $(RM) *.o */*.o */*/*.o */*/*/*.o $(LIB_FILE) | 1181 | $(RM) *.o */*.o */*/*.o */*/*/*.o $(LIB_FILE) |
1130 | $(RM) $(ALL_PROGRAMS) $(BUILT_INS) perf$X | 1182 | $(RM) $(ALL_PROGRAMS) $(BUILT_INS) perf$X |
1131 | $(RM) $(TEST_PROGRAMS) | 1183 | $(RM) $(TEST_PROGRAMS) |
1132 | $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope* | 1184 | $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* |
1133 | $(RM) -r autom4te.cache | 1185 | $(RM) -r autom4te.cache |
1134 | $(RM) config.log config.mak.autogen config.mak.append config.status config.cache | 1186 | $(RM) config.log config.mak.autogen config.mak.append config.status config.cache |
1135 | $(RM) -r $(PERF_TARNAME) .doc-tmp-dir | 1187 | $(RM) -r $(PERF_TARNAME) .doc-tmp-dir |
1136 | $(RM) $(PERF_TARNAME).tar.gz perf-core_$(PERF_VERSION)-*.tar.gz | 1188 | $(RM) $(PERF_TARNAME).tar.gz perf-core_$(PERF_VERSION)-*.tar.gz |
1137 | $(RM) $(htmldocs).tar.gz $(manpages).tar.gz | 1189 | $(RM) $(htmldocs).tar.gz $(manpages).tar.gz |
1138 | $(MAKE) -C Documentation/ clean | 1190 | $(MAKE) -C Documentation/ clean |
1139 | $(RM) PERF-VERSION-FILE PERF-CFLAGS PERF-BUILD-OPTIONS | 1191 | $(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-BUILD-OPTIONS |
1140 | 1192 | ||
1141 | .PHONY: all install clean strip | 1193 | .PHONY: all install clean strip |
1142 | .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell | 1194 | .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell |
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile new file mode 100644 index 000000000000..15130b50dfe3 --- /dev/null +++ b/tools/perf/arch/powerpc/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | ifndef NO_DWARF | ||
2 | PERF_HAVE_DWARF_REGS := 1 | ||
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | ||
4 | endif | ||
diff --git a/tools/perf/arch/powerpc/util/dwarf-regs.c b/tools/perf/arch/powerpc/util/dwarf-regs.c new file mode 100644 index 000000000000..48ae0c5e3f73 --- /dev/null +++ b/tools/perf/arch/powerpc/util/dwarf-regs.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * Mapping of DWARF debug register numbers into register names. | ||
3 | * | ||
4 | * Copyright (C) 2010 Ian Munsie, IBM Corporation. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <libio.h> | ||
13 | #include <dwarf-regs.h> | ||
14 | |||
15 | |||
16 | struct pt_regs_dwarfnum { | ||
17 | const char *name; | ||
18 | unsigned int dwarfnum; | ||
19 | }; | ||
20 | |||
21 | #define STR(s) #s | ||
22 | #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} | ||
23 | #define GPR_DWARFNUM_NAME(num) \ | ||
24 | {.name = STR(%gpr##num), .dwarfnum = num} | ||
25 | #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} | ||
26 | |||
27 | /* | ||
28 | * Reference: | ||
29 | * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html | ||
30 | */ | ||
31 | static const struct pt_regs_dwarfnum regdwarfnum_table[] = { | ||
32 | GPR_DWARFNUM_NAME(0), | ||
33 | GPR_DWARFNUM_NAME(1), | ||
34 | GPR_DWARFNUM_NAME(2), | ||
35 | GPR_DWARFNUM_NAME(3), | ||
36 | GPR_DWARFNUM_NAME(4), | ||
37 | GPR_DWARFNUM_NAME(5), | ||
38 | GPR_DWARFNUM_NAME(6), | ||
39 | GPR_DWARFNUM_NAME(7), | ||
40 | GPR_DWARFNUM_NAME(8), | ||
41 | GPR_DWARFNUM_NAME(9), | ||
42 | GPR_DWARFNUM_NAME(10), | ||
43 | GPR_DWARFNUM_NAME(11), | ||
44 | GPR_DWARFNUM_NAME(12), | ||
45 | GPR_DWARFNUM_NAME(13), | ||
46 | GPR_DWARFNUM_NAME(14), | ||
47 | GPR_DWARFNUM_NAME(15), | ||
48 | GPR_DWARFNUM_NAME(16), | ||
49 | GPR_DWARFNUM_NAME(17), | ||
50 | GPR_DWARFNUM_NAME(18), | ||
51 | GPR_DWARFNUM_NAME(19), | ||
52 | GPR_DWARFNUM_NAME(20), | ||
53 | GPR_DWARFNUM_NAME(21), | ||
54 | GPR_DWARFNUM_NAME(22), | ||
55 | GPR_DWARFNUM_NAME(23), | ||
56 | GPR_DWARFNUM_NAME(24), | ||
57 | GPR_DWARFNUM_NAME(25), | ||
58 | GPR_DWARFNUM_NAME(26), | ||
59 | GPR_DWARFNUM_NAME(27), | ||
60 | GPR_DWARFNUM_NAME(28), | ||
61 | GPR_DWARFNUM_NAME(29), | ||
62 | GPR_DWARFNUM_NAME(30), | ||
63 | GPR_DWARFNUM_NAME(31), | ||
64 | REG_DWARFNUM_NAME("%msr", 66), | ||
65 | REG_DWARFNUM_NAME("%ctr", 109), | ||
66 | REG_DWARFNUM_NAME("%link", 108), | ||
67 | REG_DWARFNUM_NAME("%xer", 101), | ||
68 | REG_DWARFNUM_NAME("%dar", 119), | ||
69 | REG_DWARFNUM_NAME("%dsisr", 118), | ||
70 | REG_DWARFNUM_END, | ||
71 | }; | ||
72 | |||
73 | /** | ||
74 | * get_arch_regstr() - lookup register name from it's DWARF register number | ||
75 | * @n: the DWARF register number | ||
76 | * | ||
77 | * get_arch_regstr() returns the name of the register in struct | ||
78 | * regdwarfnum_table from it's DWARF register number. If the register is not | ||
79 | * found in the table, this returns NULL; | ||
80 | */ | ||
81 | const char *get_arch_regstr(unsigned int n) | ||
82 | { | ||
83 | const struct pt_regs_dwarfnum *roff; | ||
84 | for (roff = regdwarfnum_table; roff->name != NULL; roff++) | ||
85 | if (roff->dwarfnum == n) | ||
86 | return roff->name; | ||
87 | return NULL; | ||
88 | } | ||
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile new file mode 100644 index 000000000000..15130b50dfe3 --- /dev/null +++ b/tools/perf/arch/x86/Makefile | |||
@@ -0,0 +1,4 @@ | |||
1 | ifndef NO_DWARF | ||
2 | PERF_HAVE_DWARF_REGS := 1 | ||
3 | LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o | ||
4 | endif | ||
diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c new file mode 100644 index 000000000000..a794d3081928 --- /dev/null +++ b/tools/perf/arch/x86/util/dwarf-regs.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * dwarf-regs.c : Mapping of DWARF debug register numbers into register names. | ||
3 | * Extracted from probe-finder.c | ||
4 | * | ||
5 | * Written by Masami Hiramatsu <mhiramat@redhat.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <libio.h> | ||
24 | #include <dwarf-regs.h> | ||
25 | |||
26 | /* | ||
27 | * Generic dwarf analysis helpers | ||
28 | */ | ||
29 | |||
30 | #define X86_32_MAX_REGS 8 | ||
31 | const char *x86_32_regs_table[X86_32_MAX_REGS] = { | ||
32 | "%ax", | ||
33 | "%cx", | ||
34 | "%dx", | ||
35 | "%bx", | ||
36 | "$stack", /* Stack address instead of %sp */ | ||
37 | "%bp", | ||
38 | "%si", | ||
39 | "%di", | ||
40 | }; | ||
41 | |||
42 | #define X86_64_MAX_REGS 16 | ||
43 | const char *x86_64_regs_table[X86_64_MAX_REGS] = { | ||
44 | "%ax", | ||
45 | "%dx", | ||
46 | "%cx", | ||
47 | "%bx", | ||
48 | "%si", | ||
49 | "%di", | ||
50 | "%bp", | ||
51 | "%sp", | ||
52 | "%r8", | ||
53 | "%r9", | ||
54 | "%r10", | ||
55 | "%r11", | ||
56 | "%r12", | ||
57 | "%r13", | ||
58 | "%r14", | ||
59 | "%r15", | ||
60 | }; | ||
61 | |||
62 | /* TODO: switching by dwarf address size */ | ||
63 | #ifdef __x86_64__ | ||
64 | #define ARCH_MAX_REGS X86_64_MAX_REGS | ||
65 | #define arch_regs_table x86_64_regs_table | ||
66 | #else | ||
67 | #define ARCH_MAX_REGS X86_32_MAX_REGS | ||
68 | #define arch_regs_table x86_32_regs_table | ||
69 | #endif | ||
70 | |||
71 | /* Return architecture dependent register string (for kprobe-tracer) */ | ||
72 | const char *get_arch_regstr(unsigned int n) | ||
73 | { | ||
74 | return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL; | ||
75 | } | ||
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 89773178e894..38dae7465142 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
@@ -10,7 +10,6 @@ | |||
10 | #include "../perf.h" | 10 | #include "../perf.h" |
11 | #include "../util/util.h" | 11 | #include "../util/util.h" |
12 | #include "../util/parse-options.h" | 12 | #include "../util/parse-options.h" |
13 | #include "../util/string.h" | ||
14 | #include "../util/header.h" | 13 | #include "../util/header.h" |
15 | #include "bench.h" | 14 | #include "bench.h" |
16 | 15 | ||
@@ -24,7 +23,7 @@ | |||
24 | 23 | ||
25 | static const char *length_str = "1MB"; | 24 | static const char *length_str = "1MB"; |
26 | static const char *routine = "default"; | 25 | static const char *routine = "default"; |
27 | static int use_clock = 0; | 26 | static bool use_clock = false; |
28 | static int clock_fd; | 27 | static int clock_fd; |
29 | 28 | ||
30 | static const struct option options[] = { | 29 | static const struct option options[] = { |
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c index 81cee78181fa..d1d1b30f99c1 100644 --- a/tools/perf/bench/sched-messaging.c +++ b/tools/perf/bench/sched-messaging.c | |||
@@ -31,9 +31,9 @@ | |||
31 | 31 | ||
32 | #define DATASIZE 100 | 32 | #define DATASIZE 100 |
33 | 33 | ||
34 | static int use_pipes = 0; | 34 | static bool use_pipes = false; |
35 | static unsigned int loops = 100; | 35 | static unsigned int loops = 100; |
36 | static unsigned int thread_mode = 0; | 36 | static bool thread_mode = false; |
37 | static unsigned int num_groups = 10; | 37 | static unsigned int num_groups = 10; |
38 | 38 | ||
39 | struct sender_context { | 39 | struct sender_context { |
@@ -256,10 +256,8 @@ static const struct option options[] = { | |||
256 | "Use pipe() instead of socketpair()"), | 256 | "Use pipe() instead of socketpair()"), |
257 | OPT_BOOLEAN('t', "thread", &thread_mode, | 257 | OPT_BOOLEAN('t', "thread", &thread_mode, |
258 | "Be multi thread instead of multi process"), | 258 | "Be multi thread instead of multi process"), |
259 | OPT_INTEGER('g', "group", &num_groups, | 259 | OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"), |
260 | "Specify number of groups"), | 260 | OPT_UINTEGER('l', "loop", &loops, "Specify number of loops"), |
261 | OPT_INTEGER('l', "loop", &loops, | ||
262 | "Specify number of loops"), | ||
263 | OPT_END() | 261 | OPT_END() |
264 | }; | 262 | }; |
265 | 263 | ||
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c index 4f77c7c27640..d9ab3ce446ac 100644 --- a/tools/perf/bench/sched-pipe.c +++ b/tools/perf/bench/sched-pipe.c | |||
@@ -93,7 +93,7 @@ int bench_sched_pipe(int argc, const char **argv, | |||
93 | 93 | ||
94 | switch (bench_format) { | 94 | switch (bench_format) { |
95 | case BENCH_FORMAT_DEFAULT: | 95 | case BENCH_FORMAT_DEFAULT: |
96 | printf("# Extecuted %d pipe operations between two tasks\n\n", | 96 | printf("# Executed %d pipe operations between two tasks\n\n", |
97 | loops); | 97 | loops); |
98 | 98 | ||
99 | result_usec = diff.tv_sec * 1000000; | 99 | result_usec = diff.tv_sec * 1000000; |
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 6ad7148451c5..77bcc9b130f5 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "util/cache.h" | 14 | #include "util/cache.h" |
15 | #include <linux/rbtree.h> | 15 | #include <linux/rbtree.h> |
16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
17 | #include "util/string.h" | ||
18 | 17 | ||
19 | #include "perf.h" | 18 | #include "perf.h" |
20 | #include "util/debug.h" | 19 | #include "util/debug.h" |
@@ -29,80 +28,16 @@ | |||
29 | 28 | ||
30 | static char const *input_name = "perf.data"; | 29 | static char const *input_name = "perf.data"; |
31 | 30 | ||
32 | static int force; | 31 | static bool force; |
33 | 32 | ||
34 | static int full_paths; | 33 | static bool full_paths; |
35 | 34 | ||
36 | static int print_line; | 35 | static bool print_line; |
37 | |||
38 | struct sym_hist { | ||
39 | u64 sum; | ||
40 | u64 ip[0]; | ||
41 | }; | ||
42 | |||
43 | struct sym_ext { | ||
44 | struct rb_node node; | ||
45 | double percent; | ||
46 | char *path; | ||
47 | }; | ||
48 | |||
49 | struct sym_priv { | ||
50 | struct sym_hist *hist; | ||
51 | struct sym_ext *ext; | ||
52 | }; | ||
53 | 36 | ||
54 | static const char *sym_hist_filter; | 37 | static const char *sym_hist_filter; |
55 | 38 | ||
56 | static int sym__alloc_hist(struct symbol *self) | 39 | static int hists__add_entry(struct hists *self, struct addr_location *al) |
57 | { | ||
58 | struct sym_priv *priv = symbol__priv(self); | ||
59 | const int size = (sizeof(*priv->hist) + | ||
60 | (self->end - self->start) * sizeof(u64)); | ||
61 | |||
62 | priv->hist = zalloc(size); | ||
63 | return priv->hist == NULL ? -1 : 0; | ||
64 | } | ||
65 | |||
66 | /* | ||
67 | * collect histogram counts | ||
68 | */ | ||
69 | static int annotate__hist_hit(struct hist_entry *he, u64 ip) | ||
70 | { | ||
71 | unsigned int sym_size, offset; | ||
72 | struct symbol *sym = he->sym; | ||
73 | struct sym_priv *priv; | ||
74 | struct sym_hist *h; | ||
75 | |||
76 | he->count++; | ||
77 | |||
78 | if (!sym || !he->map) | ||
79 | return 0; | ||
80 | |||
81 | priv = symbol__priv(sym); | ||
82 | if (priv->hist == NULL && sym__alloc_hist(sym) < 0) | ||
83 | return -ENOMEM; | ||
84 | |||
85 | sym_size = sym->end - sym->start; | ||
86 | offset = ip - sym->start; | ||
87 | |||
88 | pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip)); | ||
89 | |||
90 | if (offset >= sym_size) | ||
91 | return 0; | ||
92 | |||
93 | h = priv->hist; | ||
94 | h->sum++; | ||
95 | h->ip[offset]++; | ||
96 | |||
97 | pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start, | ||
98 | he->sym->name, ip, ip - he->sym->start, h->ip[offset]); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static int perf_session__add_hist_entry(struct perf_session *self, | ||
103 | struct addr_location *al, u64 count) | ||
104 | { | 40 | { |
105 | bool hit; | ||
106 | struct hist_entry *he; | 41 | struct hist_entry *he; |
107 | 42 | ||
108 | if (sym_hist_filter != NULL && | 43 | if (sym_hist_filter != NULL && |
@@ -116,11 +51,11 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
116 | return 0; | 51 | return 0; |
117 | } | 52 | } |
118 | 53 | ||
119 | he = __perf_session__add_hist_entry(&self->hists, al, NULL, count, &hit); | 54 | he = __hists__add_entry(self, al, NULL, 1); |
120 | if (he == NULL) | 55 | if (he == NULL) |
121 | return -ENOMEM; | 56 | return -ENOMEM; |
122 | 57 | ||
123 | return annotate__hist_hit(he, al->addr); | 58 | return hist_entry__inc_addr_samples(he, al->addr); |
124 | } | 59 | } |
125 | 60 | ||
126 | static int process_sample_event(event_t *event, struct perf_session *session) | 61 | static int process_sample_event(event_t *event, struct perf_session *session) |
@@ -136,7 +71,7 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
136 | return -1; | 71 | return -1; |
137 | } | 72 | } |
138 | 73 | ||
139 | if (!al.filtered && perf_session__add_hist_entry(session, &al, 1)) { | 74 | if (!al.filtered && hists__add_entry(&session->hists, &al)) { |
140 | pr_warning("problem incrementing symbol count, " | 75 | pr_warning("problem incrementing symbol count, " |
141 | "skipping event\n"); | 76 | "skipping event\n"); |
142 | return -1; | 77 | return -1; |
@@ -145,106 +80,11 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
145 | return 0; | 80 | return 0; |
146 | } | 81 | } |
147 | 82 | ||
148 | struct objdump_line { | ||
149 | struct list_head node; | ||
150 | s64 offset; | ||
151 | char *line; | ||
152 | }; | ||
153 | |||
154 | static struct objdump_line *objdump_line__new(s64 offset, char *line) | ||
155 | { | ||
156 | struct objdump_line *self = malloc(sizeof(*self)); | ||
157 | |||
158 | if (self != NULL) { | ||
159 | self->offset = offset; | ||
160 | self->line = line; | ||
161 | } | ||
162 | |||
163 | return self; | ||
164 | } | ||
165 | |||
166 | static void objdump_line__free(struct objdump_line *self) | ||
167 | { | ||
168 | free(self->line); | ||
169 | free(self); | ||
170 | } | ||
171 | |||
172 | static void objdump__add_line(struct list_head *head, struct objdump_line *line) | ||
173 | { | ||
174 | list_add_tail(&line->node, head); | ||
175 | } | ||
176 | |||
177 | static struct objdump_line *objdump__get_next_ip_line(struct list_head *head, | ||
178 | struct objdump_line *pos) | ||
179 | { | ||
180 | list_for_each_entry_continue(pos, head, node) | ||
181 | if (pos->offset >= 0) | ||
182 | return pos; | ||
183 | |||
184 | return NULL; | ||
185 | } | ||
186 | |||
187 | static int parse_line(FILE *file, struct hist_entry *he, | ||
188 | struct list_head *head) | ||
189 | { | ||
190 | struct symbol *sym = he->sym; | ||
191 | struct objdump_line *objdump_line; | ||
192 | char *line = NULL, *tmp, *tmp2; | ||
193 | size_t line_len; | ||
194 | s64 line_ip, offset = -1; | ||
195 | char *c; | ||
196 | |||
197 | if (getline(&line, &line_len, file) < 0) | ||
198 | return -1; | ||
199 | |||
200 | if (!line) | ||
201 | return -1; | ||
202 | |||
203 | c = strchr(line, '\n'); | ||
204 | if (c) | ||
205 | *c = 0; | ||
206 | |||
207 | line_ip = -1; | ||
208 | |||
209 | /* | ||
210 | * Strip leading spaces: | ||
211 | */ | ||
212 | tmp = line; | ||
213 | while (*tmp) { | ||
214 | if (*tmp != ' ') | ||
215 | break; | ||
216 | tmp++; | ||
217 | } | ||
218 | |||
219 | if (*tmp) { | ||
220 | /* | ||
221 | * Parse hexa addresses followed by ':' | ||
222 | */ | ||
223 | line_ip = strtoull(tmp, &tmp2, 16); | ||
224 | if (*tmp2 != ':') | ||
225 | line_ip = -1; | ||
226 | } | ||
227 | |||
228 | if (line_ip != -1) { | ||
229 | u64 start = map__rip_2objdump(he->map, sym->start); | ||
230 | offset = line_ip - start; | ||
231 | } | ||
232 | |||
233 | objdump_line = objdump_line__new(offset, line); | ||
234 | if (objdump_line == NULL) { | ||
235 | free(line); | ||
236 | return -1; | ||
237 | } | ||
238 | objdump__add_line(head, objdump_line); | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | static int objdump_line__print(struct objdump_line *self, | 83 | static int objdump_line__print(struct objdump_line *self, |
244 | struct list_head *head, | 84 | struct list_head *head, |
245 | struct hist_entry *he, u64 len) | 85 | struct hist_entry *he, u64 len) |
246 | { | 86 | { |
247 | struct symbol *sym = he->sym; | 87 | struct symbol *sym = he->ms.sym; |
248 | static const char *prev_line; | 88 | static const char *prev_line; |
249 | static const char *prev_color; | 89 | static const char *prev_color; |
250 | 90 | ||
@@ -327,7 +167,7 @@ static void insert_source_line(struct sym_ext *sym_ext) | |||
327 | 167 | ||
328 | static void free_source_line(struct hist_entry *he, int len) | 168 | static void free_source_line(struct hist_entry *he, int len) |
329 | { | 169 | { |
330 | struct sym_priv *priv = symbol__priv(he->sym); | 170 | struct sym_priv *priv = symbol__priv(he->ms.sym); |
331 | struct sym_ext *sym_ext = priv->ext; | 171 | struct sym_ext *sym_ext = priv->ext; |
332 | int i; | 172 | int i; |
333 | 173 | ||
@@ -346,7 +186,7 @@ static void free_source_line(struct hist_entry *he, int len) | |||
346 | static void | 186 | static void |
347 | get_source_line(struct hist_entry *he, int len, const char *filename) | 187 | get_source_line(struct hist_entry *he, int len, const char *filename) |
348 | { | 188 | { |
349 | struct symbol *sym = he->sym; | 189 | struct symbol *sym = he->ms.sym; |
350 | u64 start; | 190 | u64 start; |
351 | int i; | 191 | int i; |
352 | char cmd[PATH_MAX * 2]; | 192 | char cmd[PATH_MAX * 2]; |
@@ -361,7 +201,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename) | |||
361 | if (!priv->ext) | 201 | if (!priv->ext) |
362 | return; | 202 | return; |
363 | 203 | ||
364 | start = he->map->unmap_ip(he->map, sym->start); | 204 | start = he->ms.map->unmap_ip(he->ms.map, sym->start); |
365 | 205 | ||
366 | for (i = 0; i < len; i++) { | 206 | for (i = 0; i < len; i++) { |
367 | char *path = NULL; | 207 | char *path = NULL; |
@@ -425,7 +265,7 @@ static void print_summary(const char *filename) | |||
425 | 265 | ||
426 | static void hist_entry__print_hits(struct hist_entry *self) | 266 | static void hist_entry__print_hits(struct hist_entry *self) |
427 | { | 267 | { |
428 | struct symbol *sym = self->sym; | 268 | struct symbol *sym = self->ms.sym; |
429 | struct sym_priv *priv = symbol__priv(sym); | 269 | struct sym_priv *priv = symbol__priv(sym); |
430 | struct sym_hist *h = priv->hist; | 270 | struct sym_hist *h = priv->hist; |
431 | u64 len = sym->end - sym->start, offset; | 271 | u64 len = sym->end - sym->start, offset; |
@@ -439,23 +279,17 @@ static void hist_entry__print_hits(struct hist_entry *self) | |||
439 | 279 | ||
440 | static void annotate_sym(struct hist_entry *he) | 280 | static void annotate_sym(struct hist_entry *he) |
441 | { | 281 | { |
442 | struct map *map = he->map; | 282 | struct map *map = he->ms.map; |
443 | struct dso *dso = map->dso; | 283 | struct dso *dso = map->dso; |
444 | struct symbol *sym = he->sym; | 284 | struct symbol *sym = he->ms.sym; |
445 | const char *filename = dso->long_name, *d_filename; | 285 | const char *filename = dso->long_name, *d_filename; |
446 | u64 len; | 286 | u64 len; |
447 | char command[PATH_MAX*2]; | ||
448 | FILE *file; | ||
449 | LIST_HEAD(head); | 287 | LIST_HEAD(head); |
450 | struct objdump_line *pos, *n; | 288 | struct objdump_line *pos, *n; |
451 | 289 | ||
452 | if (!filename) | 290 | if (hist_entry__annotate(he, &head) < 0) |
453 | return; | 291 | return; |
454 | 292 | ||
455 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | ||
456 | filename, sym->name, map->unmap_ip(map, sym->start), | ||
457 | map->unmap_ip(map, sym->end)); | ||
458 | |||
459 | if (full_paths) | 293 | if (full_paths) |
460 | d_filename = filename; | 294 | d_filename = filename; |
461 | else | 295 | else |
@@ -472,29 +306,6 @@ static void annotate_sym(struct hist_entry *he) | |||
472 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); | 306 | printf(" Percent | Source code & Disassembly of %s\n", d_filename); |
473 | printf("------------------------------------------------\n"); | 307 | printf("------------------------------------------------\n"); |
474 | 308 | ||
475 | if (verbose >= 2) | ||
476 | printf("annotating [%p] %30s : [%p] %30s\n", | ||
477 | dso, dso->long_name, sym, sym->name); | ||
478 | |||
479 | sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s", | ||
480 | map__rip_2objdump(map, sym->start), | ||
481 | map__rip_2objdump(map, sym->end), | ||
482 | filename, filename); | ||
483 | |||
484 | if (verbose >= 3) | ||
485 | printf("doing: %s\n", command); | ||
486 | |||
487 | file = popen(command, "r"); | ||
488 | if (!file) | ||
489 | return; | ||
490 | |||
491 | while (!feof(file)) { | ||
492 | if (parse_line(file, he, &head) < 0) | ||
493 | break; | ||
494 | } | ||
495 | |||
496 | pclose(file); | ||
497 | |||
498 | if (verbose) | 309 | if (verbose) |
499 | hist_entry__print_hits(he); | 310 | hist_entry__print_hits(he); |
500 | 311 | ||
@@ -508,25 +319,25 @@ static void annotate_sym(struct hist_entry *he) | |||
508 | free_source_line(he, len); | 319 | free_source_line(he, len); |
509 | } | 320 | } |
510 | 321 | ||
511 | static void perf_session__find_annotations(struct perf_session *self) | 322 | static void hists__find_annotations(struct hists *self) |
512 | { | 323 | { |
513 | struct rb_node *nd; | 324 | struct rb_node *nd; |
514 | 325 | ||
515 | for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) { | 326 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
516 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); | 327 | struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node); |
517 | struct sym_priv *priv; | 328 | struct sym_priv *priv; |
518 | 329 | ||
519 | if (he->sym == NULL) | 330 | if (he->ms.sym == NULL) |
520 | continue; | 331 | continue; |
521 | 332 | ||
522 | priv = symbol__priv(he->sym); | 333 | priv = symbol__priv(he->ms.sym); |
523 | if (priv->hist == NULL) | 334 | if (priv->hist == NULL) |
524 | continue; | 335 | continue; |
525 | 336 | ||
526 | annotate_sym(he); | 337 | annotate_sym(he); |
527 | /* | 338 | /* |
528 | * Since we have a hist_entry per IP for the same symbol, free | 339 | * Since we have a hist_entry per IP for the same symbol, free |
529 | * he->sym->hist to signal we already processed this symbol. | 340 | * he->ms.sym->hist to signal we already processed this symbol. |
530 | */ | 341 | */ |
531 | free(priv->hist); | 342 | free(priv->hist); |
532 | priv->hist = NULL; | 343 | priv->hist = NULL; |
@@ -545,7 +356,7 @@ static int __cmd_annotate(void) | |||
545 | int ret; | 356 | int ret; |
546 | struct perf_session *session; | 357 | struct perf_session *session; |
547 | 358 | ||
548 | session = perf_session__new(input_name, O_RDONLY, force); | 359 | session = perf_session__new(input_name, O_RDONLY, force, false); |
549 | if (session == NULL) | 360 | if (session == NULL) |
550 | return -ENOMEM; | 361 | return -ENOMEM; |
551 | 362 | ||
@@ -554,7 +365,7 @@ static int __cmd_annotate(void) | |||
554 | goto out_delete; | 365 | goto out_delete; |
555 | 366 | ||
556 | if (dump_trace) { | 367 | if (dump_trace) { |
557 | event__print_totals(); | 368 | perf_session__fprintf_nr_events(session, stdout); |
558 | goto out_delete; | 369 | goto out_delete; |
559 | } | 370 | } |
560 | 371 | ||
@@ -562,11 +373,11 @@ static int __cmd_annotate(void) | |||
562 | perf_session__fprintf(session, stdout); | 373 | perf_session__fprintf(session, stdout); |
563 | 374 | ||
564 | if (verbose > 2) | 375 | if (verbose > 2) |
565 | dsos__fprintf(stdout); | 376 | perf_session__fprintf_dsos(session, stdout); |
566 | 377 | ||
567 | perf_session__collapse_resort(&session->hists); | 378 | hists__collapse_resort(&session->hists); |
568 | perf_session__output_resort(&session->hists, session->event_total[0]); | 379 | hists__output_resort(&session->hists); |
569 | perf_session__find_annotations(session); | 380 | hists__find_annotations(&session->hists); |
570 | out_delete: | 381 | out_delete: |
571 | perf_session__delete(session); | 382 | perf_session__delete(session); |
572 | 383 | ||
@@ -581,10 +392,12 @@ static const char * const annotate_usage[] = { | |||
581 | static const struct option options[] = { | 392 | static const struct option options[] = { |
582 | OPT_STRING('i', "input", &input_name, "file", | 393 | OPT_STRING('i', "input", &input_name, "file", |
583 | "input file name"), | 394 | "input file name"), |
395 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | ||
396 | "only consider symbols in these dsos"), | ||
584 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", | 397 | OPT_STRING('s', "symbol", &sym_hist_filter, "symbol", |
585 | "symbol to annotate"), | 398 | "symbol to annotate"), |
586 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 399 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
587 | OPT_BOOLEAN('v', "verbose", &verbose, | 400 | OPT_INCR('v', "verbose", &verbose, |
588 | "be more verbose (show symbol address, etc)"), | 401 | "be more verbose (show symbol address, etc)"), |
589 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 402 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
590 | "dump raw trace in ASCII"), | 403 | "dump raw trace in ASCII"), |
diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index 46996774e559..fcb96269852a 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c | |||
@@ -95,7 +95,7 @@ static void dump_suites(int subsys_index) | |||
95 | return; | 95 | return; |
96 | } | 96 | } |
97 | 97 | ||
98 | static char *bench_format_str; | 98 | static const char *bench_format_str; |
99 | int bench_format = BENCH_FORMAT_DEFAULT; | 99 | int bench_format = BENCH_FORMAT_DEFAULT; |
100 | 100 | ||
101 | static const struct option bench_options[] = { | 101 | static const struct option bench_options[] = { |
@@ -126,7 +126,7 @@ static void print_usage(void) | |||
126 | printf("\n"); | 126 | printf("\n"); |
127 | } | 127 | } |
128 | 128 | ||
129 | static int bench_str2int(char *str) | 129 | static int bench_str2int(const char *str) |
130 | { | 130 | { |
131 | if (!str) | 131 | if (!str) |
132 | return BENCH_FORMAT_DEFAULT; | 132 | return BENCH_FORMAT_DEFAULT; |
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c index 30a05f552c96..f8e3d1852029 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c | |||
@@ -27,7 +27,7 @@ static const struct option buildid_cache_options[] = { | |||
27 | "file list", "file(s) to add"), | 27 | "file list", "file(s) to add"), |
28 | OPT_STRING('r', "remove", &remove_name_list_str, "file list", | 28 | OPT_STRING('r', "remove", &remove_name_list_str, "file list", |
29 | "file(s) to remove"), | 29 | "file(s) to remove"), |
30 | OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose"), | 30 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
31 | OPT_END() | 31 | OPT_END() |
32 | }; | 32 | }; |
33 | 33 | ||
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c index d0675c02f81e..44a47e13bd67 100644 --- a/tools/perf/builtin-buildid-list.c +++ b/tools/perf/builtin-buildid-list.c | |||
@@ -16,7 +16,7 @@ | |||
16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
17 | 17 | ||
18 | static char const *input_name = "perf.data"; | 18 | static char const *input_name = "perf.data"; |
19 | static int force; | 19 | static bool force; |
20 | static bool with_hits; | 20 | static bool with_hits; |
21 | 21 | ||
22 | static const char * const buildid_list_usage[] = { | 22 | static const char * const buildid_list_usage[] = { |
@@ -29,7 +29,7 @@ static const struct option options[] = { | |||
29 | OPT_STRING('i', "input", &input_name, "file", | 29 | OPT_STRING('i', "input", &input_name, "file", |
30 | "input file name"), | 30 | "input file name"), |
31 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), | 31 | OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), |
32 | OPT_BOOLEAN('v', "verbose", &verbose, | 32 | OPT_INCR('v', "verbose", &verbose, |
33 | "be more verbose"), | 33 | "be more verbose"), |
34 | OPT_END() | 34 | OPT_END() |
35 | }; | 35 | }; |
@@ -39,14 +39,14 @@ static int __cmd_buildid_list(void) | |||
39 | int err = -1; | 39 | int err = -1; |
40 | struct perf_session *session; | 40 | struct perf_session *session; |
41 | 41 | ||
42 | session = perf_session__new(input_name, O_RDONLY, force); | 42 | session = perf_session__new(input_name, O_RDONLY, force, false); |
43 | if (session == NULL) | 43 | if (session == NULL) |
44 | return -1; | 44 | return -1; |
45 | 45 | ||
46 | if (with_hits) | 46 | if (with_hits) |
47 | perf_session__process_events(session, &build_id__mark_dso_hit_ops); | 47 | perf_session__process_events(session, &build_id__mark_dso_hit_ops); |
48 | 48 | ||
49 | dsos__fprintf_buildid(stdout, with_hits); | 49 | perf_session__fprintf_dsos_buildid(session, stdout, with_hits); |
50 | 50 | ||
51 | perf_session__delete(session); | 51 | perf_session__delete(session); |
52 | return err; | 52 | return err; |
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 1ea15d8aeed1..a6e2fdc7a04e 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -19,23 +19,15 @@ | |||
19 | static char const *input_old = "perf.data.old", | 19 | static char const *input_old = "perf.data.old", |
20 | *input_new = "perf.data"; | 20 | *input_new = "perf.data"; |
21 | static char diff__default_sort_order[] = "dso,symbol"; | 21 | static char diff__default_sort_order[] = "dso,symbol"; |
22 | static int force; | 22 | static bool force; |
23 | static bool show_displacement; | 23 | static bool show_displacement; |
24 | 24 | ||
25 | static int perf_session__add_hist_entry(struct perf_session *self, | 25 | static int hists__add_entry(struct hists *self, |
26 | struct addr_location *al, u64 count) | 26 | struct addr_location *al, u64 period) |
27 | { | 27 | { |
28 | bool hit; | 28 | if (__hists__add_entry(self, al, NULL, period) != NULL) |
29 | struct hist_entry *he = __perf_session__add_hist_entry(&self->hists, | 29 | return 0; |
30 | al, NULL, | 30 | return -ENOMEM; |
31 | count, &hit); | ||
32 | if (he == NULL) | ||
33 | return -ENOMEM; | ||
34 | |||
35 | if (hit) | ||
36 | he->count += count; | ||
37 | |||
38 | return 0; | ||
39 | } | 31 | } |
40 | 32 | ||
41 | static int diff__process_sample_event(event_t *event, struct perf_session *session) | 33 | static int diff__process_sample_event(event_t *event, struct perf_session *session) |
@@ -57,12 +49,12 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi | |||
57 | 49 | ||
58 | event__parse_sample(event, session->sample_type, &data); | 50 | event__parse_sample(event, session->sample_type, &data); |
59 | 51 | ||
60 | if (perf_session__add_hist_entry(session, &al, data.period)) { | 52 | if (hists__add_entry(&session->hists, &al, data.period)) { |
61 | pr_warning("problem incrementing symbol count, skipping event\n"); | 53 | pr_warning("problem incrementing symbol period, skipping event\n"); |
62 | return -1; | 54 | return -1; |
63 | } | 55 | } |
64 | 56 | ||
65 | session->events_stats.total += data.period; | 57 | session->hists.stats.total_period += data.period; |
66 | return 0; | 58 | return 0; |
67 | } | 59 | } |
68 | 60 | ||
@@ -95,35 +87,34 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, | |||
95 | rb_insert_color(&he->rb_node, root); | 87 | rb_insert_color(&he->rb_node, root); |
96 | } | 88 | } |
97 | 89 | ||
98 | static void perf_session__resort_hist_entries(struct perf_session *self) | 90 | static void hists__resort_entries(struct hists *self) |
99 | { | 91 | { |
100 | unsigned long position = 1; | 92 | unsigned long position = 1; |
101 | struct rb_root tmp = RB_ROOT; | 93 | struct rb_root tmp = RB_ROOT; |
102 | struct rb_node *next = rb_first(&self->hists); | 94 | struct rb_node *next = rb_first(&self->entries); |
103 | 95 | ||
104 | while (next != NULL) { | 96 | while (next != NULL) { |
105 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); | 97 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); |
106 | 98 | ||
107 | next = rb_next(&n->rb_node); | 99 | next = rb_next(&n->rb_node); |
108 | rb_erase(&n->rb_node, &self->hists); | 100 | rb_erase(&n->rb_node, &self->entries); |
109 | n->position = position++; | 101 | n->position = position++; |
110 | perf_session__insert_hist_entry_by_name(&tmp, n); | 102 | perf_session__insert_hist_entry_by_name(&tmp, n); |
111 | } | 103 | } |
112 | 104 | ||
113 | self->hists = tmp; | 105 | self->entries = tmp; |
114 | } | 106 | } |
115 | 107 | ||
116 | static void perf_session__set_hist_entries_positions(struct perf_session *self) | 108 | static void hists__set_positions(struct hists *self) |
117 | { | 109 | { |
118 | perf_session__output_resort(&self->hists, self->events_stats.total); | 110 | hists__output_resort(self); |
119 | perf_session__resort_hist_entries(self); | 111 | hists__resort_entries(self); |
120 | } | 112 | } |
121 | 113 | ||
122 | static struct hist_entry * | 114 | static struct hist_entry *hists__find_entry(struct hists *self, |
123 | perf_session__find_hist_entry(struct perf_session *self, | 115 | struct hist_entry *he) |
124 | struct hist_entry *he) | ||
125 | { | 116 | { |
126 | struct rb_node *n = self->hists.rb_node; | 117 | struct rb_node *n = self->entries.rb_node; |
127 | 118 | ||
128 | while (n) { | 119 | while (n) { |
129 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); | 120 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); |
@@ -140,14 +131,13 @@ perf_session__find_hist_entry(struct perf_session *self, | |||
140 | return NULL; | 131 | return NULL; |
141 | } | 132 | } |
142 | 133 | ||
143 | static void perf_session__match_hists(struct perf_session *old_session, | 134 | static void hists__match(struct hists *older, struct hists *newer) |
144 | struct perf_session *new_session) | ||
145 | { | 135 | { |
146 | struct rb_node *nd; | 136 | struct rb_node *nd; |
147 | 137 | ||
148 | for (nd = rb_first(&new_session->hists); nd; nd = rb_next(nd)) { | 138 | for (nd = rb_first(&newer->entries); nd; nd = rb_next(nd)) { |
149 | struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node); | 139 | struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node); |
150 | pos->pair = perf_session__find_hist_entry(old_session, pos); | 140 | pos->pair = hists__find_entry(older, pos); |
151 | } | 141 | } |
152 | } | 142 | } |
153 | 143 | ||
@@ -156,8 +146,8 @@ static int __cmd_diff(void) | |||
156 | int ret, i; | 146 | int ret, i; |
157 | struct perf_session *session[2]; | 147 | struct perf_session *session[2]; |
158 | 148 | ||
159 | session[0] = perf_session__new(input_old, O_RDONLY, force); | 149 | session[0] = perf_session__new(input_old, O_RDONLY, force, false); |
160 | session[1] = perf_session__new(input_new, O_RDONLY, force); | 150 | session[1] = perf_session__new(input_new, O_RDONLY, force, false); |
161 | if (session[0] == NULL || session[1] == NULL) | 151 | if (session[0] == NULL || session[1] == NULL) |
162 | return -ENOMEM; | 152 | return -ENOMEM; |
163 | 153 | ||
@@ -167,15 +157,13 @@ static int __cmd_diff(void) | |||
167 | goto out_delete; | 157 | goto out_delete; |
168 | } | 158 | } |
169 | 159 | ||
170 | perf_session__output_resort(&session[1]->hists, | 160 | hists__output_resort(&session[1]->hists); |
171 | session[1]->events_stats.total); | ||
172 | if (show_displacement) | 161 | if (show_displacement) |
173 | perf_session__set_hist_entries_positions(session[0]); | 162 | hists__set_positions(&session[0]->hists); |
174 | 163 | ||
175 | perf_session__match_hists(session[0], session[1]); | 164 | hists__match(&session[0]->hists, &session[1]->hists); |
176 | perf_session__fprintf_hists(&session[1]->hists, session[0], | 165 | hists__fprintf(&session[1]->hists, &session[0]->hists, |
177 | show_displacement, stdout, | 166 | show_displacement, stdout); |
178 | session[1]->events_stats.total); | ||
179 | out_delete: | 167 | out_delete: |
180 | for (i = 0; i < 2; ++i) | 168 | for (i = 0; i < 2; ++i) |
181 | perf_session__delete(session[i]); | 169 | perf_session__delete(session[i]); |
@@ -188,7 +176,7 @@ static const char * const diff_usage[] = { | |||
188 | }; | 176 | }; |
189 | 177 | ||
190 | static const struct option options[] = { | 178 | static const struct option options[] = { |
191 | OPT_BOOLEAN('v', "verbose", &verbose, | 179 | OPT_INCR('v', "verbose", &verbose, |
192 | "be more verbose (show symbol address, etc)"), | 180 | "be more verbose (show symbol address, etc)"), |
193 | OPT_BOOLEAN('m', "displacement", &show_displacement, | 181 | OPT_BOOLEAN('m', "displacement", &show_displacement, |
194 | "Show position displacement relative to baseline"), | 182 | "Show position displacement relative to baseline"), |
@@ -225,6 +213,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix __used) | |||
225 | input_new = argv[1]; | 213 | input_new = argv[1]; |
226 | } else | 214 | } else |
227 | input_new = argv[0]; | 215 | input_new = argv[0]; |
216 | } else if (symbol_conf.default_guest_vmlinux_name || | ||
217 | symbol_conf.default_guest_kallsyms) { | ||
218 | input_old = "perf.data.host"; | ||
219 | input_new = "perf.data.guest"; | ||
228 | } | 220 | } |
229 | 221 | ||
230 | symbol_conf.exclude_other = false; | 222 | symbol_conf.exclude_other = false; |
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 215b584007b1..6d5a8a7faf48 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c | |||
@@ -29,14 +29,14 @@ enum help_format { | |||
29 | HELP_FORMAT_WEB, | 29 | HELP_FORMAT_WEB, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | static int show_all = 0; | 32 | static bool show_all = false; |
33 | static enum help_format help_format = HELP_FORMAT_MAN; | 33 | static enum help_format help_format = HELP_FORMAT_MAN; |
34 | static struct option builtin_help_options[] = { | 34 | static struct option builtin_help_options[] = { |
35 | OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), | 35 | OPT_BOOLEAN('a', "all", &show_all, "print all available commands"), |
36 | OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), | 36 | OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN), |
37 | OPT_SET_INT('w', "web", &help_format, "show manual in web browser", | 37 | OPT_SET_UINT('w', "web", &help_format, "show manual in web browser", |
38 | HELP_FORMAT_WEB), | 38 | HELP_FORMAT_WEB), |
39 | OPT_SET_INT('i', "info", &help_format, "show info page", | 39 | OPT_SET_UINT('i', "info", &help_format, "show info page", |
40 | HELP_FORMAT_INFO), | 40 | HELP_FORMAT_INFO), |
41 | OPT_END(), | 41 | OPT_END(), |
42 | }; | 42 | }; |
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c new file mode 100644 index 000000000000..8e3e47b064ce --- /dev/null +++ b/tools/perf/builtin-inject.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /* | ||
2 | * builtin-inject.c | ||
3 | * | ||
4 | * Builtin inject command: Examine the live mode (stdin) event stream | ||
5 | * and repipe it to stdout while optionally injecting additional | ||
6 | * events into it. | ||
7 | */ | ||
8 | #include "builtin.h" | ||
9 | |||
10 | #include "perf.h" | ||
11 | #include "util/session.h" | ||
12 | #include "util/debug.h" | ||
13 | |||
14 | #include "util/parse-options.h" | ||
15 | |||
16 | static char const *input_name = "-"; | ||
17 | static bool inject_build_ids; | ||
18 | |||
19 | static int event__repipe(event_t *event __used, | ||
20 | struct perf_session *session __used) | ||
21 | { | ||
22 | uint32_t size; | ||
23 | void *buf = event; | ||
24 | |||
25 | size = event->header.size; | ||
26 | |||
27 | while (size) { | ||
28 | int ret = write(STDOUT_FILENO, buf, size); | ||
29 | if (ret < 0) | ||
30 | return -errno; | ||
31 | |||
32 | size -= ret; | ||
33 | buf += ret; | ||
34 | } | ||
35 | |||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | static int event__repipe_mmap(event_t *self, struct perf_session *session) | ||
40 | { | ||
41 | int err; | ||
42 | |||
43 | err = event__process_mmap(self, session); | ||
44 | event__repipe(self, session); | ||
45 | |||
46 | return err; | ||
47 | } | ||
48 | |||
49 | static int event__repipe_task(event_t *self, struct perf_session *session) | ||
50 | { | ||
51 | int err; | ||
52 | |||
53 | err = event__process_task(self, session); | ||
54 | event__repipe(self, session); | ||
55 | |||
56 | return err; | ||
57 | } | ||
58 | |||
59 | static int event__repipe_tracing_data(event_t *self, | ||
60 | struct perf_session *session) | ||
61 | { | ||
62 | int err; | ||
63 | |||
64 | event__repipe(self, session); | ||
65 | err = event__process_tracing_data(self, session); | ||
66 | |||
67 | return err; | ||
68 | } | ||
69 | |||
70 | static int dso__read_build_id(struct dso *self) | ||
71 | { | ||
72 | if (self->has_build_id) | ||
73 | return 0; | ||
74 | |||
75 | if (filename__read_build_id(self->long_name, self->build_id, | ||
76 | sizeof(self->build_id)) > 0) { | ||
77 | self->has_build_id = true; | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | return -1; | ||
82 | } | ||
83 | |||
84 | static int dso__inject_build_id(struct dso *self, struct perf_session *session) | ||
85 | { | ||
86 | u16 misc = PERF_RECORD_MISC_USER; | ||
87 | struct machine *machine; | ||
88 | int err; | ||
89 | |||
90 | if (dso__read_build_id(self) < 0) { | ||
91 | pr_debug("no build_id found for %s\n", self->long_name); | ||
92 | return -1; | ||
93 | } | ||
94 | |||
95 | machine = perf_session__find_host_machine(session); | ||
96 | if (machine == NULL) { | ||
97 | pr_err("Can't find machine for session\n"); | ||
98 | return -1; | ||
99 | } | ||
100 | |||
101 | if (self->kernel) | ||
102 | misc = PERF_RECORD_MISC_KERNEL; | ||
103 | |||
104 | err = event__synthesize_build_id(self, misc, event__repipe, | ||
105 | machine, session); | ||
106 | if (err) { | ||
107 | pr_err("Can't synthesize build_id event for %s\n", self->long_name); | ||
108 | return -1; | ||
109 | } | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | static int event__inject_buildid(event_t *event, struct perf_session *session) | ||
115 | { | ||
116 | struct addr_location al; | ||
117 | struct thread *thread; | ||
118 | u8 cpumode; | ||
119 | |||
120 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
121 | |||
122 | thread = perf_session__findnew(session, event->ip.pid); | ||
123 | if (thread == NULL) { | ||
124 | pr_err("problem processing %d event, skipping it.\n", | ||
125 | event->header.type); | ||
126 | goto repipe; | ||
127 | } | ||
128 | |||
129 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, | ||
130 | event->ip.pid, event->ip.ip, &al); | ||
131 | |||
132 | if (al.map != NULL) { | ||
133 | if (!al.map->dso->hit) { | ||
134 | al.map->dso->hit = 1; | ||
135 | if (map__load(al.map, NULL) >= 0) { | ||
136 | dso__inject_build_id(al.map->dso, session); | ||
137 | /* | ||
138 | * If this fails, too bad, let the other side | ||
139 | * account this as unresolved. | ||
140 | */ | ||
141 | } else | ||
142 | pr_warning("no symbols found in %s, maybe " | ||
143 | "install a debug package?\n", | ||
144 | al.map->dso->long_name); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | repipe: | ||
149 | event__repipe(event, session); | ||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | struct perf_event_ops inject_ops = { | ||
154 | .sample = event__repipe, | ||
155 | .mmap = event__repipe, | ||
156 | .comm = event__repipe, | ||
157 | .fork = event__repipe, | ||
158 | .exit = event__repipe, | ||
159 | .lost = event__repipe, | ||
160 | .read = event__repipe, | ||
161 | .throttle = event__repipe, | ||
162 | .unthrottle = event__repipe, | ||
163 | .attr = event__repipe, | ||
164 | .event_type = event__repipe, | ||
165 | .tracing_data = event__repipe, | ||
166 | .build_id = event__repipe, | ||
167 | }; | ||
168 | |||
169 | extern volatile int session_done; | ||
170 | |||
171 | static void sig_handler(int sig __attribute__((__unused__))) | ||
172 | { | ||
173 | session_done = 1; | ||
174 | } | ||
175 | |||
176 | static int __cmd_inject(void) | ||
177 | { | ||
178 | struct perf_session *session; | ||
179 | int ret = -EINVAL; | ||
180 | |||
181 | signal(SIGINT, sig_handler); | ||
182 | |||
183 | if (inject_build_ids) { | ||
184 | inject_ops.sample = event__inject_buildid; | ||
185 | inject_ops.mmap = event__repipe_mmap; | ||
186 | inject_ops.fork = event__repipe_task; | ||
187 | inject_ops.tracing_data = event__repipe_tracing_data; | ||
188 | } | ||
189 | |||
190 | session = perf_session__new(input_name, O_RDONLY, false, true); | ||
191 | if (session == NULL) | ||
192 | return -ENOMEM; | ||
193 | |||
194 | ret = perf_session__process_events(session, &inject_ops); | ||
195 | |||
196 | perf_session__delete(session); | ||
197 | |||
198 | return ret; | ||
199 | } | ||
200 | |||
201 | static const char * const report_usage[] = { | ||
202 | "perf inject [<options>]", | ||
203 | NULL | ||
204 | }; | ||
205 | |||
206 | static const struct option options[] = { | ||
207 | OPT_BOOLEAN('b', "build-ids", &inject_build_ids, | ||
208 | "Inject build-ids into the output stream"), | ||
209 | OPT_INCR('v', "verbose", &verbose, | ||
210 | "be more verbose (show build ids, etc)"), | ||
211 | OPT_END() | ||
212 | }; | ||
213 | |||
214 | int cmd_inject(int argc, const char **argv, const char *prefix __used) | ||
215 | { | ||
216 | argc = parse_options(argc, argv, options, report_usage, 0); | ||
217 | |||
218 | /* | ||
219 | * Any (unrecognized) arguments left? | ||
220 | */ | ||
221 | if (argc) | ||
222 | usage_with_options(report_usage, options); | ||
223 | |||
224 | if (symbol__init() < 0) | ||
225 | return -1; | ||
226 | |||
227 | return __cmd_inject(); | ||
228 | } | ||
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 924a9518931a..31f60a2535e0 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c | |||
@@ -335,8 +335,9 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
335 | } | 335 | } |
336 | 336 | ||
337 | static struct perf_event_ops event_ops = { | 337 | static struct perf_event_ops event_ops = { |
338 | .sample = process_sample_event, | 338 | .sample = process_sample_event, |
339 | .comm = event__process_comm, | 339 | .comm = event__process_comm, |
340 | .ordered_samples = true, | ||
340 | }; | 341 | }; |
341 | 342 | ||
342 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) | 343 | static double fragmentation(unsigned long n_req, unsigned long n_alloc) |
@@ -351,6 +352,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
351 | int n_lines, int is_caller) | 352 | int n_lines, int is_caller) |
352 | { | 353 | { |
353 | struct rb_node *next; | 354 | struct rb_node *next; |
355 | struct machine *machine; | ||
354 | 356 | ||
355 | printf("%.102s\n", graph_dotted_line); | 357 | printf("%.102s\n", graph_dotted_line); |
356 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); | 358 | printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); |
@@ -359,23 +361,29 @@ static void __print_result(struct rb_root *root, struct perf_session *session, | |||
359 | 361 | ||
360 | next = rb_first(root); | 362 | next = rb_first(root); |
361 | 363 | ||
364 | machine = perf_session__find_host_machine(session); | ||
365 | if (!machine) { | ||
366 | pr_err("__print_result: couldn't find kernel information\n"); | ||
367 | return; | ||
368 | } | ||
362 | while (next && n_lines--) { | 369 | while (next && n_lines--) { |
363 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, | 370 | struct alloc_stat *data = rb_entry(next, struct alloc_stat, |
364 | node); | 371 | node); |
365 | struct symbol *sym = NULL; | 372 | struct symbol *sym = NULL; |
373 | struct map *map; | ||
366 | char buf[BUFSIZ]; | 374 | char buf[BUFSIZ]; |
367 | u64 addr; | 375 | u64 addr; |
368 | 376 | ||
369 | if (is_caller) { | 377 | if (is_caller) { |
370 | addr = data->call_site; | 378 | addr = data->call_site; |
371 | if (!raw_ip) | 379 | if (!raw_ip) |
372 | sym = map_groups__find_function(&session->kmaps, addr, NULL); | 380 | sym = machine__find_kernel_function(machine, addr, &map, NULL); |
373 | } else | 381 | } else |
374 | addr = data->ptr; | 382 | addr = data->ptr; |
375 | 383 | ||
376 | if (sym != NULL) | 384 | if (sym != NULL) |
377 | snprintf(buf, sizeof(buf), "%s+%Lx", sym->name, | 385 | snprintf(buf, sizeof(buf), "%s+%Lx", sym->name, |
378 | addr - sym->start); | 386 | addr - map->unmap_ip(map, sym->start)); |
379 | else | 387 | else |
380 | snprintf(buf, sizeof(buf), "%#Lx", addr); | 388 | snprintf(buf, sizeof(buf), "%#Lx", addr); |
381 | printf(" %-34s |", buf); | 389 | printf(" %-34s |", buf); |
@@ -484,10 +492,13 @@ static void sort_result(void) | |||
484 | static int __cmd_kmem(void) | 492 | static int __cmd_kmem(void) |
485 | { | 493 | { |
486 | int err = -EINVAL; | 494 | int err = -EINVAL; |
487 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); | 495 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false); |
488 | if (session == NULL) | 496 | if (session == NULL) |
489 | return -ENOMEM; | 497 | return -ENOMEM; |
490 | 498 | ||
499 | if (perf_session__create_kernel_maps(session) < 0) | ||
500 | goto out_delete; | ||
501 | |||
491 | if (!perf_session__has_traces(session, "kmem record")) | 502 | if (!perf_session__has_traces(session, "kmem record")) |
492 | goto out_delete; | 503 | goto out_delete; |
493 | 504 | ||
@@ -718,7 +729,6 @@ static const char *record_args[] = { | |||
718 | "record", | 729 | "record", |
719 | "-a", | 730 | "-a", |
720 | "-R", | 731 | "-R", |
721 | "-M", | ||
722 | "-f", | 732 | "-f", |
723 | "-c", "1", | 733 | "-c", "1", |
724 | "-e", "kmem:kmalloc", | 734 | "-e", "kmem:kmalloc", |
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c new file mode 100644 index 000000000000..34d1e853829d --- /dev/null +++ b/tools/perf/builtin-kvm.c | |||
@@ -0,0 +1,144 @@ | |||
1 | #include "builtin.h" | ||
2 | #include "perf.h" | ||
3 | |||
4 | #include "util/util.h" | ||
5 | #include "util/cache.h" | ||
6 | #include "util/symbol.h" | ||
7 | #include "util/thread.h" | ||
8 | #include "util/header.h" | ||
9 | #include "util/session.h" | ||
10 | |||
11 | #include "util/parse-options.h" | ||
12 | #include "util/trace-event.h" | ||
13 | |||
14 | #include "util/debug.h" | ||
15 | |||
16 | #include <sys/prctl.h> | ||
17 | |||
18 | #include <semaphore.h> | ||
19 | #include <pthread.h> | ||
20 | #include <math.h> | ||
21 | |||
22 | static const char *file_name; | ||
23 | static char name_buffer[256]; | ||
24 | |||
25 | bool perf_host = 1; | ||
26 | bool perf_guest; | ||
27 | |||
28 | static const char * const kvm_usage[] = { | ||
29 | "perf kvm [<options>] {top|record|report|diff|buildid-list}", | ||
30 | NULL | ||
31 | }; | ||
32 | |||
33 | static const struct option kvm_options[] = { | ||
34 | OPT_STRING('i', "input", &file_name, "file", | ||
35 | "Input file name"), | ||
36 | OPT_STRING('o', "output", &file_name, "file", | ||
37 | "Output file name"), | ||
38 | OPT_BOOLEAN(0, "guest", &perf_guest, | ||
39 | "Collect guest os data"), | ||
40 | OPT_BOOLEAN(0, "host", &perf_host, | ||
41 | "Collect guest os data"), | ||
42 | OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory", | ||
43 | "guest mount directory under which every guest os" | ||
44 | " instance has a subdir"), | ||
45 | OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name, | ||
46 | "file", "file saving guest os vmlinux"), | ||
47 | OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms, | ||
48 | "file", "file saving guest os /proc/kallsyms"), | ||
49 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, | ||
50 | "file", "file saving guest os /proc/modules"), | ||
51 | OPT_END() | ||
52 | }; | ||
53 | |||
54 | static int __cmd_record(int argc, const char **argv) | ||
55 | { | ||
56 | int rec_argc, i = 0, j; | ||
57 | const char **rec_argv; | ||
58 | |||
59 | rec_argc = argc + 2; | ||
60 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
61 | rec_argv[i++] = strdup("record"); | ||
62 | rec_argv[i++] = strdup("-o"); | ||
63 | rec_argv[i++] = strdup(file_name); | ||
64 | for (j = 1; j < argc; j++, i++) | ||
65 | rec_argv[i] = argv[j]; | ||
66 | |||
67 | BUG_ON(i != rec_argc); | ||
68 | |||
69 | return cmd_record(i, rec_argv, NULL); | ||
70 | } | ||
71 | |||
72 | static int __cmd_report(int argc, const char **argv) | ||
73 | { | ||
74 | int rec_argc, i = 0, j; | ||
75 | const char **rec_argv; | ||
76 | |||
77 | rec_argc = argc + 2; | ||
78 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
79 | rec_argv[i++] = strdup("report"); | ||
80 | rec_argv[i++] = strdup("-i"); | ||
81 | rec_argv[i++] = strdup(file_name); | ||
82 | for (j = 1; j < argc; j++, i++) | ||
83 | rec_argv[i] = argv[j]; | ||
84 | |||
85 | BUG_ON(i != rec_argc); | ||
86 | |||
87 | return cmd_report(i, rec_argv, NULL); | ||
88 | } | ||
89 | |||
90 | static int __cmd_buildid_list(int argc, const char **argv) | ||
91 | { | ||
92 | int rec_argc, i = 0, j; | ||
93 | const char **rec_argv; | ||
94 | |||
95 | rec_argc = argc + 2; | ||
96 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); | ||
97 | rec_argv[i++] = strdup("buildid-list"); | ||
98 | rec_argv[i++] = strdup("-i"); | ||
99 | rec_argv[i++] = strdup(file_name); | ||
100 | for (j = 1; j < argc; j++, i++) | ||
101 | rec_argv[i] = argv[j]; | ||
102 | |||
103 | BUG_ON(i != rec_argc); | ||
104 | |||
105 | return cmd_buildid_list(i, rec_argv, NULL); | ||
106 | } | ||
107 | |||
108 | int cmd_kvm(int argc, const char **argv, const char *prefix __used) | ||
109 | { | ||
110 | perf_host = perf_guest = 0; | ||
111 | |||
112 | argc = parse_options(argc, argv, kvm_options, kvm_usage, | ||
113 | PARSE_OPT_STOP_AT_NON_OPTION); | ||
114 | if (!argc) | ||
115 | usage_with_options(kvm_usage, kvm_options); | ||
116 | |||
117 | if (!perf_host) | ||
118 | perf_guest = 1; | ||
119 | |||
120 | if (!file_name) { | ||
121 | if (perf_host && !perf_guest) | ||
122 | sprintf(name_buffer, "perf.data.host"); | ||
123 | else if (!perf_host && perf_guest) | ||
124 | sprintf(name_buffer, "perf.data.guest"); | ||
125 | else | ||
126 | sprintf(name_buffer, "perf.data.kvm"); | ||
127 | file_name = name_buffer; | ||
128 | } | ||
129 | |||
130 | if (!strncmp(argv[0], "rec", 3)) | ||
131 | return __cmd_record(argc, argv); | ||
132 | else if (!strncmp(argv[0], "rep", 3)) | ||
133 | return __cmd_report(argc, argv); | ||
134 | else if (!strncmp(argv[0], "diff", 4)) | ||
135 | return cmd_diff(argc, argv, NULL); | ||
136 | else if (!strncmp(argv[0], "top", 3)) | ||
137 | return cmd_top(argc, argv, NULL); | ||
138 | else if (!strncmp(argv[0], "buildid-list", 12)) | ||
139 | return __cmd_buildid_list(argc, argv); | ||
140 | else | ||
141 | usage_with_options(kvm_usage, kvm_options); | ||
142 | |||
143 | return 0; | ||
144 | } | ||
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index e12c844df1e2..821c1586a22b 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c | |||
@@ -23,6 +23,8 @@ | |||
23 | #include <linux/list.h> | 23 | #include <linux/list.h> |
24 | #include <linux/hash.h> | 24 | #include <linux/hash.h> |
25 | 25 | ||
26 | static struct perf_session *session; | ||
27 | |||
26 | /* based on kernel/lockdep.c */ | 28 | /* based on kernel/lockdep.c */ |
27 | #define LOCKHASH_BITS 12 | 29 | #define LOCKHASH_BITS 12 |
28 | #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) | 30 | #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) |
@@ -32,9 +34,6 @@ static struct list_head lockhash_table[LOCKHASH_SIZE]; | |||
32 | #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) | 34 | #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) |
33 | #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) | 35 | #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) |
34 | 36 | ||
35 | #define LOCK_STATE_UNLOCKED 0 /* initial state */ | ||
36 | #define LOCK_STATE_LOCKED 1 | ||
37 | |||
38 | struct lock_stat { | 37 | struct lock_stat { |
39 | struct list_head hash_entry; | 38 | struct list_head hash_entry; |
40 | struct rb_node rb; /* used for sorting */ | 39 | struct rb_node rb; /* used for sorting */ |
@@ -47,20 +46,151 @@ struct lock_stat { | |||
47 | void *addr; /* address of lockdep_map, used as ID */ | 46 | void *addr; /* address of lockdep_map, used as ID */ |
48 | char *name; /* for strcpy(), we cannot use const */ | 47 | char *name; /* for strcpy(), we cannot use const */ |
49 | 48 | ||
50 | int state; | ||
51 | u64 prev_event_time; /* timestamp of previous event */ | ||
52 | |||
53 | unsigned int nr_acquired; | ||
54 | unsigned int nr_acquire; | 49 | unsigned int nr_acquire; |
50 | unsigned int nr_acquired; | ||
55 | unsigned int nr_contended; | 51 | unsigned int nr_contended; |
56 | unsigned int nr_release; | 52 | unsigned int nr_release; |
57 | 53 | ||
54 | unsigned int nr_readlock; | ||
55 | unsigned int nr_trylock; | ||
58 | /* these times are in nano sec. */ | 56 | /* these times are in nano sec. */ |
59 | u64 wait_time_total; | 57 | u64 wait_time_total; |
60 | u64 wait_time_min; | 58 | u64 wait_time_min; |
61 | u64 wait_time_max; | 59 | u64 wait_time_max; |
60 | |||
61 | int discard; /* flag of blacklist */ | ||
62 | }; | 62 | }; |
63 | 63 | ||
64 | /* | ||
65 | * States of lock_seq_stat | ||
66 | * | ||
67 | * UNINITIALIZED is required for detecting first event of acquire. | ||
68 | * As the nature of lock events, there is no guarantee | ||
69 | * that the first event for the locks are acquire, | ||
70 | * it can be acquired, contended or release. | ||
71 | */ | ||
72 | #define SEQ_STATE_UNINITIALIZED 0 /* initial state */ | ||
73 | #define SEQ_STATE_RELEASED 1 | ||
74 | #define SEQ_STATE_ACQUIRING 2 | ||
75 | #define SEQ_STATE_ACQUIRED 3 | ||
76 | #define SEQ_STATE_READ_ACQUIRED 4 | ||
77 | #define SEQ_STATE_CONTENDED 5 | ||
78 | |||
79 | /* | ||
80 | * MAX_LOCK_DEPTH | ||
81 | * Imported from include/linux/sched.h. | ||
82 | * Should this be synchronized? | ||
83 | */ | ||
84 | #define MAX_LOCK_DEPTH 48 | ||
85 | |||
86 | /* | ||
87 | * struct lock_seq_stat: | ||
88 | * Place to put on state of one lock sequence | ||
89 | * 1) acquire -> acquired -> release | ||
90 | * 2) acquire -> contended -> acquired -> release | ||
91 | * 3) acquire (with read or try) -> release | ||
92 | * 4) Are there other patterns? | ||
93 | */ | ||
94 | struct lock_seq_stat { | ||
95 | struct list_head list; | ||
96 | int state; | ||
97 | u64 prev_event_time; | ||
98 | void *addr; | ||
99 | |||
100 | int read_count; | ||
101 | }; | ||
102 | |||
103 | struct thread_stat { | ||
104 | struct rb_node rb; | ||
105 | |||
106 | u32 tid; | ||
107 | struct list_head seq_list; | ||
108 | }; | ||
109 | |||
110 | static struct rb_root thread_stats; | ||
111 | |||
112 | static struct thread_stat *thread_stat_find(u32 tid) | ||
113 | { | ||
114 | struct rb_node *node; | ||
115 | struct thread_stat *st; | ||
116 | |||
117 | node = thread_stats.rb_node; | ||
118 | while (node) { | ||
119 | st = container_of(node, struct thread_stat, rb); | ||
120 | if (st->tid == tid) | ||
121 | return st; | ||
122 | else if (tid < st->tid) | ||
123 | node = node->rb_left; | ||
124 | else | ||
125 | node = node->rb_right; | ||
126 | } | ||
127 | |||
128 | return NULL; | ||
129 | } | ||
130 | |||
131 | static void thread_stat_insert(struct thread_stat *new) | ||
132 | { | ||
133 | struct rb_node **rb = &thread_stats.rb_node; | ||
134 | struct rb_node *parent = NULL; | ||
135 | struct thread_stat *p; | ||
136 | |||
137 | while (*rb) { | ||
138 | p = container_of(*rb, struct thread_stat, rb); | ||
139 | parent = *rb; | ||
140 | |||
141 | if (new->tid < p->tid) | ||
142 | rb = &(*rb)->rb_left; | ||
143 | else if (new->tid > p->tid) | ||
144 | rb = &(*rb)->rb_right; | ||
145 | else | ||
146 | BUG_ON("inserting invalid thread_stat\n"); | ||
147 | } | ||
148 | |||
149 | rb_link_node(&new->rb, parent, rb); | ||
150 | rb_insert_color(&new->rb, &thread_stats); | ||
151 | } | ||
152 | |||
153 | static struct thread_stat *thread_stat_findnew_after_first(u32 tid) | ||
154 | { | ||
155 | struct thread_stat *st; | ||
156 | |||
157 | st = thread_stat_find(tid); | ||
158 | if (st) | ||
159 | return st; | ||
160 | |||
161 | st = zalloc(sizeof(struct thread_stat)); | ||
162 | if (!st) | ||
163 | die("memory allocation failed\n"); | ||
164 | |||
165 | st->tid = tid; | ||
166 | INIT_LIST_HEAD(&st->seq_list); | ||
167 | |||
168 | thread_stat_insert(st); | ||
169 | |||
170 | return st; | ||
171 | } | ||
172 | |||
173 | static struct thread_stat *thread_stat_findnew_first(u32 tid); | ||
174 | static struct thread_stat *(*thread_stat_findnew)(u32 tid) = | ||
175 | thread_stat_findnew_first; | ||
176 | |||
177 | static struct thread_stat *thread_stat_findnew_first(u32 tid) | ||
178 | { | ||
179 | struct thread_stat *st; | ||
180 | |||
181 | st = zalloc(sizeof(struct thread_stat)); | ||
182 | if (!st) | ||
183 | die("memory allocation failed\n"); | ||
184 | st->tid = tid; | ||
185 | INIT_LIST_HEAD(&st->seq_list); | ||
186 | |||
187 | rb_link_node(&st->rb, NULL, &thread_stats.rb_node); | ||
188 | rb_insert_color(&st->rb, &thread_stats); | ||
189 | |||
190 | thread_stat_findnew = thread_stat_findnew_after_first; | ||
191 | return st; | ||
192 | } | ||
193 | |||
64 | /* build simple key function one is bigger than two */ | 194 | /* build simple key function one is bigger than two */ |
65 | #define SINGLE_KEY(member) \ | 195 | #define SINGLE_KEY(member) \ |
66 | static int lock_stat_key_ ## member(struct lock_stat *one, \ | 196 | static int lock_stat_key_ ## member(struct lock_stat *one, \ |
@@ -175,8 +305,6 @@ static struct lock_stat *lock_stat_findnew(void *addr, const char *name) | |||
175 | goto alloc_failed; | 305 | goto alloc_failed; |
176 | strcpy(new->name, name); | 306 | strcpy(new->name, name); |
177 | 307 | ||
178 | /* LOCK_STATE_UNLOCKED == 0 isn't guaranteed forever */ | ||
179 | new->state = LOCK_STATE_UNLOCKED; | ||
180 | new->wait_time_min = ULLONG_MAX; | 308 | new->wait_time_min = ULLONG_MAX; |
181 | 309 | ||
182 | list_add(&new->hash_entry, entry); | 310 | list_add(&new->hash_entry, entry); |
@@ -188,8 +316,6 @@ alloc_failed: | |||
188 | 316 | ||
189 | static char const *input_name = "perf.data"; | 317 | static char const *input_name = "perf.data"; |
190 | 318 | ||
191 | static int profile_cpu = -1; | ||
192 | |||
193 | struct raw_event_sample { | 319 | struct raw_event_sample { |
194 | u32 size; | 320 | u32 size; |
195 | char data[0]; | 321 | char data[0]; |
@@ -198,6 +324,7 @@ struct raw_event_sample { | |||
198 | struct trace_acquire_event { | 324 | struct trace_acquire_event { |
199 | void *addr; | 325 | void *addr; |
200 | const char *name; | 326 | const char *name; |
327 | int flag; | ||
201 | }; | 328 | }; |
202 | 329 | ||
203 | struct trace_acquired_event { | 330 | struct trace_acquired_event { |
@@ -241,120 +368,258 @@ struct trace_lock_handler { | |||
241 | struct thread *thread); | 368 | struct thread *thread); |
242 | }; | 369 | }; |
243 | 370 | ||
371 | static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr) | ||
372 | { | ||
373 | struct lock_seq_stat *seq; | ||
374 | |||
375 | list_for_each_entry(seq, &ts->seq_list, list) { | ||
376 | if (seq->addr == addr) | ||
377 | return seq; | ||
378 | } | ||
379 | |||
380 | seq = zalloc(sizeof(struct lock_seq_stat)); | ||
381 | if (!seq) | ||
382 | die("Not enough memory\n"); | ||
383 | seq->state = SEQ_STATE_UNINITIALIZED; | ||
384 | seq->addr = addr; | ||
385 | |||
386 | list_add(&seq->list, &ts->seq_list); | ||
387 | return seq; | ||
388 | } | ||
389 | |||
390 | enum broken_state { | ||
391 | BROKEN_ACQUIRE, | ||
392 | BROKEN_ACQUIRED, | ||
393 | BROKEN_CONTENDED, | ||
394 | BROKEN_RELEASE, | ||
395 | BROKEN_MAX, | ||
396 | }; | ||
397 | |||
398 | static int bad_hist[BROKEN_MAX]; | ||
399 | |||
400 | enum acquire_flags { | ||
401 | TRY_LOCK = 1, | ||
402 | READ_LOCK = 2, | ||
403 | }; | ||
404 | |||
244 | static void | 405 | static void |
245 | report_lock_acquire_event(struct trace_acquire_event *acquire_event, | 406 | report_lock_acquire_event(struct trace_acquire_event *acquire_event, |
246 | struct event *__event __used, | 407 | struct event *__event __used, |
247 | int cpu __used, | 408 | int cpu __used, |
248 | u64 timestamp, | 409 | u64 timestamp __used, |
249 | struct thread *thread __used) | 410 | struct thread *thread __used) |
250 | { | 411 | { |
251 | struct lock_stat *st; | 412 | struct lock_stat *ls; |
413 | struct thread_stat *ts; | ||
414 | struct lock_seq_stat *seq; | ||
415 | |||
416 | ls = lock_stat_findnew(acquire_event->addr, acquire_event->name); | ||
417 | if (ls->discard) | ||
418 | return; | ||
252 | 419 | ||
253 | st = lock_stat_findnew(acquire_event->addr, acquire_event->name); | 420 | ts = thread_stat_findnew(thread->pid); |
421 | seq = get_seq(ts, acquire_event->addr); | ||
254 | 422 | ||
255 | switch (st->state) { | 423 | switch (seq->state) { |
256 | case LOCK_STATE_UNLOCKED: | 424 | case SEQ_STATE_UNINITIALIZED: |
425 | case SEQ_STATE_RELEASED: | ||
426 | if (!acquire_event->flag) { | ||
427 | seq->state = SEQ_STATE_ACQUIRING; | ||
428 | } else { | ||
429 | if (acquire_event->flag & TRY_LOCK) | ||
430 | ls->nr_trylock++; | ||
431 | if (acquire_event->flag & READ_LOCK) | ||
432 | ls->nr_readlock++; | ||
433 | seq->state = SEQ_STATE_READ_ACQUIRED; | ||
434 | seq->read_count = 1; | ||
435 | ls->nr_acquired++; | ||
436 | } | ||
437 | break; | ||
438 | case SEQ_STATE_READ_ACQUIRED: | ||
439 | if (acquire_event->flag & READ_LOCK) { | ||
440 | seq->read_count++; | ||
441 | ls->nr_acquired++; | ||
442 | goto end; | ||
443 | } else { | ||
444 | goto broken; | ||
445 | } | ||
257 | break; | 446 | break; |
258 | case LOCK_STATE_LOCKED: | 447 | case SEQ_STATE_ACQUIRED: |
448 | case SEQ_STATE_ACQUIRING: | ||
449 | case SEQ_STATE_CONTENDED: | ||
450 | broken: | ||
451 | /* broken lock sequence, discard it */ | ||
452 | ls->discard = 1; | ||
453 | bad_hist[BROKEN_ACQUIRE]++; | ||
454 | list_del(&seq->list); | ||
455 | free(seq); | ||
456 | goto end; | ||
259 | break; | 457 | break; |
260 | default: | 458 | default: |
261 | BUG_ON(1); | 459 | BUG_ON("Unknown state of lock sequence found!\n"); |
262 | break; | 460 | break; |
263 | } | 461 | } |
264 | 462 | ||
265 | st->prev_event_time = timestamp; | 463 | ls->nr_acquire++; |
464 | seq->prev_event_time = timestamp; | ||
465 | end: | ||
466 | return; | ||
266 | } | 467 | } |
267 | 468 | ||
268 | static void | 469 | static void |
269 | report_lock_acquired_event(struct trace_acquired_event *acquired_event, | 470 | report_lock_acquired_event(struct trace_acquired_event *acquired_event, |
270 | struct event *__event __used, | 471 | struct event *__event __used, |
271 | int cpu __used, | 472 | int cpu __used, |
272 | u64 timestamp, | 473 | u64 timestamp __used, |
273 | struct thread *thread __used) | 474 | struct thread *thread __used) |
274 | { | 475 | { |
275 | struct lock_stat *st; | 476 | struct lock_stat *ls; |
477 | struct thread_stat *ts; | ||
478 | struct lock_seq_stat *seq; | ||
479 | u64 contended_term; | ||
480 | |||
481 | ls = lock_stat_findnew(acquired_event->addr, acquired_event->name); | ||
482 | if (ls->discard) | ||
483 | return; | ||
276 | 484 | ||
277 | st = lock_stat_findnew(acquired_event->addr, acquired_event->name); | 485 | ts = thread_stat_findnew(thread->pid); |
486 | seq = get_seq(ts, acquired_event->addr); | ||
278 | 487 | ||
279 | switch (st->state) { | 488 | switch (seq->state) { |
280 | case LOCK_STATE_UNLOCKED: | 489 | case SEQ_STATE_UNINITIALIZED: |
281 | st->state = LOCK_STATE_LOCKED; | 490 | /* orphan event, do nothing */ |
282 | st->nr_acquired++; | 491 | return; |
492 | case SEQ_STATE_ACQUIRING: | ||
493 | break; | ||
494 | case SEQ_STATE_CONTENDED: | ||
495 | contended_term = timestamp - seq->prev_event_time; | ||
496 | ls->wait_time_total += contended_term; | ||
497 | if (contended_term < ls->wait_time_min) | ||
498 | ls->wait_time_min = contended_term; | ||
499 | if (ls->wait_time_max < contended_term) | ||
500 | ls->wait_time_max = contended_term; | ||
283 | break; | 501 | break; |
284 | case LOCK_STATE_LOCKED: | 502 | case SEQ_STATE_RELEASED: |
503 | case SEQ_STATE_ACQUIRED: | ||
504 | case SEQ_STATE_READ_ACQUIRED: | ||
505 | /* broken lock sequence, discard it */ | ||
506 | ls->discard = 1; | ||
507 | bad_hist[BROKEN_ACQUIRED]++; | ||
508 | list_del(&seq->list); | ||
509 | free(seq); | ||
510 | goto end; | ||
285 | break; | 511 | break; |
512 | |||
286 | default: | 513 | default: |
287 | BUG_ON(1); | 514 | BUG_ON("Unknown state of lock sequence found!\n"); |
288 | break; | 515 | break; |
289 | } | 516 | } |
290 | 517 | ||
291 | st->prev_event_time = timestamp; | 518 | seq->state = SEQ_STATE_ACQUIRED; |
519 | ls->nr_acquired++; | ||
520 | seq->prev_event_time = timestamp; | ||
521 | end: | ||
522 | return; | ||
292 | } | 523 | } |
293 | 524 | ||
294 | static void | 525 | static void |
295 | report_lock_contended_event(struct trace_contended_event *contended_event, | 526 | report_lock_contended_event(struct trace_contended_event *contended_event, |
296 | struct event *__event __used, | 527 | struct event *__event __used, |
297 | int cpu __used, | 528 | int cpu __used, |
298 | u64 timestamp, | 529 | u64 timestamp __used, |
299 | struct thread *thread __used) | 530 | struct thread *thread __used) |
300 | { | 531 | { |
301 | struct lock_stat *st; | 532 | struct lock_stat *ls; |
533 | struct thread_stat *ts; | ||
534 | struct lock_seq_stat *seq; | ||
302 | 535 | ||
303 | st = lock_stat_findnew(contended_event->addr, contended_event->name); | 536 | ls = lock_stat_findnew(contended_event->addr, contended_event->name); |
537 | if (ls->discard) | ||
538 | return; | ||
304 | 539 | ||
305 | switch (st->state) { | 540 | ts = thread_stat_findnew(thread->pid); |
306 | case LOCK_STATE_UNLOCKED: | 541 | seq = get_seq(ts, contended_event->addr); |
542 | |||
543 | switch (seq->state) { | ||
544 | case SEQ_STATE_UNINITIALIZED: | ||
545 | /* orphan event, do nothing */ | ||
546 | return; | ||
547 | case SEQ_STATE_ACQUIRING: | ||
307 | break; | 548 | break; |
308 | case LOCK_STATE_LOCKED: | 549 | case SEQ_STATE_RELEASED: |
309 | st->nr_contended++; | 550 | case SEQ_STATE_ACQUIRED: |
551 | case SEQ_STATE_READ_ACQUIRED: | ||
552 | case SEQ_STATE_CONTENDED: | ||
553 | /* broken lock sequence, discard it */ | ||
554 | ls->discard = 1; | ||
555 | bad_hist[BROKEN_CONTENDED]++; | ||
556 | list_del(&seq->list); | ||
557 | free(seq); | ||
558 | goto end; | ||
310 | break; | 559 | break; |
311 | default: | 560 | default: |
312 | BUG_ON(1); | 561 | BUG_ON("Unknown state of lock sequence found!\n"); |
313 | break; | 562 | break; |
314 | } | 563 | } |
315 | 564 | ||
316 | st->prev_event_time = timestamp; | 565 | seq->state = SEQ_STATE_CONTENDED; |
566 | ls->nr_contended++; | ||
567 | seq->prev_event_time = timestamp; | ||
568 | end: | ||
569 | return; | ||
317 | } | 570 | } |
318 | 571 | ||
319 | static void | 572 | static void |
320 | report_lock_release_event(struct trace_release_event *release_event, | 573 | report_lock_release_event(struct trace_release_event *release_event, |
321 | struct event *__event __used, | 574 | struct event *__event __used, |
322 | int cpu __used, | 575 | int cpu __used, |
323 | u64 timestamp, | 576 | u64 timestamp __used, |
324 | struct thread *thread __used) | 577 | struct thread *thread __used) |
325 | { | 578 | { |
326 | struct lock_stat *st; | 579 | struct lock_stat *ls; |
327 | u64 hold_time; | 580 | struct thread_stat *ts; |
581 | struct lock_seq_stat *seq; | ||
328 | 582 | ||
329 | st = lock_stat_findnew(release_event->addr, release_event->name); | 583 | ls = lock_stat_findnew(release_event->addr, release_event->name); |
584 | if (ls->discard) | ||
585 | return; | ||
330 | 586 | ||
331 | switch (st->state) { | 587 | ts = thread_stat_findnew(thread->pid); |
332 | case LOCK_STATE_UNLOCKED: | 588 | seq = get_seq(ts, release_event->addr); |
333 | break; | ||
334 | case LOCK_STATE_LOCKED: | ||
335 | st->state = LOCK_STATE_UNLOCKED; | ||
336 | hold_time = timestamp - st->prev_event_time; | ||
337 | 589 | ||
338 | if (timestamp < st->prev_event_time) { | 590 | switch (seq->state) { |
339 | /* terribly, this can happen... */ | 591 | case SEQ_STATE_UNINITIALIZED: |
592 | goto end; | ||
593 | break; | ||
594 | case SEQ_STATE_ACQUIRED: | ||
595 | break; | ||
596 | case SEQ_STATE_READ_ACQUIRED: | ||
597 | seq->read_count--; | ||
598 | BUG_ON(seq->read_count < 0); | ||
599 | if (!seq->read_count) { | ||
600 | ls->nr_release++; | ||
340 | goto end; | 601 | goto end; |
341 | } | 602 | } |
342 | 603 | break; | |
343 | if (st->wait_time_min > hold_time) | 604 | case SEQ_STATE_ACQUIRING: |
344 | st->wait_time_min = hold_time; | 605 | case SEQ_STATE_CONTENDED: |
345 | if (st->wait_time_max < hold_time) | 606 | case SEQ_STATE_RELEASED: |
346 | st->wait_time_max = hold_time; | 607 | /* broken lock sequence, discard it */ |
347 | st->wait_time_total += hold_time; | 608 | ls->discard = 1; |
348 | 609 | bad_hist[BROKEN_RELEASE]++; | |
349 | st->nr_release++; | 610 | goto free_seq; |
350 | break; | 611 | break; |
351 | default: | 612 | default: |
352 | BUG_ON(1); | 613 | BUG_ON("Unknown state of lock sequence found!\n"); |
353 | break; | 614 | break; |
354 | } | 615 | } |
355 | 616 | ||
617 | ls->nr_release++; | ||
618 | free_seq: | ||
619 | list_del(&seq->list); | ||
620 | free(seq); | ||
356 | end: | 621 | end: |
357 | st->prev_event_time = timestamp; | 622 | return; |
358 | } | 623 | } |
359 | 624 | ||
360 | /* lock oriented handlers */ | 625 | /* lock oriented handlers */ |
@@ -381,6 +646,7 @@ process_lock_acquire_event(void *data, | |||
381 | tmp = raw_field_value(event, "lockdep_addr", data); | 646 | tmp = raw_field_value(event, "lockdep_addr", data); |
382 | memcpy(&acquire_event.addr, &tmp, sizeof(void *)); | 647 | memcpy(&acquire_event.addr, &tmp, sizeof(void *)); |
383 | acquire_event.name = (char *)raw_field_ptr(event, "name", data); | 648 | acquire_event.name = (char *)raw_field_ptr(event, "name", data); |
649 | acquire_event.flag = (int)raw_field_value(event, "flag", data); | ||
384 | 650 | ||
385 | if (trace_handler->acquire_event) | 651 | if (trace_handler->acquire_event) |
386 | trace_handler->acquire_event(&acquire_event, event, cpu, timestamp, thread); | 652 | trace_handler->acquire_event(&acquire_event, event, cpu, timestamp, thread); |
@@ -441,8 +707,7 @@ process_lock_release_event(void *data, | |||
441 | } | 707 | } |
442 | 708 | ||
443 | static void | 709 | static void |
444 | process_raw_event(void *data, int cpu, | 710 | process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread) |
445 | u64 timestamp, struct thread *thread) | ||
446 | { | 711 | { |
447 | struct event *event; | 712 | struct event *event; |
448 | int type; | 713 | int type; |
@@ -460,173 +725,19 @@ process_raw_event(void *data, int cpu, | |||
460 | process_lock_release_event(data, event, cpu, timestamp, thread); | 725 | process_lock_release_event(data, event, cpu, timestamp, thread); |
461 | } | 726 | } |
462 | 727 | ||
463 | struct raw_event_queue { | 728 | static void print_bad_events(int bad, int total) |
464 | u64 timestamp; | ||
465 | int cpu; | ||
466 | void *data; | ||
467 | struct thread *thread; | ||
468 | struct list_head list; | ||
469 | }; | ||
470 | |||
471 | static LIST_HEAD(raw_event_head); | ||
472 | |||
473 | #define FLUSH_PERIOD (5 * NSEC_PER_SEC) | ||
474 | |||
475 | static u64 flush_limit = ULLONG_MAX; | ||
476 | static u64 last_flush = 0; | ||
477 | struct raw_event_queue *last_inserted; | ||
478 | |||
479 | static void flush_raw_event_queue(u64 limit) | ||
480 | { | ||
481 | struct raw_event_queue *tmp, *iter; | ||
482 | |||
483 | list_for_each_entry_safe(iter, tmp, &raw_event_head, list) { | ||
484 | if (iter->timestamp > limit) | ||
485 | return; | ||
486 | |||
487 | if (iter == last_inserted) | ||
488 | last_inserted = NULL; | ||
489 | |||
490 | process_raw_event(iter->data, iter->cpu, iter->timestamp, | ||
491 | iter->thread); | ||
492 | |||
493 | last_flush = iter->timestamp; | ||
494 | list_del(&iter->list); | ||
495 | free(iter->data); | ||
496 | free(iter); | ||
497 | } | ||
498 | } | ||
499 | |||
500 | static void __queue_raw_event_end(struct raw_event_queue *new) | ||
501 | { | ||
502 | struct raw_event_queue *iter; | ||
503 | |||
504 | list_for_each_entry_reverse(iter, &raw_event_head, list) { | ||
505 | if (iter->timestamp < new->timestamp) { | ||
506 | list_add(&new->list, &iter->list); | ||
507 | return; | ||
508 | } | ||
509 | } | ||
510 | |||
511 | list_add(&new->list, &raw_event_head); | ||
512 | } | ||
513 | |||
514 | static void __queue_raw_event_before(struct raw_event_queue *new, | ||
515 | struct raw_event_queue *iter) | ||
516 | { | 729 | { |
517 | list_for_each_entry_continue_reverse(iter, &raw_event_head, list) { | 730 | /* Output for debug, this have to be removed */ |
518 | if (iter->timestamp < new->timestamp) { | 731 | int i; |
519 | list_add(&new->list, &iter->list); | 732 | const char *name[4] = |
520 | return; | 733 | { "acquire", "acquired", "contended", "release" }; |
521 | } | 734 | |
522 | } | 735 | pr_info("\n=== output for debug===\n\n"); |
523 | 736 | pr_info("bad: %d, total: %d\n", bad, total); | |
524 | list_add(&new->list, &raw_event_head); | 737 | pr_info("bad rate: %f %%\n", (double)bad / (double)total * 100); |
525 | } | 738 | pr_info("histogram of events caused bad sequence\n"); |
526 | 739 | for (i = 0; i < BROKEN_MAX; i++) | |
527 | static void __queue_raw_event_after(struct raw_event_queue *new, | 740 | pr_info(" %10s: %d\n", name[i], bad_hist[i]); |
528 | struct raw_event_queue *iter) | ||
529 | { | ||
530 | list_for_each_entry_continue(iter, &raw_event_head, list) { | ||
531 | if (iter->timestamp > new->timestamp) { | ||
532 | list_add_tail(&new->list, &iter->list); | ||
533 | return; | ||
534 | } | ||
535 | } | ||
536 | list_add_tail(&new->list, &raw_event_head); | ||
537 | } | ||
538 | |||
539 | /* The queue is ordered by time */ | ||
540 | static void __queue_raw_event(struct raw_event_queue *new) | ||
541 | { | ||
542 | if (!last_inserted) { | ||
543 | __queue_raw_event_end(new); | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | /* | ||
548 | * Most of the time the current event has a timestamp | ||
549 | * very close to the last event inserted, unless we just switched | ||
550 | * to another event buffer. Having a sorting based on a list and | ||
551 | * on the last inserted event that is close to the current one is | ||
552 | * probably more efficient than an rbtree based sorting. | ||
553 | */ | ||
554 | if (last_inserted->timestamp >= new->timestamp) | ||
555 | __queue_raw_event_before(new, last_inserted); | ||
556 | else | ||
557 | __queue_raw_event_after(new, last_inserted); | ||
558 | } | ||
559 | |||
560 | static void queue_raw_event(void *data, int raw_size, int cpu, | ||
561 | u64 timestamp, struct thread *thread) | ||
562 | { | ||
563 | struct raw_event_queue *new; | ||
564 | |||
565 | if (flush_limit == ULLONG_MAX) | ||
566 | flush_limit = timestamp + FLUSH_PERIOD; | ||
567 | |||
568 | if (timestamp < last_flush) { | ||
569 | printf("Warning: Timestamp below last timeslice flush\n"); | ||
570 | return; | ||
571 | } | ||
572 | |||
573 | new = malloc(sizeof(*new)); | ||
574 | if (!new) | ||
575 | die("Not enough memory\n"); | ||
576 | |||
577 | new->timestamp = timestamp; | ||
578 | new->cpu = cpu; | ||
579 | new->thread = thread; | ||
580 | |||
581 | new->data = malloc(raw_size); | ||
582 | if (!new->data) | ||
583 | die("Not enough memory\n"); | ||
584 | |||
585 | memcpy(new->data, data, raw_size); | ||
586 | |||
587 | __queue_raw_event(new); | ||
588 | last_inserted = new; | ||
589 | |||
590 | /* | ||
591 | * We want to have a slice of events covering 2 * FLUSH_PERIOD | ||
592 | * If FLUSH_PERIOD is big enough, it ensures every events that occured | ||
593 | * in the first half of the timeslice have all been buffered and there | ||
594 | * are none remaining (we need that because of the weakly ordered | ||
595 | * event recording we have). Then once we reach the 2 * FLUSH_PERIOD | ||
596 | * timeslice, we flush the first half to be gentle with the memory | ||
597 | * (the second half can still get new events in the middle, so wait | ||
598 | * another period to flush it) | ||
599 | */ | ||
600 | if (new->timestamp > flush_limit && | ||
601 | new->timestamp - flush_limit > FLUSH_PERIOD) { | ||
602 | flush_limit += FLUSH_PERIOD; | ||
603 | flush_raw_event_queue(flush_limit); | ||
604 | } | ||
605 | } | ||
606 | |||
607 | static int process_sample_event(event_t *event, struct perf_session *session) | ||
608 | { | ||
609 | struct thread *thread; | ||
610 | struct sample_data data; | ||
611 | |||
612 | bzero(&data, sizeof(struct sample_data)); | ||
613 | event__parse_sample(event, session->sample_type, &data); | ||
614 | thread = perf_session__findnew(session, data.pid); | ||
615 | |||
616 | if (thread == NULL) { | ||
617 | pr_debug("problem processing %d event, skipping it.\n", | ||
618 | event->header.type); | ||
619 | return -1; | ||
620 | } | ||
621 | |||
622 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | ||
623 | |||
624 | if (profile_cpu != -1 && profile_cpu != (int) data.cpu) | ||
625 | return 0; | ||
626 | |||
627 | queue_raw_event(data.raw_data, data.raw_size, data.cpu, data.time, thread); | ||
628 | |||
629 | return 0; | ||
630 | } | 741 | } |
631 | 742 | ||
632 | /* TODO: various way to print, coloring, nano or milli sec */ | 743 | /* TODO: various way to print, coloring, nano or milli sec */ |
@@ -634,26 +745,30 @@ static void print_result(void) | |||
634 | { | 745 | { |
635 | struct lock_stat *st; | 746 | struct lock_stat *st; |
636 | char cut_name[20]; | 747 | char cut_name[20]; |
748 | int bad, total; | ||
637 | 749 | ||
638 | printf("%18s ", "ID"); | 750 | pr_info("%20s ", "Name"); |
639 | printf("%20s ", "Name"); | 751 | pr_info("%10s ", "acquired"); |
640 | printf("%10s ", "acquired"); | 752 | pr_info("%10s ", "contended"); |
641 | printf("%10s ", "contended"); | ||
642 | 753 | ||
643 | printf("%15s ", "total wait (ns)"); | 754 | pr_info("%15s ", "total wait (ns)"); |
644 | printf("%15s ", "max wait (ns)"); | 755 | pr_info("%15s ", "max wait (ns)"); |
645 | printf("%15s ", "min wait (ns)"); | 756 | pr_info("%15s ", "min wait (ns)"); |
646 | 757 | ||
647 | printf("\n\n"); | 758 | pr_info("\n\n"); |
648 | 759 | ||
760 | bad = total = 0; | ||
649 | while ((st = pop_from_result())) { | 761 | while ((st = pop_from_result())) { |
762 | total++; | ||
763 | if (st->discard) { | ||
764 | bad++; | ||
765 | continue; | ||
766 | } | ||
650 | bzero(cut_name, 20); | 767 | bzero(cut_name, 20); |
651 | 768 | ||
652 | printf("%p ", st->addr); | ||
653 | |||
654 | if (strlen(st->name) < 16) { | 769 | if (strlen(st->name) < 16) { |
655 | /* output raw name */ | 770 | /* output raw name */ |
656 | printf("%20s ", st->name); | 771 | pr_info("%20s ", st->name); |
657 | } else { | 772 | } else { |
658 | strncpy(cut_name, st->name, 16); | 773 | strncpy(cut_name, st->name, 16); |
659 | cut_name[16] = '.'; | 774 | cut_name[16] = '.'; |
@@ -661,18 +776,39 @@ static void print_result(void) | |||
661 | cut_name[18] = '.'; | 776 | cut_name[18] = '.'; |
662 | cut_name[19] = '\0'; | 777 | cut_name[19] = '\0'; |
663 | /* cut off name for saving output style */ | 778 | /* cut off name for saving output style */ |
664 | printf("%20s ", cut_name); | 779 | pr_info("%20s ", cut_name); |
665 | } | 780 | } |
666 | 781 | ||
667 | printf("%10u ", st->nr_acquired); | 782 | pr_info("%10u ", st->nr_acquired); |
668 | printf("%10u ", st->nr_contended); | 783 | pr_info("%10u ", st->nr_contended); |
669 | 784 | ||
670 | printf("%15llu ", st->wait_time_total); | 785 | pr_info("%15llu ", st->wait_time_total); |
671 | printf("%15llu ", st->wait_time_max); | 786 | pr_info("%15llu ", st->wait_time_max); |
672 | printf("%15llu ", st->wait_time_min == ULLONG_MAX ? | 787 | pr_info("%15llu ", st->wait_time_min == ULLONG_MAX ? |
673 | 0 : st->wait_time_min); | 788 | 0 : st->wait_time_min); |
674 | printf("\n"); | 789 | pr_info("\n"); |
675 | } | 790 | } |
791 | |||
792 | print_bad_events(bad, total); | ||
793 | } | ||
794 | |||
795 | static bool info_threads, info_map; | ||
796 | |||
797 | static void dump_threads(void) | ||
798 | { | ||
799 | struct thread_stat *st; | ||
800 | struct rb_node *node; | ||
801 | struct thread *t; | ||
802 | |||
803 | pr_info("%10s: comm\n", "Thread ID"); | ||
804 | |||
805 | node = rb_first(&thread_stats); | ||
806 | while (node) { | ||
807 | st = container_of(node, struct thread_stat, rb); | ||
808 | t = perf_session__findnew(session, st->tid); | ||
809 | pr_info("%10d: %s\n", st->tid, t->comm); | ||
810 | node = rb_next(node); | ||
811 | }; | ||
676 | } | 812 | } |
677 | 813 | ||
678 | static void dump_map(void) | 814 | static void dump_map(void) |
@@ -680,23 +816,53 @@ static void dump_map(void) | |||
680 | unsigned int i; | 816 | unsigned int i; |
681 | struct lock_stat *st; | 817 | struct lock_stat *st; |
682 | 818 | ||
819 | pr_info("Address of instance: name of class\n"); | ||
683 | for (i = 0; i < LOCKHASH_SIZE; i++) { | 820 | for (i = 0; i < LOCKHASH_SIZE; i++) { |
684 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { | 821 | list_for_each_entry(st, &lockhash_table[i], hash_entry) { |
685 | printf("%p: %s\n", st->addr, st->name); | 822 | pr_info(" %p: %s\n", st->addr, st->name); |
686 | } | 823 | } |
687 | } | 824 | } |
688 | } | 825 | } |
689 | 826 | ||
827 | static void dump_info(void) | ||
828 | { | ||
829 | if (info_threads) | ||
830 | dump_threads(); | ||
831 | else if (info_map) | ||
832 | dump_map(); | ||
833 | else | ||
834 | die("Unknown type of information\n"); | ||
835 | } | ||
836 | |||
837 | static int process_sample_event(event_t *self, struct perf_session *s) | ||
838 | { | ||
839 | struct sample_data data; | ||
840 | struct thread *thread; | ||
841 | |||
842 | bzero(&data, sizeof(data)); | ||
843 | event__parse_sample(self, s->sample_type, &data); | ||
844 | |||
845 | thread = perf_session__findnew(s, data.tid); | ||
846 | if (thread == NULL) { | ||
847 | pr_debug("problem processing %d event, skipping it.\n", | ||
848 | self->header.type); | ||
849 | return -1; | ||
850 | } | ||
851 | |||
852 | process_raw_event(data.raw_data, data.cpu, data.time, thread); | ||
853 | |||
854 | return 0; | ||
855 | } | ||
856 | |||
690 | static struct perf_event_ops eops = { | 857 | static struct perf_event_ops eops = { |
691 | .sample = process_sample_event, | 858 | .sample = process_sample_event, |
692 | .comm = event__process_comm, | 859 | .comm = event__process_comm, |
860 | .ordered_samples = true, | ||
693 | }; | 861 | }; |
694 | 862 | ||
695 | static struct perf_session *session; | ||
696 | |||
697 | static int read_events(void) | 863 | static int read_events(void) |
698 | { | 864 | { |
699 | session = perf_session__new(input_name, O_RDONLY, 0); | 865 | session = perf_session__new(input_name, O_RDONLY, 0, false); |
700 | if (!session) | 866 | if (!session) |
701 | die("Initializing perf session failed\n"); | 867 | die("Initializing perf session failed\n"); |
702 | 868 | ||
@@ -720,7 +886,6 @@ static void __cmd_report(void) | |||
720 | setup_pager(); | 886 | setup_pager(); |
721 | select_key(); | 887 | select_key(); |
722 | read_events(); | 888 | read_events(); |
723 | flush_raw_event_queue(ULLONG_MAX); | ||
724 | sort_result(); | 889 | sort_result(); |
725 | print_result(); | 890 | print_result(); |
726 | } | 891 | } |
@@ -737,6 +902,19 @@ static const struct option report_options[] = { | |||
737 | OPT_END() | 902 | OPT_END() |
738 | }; | 903 | }; |
739 | 904 | ||
905 | static const char * const info_usage[] = { | ||
906 | "perf lock info [<options>]", | ||
907 | NULL | ||
908 | }; | ||
909 | |||
910 | static const struct option info_options[] = { | ||
911 | OPT_BOOLEAN('t', "threads", &info_threads, | ||
912 | "dump thread list in perf.data"), | ||
913 | OPT_BOOLEAN('m', "map", &info_map, | ||
914 | "map of lock instances (name:address table)"), | ||
915 | OPT_END() | ||
916 | }; | ||
917 | |||
740 | static const char * const lock_usage[] = { | 918 | static const char * const lock_usage[] = { |
741 | "perf lock [<options>] {record|trace|report}", | 919 | "perf lock [<options>] {record|trace|report}", |
742 | NULL | 920 | NULL |
@@ -744,14 +922,13 @@ static const char * const lock_usage[] = { | |||
744 | 922 | ||
745 | static const struct option lock_options[] = { | 923 | static const struct option lock_options[] = { |
746 | OPT_STRING('i', "input", &input_name, "file", "input file name"), | 924 | OPT_STRING('i', "input", &input_name, "file", "input file name"), |
747 | OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), | 925 | OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), |
748 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), | 926 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), |
749 | OPT_END() | 927 | OPT_END() |
750 | }; | 928 | }; |
751 | 929 | ||
752 | static const char *record_args[] = { | 930 | static const char *record_args[] = { |
753 | "record", | 931 | "record", |
754 | "-a", | ||
755 | "-R", | 932 | "-R", |
756 | "-f", | 933 | "-f", |
757 | "-m", "1024", | 934 | "-m", "1024", |
@@ -808,12 +985,18 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used) | |||
808 | } else if (!strcmp(argv[0], "trace")) { | 985 | } else if (!strcmp(argv[0], "trace")) { |
809 | /* Aliased to 'perf trace' */ | 986 | /* Aliased to 'perf trace' */ |
810 | return cmd_trace(argc, argv, prefix); | 987 | return cmd_trace(argc, argv, prefix); |
811 | } else if (!strcmp(argv[0], "map")) { | 988 | } else if (!strcmp(argv[0], "info")) { |
989 | if (argc) { | ||
990 | argc = parse_options(argc, argv, | ||
991 | info_options, info_usage, 0); | ||
992 | if (argc) | ||
993 | usage_with_options(info_usage, info_options); | ||
994 | } | ||
812 | /* recycling report_lock_ops */ | 995 | /* recycling report_lock_ops */ |
813 | trace_handler = &report_lock_ops; | 996 | trace_handler = &report_lock_ops; |
814 | setup_pager(); | 997 | setup_pager(); |
815 | read_events(); | 998 | read_events(); |
816 | dump_map(); | 999 | dump_info(); |
817 | } else { | 1000 | } else { |
818 | usage_with_options(lock_usage, lock_options); | 1001 | usage_with_options(lock_usage, lock_options); |
819 | } | 1002 | } |
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 152d6c9b1fa4..61c6d70732c9 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -36,13 +36,10 @@ | |||
36 | #include "builtin.h" | 36 | #include "builtin.h" |
37 | #include "util/util.h" | 37 | #include "util/util.h" |
38 | #include "util/strlist.h" | 38 | #include "util/strlist.h" |
39 | #include "util/event.h" | 39 | #include "util/symbol.h" |
40 | #include "util/debug.h" | 40 | #include "util/debug.h" |
41 | #include "util/debugfs.h" | 41 | #include "util/debugfs.h" |
42 | #include "util/symbol.h" | ||
43 | #include "util/thread.h" | ||
44 | #include "util/parse-options.h" | 42 | #include "util/parse-options.h" |
45 | #include "util/parse-events.h" /* For debugfs_path */ | ||
46 | #include "util/probe-finder.h" | 43 | #include "util/probe-finder.h" |
47 | #include "util/probe-event.h" | 44 | #include "util/probe-event.h" |
48 | 45 | ||
@@ -50,103 +47,84 @@ | |||
50 | 47 | ||
51 | /* Session management structure */ | 48 | /* Session management structure */ |
52 | static struct { | 49 | static struct { |
53 | bool need_dwarf; | ||
54 | bool list_events; | 50 | bool list_events; |
55 | bool force_add; | 51 | bool force_add; |
56 | bool show_lines; | 52 | bool show_lines; |
57 | int nr_probe; | 53 | int nevents; |
58 | struct probe_point probes[MAX_PROBES]; | 54 | struct perf_probe_event events[MAX_PROBES]; |
59 | struct strlist *dellist; | 55 | struct strlist *dellist; |
60 | struct map_groups kmap_groups; | ||
61 | struct map *kmaps[MAP__NR_TYPES]; | ||
62 | struct line_range line_range; | 56 | struct line_range line_range; |
63 | } session; | 57 | int max_probe_points; |
58 | } params; | ||
64 | 59 | ||
65 | 60 | ||
66 | /* Parse an event definition. Note that any error must die. */ | 61 | /* Parse an event definition. Note that any error must die. */ |
67 | static void parse_probe_event(const char *str) | 62 | static int parse_probe_event(const char *str) |
68 | { | 63 | { |
69 | struct probe_point *pp = &session.probes[session.nr_probe]; | 64 | struct perf_probe_event *pev = ¶ms.events[params.nevents]; |
65 | int ret; | ||
70 | 66 | ||
71 | pr_debug("probe-definition(%d): %s\n", session.nr_probe, str); | 67 | pr_debug("probe-definition(%d): %s\n", params.nevents, str); |
72 | if (++session.nr_probe == MAX_PROBES) | 68 | if (++params.nevents == MAX_PROBES) |
73 | die("Too many probes (> %d) are specified.", MAX_PROBES); | 69 | die("Too many probes (> %d) are specified.", MAX_PROBES); |
74 | 70 | ||
75 | /* Parse perf-probe event into probe_point */ | 71 | /* Parse a perf-probe command into event */ |
76 | parse_perf_probe_event(str, pp, &session.need_dwarf); | 72 | ret = parse_perf_probe_command(str, pev); |
73 | pr_debug("%d arguments\n", pev->nargs); | ||
77 | 74 | ||
78 | pr_debug("%d arguments\n", pp->nr_args); | 75 | return ret; |
79 | } | 76 | } |
80 | 77 | ||
81 | static void parse_probe_event_argv(int argc, const char **argv) | 78 | static int parse_probe_event_argv(int argc, const char **argv) |
82 | { | 79 | { |
83 | int i, len; | 80 | int i, len, ret; |
84 | char *buf; | 81 | char *buf; |
85 | 82 | ||
86 | /* Bind up rest arguments */ | 83 | /* Bind up rest arguments */ |
87 | len = 0; | 84 | len = 0; |
88 | for (i = 0; i < argc; i++) | 85 | for (i = 0; i < argc; i++) |
89 | len += strlen(argv[i]) + 1; | 86 | len += strlen(argv[i]) + 1; |
90 | buf = zalloc(len + 1); | 87 | buf = xzalloc(len + 1); |
91 | if (!buf) | ||
92 | die("Failed to allocate memory for binding arguments."); | ||
93 | len = 0; | 88 | len = 0; |
94 | for (i = 0; i < argc; i++) | 89 | for (i = 0; i < argc; i++) |
95 | len += sprintf(&buf[len], "%s ", argv[i]); | 90 | len += sprintf(&buf[len], "%s ", argv[i]); |
96 | parse_probe_event(buf); | 91 | ret = parse_probe_event(buf); |
97 | free(buf); | 92 | free(buf); |
93 | return ret; | ||
98 | } | 94 | } |
99 | 95 | ||
100 | static int opt_add_probe_event(const struct option *opt __used, | 96 | static int opt_add_probe_event(const struct option *opt __used, |
101 | const char *str, int unset __used) | 97 | const char *str, int unset __used) |
102 | { | 98 | { |
103 | if (str) | 99 | if (str) |
104 | parse_probe_event(str); | 100 | return parse_probe_event(str); |
105 | return 0; | 101 | else |
102 | return 0; | ||
106 | } | 103 | } |
107 | 104 | ||
108 | static int opt_del_probe_event(const struct option *opt __used, | 105 | static int opt_del_probe_event(const struct option *opt __used, |
109 | const char *str, int unset __used) | 106 | const char *str, int unset __used) |
110 | { | 107 | { |
111 | if (str) { | 108 | if (str) { |
112 | if (!session.dellist) | 109 | if (!params.dellist) |
113 | session.dellist = strlist__new(true, NULL); | 110 | params.dellist = strlist__new(true, NULL); |
114 | strlist__add(session.dellist, str); | 111 | strlist__add(params.dellist, str); |
115 | } | 112 | } |
116 | return 0; | 113 | return 0; |
117 | } | 114 | } |
118 | 115 | ||
119 | /* Currently just checking function name from symbol map */ | 116 | #ifdef DWARF_SUPPORT |
120 | static void evaluate_probe_point(struct probe_point *pp) | ||
121 | { | ||
122 | struct symbol *sym; | ||
123 | sym = map__find_symbol_by_name(session.kmaps[MAP__FUNCTION], | ||
124 | pp->function, NULL); | ||
125 | if (!sym) | ||
126 | die("Kernel symbol \'%s\' not found - probe not added.", | ||
127 | pp->function); | ||
128 | } | ||
129 | |||
130 | #ifndef NO_DWARF_SUPPORT | ||
131 | static int open_vmlinux(void) | ||
132 | { | ||
133 | if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) { | ||
134 | pr_debug("Failed to load kernel map.\n"); | ||
135 | return -EINVAL; | ||
136 | } | ||
137 | pr_debug("Try to open %s\n", | ||
138 | session.kmaps[MAP__FUNCTION]->dso->long_name); | ||
139 | return open(session.kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | ||
140 | } | ||
141 | |||
142 | static int opt_show_lines(const struct option *opt __used, | 117 | static int opt_show_lines(const struct option *opt __used, |
143 | const char *str, int unset __used) | 118 | const char *str, int unset __used) |
144 | { | 119 | { |
120 | int ret = 0; | ||
121 | |||
145 | if (str) | 122 | if (str) |
146 | parse_line_range_desc(str, &session.line_range); | 123 | ret = parse_line_range_desc(str, ¶ms.line_range); |
147 | INIT_LIST_HEAD(&session.line_range.line_list); | 124 | INIT_LIST_HEAD(¶ms.line_range.line_list); |
148 | session.show_lines = true; | 125 | params.show_lines = true; |
149 | return 0; | 126 | |
127 | return ret; | ||
150 | } | 128 | } |
151 | #endif | 129 | #endif |
152 | 130 | ||
@@ -155,29 +133,25 @@ static const char * const probe_usage[] = { | |||
155 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", | 133 | "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]", |
156 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", | 134 | "perf probe [<options>] --del '[GROUP:]EVENT' ...", |
157 | "perf probe --list", | 135 | "perf probe --list", |
158 | #ifndef NO_DWARF_SUPPORT | 136 | #ifdef DWARF_SUPPORT |
159 | "perf probe --line 'LINEDESC'", | 137 | "perf probe --line 'LINEDESC'", |
160 | #endif | 138 | #endif |
161 | NULL | 139 | NULL |
162 | }; | 140 | }; |
163 | 141 | ||
164 | static const struct option options[] = { | 142 | static const struct option options[] = { |
165 | OPT_BOOLEAN('v', "verbose", &verbose, | 143 | OPT_INCR('v', "verbose", &verbose, |
166 | "be more verbose (show parsed arguments, etc)"), | 144 | "be more verbose (show parsed arguments, etc)"), |
167 | #ifndef NO_DWARF_SUPPORT | 145 | OPT_BOOLEAN('l', "list", ¶ms.list_events, |
168 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | ||
169 | "file", "vmlinux pathname"), | ||
170 | #endif | ||
171 | OPT_BOOLEAN('l', "list", &session.list_events, | ||
172 | "list up current probe events"), | 146 | "list up current probe events"), |
173 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", | 147 | OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.", |
174 | opt_del_probe_event), | 148 | opt_del_probe_event), |
175 | OPT_CALLBACK('a', "add", NULL, | 149 | OPT_CALLBACK('a', "add", NULL, |
176 | #ifdef NO_DWARF_SUPPORT | 150 | #ifdef DWARF_SUPPORT |
177 | "[EVENT=]FUNC[+OFF|%return] [ARG ...]", | ||
178 | #else | ||
179 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" | 151 | "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT" |
180 | " [ARG ...]", | 152 | " [[NAME=]ARG ...]", |
153 | #else | ||
154 | "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]", | ||
181 | #endif | 155 | #endif |
182 | "probe point definition, where\n" | 156 | "probe point definition, where\n" |
183 | "\t\tGROUP:\tGroup name (optional)\n" | 157 | "\t\tGROUP:\tGroup name (optional)\n" |
@@ -185,51 +159,35 @@ static const struct option options[] = { | |||
185 | "\t\tFUNC:\tFunction name\n" | 159 | "\t\tFUNC:\tFunction name\n" |
186 | "\t\tOFF:\tOffset from function entry (in byte)\n" | 160 | "\t\tOFF:\tOffset from function entry (in byte)\n" |
187 | "\t\t%return:\tPut the probe at function return\n" | 161 | "\t\t%return:\tPut the probe at function return\n" |
188 | #ifdef NO_DWARF_SUPPORT | 162 | #ifdef DWARF_SUPPORT |
189 | "\t\tARG:\tProbe argument (only \n" | ||
190 | #else | ||
191 | "\t\tSRC:\tSource code path\n" | 163 | "\t\tSRC:\tSource code path\n" |
192 | "\t\tRL:\tRelative line number from function entry.\n" | 164 | "\t\tRL:\tRelative line number from function entry.\n" |
193 | "\t\tAL:\tAbsolute line number in file.\n" | 165 | "\t\tAL:\tAbsolute line number in file.\n" |
194 | "\t\tPT:\tLazy expression of line code.\n" | 166 | "\t\tPT:\tLazy expression of line code.\n" |
195 | "\t\tARG:\tProbe argument (local variable name or\n" | 167 | "\t\tARG:\tProbe argument (local variable name or\n" |
196 | #endif | ||
197 | "\t\t\tkprobe-tracer argument format.)\n", | 168 | "\t\t\tkprobe-tracer argument format.)\n", |
169 | #else | ||
170 | "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n", | ||
171 | #endif | ||
198 | opt_add_probe_event), | 172 | opt_add_probe_event), |
199 | OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events" | 173 | OPT_BOOLEAN('f', "force", ¶ms.force_add, "forcibly add events" |
200 | " with existing name"), | 174 | " with existing name"), |
201 | #ifndef NO_DWARF_SUPPORT | 175 | #ifdef DWARF_SUPPORT |
202 | OPT_CALLBACK('L', "line", NULL, | 176 | OPT_CALLBACK('L', "line", NULL, |
203 | "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]", | 177 | "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]", |
204 | "Show source code lines.", opt_show_lines), | 178 | "Show source code lines.", opt_show_lines), |
179 | OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, | ||
180 | "file", "vmlinux pathname"), | ||
205 | #endif | 181 | #endif |
182 | OPT__DRY_RUN(&probe_event_dry_run), | ||
183 | OPT_INTEGER('\0', "max-probes", ¶ms.max_probe_points, | ||
184 | "Set how many probe points can be found for a probe."), | ||
206 | OPT_END() | 185 | OPT_END() |
207 | }; | 186 | }; |
208 | 187 | ||
209 | /* Initialize symbol maps for vmlinux */ | ||
210 | static void init_vmlinux(void) | ||
211 | { | ||
212 | symbol_conf.sort_by_name = true; | ||
213 | if (symbol_conf.vmlinux_name == NULL) | ||
214 | symbol_conf.try_vmlinux_path = true; | ||
215 | else | ||
216 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
217 | if (symbol__init() < 0) | ||
218 | die("Failed to init symbol map."); | ||
219 | |||
220 | map_groups__init(&session.kmap_groups); | ||
221 | if (map_groups__create_kernel_maps(&session.kmap_groups, | ||
222 | session.kmaps) < 0) | ||
223 | die("Failed to create kernel maps."); | ||
224 | } | ||
225 | |||
226 | int cmd_probe(int argc, const char **argv, const char *prefix __used) | 188 | int cmd_probe(int argc, const char **argv, const char *prefix __used) |
227 | { | 189 | { |
228 | int i, ret; | 190 | int ret; |
229 | #ifndef NO_DWARF_SUPPORT | ||
230 | int fd; | ||
231 | #endif | ||
232 | struct probe_point *pp; | ||
233 | 191 | ||
234 | argc = parse_options(argc, argv, options, probe_usage, | 192 | argc = parse_options(argc, argv, options, probe_usage, |
235 | PARSE_OPT_STOP_AT_NON_OPTION); | 193 | PARSE_OPT_STOP_AT_NON_OPTION); |
@@ -238,123 +196,69 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) | |||
238 | pr_warning(" Error: '-' is not supported.\n"); | 196 | pr_warning(" Error: '-' is not supported.\n"); |
239 | usage_with_options(probe_usage, options); | 197 | usage_with_options(probe_usage, options); |
240 | } | 198 | } |
241 | parse_probe_event_argv(argc, argv); | 199 | ret = parse_probe_event_argv(argc, argv); |
200 | if (ret < 0) { | ||
201 | pr_err(" Error: Parse Error. (%d)\n", ret); | ||
202 | return ret; | ||
203 | } | ||
242 | } | 204 | } |
243 | 205 | ||
244 | if ((!session.nr_probe && !session.dellist && !session.list_events && | 206 | if (params.max_probe_points == 0) |
245 | !session.show_lines)) | 207 | params.max_probe_points = MAX_PROBES; |
246 | usage_with_options(probe_usage, options); | ||
247 | 208 | ||
248 | if (debugfs_valid_mountpoint(debugfs_path) < 0) | 209 | if ((!params.nevents && !params.dellist && !params.list_events && |
249 | die("Failed to find debugfs path."); | 210 | !params.show_lines)) |
211 | usage_with_options(probe_usage, options); | ||
250 | 212 | ||
251 | if (session.list_events) { | 213 | if (params.list_events) { |
252 | if (session.nr_probe != 0 || session.dellist) { | 214 | if (params.nevents != 0 || params.dellist) { |
253 | pr_warning(" Error: Don't use --list with" | 215 | pr_err(" Error: Don't use --list with --add/--del.\n"); |
254 | " --add/--del.\n"); | ||
255 | usage_with_options(probe_usage, options); | 216 | usage_with_options(probe_usage, options); |
256 | } | 217 | } |
257 | if (session.show_lines) { | 218 | if (params.show_lines) { |
258 | pr_warning(" Error: Don't use --list with --line.\n"); | 219 | pr_err(" Error: Don't use --list with --line.\n"); |
259 | usage_with_options(probe_usage, options); | 220 | usage_with_options(probe_usage, options); |
260 | } | 221 | } |
261 | show_perf_probe_events(); | 222 | ret = show_perf_probe_events(); |
262 | return 0; | 223 | if (ret < 0) |
224 | pr_err(" Error: Failed to show event list. (%d)\n", | ||
225 | ret); | ||
226 | return ret; | ||
263 | } | 227 | } |
264 | 228 | ||
265 | #ifndef NO_DWARF_SUPPORT | 229 | #ifdef DWARF_SUPPORT |
266 | if (session.show_lines) { | 230 | if (params.show_lines) { |
267 | if (session.nr_probe != 0 || session.dellist) { | 231 | if (params.nevents != 0 || params.dellist) { |
268 | pr_warning(" Error: Don't use --line with" | 232 | pr_warning(" Error: Don't use --line with" |
269 | " --add/--del.\n"); | 233 | " --add/--del.\n"); |
270 | usage_with_options(probe_usage, options); | 234 | usage_with_options(probe_usage, options); |
271 | } | 235 | } |
272 | init_vmlinux(); | ||
273 | fd = open_vmlinux(); | ||
274 | if (fd < 0) | ||
275 | die("Could not open debuginfo file."); | ||
276 | ret = find_line_range(fd, &session.line_range); | ||
277 | if (ret <= 0) | ||
278 | die("Source line is not found.\n"); | ||
279 | close(fd); | ||
280 | show_line_range(&session.line_range); | ||
281 | return 0; | ||
282 | } | ||
283 | #endif | ||
284 | 236 | ||
285 | if (session.dellist) { | 237 | ret = show_line_range(¶ms.line_range); |
286 | del_trace_kprobe_events(session.dellist); | 238 | if (ret < 0) |
287 | strlist__delete(session.dellist); | 239 | pr_err(" Error: Failed to show lines. (%d)\n", ret); |
288 | if (session.nr_probe == 0) | 240 | return ret; |
289 | return 0; | ||
290 | } | 241 | } |
242 | #endif | ||
291 | 243 | ||
292 | /* Add probes */ | 244 | if (params.dellist) { |
293 | init_vmlinux(); | 245 | ret = del_perf_probe_events(params.dellist); |
294 | 246 | strlist__delete(params.dellist); | |
295 | if (session.need_dwarf) | 247 | if (ret < 0) { |
296 | #ifdef NO_DWARF_SUPPORT | 248 | pr_err(" Error: Failed to delete events. (%d)\n", ret); |
297 | die("Debuginfo-analysis is not supported"); | 249 | return ret; |
298 | #else /* !NO_DWARF_SUPPORT */ | ||
299 | pr_debug("Some probes require debuginfo.\n"); | ||
300 | |||
301 | fd = open_vmlinux(); | ||
302 | if (fd < 0) { | ||
303 | if (session.need_dwarf) | ||
304 | die("Could not open debuginfo file."); | ||
305 | |||
306 | pr_debug("Could not open vmlinux/module file." | ||
307 | " Try to use symbols.\n"); | ||
308 | goto end_dwarf; | ||
309 | } | ||
310 | |||
311 | /* Searching probe points */ | ||
312 | for (i = 0; i < session.nr_probe; i++) { | ||
313 | pp = &session.probes[i]; | ||
314 | if (pp->found) | ||
315 | continue; | ||
316 | |||
317 | lseek(fd, SEEK_SET, 0); | ||
318 | ret = find_probe_point(fd, pp); | ||
319 | if (ret > 0) | ||
320 | continue; | ||
321 | if (ret == 0) { /* No error but failed to find probe point. */ | ||
322 | synthesize_perf_probe_point(pp); | ||
323 | die("Probe point '%s' not found. - probe not added.", | ||
324 | pp->probes[0]); | ||
325 | } | ||
326 | /* Error path */ | ||
327 | if (session.need_dwarf) { | ||
328 | if (ret == -ENOENT) | ||
329 | pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
330 | die("Could not analyze debuginfo."); | ||
331 | } | 250 | } |
332 | pr_debug("An error occurred in debuginfo analysis." | ||
333 | " Try to use symbols.\n"); | ||
334 | break; | ||
335 | } | 251 | } |
336 | close(fd); | ||
337 | |||
338 | end_dwarf: | ||
339 | #endif /* !NO_DWARF_SUPPORT */ | ||
340 | 252 | ||
341 | /* Synthesize probes without dwarf */ | 253 | if (params.nevents) { |
342 | for (i = 0; i < session.nr_probe; i++) { | 254 | ret = add_perf_probe_events(params.events, params.nevents, |
343 | pp = &session.probes[i]; | 255 | params.force_add, |
344 | if (pp->found) /* This probe is already found. */ | 256 | params.max_probe_points); |
345 | continue; | 257 | if (ret < 0) { |
346 | 258 | pr_err(" Error: Failed to add events. (%d)\n", ret); | |
347 | evaluate_probe_point(pp); | 259 | return ret; |
348 | ret = synthesize_trace_kprobe_event(pp); | 260 | } |
349 | if (ret == -E2BIG) | ||
350 | die("probe point definition becomes too long."); | ||
351 | else if (ret < 0) | ||
352 | die("Failed to synthesize a probe point."); | ||
353 | } | 261 | } |
354 | |||
355 | /* Settng up probe points */ | ||
356 | add_trace_kprobe_events(session.probes, session.nr_probe, | ||
357 | session.force_add); | ||
358 | return 0; | 262 | return 0; |
359 | } | 263 | } |
360 | 264 | ||
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3b8b6387c47c..cb46c7d0ea99 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include "util/util.h" | 15 | #include "util/util.h" |
16 | #include "util/parse-options.h" | 16 | #include "util/parse-options.h" |
17 | #include "util/parse-events.h" | 17 | #include "util/parse-events.h" |
18 | #include "util/string.h" | ||
19 | 18 | ||
20 | #include "util/header.h" | 19 | #include "util/header.h" |
21 | #include "util/event.h" | 20 | #include "util/event.h" |
@@ -27,31 +26,41 @@ | |||
27 | #include <unistd.h> | 26 | #include <unistd.h> |
28 | #include <sched.h> | 27 | #include <sched.h> |
29 | 28 | ||
30 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 29 | enum write_mode_t { |
30 | WRITE_FORCE, | ||
31 | WRITE_APPEND | ||
32 | }; | ||
33 | |||
34 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; | ||
31 | 35 | ||
32 | static long default_interval = 0; | 36 | static u64 user_interval = ULLONG_MAX; |
37 | static u64 default_interval = 0; | ||
33 | 38 | ||
34 | static int nr_cpus = 0; | 39 | static int nr_cpus = 0; |
35 | static unsigned int page_size; | 40 | static unsigned int page_size; |
36 | static unsigned int mmap_pages = 128; | 41 | static unsigned int mmap_pages = 128; |
42 | static unsigned int user_freq = UINT_MAX; | ||
37 | static int freq = 1000; | 43 | static int freq = 1000; |
38 | static int output; | 44 | static int output; |
45 | static int pipe_output = 0; | ||
39 | static const char *output_name = "perf.data"; | 46 | static const char *output_name = "perf.data"; |
40 | static int group = 0; | 47 | static int group = 0; |
41 | static unsigned int realtime_prio = 0; | 48 | static int realtime_prio = 0; |
42 | static int raw_samples = 0; | 49 | static bool raw_samples = false; |
43 | static int system_wide = 0; | 50 | static bool system_wide = false; |
44 | static int profile_cpu = -1; | 51 | static int profile_cpu = -1; |
45 | static pid_t target_pid = -1; | 52 | static pid_t target_pid = -1; |
53 | static pid_t target_tid = -1; | ||
54 | static pid_t *all_tids = NULL; | ||
55 | static int thread_num = 0; | ||
46 | static pid_t child_pid = -1; | 56 | static pid_t child_pid = -1; |
47 | static int inherit = 1; | 57 | static bool no_inherit = false; |
48 | static int force = 0; | 58 | static enum write_mode_t write_mode = WRITE_FORCE; |
49 | static int append_file = 0; | 59 | static bool call_graph = false; |
50 | static int call_graph = 0; | 60 | static bool inherit_stat = false; |
51 | static int inherit_stat = 0; | 61 | static bool no_samples = false; |
52 | static int no_samples = 0; | 62 | static bool sample_address = false; |
53 | static int sample_address = 0; | 63 | static bool multiplex = false; |
54 | static int multiplex = 0; | ||
55 | static int multiplex_fd = -1; | 64 | static int multiplex_fd = -1; |
56 | 65 | ||
57 | static long samples = 0; | 66 | static long samples = 0; |
@@ -60,7 +69,7 @@ static struct timeval this_read; | |||
60 | 69 | ||
61 | static u64 bytes_written = 0; | 70 | static u64 bytes_written = 0; |
62 | 71 | ||
63 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; | 72 | static struct pollfd *event_array; |
64 | 73 | ||
65 | static int nr_poll = 0; | 74 | static int nr_poll = 0; |
66 | static int nr_cpu = 0; | 75 | static int nr_cpu = 0; |
@@ -77,7 +86,7 @@ struct mmap_data { | |||
77 | unsigned int prev; | 86 | unsigned int prev; |
78 | }; | 87 | }; |
79 | 88 | ||
80 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 89 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
81 | 90 | ||
82 | static unsigned long mmap_read_head(struct mmap_data *md) | 91 | static unsigned long mmap_read_head(struct mmap_data *md) |
83 | { | 92 | { |
@@ -101,6 +110,11 @@ static void mmap_write_tail(struct mmap_data *md, unsigned long tail) | |||
101 | pc->data_tail = tail; | 110 | pc->data_tail = tail; |
102 | } | 111 | } |
103 | 112 | ||
113 | static void advance_output(size_t size) | ||
114 | { | ||
115 | bytes_written += size; | ||
116 | } | ||
117 | |||
104 | static void write_output(void *buf, size_t size) | 118 | static void write_output(void *buf, size_t size) |
105 | { | 119 | { |
106 | while (size) { | 120 | while (size) { |
@@ -225,12 +239,13 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n | |||
225 | return h_attr; | 239 | return h_attr; |
226 | } | 240 | } |
227 | 241 | ||
228 | static void create_counter(int counter, int cpu, pid_t pid) | 242 | static void create_counter(int counter, int cpu) |
229 | { | 243 | { |
230 | char *filter = filters[counter]; | 244 | char *filter = filters[counter]; |
231 | struct perf_event_attr *attr = attrs + counter; | 245 | struct perf_event_attr *attr = attrs + counter; |
232 | struct perf_header_attr *h_attr; | 246 | struct perf_header_attr *h_attr; |
233 | int track = !counter; /* only the first counter needs these */ | 247 | int track = !counter; /* only the first counter needs these */ |
248 | int thread_index; | ||
234 | int ret; | 249 | int ret; |
235 | struct { | 250 | struct { |
236 | u64 count; | 251 | u64 count; |
@@ -248,10 +263,19 @@ static void create_counter(int counter, int cpu, pid_t pid) | |||
248 | if (nr_counters > 1) | 263 | if (nr_counters > 1) |
249 | attr->sample_type |= PERF_SAMPLE_ID; | 264 | attr->sample_type |= PERF_SAMPLE_ID; |
250 | 265 | ||
251 | if (freq) { | 266 | /* |
252 | attr->sample_type |= PERF_SAMPLE_PERIOD; | 267 | * We default some events to a 1 default interval. But keep |
253 | attr->freq = 1; | 268 | * it a weak assumption overridable by the user. |
254 | attr->sample_freq = freq; | 269 | */ |
270 | if (!attr->sample_period || (user_freq != UINT_MAX && | ||
271 | user_interval != ULLONG_MAX)) { | ||
272 | if (freq) { | ||
273 | attr->sample_type |= PERF_SAMPLE_PERIOD; | ||
274 | attr->freq = 1; | ||
275 | attr->sample_freq = freq; | ||
276 | } else { | ||
277 | attr->sample_period = default_interval; | ||
278 | } | ||
255 | } | 279 | } |
256 | 280 | ||
257 | if (no_samples) | 281 | if (no_samples) |
@@ -274,119 +298,130 @@ static void create_counter(int counter, int cpu, pid_t pid) | |||
274 | 298 | ||
275 | attr->mmap = track; | 299 | attr->mmap = track; |
276 | attr->comm = track; | 300 | attr->comm = track; |
277 | attr->inherit = inherit; | 301 | attr->inherit = !no_inherit; |
278 | attr->disabled = 1; | 302 | if (target_pid == -1 && target_tid == -1 && !system_wide) { |
303 | attr->disabled = 1; | ||
304 | attr->enable_on_exec = 1; | ||
305 | } | ||
279 | 306 | ||
307 | for (thread_index = 0; thread_index < thread_num; thread_index++) { | ||
280 | try_again: | 308 | try_again: |
281 | fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0); | 309 | fd[nr_cpu][counter][thread_index] = sys_perf_event_open(attr, |
282 | 310 | all_tids[thread_index], cpu, group_fd, 0); | |
283 | if (fd[nr_cpu][counter] < 0) { | 311 | |
284 | int err = errno; | 312 | if (fd[nr_cpu][counter][thread_index] < 0) { |
285 | 313 | int err = errno; | |
286 | if (err == EPERM || err == EACCES) | 314 | |
287 | die("Permission error - are you root?\n"); | 315 | if (err == EPERM || err == EACCES) |
288 | else if (err == ENODEV && profile_cpu != -1) | 316 | die("Permission error - are you root?\n" |
289 | die("No such device - did you specify an out-of-range profile CPU?\n"); | 317 | "\t Consider tweaking" |
318 | " /proc/sys/kernel/perf_event_paranoid.\n"); | ||
319 | else if (err == ENODEV && profile_cpu != -1) { | ||
320 | die("No such device - did you specify" | ||
321 | " an out-of-range profile CPU?\n"); | ||
322 | } | ||
290 | 323 | ||
291 | /* | 324 | /* |
292 | * If it's cycles then fall back to hrtimer | 325 | * If it's cycles then fall back to hrtimer |
293 | * based cpu-clock-tick sw counter, which | 326 | * based cpu-clock-tick sw counter, which |
294 | * is always available even if no PMU support: | 327 | * is always available even if no PMU support: |
295 | */ | 328 | */ |
296 | if (attr->type == PERF_TYPE_HARDWARE | 329 | if (attr->type == PERF_TYPE_HARDWARE |
297 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | 330 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { |
298 | 331 | ||
299 | if (verbose) | 332 | if (verbose) |
300 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | 333 | warning(" ... trying to fall back to cpu-clock-ticks\n"); |
301 | attr->type = PERF_TYPE_SOFTWARE; | 334 | attr->type = PERF_TYPE_SOFTWARE; |
302 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | 335 | attr->config = PERF_COUNT_SW_CPU_CLOCK; |
303 | goto try_again; | 336 | goto try_again; |
304 | } | 337 | } |
305 | printf("\n"); | 338 | printf("\n"); |
306 | error("perfcounter syscall returned with %d (%s)\n", | 339 | error("perfcounter syscall returned with %d (%s)\n", |
307 | fd[nr_cpu][counter], strerror(err)); | 340 | fd[nr_cpu][counter][thread_index], strerror(err)); |
308 | 341 | ||
309 | #if defined(__i386__) || defined(__x86_64__) | 342 | #if defined(__i386__) || defined(__x86_64__) |
310 | if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP) | 343 | if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP) |
311 | die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n"); | 344 | die("No hardware sampling interrupt available." |
345 | " No APIC? If so then you can boot the kernel" | ||
346 | " with the \"lapic\" boot parameter to" | ||
347 | " force-enable it.\n"); | ||
312 | #endif | 348 | #endif |
313 | 349 | ||
314 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 350 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
315 | exit(-1); | 351 | exit(-1); |
316 | } | 352 | } |
317 | 353 | ||
318 | h_attr = get_header_attr(attr, counter); | 354 | h_attr = get_header_attr(attr, counter); |
319 | if (h_attr == NULL) | 355 | if (h_attr == NULL) |
320 | die("nomem\n"); | 356 | die("nomem\n"); |
321 | 357 | ||
322 | if (!file_new) { | 358 | if (!file_new) { |
323 | if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { | 359 | if (memcmp(&h_attr->attr, attr, sizeof(*attr))) { |
324 | fprintf(stderr, "incompatible append\n"); | 360 | fprintf(stderr, "incompatible append\n"); |
325 | exit(-1); | 361 | exit(-1); |
362 | } | ||
326 | } | 363 | } |
327 | } | ||
328 | 364 | ||
329 | if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) { | 365 | if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) { |
330 | perror("Unable to read perf file descriptor\n"); | 366 | perror("Unable to read perf file descriptor\n"); |
331 | exit(-1); | 367 | exit(-1); |
332 | } | 368 | } |
333 | 369 | ||
334 | if (perf_header_attr__add_id(h_attr, read_data.id) < 0) { | 370 | if (perf_header_attr__add_id(h_attr, read_data.id) < 0) { |
335 | pr_warning("Not enough memory to add id\n"); | 371 | pr_warning("Not enough memory to add id\n"); |
336 | exit(-1); | 372 | exit(-1); |
337 | } | 373 | } |
338 | 374 | ||
339 | assert(fd[nr_cpu][counter] >= 0); | 375 | assert(fd[nr_cpu][counter][thread_index] >= 0); |
340 | fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK); | 376 | fcntl(fd[nr_cpu][counter][thread_index], F_SETFL, O_NONBLOCK); |
341 | 377 | ||
342 | /* | 378 | /* |
343 | * First counter acts as the group leader: | 379 | * First counter acts as the group leader: |
344 | */ | 380 | */ |
345 | if (group && group_fd == -1) | 381 | if (group && group_fd == -1) |
346 | group_fd = fd[nr_cpu][counter]; | 382 | group_fd = fd[nr_cpu][counter][thread_index]; |
347 | if (multiplex && multiplex_fd == -1) | 383 | if (multiplex && multiplex_fd == -1) |
348 | multiplex_fd = fd[nr_cpu][counter]; | 384 | multiplex_fd = fd[nr_cpu][counter][thread_index]; |
349 | 385 | ||
350 | if (multiplex && fd[nr_cpu][counter] != multiplex_fd) { | 386 | if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) { |
351 | 387 | ||
352 | ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); | 388 | ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd); |
353 | assert(ret != -1); | 389 | assert(ret != -1); |
354 | } else { | 390 | } else { |
355 | event_array[nr_poll].fd = fd[nr_cpu][counter]; | 391 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; |
356 | event_array[nr_poll].events = POLLIN; | 392 | event_array[nr_poll].events = POLLIN; |
357 | nr_poll++; | 393 | nr_poll++; |
358 | 394 | ||
359 | mmap_array[nr_cpu][counter].counter = counter; | 395 | mmap_array[nr_cpu][counter][thread_index].counter = counter; |
360 | mmap_array[nr_cpu][counter].prev = 0; | 396 | mmap_array[nr_cpu][counter][thread_index].prev = 0; |
361 | mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1; | 397 | mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; |
362 | mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size, | 398 | mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, |
363 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0); | 399 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); |
364 | if (mmap_array[nr_cpu][counter].base == MAP_FAILED) { | 400 | if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { |
365 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 401 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
366 | exit(-1); | 402 | exit(-1); |
403 | } | ||
367 | } | 404 | } |
368 | } | ||
369 | 405 | ||
370 | if (filter != NULL) { | 406 | if (filter != NULL) { |
371 | ret = ioctl(fd[nr_cpu][counter], | 407 | ret = ioctl(fd[nr_cpu][counter][thread_index], |
372 | PERF_EVENT_IOC_SET_FILTER, filter); | 408 | PERF_EVENT_IOC_SET_FILTER, filter); |
373 | if (ret) { | 409 | if (ret) { |
374 | error("failed to set filter with %d (%s)\n", errno, | 410 | error("failed to set filter with %d (%s)\n", errno, |
375 | strerror(errno)); | 411 | strerror(errno)); |
376 | exit(-1); | 412 | exit(-1); |
413 | } | ||
377 | } | 414 | } |
378 | } | 415 | } |
379 | |||
380 | ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE); | ||
381 | } | 416 | } |
382 | 417 | ||
383 | static void open_counters(int cpu, pid_t pid) | 418 | static void open_counters(int cpu) |
384 | { | 419 | { |
385 | int counter; | 420 | int counter; |
386 | 421 | ||
387 | group_fd = -1; | 422 | group_fd = -1; |
388 | for (counter = 0; counter < nr_counters; counter++) | 423 | for (counter = 0; counter < nr_counters; counter++) |
389 | create_counter(counter, cpu, pid); | 424 | create_counter(counter, cpu); |
390 | 425 | ||
391 | nr_cpu++; | 426 | nr_cpu++; |
392 | } | 427 | } |
@@ -406,10 +441,80 @@ static int process_buildids(void) | |||
406 | 441 | ||
407 | static void atexit_header(void) | 442 | static void atexit_header(void) |
408 | { | 443 | { |
409 | session->header.data_size += bytes_written; | 444 | if (!pipe_output) { |
445 | session->header.data_size += bytes_written; | ||
446 | |||
447 | process_buildids(); | ||
448 | perf_header__write(&session->header, output, true); | ||
449 | } | ||
450 | } | ||
451 | |||
452 | static void event__synthesize_guest_os(struct machine *machine, void *data) | ||
453 | { | ||
454 | int err; | ||
455 | char *guest_kallsyms; | ||
456 | char path[PATH_MAX]; | ||
457 | struct perf_session *psession = data; | ||
458 | |||
459 | if (machine__is_host(machine)) | ||
460 | return; | ||
461 | |||
462 | /* | ||
463 | *As for guest kernel when processing subcommand record&report, | ||
464 | *we arrange module mmap prior to guest kernel mmap and trigger | ||
465 | *a preload dso because default guest module symbols are loaded | ||
466 | *from guest kallsyms instead of /lib/modules/XXX/XXX. This | ||
467 | *method is used to avoid symbol missing when the first addr is | ||
468 | *in module instead of in guest kernel. | ||
469 | */ | ||
470 | err = event__synthesize_modules(process_synthesized_event, | ||
471 | psession, machine); | ||
472 | if (err < 0) | ||
473 | pr_err("Couldn't record guest kernel [%d]'s reference" | ||
474 | " relocation symbol.\n", machine->pid); | ||
475 | |||
476 | if (machine__is_default_guest(machine)) | ||
477 | guest_kallsyms = (char *) symbol_conf.default_guest_kallsyms; | ||
478 | else { | ||
479 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); | ||
480 | guest_kallsyms = path; | ||
481 | } | ||
482 | |||
483 | /* | ||
484 | * We use _stext for guest kernel because guest kernel's /proc/kallsyms | ||
485 | * have no _text sometimes. | ||
486 | */ | ||
487 | err = event__synthesize_kernel_mmap(process_synthesized_event, | ||
488 | psession, machine, "_text"); | ||
489 | if (err < 0) | ||
490 | err = event__synthesize_kernel_mmap(process_synthesized_event, | ||
491 | psession, machine, "_stext"); | ||
492 | if (err < 0) | ||
493 | pr_err("Couldn't record guest kernel [%d]'s reference" | ||
494 | " relocation symbol.\n", machine->pid); | ||
495 | } | ||
496 | |||
497 | static struct perf_event_header finished_round_event = { | ||
498 | .size = sizeof(struct perf_event_header), | ||
499 | .type = PERF_RECORD_FINISHED_ROUND, | ||
500 | }; | ||
501 | |||
502 | static void mmap_read_all(void) | ||
503 | { | ||
504 | int i, counter, thread; | ||
410 | 505 | ||
411 | process_buildids(); | 506 | for (i = 0; i < nr_cpu; i++) { |
412 | perf_header__write(&session->header, output, true); | 507 | for (counter = 0; counter < nr_counters; counter++) { |
508 | for (thread = 0; thread < thread_num; thread++) { | ||
509 | if (mmap_array[i][counter][thread].base) | ||
510 | mmap_read(&mmap_array[i][counter][thread]); | ||
511 | } | ||
512 | |||
513 | } | ||
514 | } | ||
515 | |||
516 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) | ||
517 | write_output(&finished_round_event, sizeof(finished_round_event)); | ||
413 | } | 518 | } |
414 | 519 | ||
415 | static int __cmd_record(int argc, const char **argv) | 520 | static int __cmd_record(int argc, const char **argv) |
@@ -421,8 +526,9 @@ static int __cmd_record(int argc, const char **argv) | |||
421 | int err; | 526 | int err; |
422 | unsigned long waking = 0; | 527 | unsigned long waking = 0; |
423 | int child_ready_pipe[2], go_pipe[2]; | 528 | int child_ready_pipe[2], go_pipe[2]; |
424 | const bool forks = target_pid == -1 && argc > 0; | 529 | const bool forks = argc > 0; |
425 | char buf; | 530 | char buf; |
531 | struct machine *machine; | ||
426 | 532 | ||
427 | page_size = sysconf(_SC_PAGE_SIZE); | 533 | page_size = sysconf(_SC_PAGE_SIZE); |
428 | 534 | ||
@@ -435,70 +541,63 @@ static int __cmd_record(int argc, const char **argv) | |||
435 | exit(-1); | 541 | exit(-1); |
436 | } | 542 | } |
437 | 543 | ||
438 | if (!stat(output_name, &st) && st.st_size) { | 544 | if (!strcmp(output_name, "-")) |
439 | if (!force) { | 545 | pipe_output = 1; |
440 | if (!append_file) { | 546 | else if (!stat(output_name, &st) && st.st_size) { |
441 | pr_err("Error, output file %s exists, use -A " | 547 | if (write_mode == WRITE_FORCE) { |
442 | "to append or -f to overwrite.\n", | ||
443 | output_name); | ||
444 | exit(-1); | ||
445 | } | ||
446 | } else { | ||
447 | char oldname[PATH_MAX]; | 548 | char oldname[PATH_MAX]; |
448 | snprintf(oldname, sizeof(oldname), "%s.old", | 549 | snprintf(oldname, sizeof(oldname), "%s.old", |
449 | output_name); | 550 | output_name); |
450 | unlink(oldname); | 551 | unlink(oldname); |
451 | rename(output_name, oldname); | 552 | rename(output_name, oldname); |
452 | } | 553 | } |
453 | } else { | 554 | } else if (write_mode == WRITE_APPEND) { |
454 | append_file = 0; | 555 | write_mode = WRITE_FORCE; |
455 | } | 556 | } |
456 | 557 | ||
457 | flags = O_CREAT|O_RDWR; | 558 | flags = O_CREAT|O_RDWR; |
458 | if (append_file) | 559 | if (write_mode == WRITE_APPEND) |
459 | file_new = 0; | 560 | file_new = 0; |
460 | else | 561 | else |
461 | flags |= O_TRUNC; | 562 | flags |= O_TRUNC; |
462 | 563 | ||
463 | output = open(output_name, flags, S_IRUSR|S_IWUSR); | 564 | if (pipe_output) |
565 | output = STDOUT_FILENO; | ||
566 | else | ||
567 | output = open(output_name, flags, S_IRUSR | S_IWUSR); | ||
464 | if (output < 0) { | 568 | if (output < 0) { |
465 | perror("failed to create output file"); | 569 | perror("failed to create output file"); |
466 | exit(-1); | 570 | exit(-1); |
467 | } | 571 | } |
468 | 572 | ||
469 | session = perf_session__new(output_name, O_WRONLY, force); | 573 | session = perf_session__new(output_name, O_WRONLY, |
574 | write_mode == WRITE_FORCE, false); | ||
470 | if (session == NULL) { | 575 | if (session == NULL) { |
471 | pr_err("Not enough memory for reading perf file header\n"); | 576 | pr_err("Not enough memory for reading perf file header\n"); |
472 | return -1; | 577 | return -1; |
473 | } | 578 | } |
474 | 579 | ||
475 | if (!file_new) { | 580 | if (!file_new) { |
476 | err = perf_header__read(&session->header, output); | 581 | err = perf_header__read(session, output); |
477 | if (err < 0) | 582 | if (err < 0) |
478 | return err; | 583 | return err; |
479 | } | 584 | } |
480 | 585 | ||
481 | if (raw_samples) { | 586 | if (have_tracepoints(attrs, nr_counters)) |
482 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); | 587 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); |
483 | } else { | ||
484 | for (i = 0; i < nr_counters; i++) { | ||
485 | if (attrs[i].sample_type & PERF_SAMPLE_RAW) { | ||
486 | perf_header__set_feat(&session->header, HEADER_TRACE_INFO); | ||
487 | break; | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | 588 | ||
492 | atexit(atexit_header); | 589 | atexit(atexit_header); |
493 | 590 | ||
494 | if (forks) { | 591 | if (forks) { |
495 | pid = fork(); | 592 | child_pid = fork(); |
496 | if (pid < 0) { | 593 | if (pid < 0) { |
497 | perror("failed to fork"); | 594 | perror("failed to fork"); |
498 | exit(-1); | 595 | exit(-1); |
499 | } | 596 | } |
500 | 597 | ||
501 | if (!pid) { | 598 | if (!child_pid) { |
599 | if (pipe_output) | ||
600 | dup2(2, 1); | ||
502 | close(child_ready_pipe[0]); | 601 | close(child_ready_pipe[0]); |
503 | close(go_pipe[1]); | 602 | close(go_pipe[1]); |
504 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 603 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -527,10 +626,8 @@ static int __cmd_record(int argc, const char **argv) | |||
527 | exit(-1); | 626 | exit(-1); |
528 | } | 627 | } |
529 | 628 | ||
530 | child_pid = pid; | 629 | if (!system_wide && target_tid == -1 && target_pid == -1) |
531 | 630 | all_tids[0] = child_pid; | |
532 | if (!system_wide) | ||
533 | target_pid = pid; | ||
534 | 631 | ||
535 | close(child_ready_pipe[1]); | 632 | close(child_ready_pipe[1]); |
536 | close(go_pipe[0]); | 633 | close(go_pipe[0]); |
@@ -544,16 +641,19 @@ static int __cmd_record(int argc, const char **argv) | |||
544 | close(child_ready_pipe[0]); | 641 | close(child_ready_pipe[0]); |
545 | } | 642 | } |
546 | 643 | ||
547 | 644 | if ((!system_wide && no_inherit) || profile_cpu != -1) { | |
548 | if ((!system_wide && !inherit) || profile_cpu != -1) { | 645 | open_counters(profile_cpu); |
549 | open_counters(profile_cpu, target_pid); | ||
550 | } else { | 646 | } else { |
551 | nr_cpus = read_cpu_map(); | 647 | nr_cpus = read_cpu_map(); |
552 | for (i = 0; i < nr_cpus; i++) | 648 | for (i = 0; i < nr_cpus; i++) |
553 | open_counters(cpumap[i], target_pid); | 649 | open_counters(cpumap[i]); |
554 | } | 650 | } |
555 | 651 | ||
556 | if (file_new) { | 652 | if (pipe_output) { |
653 | err = perf_header__write_pipe(output); | ||
654 | if (err < 0) | ||
655 | return err; | ||
656 | } else if (file_new) { | ||
557 | err = perf_header__write(&session->header, output, false); | 657 | err = perf_header__write(&session->header, output, false); |
558 | if (err < 0) | 658 | if (err < 0) |
559 | return err; | 659 | return err; |
@@ -561,21 +661,70 @@ static int __cmd_record(int argc, const char **argv) | |||
561 | 661 | ||
562 | post_processing_offset = lseek(output, 0, SEEK_CUR); | 662 | post_processing_offset = lseek(output, 0, SEEK_CUR); |
563 | 663 | ||
664 | if (pipe_output) { | ||
665 | err = event__synthesize_attrs(&session->header, | ||
666 | process_synthesized_event, | ||
667 | session); | ||
668 | if (err < 0) { | ||
669 | pr_err("Couldn't synthesize attrs.\n"); | ||
670 | return err; | ||
671 | } | ||
672 | |||
673 | err = event__synthesize_event_types(process_synthesized_event, | ||
674 | session); | ||
675 | if (err < 0) { | ||
676 | pr_err("Couldn't synthesize event_types.\n"); | ||
677 | return err; | ||
678 | } | ||
679 | |||
680 | if (have_tracepoints(attrs, nr_counters)) { | ||
681 | /* | ||
682 | * FIXME err <= 0 here actually means that | ||
683 | * there were no tracepoints so its not really | ||
684 | * an error, just that we don't need to | ||
685 | * synthesize anything. We really have to | ||
686 | * return this more properly and also | ||
687 | * propagate errors that now are calling die() | ||
688 | */ | ||
689 | err = event__synthesize_tracing_data(output, attrs, | ||
690 | nr_counters, | ||
691 | process_synthesized_event, | ||
692 | session); | ||
693 | if (err <= 0) { | ||
694 | pr_err("Couldn't record tracing data.\n"); | ||
695 | return err; | ||
696 | } | ||
697 | advance_output(err); | ||
698 | } | ||
699 | } | ||
700 | |||
701 | machine = perf_session__find_host_machine(session); | ||
702 | if (!machine) { | ||
703 | pr_err("Couldn't find native kernel information.\n"); | ||
704 | return -1; | ||
705 | } | ||
706 | |||
564 | err = event__synthesize_kernel_mmap(process_synthesized_event, | 707 | err = event__synthesize_kernel_mmap(process_synthesized_event, |
565 | session, "_text"); | 708 | session, machine, "_text"); |
709 | if (err < 0) | ||
710 | err = event__synthesize_kernel_mmap(process_synthesized_event, | ||
711 | session, machine, "_stext"); | ||
566 | if (err < 0) { | 712 | if (err < 0) { |
567 | pr_err("Couldn't record kernel reference relocation symbol.\n"); | 713 | pr_err("Couldn't record kernel reference relocation symbol.\n"); |
568 | return err; | 714 | return err; |
569 | } | 715 | } |
570 | 716 | ||
571 | err = event__synthesize_modules(process_synthesized_event, session); | 717 | err = event__synthesize_modules(process_synthesized_event, |
718 | session, machine); | ||
572 | if (err < 0) { | 719 | if (err < 0) { |
573 | pr_err("Couldn't record kernel reference relocation symbol.\n"); | 720 | pr_err("Couldn't record kernel reference relocation symbol.\n"); |
574 | return err; | 721 | return err; |
575 | } | 722 | } |
723 | if (perf_guest) | ||
724 | perf_session__process_machines(session, event__synthesize_guest_os); | ||
576 | 725 | ||
577 | if (!system_wide && profile_cpu == -1) | 726 | if (!system_wide && profile_cpu == -1) |
578 | event__synthesize_thread(target_pid, process_synthesized_event, | 727 | event__synthesize_thread(target_tid, process_synthesized_event, |
579 | session); | 728 | session); |
580 | else | 729 | else |
581 | event__synthesize_threads(process_synthesized_event, session); | 730 | event__synthesize_threads(process_synthesized_event, session); |
@@ -598,13 +747,9 @@ static int __cmd_record(int argc, const char **argv) | |||
598 | 747 | ||
599 | for (;;) { | 748 | for (;;) { |
600 | int hits = samples; | 749 | int hits = samples; |
750 | int thread; | ||
601 | 751 | ||
602 | for (i = 0; i < nr_cpu; i++) { | 752 | mmap_read_all(); |
603 | for (counter = 0; counter < nr_counters; counter++) { | ||
604 | if (mmap_array[i][counter].base) | ||
605 | mmap_read(&mmap_array[i][counter]); | ||
606 | } | ||
607 | } | ||
608 | 753 | ||
609 | if (hits == samples) { | 754 | if (hits == samples) { |
610 | if (done) | 755 | if (done) |
@@ -615,8 +760,15 @@ static int __cmd_record(int argc, const char **argv) | |||
615 | 760 | ||
616 | if (done) { | 761 | if (done) { |
617 | for (i = 0; i < nr_cpu; i++) { | 762 | for (i = 0; i < nr_cpu; i++) { |
618 | for (counter = 0; counter < nr_counters; counter++) | 763 | for (counter = 0; |
619 | ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE); | 764 | counter < nr_counters; |
765 | counter++) { | ||
766 | for (thread = 0; | ||
767 | thread < thread_num; | ||
768 | thread++) | ||
769 | ioctl(fd[i][counter][thread], | ||
770 | PERF_EVENT_IOC_DISABLE); | ||
771 | } | ||
620 | } | 772 | } |
621 | } | 773 | } |
622 | } | 774 | } |
@@ -641,6 +793,8 @@ static const char * const record_usage[] = { | |||
641 | NULL | 793 | NULL |
642 | }; | 794 | }; |
643 | 795 | ||
796 | static bool force, append_file; | ||
797 | |||
644 | static const struct option options[] = { | 798 | static const struct option options[] = { |
645 | OPT_CALLBACK('e', "event", NULL, "event", | 799 | OPT_CALLBACK('e', "event", NULL, "event", |
646 | "event selector. use 'perf list' to list available events", | 800 | "event selector. use 'perf list' to list available events", |
@@ -648,7 +802,9 @@ static const struct option options[] = { | |||
648 | OPT_CALLBACK(0, "filter", NULL, "filter", | 802 | OPT_CALLBACK(0, "filter", NULL, "filter", |
649 | "event filter", parse_filter), | 803 | "event filter", parse_filter), |
650 | OPT_INTEGER('p', "pid", &target_pid, | 804 | OPT_INTEGER('p', "pid", &target_pid, |
651 | "record events on existing pid"), | 805 | "record events on existing process id"), |
806 | OPT_INTEGER('t', "tid", &target_tid, | ||
807 | "record events on existing thread id"), | ||
652 | OPT_INTEGER('r', "realtime", &realtime_prio, | 808 | OPT_INTEGER('r', "realtime", &realtime_prio, |
653 | "collect data with this RT SCHED_FIFO priority"), | 809 | "collect data with this RT SCHED_FIFO priority"), |
654 | OPT_BOOLEAN('R', "raw-samples", &raw_samples, | 810 | OPT_BOOLEAN('R', "raw-samples", &raw_samples, |
@@ -660,20 +816,17 @@ static const struct option options[] = { | |||
660 | OPT_INTEGER('C', "profile_cpu", &profile_cpu, | 816 | OPT_INTEGER('C', "profile_cpu", &profile_cpu, |
661 | "CPU to profile on"), | 817 | "CPU to profile on"), |
662 | OPT_BOOLEAN('f', "force", &force, | 818 | OPT_BOOLEAN('f', "force", &force, |
663 | "overwrite existing data file"), | 819 | "overwrite existing data file (deprecated)"), |
664 | OPT_LONG('c', "count", &default_interval, | 820 | OPT_U64('c', "count", &user_interval, "event period to sample"), |
665 | "event period to sample"), | ||
666 | OPT_STRING('o', "output", &output_name, "file", | 821 | OPT_STRING('o', "output", &output_name, "file", |
667 | "output file name"), | 822 | "output file name"), |
668 | OPT_BOOLEAN('i', "inherit", &inherit, | 823 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, |
669 | "child tasks inherit counters"), | 824 | "child tasks do not inherit counters"), |
670 | OPT_INTEGER('F', "freq", &freq, | 825 | OPT_UINTEGER('F', "freq", &user_freq, "profile at this frequency"), |
671 | "profile at this frequency"), | 826 | OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), |
672 | OPT_INTEGER('m', "mmap-pages", &mmap_pages, | ||
673 | "number of mmap data pages"), | ||
674 | OPT_BOOLEAN('g', "call-graph", &call_graph, | 827 | OPT_BOOLEAN('g', "call-graph", &call_graph, |
675 | "do call-graph (stack chain/backtrace) recording"), | 828 | "do call-graph (stack chain/backtrace) recording"), |
676 | OPT_BOOLEAN('v', "verbose", &verbose, | 829 | OPT_INCR('v', "verbose", &verbose, |
677 | "be more verbose (show counter open errors, etc)"), | 830 | "be more verbose (show counter open errors, etc)"), |
678 | OPT_BOOLEAN('s', "stat", &inherit_stat, | 831 | OPT_BOOLEAN('s', "stat", &inherit_stat, |
679 | "per thread counts"), | 832 | "per thread counts"), |
@@ -688,13 +841,24 @@ static const struct option options[] = { | |||
688 | 841 | ||
689 | int cmd_record(int argc, const char **argv, const char *prefix __used) | 842 | int cmd_record(int argc, const char **argv, const char *prefix __used) |
690 | { | 843 | { |
691 | int counter; | 844 | int i,j; |
692 | 845 | ||
693 | argc = parse_options(argc, argv, options, record_usage, | 846 | argc = parse_options(argc, argv, options, record_usage, |
694 | PARSE_OPT_STOP_AT_NON_OPTION); | 847 | PARSE_OPT_STOP_AT_NON_OPTION); |
695 | if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1) | 848 | if (!argc && target_pid == -1 && target_tid == -1 && |
849 | !system_wide && profile_cpu == -1) | ||
696 | usage_with_options(record_usage, options); | 850 | usage_with_options(record_usage, options); |
697 | 851 | ||
852 | if (force && append_file) { | ||
853 | fprintf(stderr, "Can't overwrite and append at the same time." | ||
854 | " You need to choose between -f and -A"); | ||
855 | usage_with_options(record_usage, options); | ||
856 | } else if (append_file) { | ||
857 | write_mode = WRITE_APPEND; | ||
858 | } else { | ||
859 | write_mode = WRITE_FORCE; | ||
860 | } | ||
861 | |||
698 | symbol__init(); | 862 | symbol__init(); |
699 | 863 | ||
700 | if (!nr_counters) { | 864 | if (!nr_counters) { |
@@ -703,6 +867,42 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
703 | attrs[0].config = PERF_COUNT_HW_CPU_CYCLES; | 867 | attrs[0].config = PERF_COUNT_HW_CPU_CYCLES; |
704 | } | 868 | } |
705 | 869 | ||
870 | if (target_pid != -1) { | ||
871 | target_tid = target_pid; | ||
872 | thread_num = find_all_tid(target_pid, &all_tids); | ||
873 | if (thread_num <= 0) { | ||
874 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
875 | target_pid); | ||
876 | usage_with_options(record_usage, options); | ||
877 | } | ||
878 | } else { | ||
879 | all_tids=malloc(sizeof(pid_t)); | ||
880 | if (!all_tids) | ||
881 | return -ENOMEM; | ||
882 | |||
883 | all_tids[0] = target_tid; | ||
884 | thread_num = 1; | ||
885 | } | ||
886 | |||
887 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
888 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
889 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
890 | mmap_array[i][j] = zalloc( | ||
891 | sizeof(struct mmap_data)*thread_num); | ||
892 | if (!fd[i][j] || !mmap_array[i][j]) | ||
893 | return -ENOMEM; | ||
894 | } | ||
895 | } | ||
896 | event_array = malloc( | ||
897 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); | ||
898 | if (!event_array) | ||
899 | return -ENOMEM; | ||
900 | |||
901 | if (user_interval != ULLONG_MAX) | ||
902 | default_interval = user_interval; | ||
903 | if (user_freq != UINT_MAX) | ||
904 | freq = user_freq; | ||
905 | |||
706 | /* | 906 | /* |
707 | * User specified count overrides default frequency. | 907 | * User specified count overrides default frequency. |
708 | */ | 908 | */ |
@@ -715,12 +915,5 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) | |||
715 | exit(EXIT_FAILURE); | 915 | exit(EXIT_FAILURE); |
716 | } | 916 | } |
717 | 917 | ||
718 | for (counter = 0; counter < nr_counters; counter++) { | ||
719 | if (attrs[counter].sample_period) | ||
720 | continue; | ||
721 | |||
722 | attrs[counter].sample_period = default_interval; | ||
723 | } | ||
724 | |||
725 | return __cmd_record(argc, argv); | 918 | return __cmd_record(argc, argv); |
726 | } | 919 | } |
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index f815de25d0fc..1d3c1003b43a 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c | |||
@@ -14,7 +14,6 @@ | |||
14 | #include "util/cache.h" | 14 | #include "util/cache.h" |
15 | #include <linux/rbtree.h> | 15 | #include <linux/rbtree.h> |
16 | #include "util/symbol.h" | 16 | #include "util/symbol.h" |
17 | #include "util/string.h" | ||
18 | #include "util/callchain.h" | 17 | #include "util/callchain.h" |
19 | #include "util/strlist.h" | 18 | #include "util/strlist.h" |
20 | #include "util/values.h" | 19 | #include "util/values.h" |
@@ -33,28 +32,29 @@ | |||
33 | 32 | ||
34 | static char const *input_name = "perf.data"; | 33 | static char const *input_name = "perf.data"; |
35 | 34 | ||
36 | static int force; | 35 | static bool force; |
37 | static bool hide_unresolved; | 36 | static bool hide_unresolved; |
38 | static bool dont_use_callchains; | 37 | static bool dont_use_callchains; |
39 | 38 | ||
40 | static int show_threads; | 39 | static bool show_threads; |
41 | static struct perf_read_values show_threads_values; | 40 | static struct perf_read_values show_threads_values; |
42 | 41 | ||
43 | static char default_pretty_printing_style[] = "normal"; | 42 | static const char default_pretty_printing_style[] = "normal"; |
44 | static char *pretty_printing_style = default_pretty_printing_style; | 43 | static const char *pretty_printing_style = default_pretty_printing_style; |
45 | 44 | ||
46 | static char callchain_default_opt[] = "fractal,0.5"; | 45 | static char callchain_default_opt[] = "fractal,0.5"; |
47 | 46 | ||
48 | static struct event_stat_id *get_stats(struct perf_session *self, | 47 | static struct hists *perf_session__hists_findnew(struct perf_session *self, |
49 | u64 event_stream, u32 type, u64 config) | 48 | u64 event_stream, u32 type, |
49 | u64 config) | ||
50 | { | 50 | { |
51 | struct rb_node **p = &self->stats_by_id.rb_node; | 51 | struct rb_node **p = &self->hists_tree.rb_node; |
52 | struct rb_node *parent = NULL; | 52 | struct rb_node *parent = NULL; |
53 | struct event_stat_id *iter, *new; | 53 | struct hists *iter, *new; |
54 | 54 | ||
55 | while (*p != NULL) { | 55 | while (*p != NULL) { |
56 | parent = *p; | 56 | parent = *p; |
57 | iter = rb_entry(parent, struct event_stat_id, rb_node); | 57 | iter = rb_entry(parent, struct hists, rb_node); |
58 | if (iter->config == config) | 58 | if (iter->config == config) |
59 | return iter; | 59 | return iter; |
60 | 60 | ||
@@ -65,15 +65,15 @@ static struct event_stat_id *get_stats(struct perf_session *self, | |||
65 | p = &(*p)->rb_left; | 65 | p = &(*p)->rb_left; |
66 | } | 66 | } |
67 | 67 | ||
68 | new = malloc(sizeof(struct event_stat_id)); | 68 | new = malloc(sizeof(struct hists)); |
69 | if (new == NULL) | 69 | if (new == NULL) |
70 | return NULL; | 70 | return NULL; |
71 | memset(new, 0, sizeof(struct event_stat_id)); | 71 | memset(new, 0, sizeof(struct hists)); |
72 | new->event_stream = event_stream; | 72 | new->event_stream = event_stream; |
73 | new->config = config; | 73 | new->config = config; |
74 | new->type = type; | 74 | new->type = type; |
75 | rb_link_node(&new->rb_node, parent, p); | 75 | rb_link_node(&new->rb_node, parent, p); |
76 | rb_insert_color(&new->rb_node, &self->stats_by_id); | 76 | rb_insert_color(&new->rb_node, &self->hists_tree); |
77 | return new; | 77 | return new; |
78 | } | 78 | } |
79 | 79 | ||
@@ -81,70 +81,71 @@ static int perf_session__add_hist_entry(struct perf_session *self, | |||
81 | struct addr_location *al, | 81 | struct addr_location *al, |
82 | struct sample_data *data) | 82 | struct sample_data *data) |
83 | { | 83 | { |
84 | struct symbol **syms = NULL, *parent = NULL; | 84 | struct map_symbol *syms = NULL; |
85 | bool hit; | 85 | struct symbol *parent = NULL; |
86 | int err = -ENOMEM; | ||
86 | struct hist_entry *he; | 87 | struct hist_entry *he; |
87 | struct event_stat_id *stats; | 88 | struct hists *hists; |
88 | struct perf_event_attr *attr; | 89 | struct perf_event_attr *attr; |
89 | 90 | ||
90 | if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain) | 91 | if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain) { |
91 | syms = perf_session__resolve_callchain(self, al->thread, | 92 | syms = perf_session__resolve_callchain(self, al->thread, |
92 | data->callchain, &parent); | 93 | data->callchain, &parent); |
94 | if (syms == NULL) | ||
95 | return -ENOMEM; | ||
96 | } | ||
93 | 97 | ||
94 | attr = perf_header__find_attr(data->id, &self->header); | 98 | attr = perf_header__find_attr(data->id, &self->header); |
95 | if (attr) | 99 | if (attr) |
96 | stats = get_stats(self, data->id, attr->type, attr->config); | 100 | hists = perf_session__hists_findnew(self, data->id, attr->type, attr->config); |
97 | else | 101 | else |
98 | stats = get_stats(self, data->id, 0, 0); | 102 | hists = perf_session__hists_findnew(self, data->id, 0, 0); |
99 | if (stats == NULL) | 103 | if (hists == NULL) |
100 | return -ENOMEM; | 104 | goto out_free_syms; |
101 | he = __perf_session__add_hist_entry(&stats->hists, al, parent, | 105 | he = __hists__add_entry(hists, al, parent, data->period); |
102 | data->period, &hit); | ||
103 | if (he == NULL) | 106 | if (he == NULL) |
104 | return -ENOMEM; | 107 | goto out_free_syms; |
105 | 108 | err = 0; | |
106 | if (hit) | ||
107 | he->count += data->period; | ||
108 | |||
109 | if (symbol_conf.use_callchain) { | 109 | if (symbol_conf.use_callchain) { |
110 | if (!hit) | 110 | err = append_chain(he->callchain, data->callchain, syms); |
111 | callchain_init(&he->callchain); | 111 | if (err) |
112 | append_chain(&he->callchain, data->callchain, syms); | 112 | goto out_free_syms; |
113 | free(syms); | ||
114 | } | 113 | } |
115 | 114 | /* | |
116 | return 0; | 115 | * Only in the newt browser we are doing integrated annotation, |
117 | } | 116 | * so we don't allocated the extra space needed because the stdio |
118 | 117 | * code will not use it. | |
119 | static int validate_chain(struct ip_callchain *chain, event_t *event) | 118 | */ |
120 | { | 119 | if (use_browser) |
121 | unsigned int chain_size; | 120 | err = hist_entry__inc_addr_samples(he, al->addr); |
122 | 121 | out_free_syms: | |
123 | chain_size = event->header.size; | 122 | free(syms); |
124 | chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event; | 123 | return err; |
125 | |||
126 | if (chain->nr*sizeof(u64) > chain_size) | ||
127 | return -1; | ||
128 | |||
129 | return 0; | ||
130 | } | 124 | } |
131 | 125 | ||
132 | static int add_event_total(struct perf_session *session, | 126 | static int add_event_total(struct perf_session *session, |
133 | struct sample_data *data, | 127 | struct sample_data *data, |
134 | struct perf_event_attr *attr) | 128 | struct perf_event_attr *attr) |
135 | { | 129 | { |
136 | struct event_stat_id *stats; | 130 | struct hists *hists; |
137 | 131 | ||
138 | if (attr) | 132 | if (attr) |
139 | stats = get_stats(session, data->id, attr->type, attr->config); | 133 | hists = perf_session__hists_findnew(session, data->id, |
134 | attr->type, attr->config); | ||
140 | else | 135 | else |
141 | stats = get_stats(session, data->id, 0, 0); | 136 | hists = perf_session__hists_findnew(session, data->id, 0, 0); |
142 | 137 | ||
143 | if (!stats) | 138 | if (!hists) |
144 | return -ENOMEM; | 139 | return -ENOMEM; |
145 | 140 | ||
146 | stats->stats.total += data->period; | 141 | hists->stats.total_period += data->period; |
147 | session->events_stats.total += data->period; | 142 | /* |
143 | * FIXME: add_event_total should be moved from here to | ||
144 | * perf_session__process_event so that the proper hist is passed to | ||
145 | * the event_op methods. | ||
146 | */ | ||
147 | hists__inc_nr_events(hists, PERF_RECORD_SAMPLE); | ||
148 | session->hists.stats.total_period += data->period; | ||
148 | return 0; | 149 | return 0; |
149 | } | 150 | } |
150 | 151 | ||
@@ -164,7 +165,7 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
164 | 165 | ||
165 | dump_printf("... chain: nr:%Lu\n", data.callchain->nr); | 166 | dump_printf("... chain: nr:%Lu\n", data.callchain->nr); |
166 | 167 | ||
167 | if (validate_chain(data.callchain, event) < 0) { | 168 | if (!ip_callchain__valid(data.callchain, event)) { |
168 | pr_debug("call-chain problem with event, " | 169 | pr_debug("call-chain problem with event, " |
169 | "skipping it.\n"); | 170 | "skipping it.\n"); |
170 | return 0; | 171 | return 0; |
@@ -187,14 +188,14 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
187 | return 0; | 188 | return 0; |
188 | 189 | ||
189 | if (perf_session__add_hist_entry(session, &al, &data)) { | 190 | if (perf_session__add_hist_entry(session, &al, &data)) { |
190 | pr_debug("problem incrementing symbol count, skipping event\n"); | 191 | pr_debug("problem incrementing symbol period, skipping event\n"); |
191 | return -1; | 192 | return -1; |
192 | } | 193 | } |
193 | 194 | ||
194 | attr = perf_header__find_attr(data.id, &session->header); | 195 | attr = perf_header__find_attr(data.id, &session->header); |
195 | 196 | ||
196 | if (add_event_total(session, &data, attr)) { | 197 | if (add_event_total(session, &data, attr)) { |
197 | pr_debug("problem adding event count\n"); | 198 | pr_debug("problem adding event period\n"); |
198 | return -1; | 199 | return -1; |
199 | } | 200 | } |
200 | 201 | ||
@@ -260,15 +261,43 @@ static struct perf_event_ops event_ops = { | |||
260 | .fork = event__process_task, | 261 | .fork = event__process_task, |
261 | .lost = event__process_lost, | 262 | .lost = event__process_lost, |
262 | .read = process_read_event, | 263 | .read = process_read_event, |
264 | .attr = event__process_attr, | ||
265 | .event_type = event__process_event_type, | ||
266 | .tracing_data = event__process_tracing_data, | ||
267 | .build_id = event__process_build_id, | ||
263 | }; | 268 | }; |
264 | 269 | ||
270 | extern volatile int session_done; | ||
271 | |||
272 | static void sig_handler(int sig __used) | ||
273 | { | ||
274 | session_done = 1; | ||
275 | } | ||
276 | |||
277 | static size_t hists__fprintf_nr_sample_events(struct hists *self, | ||
278 | const char *evname, FILE *fp) | ||
279 | { | ||
280 | size_t ret; | ||
281 | char unit; | ||
282 | unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE]; | ||
283 | |||
284 | nr_events = convert_unit(nr_events, &unit); | ||
285 | ret = fprintf(fp, "# Events: %lu%c", nr_events, unit); | ||
286 | if (evname != NULL) | ||
287 | ret += fprintf(fp, " %s", evname); | ||
288 | return ret + fprintf(fp, "\n#\n"); | ||
289 | } | ||
290 | |||
265 | static int __cmd_report(void) | 291 | static int __cmd_report(void) |
266 | { | 292 | { |
267 | int ret = -EINVAL; | 293 | int ret = -EINVAL; |
268 | struct perf_session *session; | 294 | struct perf_session *session; |
269 | struct rb_node *next; | 295 | struct rb_node *next; |
296 | const char *help = "For a higher level overview, try: perf report --sort comm,dso"; | ||
297 | |||
298 | signal(SIGINT, sig_handler); | ||
270 | 299 | ||
271 | session = perf_session__new(input_name, O_RDONLY, force); | 300 | session = perf_session__new(input_name, O_RDONLY, force, false); |
272 | if (session == NULL) | 301 | if (session == NULL) |
273 | return -ENOMEM; | 302 | return -ENOMEM; |
274 | 303 | ||
@@ -284,7 +313,7 @@ static int __cmd_report(void) | |||
284 | goto out_delete; | 313 | goto out_delete; |
285 | 314 | ||
286 | if (dump_trace) { | 315 | if (dump_trace) { |
287 | event__print_totals(); | 316 | perf_session__fprintf_nr_events(session, stdout); |
288 | goto out_delete; | 317 | goto out_delete; |
289 | } | 318 | } |
290 | 319 | ||
@@ -292,39 +321,42 @@ static int __cmd_report(void) | |||
292 | perf_session__fprintf(session, stdout); | 321 | perf_session__fprintf(session, stdout); |
293 | 322 | ||
294 | if (verbose > 2) | 323 | if (verbose > 2) |
295 | dsos__fprintf(stdout); | 324 | perf_session__fprintf_dsos(session, stdout); |
296 | 325 | ||
297 | next = rb_first(&session->stats_by_id); | 326 | next = rb_first(&session->hists_tree); |
298 | while (next) { | 327 | while (next) { |
299 | struct event_stat_id *stats; | 328 | struct hists *hists; |
300 | 329 | ||
301 | stats = rb_entry(next, struct event_stat_id, rb_node); | 330 | hists = rb_entry(next, struct hists, rb_node); |
302 | perf_session__collapse_resort(&stats->hists); | 331 | hists__collapse_resort(hists); |
303 | perf_session__output_resort(&stats->hists, stats->stats.total); | 332 | hists__output_resort(hists); |
304 | if (rb_first(&session->stats_by_id) == | 333 | if (use_browser) |
305 | rb_last(&session->stats_by_id)) | 334 | hists__browse(hists, help, input_name); |
306 | fprintf(stdout, "# Samples: %Ld\n#\n", | 335 | else { |
307 | stats->stats.total); | 336 | const char *evname = NULL; |
308 | else | 337 | if (rb_first(&session->hists.entries) != |
309 | fprintf(stdout, "# Samples: %Ld %s\n#\n", | 338 | rb_last(&session->hists.entries)) |
310 | stats->stats.total, | 339 | evname = __event_name(hists->type, hists->config); |
311 | __event_name(stats->type, stats->config)); | 340 | |
312 | 341 | hists__fprintf_nr_sample_events(hists, evname, stdout); | |
313 | perf_session__fprintf_hists(&stats->hists, NULL, false, stdout, | 342 | |
314 | stats->stats.total); | 343 | hists__fprintf(hists, NULL, false, stdout); |
315 | fprintf(stdout, "\n\n"); | 344 | fprintf(stdout, "\n\n"); |
316 | next = rb_next(&stats->rb_node); | 345 | } |
346 | |||
347 | next = rb_next(&hists->rb_node); | ||
317 | } | 348 | } |
318 | 349 | ||
319 | if (sort_order == default_sort_order && | 350 | if (!use_browser && sort_order == default_sort_order && |
320 | parent_pattern == default_parent_pattern) | 351 | parent_pattern == default_parent_pattern) { |
321 | fprintf(stdout, "#\n# (For a higher level overview, try: perf report --sort comm,dso)\n#\n"); | 352 | fprintf(stdout, "#\n# (%s)\n#\n", help); |
322 | 353 | ||
323 | if (show_threads) { | 354 | if (show_threads) { |
324 | bool raw_printing_style = !strcmp(pretty_printing_style, "raw"); | 355 | bool style = !strcmp(pretty_printing_style, "raw"); |
325 | perf_read_values_display(stdout, &show_threads_values, | 356 | perf_read_values_display(stdout, &show_threads_values, |
326 | raw_printing_style); | 357 | style); |
327 | perf_read_values_destroy(&show_threads_values); | 358 | perf_read_values_destroy(&show_threads_values); |
359 | } | ||
328 | } | 360 | } |
329 | out_delete: | 361 | out_delete: |
330 | perf_session__delete(session); | 362 | perf_session__delete(session); |
@@ -335,7 +367,7 @@ static int | |||
335 | parse_callchain_opt(const struct option *opt __used, const char *arg, | 367 | parse_callchain_opt(const struct option *opt __used, const char *arg, |
336 | int unset) | 368 | int unset) |
337 | { | 369 | { |
338 | char *tok; | 370 | char *tok, *tok2; |
339 | char *endptr; | 371 | char *endptr; |
340 | 372 | ||
341 | /* | 373 | /* |
@@ -380,10 +412,13 @@ parse_callchain_opt(const struct option *opt __used, const char *arg, | |||
380 | if (!tok) | 412 | if (!tok) |
381 | goto setup; | 413 | goto setup; |
382 | 414 | ||
415 | tok2 = strtok(NULL, ","); | ||
383 | callchain_param.min_percent = strtod(tok, &endptr); | 416 | callchain_param.min_percent = strtod(tok, &endptr); |
384 | if (tok == endptr) | 417 | if (tok == endptr) |
385 | return -1; | 418 | return -1; |
386 | 419 | ||
420 | if (tok2) | ||
421 | callchain_param.print_limit = strtod(tok2, &endptr); | ||
387 | setup: | 422 | setup: |
388 | if (register_callchain_param(&callchain_param) < 0) { | 423 | if (register_callchain_param(&callchain_param) < 0) { |
389 | fprintf(stderr, "Can't register callchain params\n"); | 424 | fprintf(stderr, "Can't register callchain params\n"); |
@@ -400,7 +435,7 @@ static const char * const report_usage[] = { | |||
400 | static const struct option options[] = { | 435 | static const struct option options[] = { |
401 | OPT_STRING('i', "input", &input_name, "file", | 436 | OPT_STRING('i', "input", &input_name, "file", |
402 | "input file name"), | 437 | "input file name"), |
403 | OPT_BOOLEAN('v', "verbose", &verbose, | 438 | OPT_INCR('v', "verbose", &verbose, |
404 | "be more verbose (show symbol address, etc)"), | 439 | "be more verbose (show symbol address, etc)"), |
405 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 440 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
406 | "dump raw trace in ASCII"), | 441 | "dump raw trace in ASCII"), |
@@ -419,12 +454,14 @@ static const struct option options[] = { | |||
419 | "sort by key(s): pid, comm, dso, symbol, parent"), | 454 | "sort by key(s): pid, comm, dso, symbol, parent"), |
420 | OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths, | 455 | OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths, |
421 | "Don't shorten the pathnames taking into account the cwd"), | 456 | "Don't shorten the pathnames taking into account the cwd"), |
457 | OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization, | ||
458 | "Show sample percentage for different cpu modes"), | ||
422 | OPT_STRING('p', "parent", &parent_pattern, "regex", | 459 | OPT_STRING('p', "parent", &parent_pattern, "regex", |
423 | "regex filter to identify parent, see: '--sort parent'"), | 460 | "regex filter to identify parent, see: '--sort parent'"), |
424 | OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, | 461 | OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other, |
425 | "Only display entries with parent-match"), | 462 | "Only display entries with parent-match"), |
426 | OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent", | 463 | OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent", |
427 | "Display callchains using output_type and min percent threshold. " | 464 | "Display callchains using output_type (graph, flat, fractal, or none) and min percent threshold. " |
428 | "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt), | 465 | "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt), |
429 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", | 466 | OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]", |
430 | "only consider symbols in these dsos"), | 467 | "only consider symbols in these dsos"), |
@@ -447,7 +484,15 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
447 | { | 484 | { |
448 | argc = parse_options(argc, argv, options, report_usage, 0); | 485 | argc = parse_options(argc, argv, options, report_usage, 0); |
449 | 486 | ||
450 | setup_pager(); | 487 | if (strcmp(input_name, "-") != 0) |
488 | setup_browser(); | ||
489 | /* | ||
490 | * Only in the newt browser we are doing integrated annotation, | ||
491 | * so don't allocate extra space that won't be used in the stdio | ||
492 | * implementation. | ||
493 | */ | ||
494 | if (use_browser) | ||
495 | symbol_conf.priv_size = sizeof(struct sym_priv); | ||
451 | 496 | ||
452 | if (symbol__init() < 0) | 497 | if (symbol__init() < 0) |
453 | return -1; | 498 | return -1; |
@@ -455,7 +500,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used) | |||
455 | setup_sorting(report_usage, options); | 500 | setup_sorting(report_usage, options); |
456 | 501 | ||
457 | if (parent_pattern != default_parent_pattern) { | 502 | if (parent_pattern != default_parent_pattern) { |
458 | sort_dimension__add("parent"); | 503 | if (sort_dimension__add("parent") < 0) |
504 | return -1; | ||
459 | sort_parent.elide = 1; | 505 | sort_parent.elide = 1; |
460 | } else | 506 | } else |
461 | symbol_conf.exclude_other = false; | 507 | symbol_conf.exclude_other = false; |
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 4f5a03e43444..f67bce2a83b4 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -22,7 +22,7 @@ | |||
22 | static char const *input_name = "perf.data"; | 22 | static char const *input_name = "perf.data"; |
23 | 23 | ||
24 | static char default_sort_order[] = "avg, max, switch, runtime"; | 24 | static char default_sort_order[] = "avg, max, switch, runtime"; |
25 | static char *sort_order = default_sort_order; | 25 | static const char *sort_order = default_sort_order; |
26 | 26 | ||
27 | static int profile_cpu = -1; | 27 | static int profile_cpu = -1; |
28 | 28 | ||
@@ -68,10 +68,10 @@ enum sched_event_type { | |||
68 | 68 | ||
69 | struct sched_atom { | 69 | struct sched_atom { |
70 | enum sched_event_type type; | 70 | enum sched_event_type type; |
71 | int specific_wait; | ||
71 | u64 timestamp; | 72 | u64 timestamp; |
72 | u64 duration; | 73 | u64 duration; |
73 | unsigned long nr; | 74 | unsigned long nr; |
74 | int specific_wait; | ||
75 | sem_t *wait_sem; | 75 | sem_t *wait_sem; |
76 | struct task_desc *wakee; | 76 | struct task_desc *wakee; |
77 | }; | 77 | }; |
@@ -105,7 +105,7 @@ static u64 sum_runtime; | |||
105 | static u64 sum_fluct; | 105 | static u64 sum_fluct; |
106 | static u64 run_avg; | 106 | static u64 run_avg; |
107 | 107 | ||
108 | static unsigned long replay_repeat = 10; | 108 | static unsigned int replay_repeat = 10; |
109 | static unsigned long nr_timestamps; | 109 | static unsigned long nr_timestamps; |
110 | static unsigned long nr_unordered_timestamps; | 110 | static unsigned long nr_unordered_timestamps; |
111 | static unsigned long nr_state_machine_bugs; | 111 | static unsigned long nr_state_machine_bugs; |
@@ -1641,30 +1641,26 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
1641 | return 0; | 1641 | return 0; |
1642 | } | 1642 | } |
1643 | 1643 | ||
1644 | static int process_lost_event(event_t *event __used, | ||
1645 | struct perf_session *session __used) | ||
1646 | { | ||
1647 | nr_lost_chunks++; | ||
1648 | nr_lost_events += event->lost.lost; | ||
1649 | |||
1650 | return 0; | ||
1651 | } | ||
1652 | |||
1653 | static struct perf_event_ops event_ops = { | 1644 | static struct perf_event_ops event_ops = { |
1654 | .sample = process_sample_event, | 1645 | .sample = process_sample_event, |
1655 | .comm = event__process_comm, | 1646 | .comm = event__process_comm, |
1656 | .lost = process_lost_event, | 1647 | .lost = event__process_lost, |
1648 | .ordered_samples = true, | ||
1657 | }; | 1649 | }; |
1658 | 1650 | ||
1659 | static int read_events(void) | 1651 | static int read_events(void) |
1660 | { | 1652 | { |
1661 | int err = -EINVAL; | 1653 | int err = -EINVAL; |
1662 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); | 1654 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false); |
1663 | if (session == NULL) | 1655 | if (session == NULL) |
1664 | return -ENOMEM; | 1656 | return -ENOMEM; |
1665 | 1657 | ||
1666 | if (perf_session__has_traces(session, "record -R")) | 1658 | if (perf_session__has_traces(session, "record -R")) { |
1667 | err = perf_session__process_events(session, &event_ops); | 1659 | err = perf_session__process_events(session, &event_ops); |
1660 | nr_events = session->hists.stats.nr_events[0]; | ||
1661 | nr_lost_events = session->hists.stats.total_lost; | ||
1662 | nr_lost_chunks = session->hists.stats.nr_events[PERF_RECORD_LOST]; | ||
1663 | } | ||
1668 | 1664 | ||
1669 | perf_session__delete(session); | 1665 | perf_session__delete(session); |
1670 | return err; | 1666 | return err; |
@@ -1790,7 +1786,7 @@ static const char * const sched_usage[] = { | |||
1790 | static const struct option sched_options[] = { | 1786 | static const struct option sched_options[] = { |
1791 | OPT_STRING('i', "input", &input_name, "file", | 1787 | OPT_STRING('i', "input", &input_name, "file", |
1792 | "input file name"), | 1788 | "input file name"), |
1793 | OPT_BOOLEAN('v', "verbose", &verbose, | 1789 | OPT_INCR('v', "verbose", &verbose, |
1794 | "be more verbose (show symbol address, etc)"), | 1790 | "be more verbose (show symbol address, etc)"), |
1795 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 1791 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1796 | "dump raw trace in ASCII"), | 1792 | "dump raw trace in ASCII"), |
@@ -1805,7 +1801,7 @@ static const char * const latency_usage[] = { | |||
1805 | static const struct option latency_options[] = { | 1801 | static const struct option latency_options[] = { |
1806 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", | 1802 | OPT_STRING('s', "sort", &sort_order, "key[,key2...]", |
1807 | "sort by key(s): runtime, switch, avg, max"), | 1803 | "sort by key(s): runtime, switch, avg, max"), |
1808 | OPT_BOOLEAN('v', "verbose", &verbose, | 1804 | OPT_INCR('v', "verbose", &verbose, |
1809 | "be more verbose (show symbol address, etc)"), | 1805 | "be more verbose (show symbol address, etc)"), |
1810 | OPT_INTEGER('C', "CPU", &profile_cpu, | 1806 | OPT_INTEGER('C', "CPU", &profile_cpu, |
1811 | "CPU to profile on"), | 1807 | "CPU to profile on"), |
@@ -1820,9 +1816,9 @@ static const char * const replay_usage[] = { | |||
1820 | }; | 1816 | }; |
1821 | 1817 | ||
1822 | static const struct option replay_options[] = { | 1818 | static const struct option replay_options[] = { |
1823 | OPT_INTEGER('r', "repeat", &replay_repeat, | 1819 | OPT_UINTEGER('r', "repeat", &replay_repeat, |
1824 | "repeat the workload replay N times (-1: infinite)"), | 1820 | "repeat the workload replay N times (-1: infinite)"), |
1825 | OPT_BOOLEAN('v', "verbose", &verbose, | 1821 | OPT_INCR('v', "verbose", &verbose, |
1826 | "be more verbose (show symbol address, etc)"), | 1822 | "be more verbose (show symbol address, etc)"), |
1827 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 1823 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1828 | "dump raw trace in ASCII"), | 1824 | "dump raw trace in ASCII"), |
@@ -1850,7 +1846,6 @@ static const char *record_args[] = { | |||
1850 | "record", | 1846 | "record", |
1851 | "-a", | 1847 | "-a", |
1852 | "-R", | 1848 | "-R", |
1853 | "-M", | ||
1854 | "-f", | 1849 | "-f", |
1855 | "-m", "1024", | 1850 | "-m", "1024", |
1856 | "-c", "1", | 1851 | "-c", "1", |
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 95db31cff6fd..ff8c413b7e73 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include "util/debug.h" | 46 | #include "util/debug.h" |
47 | #include "util/header.h" | 47 | #include "util/header.h" |
48 | #include "util/cpumap.h" | 48 | #include "util/cpumap.h" |
49 | #include "util/thread.h" | ||
49 | 50 | ||
50 | #include <sys/prctl.h> | 51 | #include <sys/prctl.h> |
51 | #include <math.h> | 52 | #include <math.h> |
@@ -66,18 +67,21 @@ static struct perf_event_attr default_attrs[] = { | |||
66 | 67 | ||
67 | }; | 68 | }; |
68 | 69 | ||
69 | static int system_wide = 0; | 70 | static bool system_wide = false; |
70 | static unsigned int nr_cpus = 0; | 71 | static unsigned int nr_cpus = 0; |
71 | static int run_idx = 0; | 72 | static int run_idx = 0; |
72 | 73 | ||
73 | static int run_count = 1; | 74 | static int run_count = 1; |
74 | static int inherit = 1; | 75 | static bool no_inherit = false; |
75 | static int scale = 1; | 76 | static bool scale = true; |
76 | static pid_t target_pid = -1; | 77 | static pid_t target_pid = -1; |
78 | static pid_t target_tid = -1; | ||
79 | static pid_t *all_tids = NULL; | ||
80 | static int thread_num = 0; | ||
77 | static pid_t child_pid = -1; | 81 | static pid_t child_pid = -1; |
78 | static int null_run = 0; | 82 | static bool null_run = false; |
79 | 83 | ||
80 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 84 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
81 | 85 | ||
82 | static int event_scaled[MAX_COUNTERS]; | 86 | static int event_scaled[MAX_COUNTERS]; |
83 | 87 | ||
@@ -140,9 +144,11 @@ struct stats runtime_branches_stats; | |||
140 | #define ERR_PERF_OPEN \ | 144 | #define ERR_PERF_OPEN \ |
141 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" | 145 | "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n" |
142 | 146 | ||
143 | static void create_perf_stat_counter(int counter, int pid) | 147 | static int create_perf_stat_counter(int counter) |
144 | { | 148 | { |
145 | struct perf_event_attr *attr = attrs + counter; | 149 | struct perf_event_attr *attr = attrs + counter; |
150 | int thread; | ||
151 | int ncreated = 0; | ||
146 | 152 | ||
147 | if (scale) | 153 | if (scale) |
148 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | | 154 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
@@ -152,21 +158,33 @@ static void create_perf_stat_counter(int counter, int pid) | |||
152 | unsigned int cpu; | 158 | unsigned int cpu; |
153 | 159 | ||
154 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 160 | for (cpu = 0; cpu < nr_cpus; cpu++) { |
155 | fd[cpu][counter] = sys_perf_event_open(attr, -1, cpumap[cpu], -1, 0); | 161 | fd[cpu][counter][0] = sys_perf_event_open(attr, |
156 | if (fd[cpu][counter] < 0 && verbose) | 162 | -1, cpumap[cpu], -1, 0); |
157 | fprintf(stderr, ERR_PERF_OPEN, counter, | 163 | if (fd[cpu][counter][0] < 0) |
158 | fd[cpu][counter], strerror(errno)); | 164 | pr_debug(ERR_PERF_OPEN, counter, |
165 | fd[cpu][counter][0], strerror(errno)); | ||
166 | else | ||
167 | ++ncreated; | ||
159 | } | 168 | } |
160 | } else { | 169 | } else { |
161 | attr->inherit = inherit; | 170 | attr->inherit = !no_inherit; |
162 | attr->disabled = 1; | 171 | if (target_pid == -1 && target_tid == -1) { |
163 | attr->enable_on_exec = 1; | 172 | attr->disabled = 1; |
164 | 173 | attr->enable_on_exec = 1; | |
165 | fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0); | 174 | } |
166 | if (fd[0][counter] < 0 && verbose) | 175 | for (thread = 0; thread < thread_num; thread++) { |
167 | fprintf(stderr, ERR_PERF_OPEN, counter, | 176 | fd[0][counter][thread] = sys_perf_event_open(attr, |
168 | fd[0][counter], strerror(errno)); | 177 | all_tids[thread], -1, -1, 0); |
178 | if (fd[0][counter][thread] < 0) | ||
179 | pr_debug(ERR_PERF_OPEN, counter, | ||
180 | fd[0][counter][thread], | ||
181 | strerror(errno)); | ||
182 | else | ||
183 | ++ncreated; | ||
184 | } | ||
169 | } | 185 | } |
186 | |||
187 | return ncreated; | ||
170 | } | 188 | } |
171 | 189 | ||
172 | /* | 190 | /* |
@@ -190,25 +208,28 @@ static void read_counter(int counter) | |||
190 | unsigned int cpu; | 208 | unsigned int cpu; |
191 | size_t res, nv; | 209 | size_t res, nv; |
192 | int scaled; | 210 | int scaled; |
193 | int i; | 211 | int i, thread; |
194 | 212 | ||
195 | count[0] = count[1] = count[2] = 0; | 213 | count[0] = count[1] = count[2] = 0; |
196 | 214 | ||
197 | nv = scale ? 3 : 1; | 215 | nv = scale ? 3 : 1; |
198 | for (cpu = 0; cpu < nr_cpus; cpu++) { | 216 | for (cpu = 0; cpu < nr_cpus; cpu++) { |
199 | if (fd[cpu][counter] < 0) | 217 | for (thread = 0; thread < thread_num; thread++) { |
200 | continue; | 218 | if (fd[cpu][counter][thread] < 0) |
201 | 219 | continue; | |
202 | res = read(fd[cpu][counter], single_count, nv * sizeof(u64)); | 220 | |
203 | assert(res == nv * sizeof(u64)); | 221 | res = read(fd[cpu][counter][thread], |
204 | 222 | single_count, nv * sizeof(u64)); | |
205 | close(fd[cpu][counter]); | 223 | assert(res == nv * sizeof(u64)); |
206 | fd[cpu][counter] = -1; | 224 | |
207 | 225 | close(fd[cpu][counter][thread]); | |
208 | count[0] += single_count[0]; | 226 | fd[cpu][counter][thread] = -1; |
209 | if (scale) { | 227 | |
210 | count[1] += single_count[1]; | 228 | count[0] += single_count[0]; |
211 | count[2] += single_count[2]; | 229 | if (scale) { |
230 | count[1] += single_count[1]; | ||
231 | count[2] += single_count[2]; | ||
232 | } | ||
212 | } | 233 | } |
213 | } | 234 | } |
214 | 235 | ||
@@ -250,10 +271,9 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
250 | { | 271 | { |
251 | unsigned long long t0, t1; | 272 | unsigned long long t0, t1; |
252 | int status = 0; | 273 | int status = 0; |
253 | int counter; | 274 | int counter, ncreated = 0; |
254 | int pid = target_pid; | ||
255 | int child_ready_pipe[2], go_pipe[2]; | 275 | int child_ready_pipe[2], go_pipe[2]; |
256 | const bool forks = (target_pid == -1 && argc > 0); | 276 | const bool forks = (argc > 0); |
257 | char buf; | 277 | char buf; |
258 | 278 | ||
259 | if (!system_wide) | 279 | if (!system_wide) |
@@ -265,10 +285,10 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
265 | } | 285 | } |
266 | 286 | ||
267 | if (forks) { | 287 | if (forks) { |
268 | if ((pid = fork()) < 0) | 288 | if ((child_pid = fork()) < 0) |
269 | perror("failed to fork"); | 289 | perror("failed to fork"); |
270 | 290 | ||
271 | if (!pid) { | 291 | if (!child_pid) { |
272 | close(child_ready_pipe[0]); | 292 | close(child_ready_pipe[0]); |
273 | close(go_pipe[1]); | 293 | close(go_pipe[1]); |
274 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); | 294 | fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC); |
@@ -297,7 +317,8 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
297 | exit(-1); | 317 | exit(-1); |
298 | } | 318 | } |
299 | 319 | ||
300 | child_pid = pid; | 320 | if (target_tid == -1 && target_pid == -1 && !system_wide) |
321 | all_tids[0] = child_pid; | ||
301 | 322 | ||
302 | /* | 323 | /* |
303 | * Wait for the child to be ready to exec. | 324 | * Wait for the child to be ready to exec. |
@@ -310,7 +331,16 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
310 | } | 331 | } |
311 | 332 | ||
312 | for (counter = 0; counter < nr_counters; counter++) | 333 | for (counter = 0; counter < nr_counters; counter++) |
313 | create_perf_stat_counter(counter, pid); | 334 | ncreated += create_perf_stat_counter(counter); |
335 | |||
336 | if (ncreated == 0) { | ||
337 | pr_err("No permission to collect %sstats.\n" | ||
338 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n", | ||
339 | system_wide ? "system-wide " : ""); | ||
340 | if (child_pid != -1) | ||
341 | kill(child_pid, SIGTERM); | ||
342 | return -1; | ||
343 | } | ||
314 | 344 | ||
315 | /* | 345 | /* |
316 | * Enable counters and exec the command: | 346 | * Enable counters and exec the command: |
@@ -321,7 +351,7 @@ static int run_perf_stat(int argc __used, const char **argv) | |||
321 | close(go_pipe[1]); | 351 | close(go_pipe[1]); |
322 | wait(&status); | 352 | wait(&status); |
323 | } else { | 353 | } else { |
324 | while(!done); | 354 | while(!done) sleep(1); |
325 | } | 355 | } |
326 | 356 | ||
327 | t1 = rdclock(); | 357 | t1 = rdclock(); |
@@ -429,12 +459,14 @@ static void print_stat(int argc, const char **argv) | |||
429 | 459 | ||
430 | fprintf(stderr, "\n"); | 460 | fprintf(stderr, "\n"); |
431 | fprintf(stderr, " Performance counter stats for "); | 461 | fprintf(stderr, " Performance counter stats for "); |
432 | if(target_pid == -1) { | 462 | if(target_pid == -1 && target_tid == -1) { |
433 | fprintf(stderr, "\'%s", argv[0]); | 463 | fprintf(stderr, "\'%s", argv[0]); |
434 | for (i = 1; i < argc; i++) | 464 | for (i = 1; i < argc; i++) |
435 | fprintf(stderr, " %s", argv[i]); | 465 | fprintf(stderr, " %s", argv[i]); |
436 | }else | 466 | } else if (target_pid != -1) |
437 | fprintf(stderr, "task pid \'%d", target_pid); | 467 | fprintf(stderr, "process id \'%d", target_pid); |
468 | else | ||
469 | fprintf(stderr, "thread id \'%d", target_tid); | ||
438 | 470 | ||
439 | fprintf(stderr, "\'"); | 471 | fprintf(stderr, "\'"); |
440 | if (run_count > 1) | 472 | if (run_count > 1) |
@@ -459,7 +491,7 @@ static volatile int signr = -1; | |||
459 | 491 | ||
460 | static void skip_signal(int signo) | 492 | static void skip_signal(int signo) |
461 | { | 493 | { |
462 | if(target_pid != -1) | 494 | if(child_pid == -1) |
463 | done = 1; | 495 | done = 1; |
464 | 496 | ||
465 | signr = signo; | 497 | signr = signo; |
@@ -486,15 +518,17 @@ static const struct option options[] = { | |||
486 | OPT_CALLBACK('e', "event", NULL, "event", | 518 | OPT_CALLBACK('e', "event", NULL, "event", |
487 | "event selector. use 'perf list' to list available events", | 519 | "event selector. use 'perf list' to list available events", |
488 | parse_events), | 520 | parse_events), |
489 | OPT_BOOLEAN('i', "inherit", &inherit, | 521 | OPT_BOOLEAN('i', "no-inherit", &no_inherit, |
490 | "child tasks inherit counters"), | 522 | "child tasks do not inherit counters"), |
491 | OPT_INTEGER('p', "pid", &target_pid, | 523 | OPT_INTEGER('p', "pid", &target_pid, |
492 | "stat events on existing pid"), | 524 | "stat events on existing process id"), |
525 | OPT_INTEGER('t', "tid", &target_tid, | ||
526 | "stat events on existing thread id"), | ||
493 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 527 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
494 | "system-wide collection from all CPUs"), | 528 | "system-wide collection from all CPUs"), |
495 | OPT_BOOLEAN('c', "scale", &scale, | 529 | OPT_BOOLEAN('c', "scale", &scale, |
496 | "scale/normalize counters"), | 530 | "scale/normalize counters"), |
497 | OPT_BOOLEAN('v', "verbose", &verbose, | 531 | OPT_INCR('v', "verbose", &verbose, |
498 | "be more verbose (show counter open errors, etc)"), | 532 | "be more verbose (show counter open errors, etc)"), |
499 | OPT_INTEGER('r', "repeat", &run_count, | 533 | OPT_INTEGER('r', "repeat", &run_count, |
500 | "repeat command and print average + stddev (max: 100)"), | 534 | "repeat command and print average + stddev (max: 100)"), |
@@ -506,10 +540,11 @@ static const struct option options[] = { | |||
506 | int cmd_stat(int argc, const char **argv, const char *prefix __used) | 540 | int cmd_stat(int argc, const char **argv, const char *prefix __used) |
507 | { | 541 | { |
508 | int status; | 542 | int status; |
543 | int i,j; | ||
509 | 544 | ||
510 | argc = parse_options(argc, argv, options, stat_usage, | 545 | argc = parse_options(argc, argv, options, stat_usage, |
511 | PARSE_OPT_STOP_AT_NON_OPTION); | 546 | PARSE_OPT_STOP_AT_NON_OPTION); |
512 | if (!argc && target_pid == -1) | 547 | if (!argc && target_pid == -1 && target_tid == -1) |
513 | usage_with_options(stat_usage, options); | 548 | usage_with_options(stat_usage, options); |
514 | if (run_count <= 0) | 549 | if (run_count <= 0) |
515 | usage_with_options(stat_usage, options); | 550 | usage_with_options(stat_usage, options); |
@@ -525,6 +560,31 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
525 | else | 560 | else |
526 | nr_cpus = 1; | 561 | nr_cpus = 1; |
527 | 562 | ||
563 | if (target_pid != -1) { | ||
564 | target_tid = target_pid; | ||
565 | thread_num = find_all_tid(target_pid, &all_tids); | ||
566 | if (thread_num <= 0) { | ||
567 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
568 | target_pid); | ||
569 | usage_with_options(stat_usage, options); | ||
570 | } | ||
571 | } else { | ||
572 | all_tids=malloc(sizeof(pid_t)); | ||
573 | if (!all_tids) | ||
574 | return -ENOMEM; | ||
575 | |||
576 | all_tids[0] = target_tid; | ||
577 | thread_num = 1; | ||
578 | } | ||
579 | |||
580 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
581 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
582 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
583 | if (!fd[i][j]) | ||
584 | return -ENOMEM; | ||
585 | } | ||
586 | } | ||
587 | |||
528 | /* | 588 | /* |
529 | * We dont want to block the signals - that would cause | 589 | * We dont want to block the signals - that would cause |
530 | * child tasks to inherit that and Ctrl-C would not work. | 590 | * child tasks to inherit that and Ctrl-C would not work. |
@@ -543,7 +603,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) | |||
543 | status = run_perf_stat(argc, argv); | 603 | status = run_perf_stat(argc, argv); |
544 | } | 604 | } |
545 | 605 | ||
546 | print_stat(argc, argv); | 606 | if (status != -1) |
607 | print_stat(argc, argv); | ||
547 | 608 | ||
548 | return status; | 609 | return status; |
549 | } | 610 | } |
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c new file mode 100644 index 000000000000..035b9fa063a9 --- /dev/null +++ b/tools/perf/builtin-test.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | * builtin-test.c | ||
3 | * | ||
4 | * Builtin regression testing command: ever growing number of sanity tests | ||
5 | */ | ||
6 | #include "builtin.h" | ||
7 | |||
8 | #include "util/cache.h" | ||
9 | #include "util/debug.h" | ||
10 | #include "util/parse-options.h" | ||
11 | #include "util/session.h" | ||
12 | #include "util/symbol.h" | ||
13 | #include "util/thread.h" | ||
14 | |||
15 | static long page_size; | ||
16 | |||
17 | static int vmlinux_matches_kallsyms_filter(struct map *map __used, struct symbol *sym) | ||
18 | { | ||
19 | bool *visited = symbol__priv(sym); | ||
20 | *visited = true; | ||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | static int test__vmlinux_matches_kallsyms(void) | ||
25 | { | ||
26 | int err = -1; | ||
27 | struct rb_node *nd; | ||
28 | struct symbol *sym; | ||
29 | struct map *kallsyms_map, *vmlinux_map; | ||
30 | struct machine kallsyms, vmlinux; | ||
31 | enum map_type type = MAP__FUNCTION; | ||
32 | struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", }; | ||
33 | |||
34 | /* | ||
35 | * Step 1: | ||
36 | * | ||
37 | * Init the machines that will hold kernel, modules obtained from | ||
38 | * both vmlinux + .ko files and from /proc/kallsyms split by modules. | ||
39 | */ | ||
40 | machine__init(&kallsyms, "", HOST_KERNEL_ID); | ||
41 | machine__init(&vmlinux, "", HOST_KERNEL_ID); | ||
42 | |||
43 | /* | ||
44 | * Step 2: | ||
45 | * | ||
46 | * Create the kernel maps for kallsyms and the DSO where we will then | ||
47 | * load /proc/kallsyms. Also create the modules maps from /proc/modules | ||
48 | * and find the .ko files that match them in /lib/modules/`uname -r`/. | ||
49 | */ | ||
50 | if (machine__create_kernel_maps(&kallsyms) < 0) { | ||
51 | pr_debug("machine__create_kernel_maps "); | ||
52 | return -1; | ||
53 | } | ||
54 | |||
55 | /* | ||
56 | * Step 3: | ||
57 | * | ||
58 | * Load and split /proc/kallsyms into multiple maps, one per module. | ||
59 | */ | ||
60 | if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) { | ||
61 | pr_debug("dso__load_kallsyms "); | ||
62 | goto out; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Step 4: | ||
67 | * | ||
68 | * kallsyms will be internally on demand sorted by name so that we can | ||
69 | * find the reference relocation * symbol, i.e. the symbol we will use | ||
70 | * to see if the running kernel was relocated by checking if it has the | ||
71 | * same value in the vmlinux file we load. | ||
72 | */ | ||
73 | kallsyms_map = machine__kernel_map(&kallsyms, type); | ||
74 | |||
75 | sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL); | ||
76 | if (sym == NULL) { | ||
77 | pr_debug("dso__find_symbol_by_name "); | ||
78 | goto out; | ||
79 | } | ||
80 | |||
81 | ref_reloc_sym.addr = sym->start; | ||
82 | |||
83 | /* | ||
84 | * Step 5: | ||
85 | * | ||
86 | * Now repeat step 2, this time for the vmlinux file we'll auto-locate. | ||
87 | */ | ||
88 | if (machine__create_kernel_maps(&vmlinux) < 0) { | ||
89 | pr_debug("machine__create_kernel_maps "); | ||
90 | goto out; | ||
91 | } | ||
92 | |||
93 | vmlinux_map = machine__kernel_map(&vmlinux, type); | ||
94 | map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym; | ||
95 | |||
96 | /* | ||
97 | * Step 6: | ||
98 | * | ||
99 | * Locate a vmlinux file in the vmlinux path that has a buildid that | ||
100 | * matches the one of the running kernel. | ||
101 | * | ||
102 | * While doing that look if we find the ref reloc symbol, if we find it | ||
103 | * we'll have its ref_reloc_symbol.unrelocated_addr and then | ||
104 | * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines | ||
105 | * to fixup the symbols. | ||
106 | */ | ||
107 | if (machine__load_vmlinux_path(&vmlinux, type, | ||
108 | vmlinux_matches_kallsyms_filter) <= 0) { | ||
109 | pr_debug("machine__load_vmlinux_path "); | ||
110 | goto out; | ||
111 | } | ||
112 | |||
113 | err = 0; | ||
114 | /* | ||
115 | * Step 7: | ||
116 | * | ||
117 | * Now look at the symbols in the vmlinux DSO and check if we find all of them | ||
118 | * in the kallsyms dso. For the ones that are in both, check its names and | ||
119 | * end addresses too. | ||
120 | */ | ||
121 | for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) { | ||
122 | struct symbol *pair; | ||
123 | |||
124 | sym = rb_entry(nd, struct symbol, rb_node); | ||
125 | pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL); | ||
126 | |||
127 | if (pair && pair->start == sym->start) { | ||
128 | next_pair: | ||
129 | if (strcmp(sym->name, pair->name) == 0) { | ||
130 | /* | ||
131 | * kallsyms don't have the symbol end, so we | ||
132 | * set that by using the next symbol start - 1, | ||
133 | * in some cases we get this up to a page | ||
134 | * wrong, trace_kmalloc when I was developing | ||
135 | * this code was one such example, 2106 bytes | ||
136 | * off the real size. More than that and we | ||
137 | * _really_ have a problem. | ||
138 | */ | ||
139 | s64 skew = sym->end - pair->end; | ||
140 | if (llabs(skew) < page_size) | ||
141 | continue; | ||
142 | |||
143 | pr_debug("%#Lx: diff end addr for %s v: %#Lx k: %#Lx\n", | ||
144 | sym->start, sym->name, sym->end, pair->end); | ||
145 | } else { | ||
146 | struct rb_node *nnd = rb_prev(&pair->rb_node); | ||
147 | |||
148 | if (nnd) { | ||
149 | struct symbol *next = rb_entry(nnd, struct symbol, rb_node); | ||
150 | |||
151 | if (next->start == sym->start) { | ||
152 | pair = next; | ||
153 | goto next_pair; | ||
154 | } | ||
155 | } | ||
156 | pr_debug("%#Lx: diff name v: %s k: %s\n", | ||
157 | sym->start, sym->name, pair->name); | ||
158 | } | ||
159 | } else | ||
160 | pr_debug("%#Lx: %s not on kallsyms\n", sym->start, sym->name); | ||
161 | |||
162 | err = -1; | ||
163 | } | ||
164 | |||
165 | if (!verbose) | ||
166 | goto out; | ||
167 | |||
168 | pr_info("Maps only in vmlinux:\n"); | ||
169 | |||
170 | for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) { | ||
171 | struct map *pos = rb_entry(nd, struct map, rb_node), *pair; | ||
172 | /* | ||
173 | * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while | ||
174 | * the kernel will have the path for the vmlinux file being used, | ||
175 | * so use the short name, less descriptive but the same ("[kernel]" in | ||
176 | * both cases. | ||
177 | */ | ||
178 | pair = map_groups__find_by_name(&kallsyms.kmaps, type, | ||
179 | (pos->dso->kernel ? | ||
180 | pos->dso->short_name : | ||
181 | pos->dso->name)); | ||
182 | if (pair) | ||
183 | pair->priv = 1; | ||
184 | else | ||
185 | map__fprintf(pos, stderr); | ||
186 | } | ||
187 | |||
188 | pr_info("Maps in vmlinux with a different name in kallsyms:\n"); | ||
189 | |||
190 | for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) { | ||
191 | struct map *pos = rb_entry(nd, struct map, rb_node), *pair; | ||
192 | |||
193 | pair = map_groups__find(&kallsyms.kmaps, type, pos->start); | ||
194 | if (pair == NULL || pair->priv) | ||
195 | continue; | ||
196 | |||
197 | if (pair->start == pos->start) { | ||
198 | pair->priv = 1; | ||
199 | pr_info(" %Lx-%Lx %Lx %s in kallsyms as", | ||
200 | pos->start, pos->end, pos->pgoff, pos->dso->name); | ||
201 | if (pos->pgoff != pair->pgoff || pos->end != pair->end) | ||
202 | pr_info(": \n*%Lx-%Lx %Lx", | ||
203 | pair->start, pair->end, pair->pgoff); | ||
204 | pr_info(" %s\n", pair->dso->name); | ||
205 | pair->priv = 1; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | pr_info("Maps only in kallsyms:\n"); | ||
210 | |||
211 | for (nd = rb_first(&kallsyms.kmaps.maps[type]); | ||
212 | nd; nd = rb_next(nd)) { | ||
213 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
214 | |||
215 | if (!pos->priv) | ||
216 | map__fprintf(pos, stderr); | ||
217 | } | ||
218 | out: | ||
219 | return err; | ||
220 | } | ||
221 | |||
222 | static struct test { | ||
223 | const char *desc; | ||
224 | int (*func)(void); | ||
225 | } tests[] = { | ||
226 | { | ||
227 | .desc = "vmlinux symtab matches kallsyms", | ||
228 | .func = test__vmlinux_matches_kallsyms, | ||
229 | }, | ||
230 | { | ||
231 | .func = NULL, | ||
232 | }, | ||
233 | }; | ||
234 | |||
235 | static int __cmd_test(void) | ||
236 | { | ||
237 | int i = 0; | ||
238 | |||
239 | page_size = sysconf(_SC_PAGE_SIZE); | ||
240 | |||
241 | while (tests[i].func) { | ||
242 | int err; | ||
243 | pr_info("%2d: %s:", i + 1, tests[i].desc); | ||
244 | pr_debug("\n--- start ---\n"); | ||
245 | err = tests[i].func(); | ||
246 | pr_debug("---- end ----\n%s:", tests[i].desc); | ||
247 | pr_info(" %s\n", err ? "FAILED!\n" : "Ok"); | ||
248 | ++i; | ||
249 | } | ||
250 | |||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static const char * const test_usage[] = { | ||
255 | "perf test [<options>]", | ||
256 | NULL, | ||
257 | }; | ||
258 | |||
259 | static const struct option test_options[] = { | ||
260 | OPT_INTEGER('v', "verbose", &verbose, | ||
261 | "be more verbose (show symbol address, etc)"), | ||
262 | OPT_END() | ||
263 | }; | ||
264 | |||
265 | int cmd_test(int argc, const char **argv, const char *prefix __used) | ||
266 | { | ||
267 | argc = parse_options(argc, argv, test_options, test_usage, 0); | ||
268 | if (argc) | ||
269 | usage_with_options(test_usage, test_options); | ||
270 | |||
271 | symbol_conf.priv_size = sizeof(int); | ||
272 | symbol_conf.sort_by_name = true; | ||
273 | symbol_conf.try_vmlinux_path = true; | ||
274 | |||
275 | if (symbol__init() < 0) | ||
276 | return -1; | ||
277 | |||
278 | setup_pager(); | ||
279 | |||
280 | return __cmd_test(); | ||
281 | } | ||
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 0d4d8ff7914b..5a52ed9fc10b 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include "util/cache.h" | 21 | #include "util/cache.h" |
22 | #include <linux/rbtree.h> | 22 | #include <linux/rbtree.h> |
23 | #include "util/symbol.h" | 23 | #include "util/symbol.h" |
24 | #include "util/string.h" | ||
25 | #include "util/callchain.h" | 24 | #include "util/callchain.h" |
26 | #include "util/strlist.h" | 25 | #include "util/strlist.h" |
27 | 26 | ||
@@ -43,7 +42,7 @@ static u64 turbo_frequency; | |||
43 | 42 | ||
44 | static u64 first_time, last_time; | 43 | static u64 first_time, last_time; |
45 | 44 | ||
46 | static int power_only; | 45 | static bool power_only; |
47 | 46 | ||
48 | 47 | ||
49 | struct per_pid; | 48 | struct per_pid; |
@@ -78,8 +77,6 @@ struct per_pid { | |||
78 | 77 | ||
79 | struct per_pidcomm *all; | 78 | struct per_pidcomm *all; |
80 | struct per_pidcomm *current; | 79 | struct per_pidcomm *current; |
81 | |||
82 | int painted; | ||
83 | }; | 80 | }; |
84 | 81 | ||
85 | 82 | ||
@@ -146,9 +143,6 @@ struct wake_event { | |||
146 | static struct power_event *power_events; | 143 | static struct power_event *power_events; |
147 | static struct wake_event *wake_events; | 144 | static struct wake_event *wake_events; |
148 | 145 | ||
149 | struct sample_wrapper *all_samples; | ||
150 | |||
151 | |||
152 | struct process_filter; | 146 | struct process_filter; |
153 | struct process_filter { | 147 | struct process_filter { |
154 | char *name; | 148 | char *name; |
@@ -569,88 +563,6 @@ static void end_sample_processing(void) | |||
569 | } | 563 | } |
570 | } | 564 | } |
571 | 565 | ||
572 | static u64 sample_time(event_t *event, const struct perf_session *session) | ||
573 | { | ||
574 | int cursor; | ||
575 | |||
576 | cursor = 0; | ||
577 | if (session->sample_type & PERF_SAMPLE_IP) | ||
578 | cursor++; | ||
579 | if (session->sample_type & PERF_SAMPLE_TID) | ||
580 | cursor++; | ||
581 | if (session->sample_type & PERF_SAMPLE_TIME) | ||
582 | return event->sample.array[cursor]; | ||
583 | return 0; | ||
584 | } | ||
585 | |||
586 | |||
587 | /* | ||
588 | * We first queue all events, sorted backwards by insertion. | ||
589 | * The order will get flipped later. | ||
590 | */ | ||
591 | static int queue_sample_event(event_t *event, struct perf_session *session) | ||
592 | { | ||
593 | struct sample_wrapper *copy, *prev; | ||
594 | int size; | ||
595 | |||
596 | size = event->sample.header.size + sizeof(struct sample_wrapper) + 8; | ||
597 | |||
598 | copy = malloc(size); | ||
599 | if (!copy) | ||
600 | return 1; | ||
601 | |||
602 | memset(copy, 0, size); | ||
603 | |||
604 | copy->next = NULL; | ||
605 | copy->timestamp = sample_time(event, session); | ||
606 | |||
607 | memcpy(©->data, event, event->sample.header.size); | ||
608 | |||
609 | /* insert in the right place in the list */ | ||
610 | |||
611 | if (!all_samples) { | ||
612 | /* first sample ever */ | ||
613 | all_samples = copy; | ||
614 | return 0; | ||
615 | } | ||
616 | |||
617 | if (all_samples->timestamp < copy->timestamp) { | ||
618 | /* insert at the head of the list */ | ||
619 | copy->next = all_samples; | ||
620 | all_samples = copy; | ||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | prev = all_samples; | ||
625 | while (prev->next) { | ||
626 | if (prev->next->timestamp < copy->timestamp) { | ||
627 | copy->next = prev->next; | ||
628 | prev->next = copy; | ||
629 | return 0; | ||
630 | } | ||
631 | prev = prev->next; | ||
632 | } | ||
633 | /* insert at the end of the list */ | ||
634 | prev->next = copy; | ||
635 | |||
636 | return 0; | ||
637 | } | ||
638 | |||
639 | static void sort_queued_samples(void) | ||
640 | { | ||
641 | struct sample_wrapper *cursor, *next; | ||
642 | |||
643 | cursor = all_samples; | ||
644 | all_samples = NULL; | ||
645 | |||
646 | while (cursor) { | ||
647 | next = cursor->next; | ||
648 | cursor->next = all_samples; | ||
649 | all_samples = cursor; | ||
650 | cursor = next; | ||
651 | } | ||
652 | } | ||
653 | |||
654 | /* | 566 | /* |
655 | * Sort the pid datastructure | 567 | * Sort the pid datastructure |
656 | */ | 568 | */ |
@@ -1014,31 +926,17 @@ static void write_svg_file(const char *filename) | |||
1014 | svg_close(); | 926 | svg_close(); |
1015 | } | 927 | } |
1016 | 928 | ||
1017 | static void process_samples(struct perf_session *session) | ||
1018 | { | ||
1019 | struct sample_wrapper *cursor; | ||
1020 | event_t *event; | ||
1021 | |||
1022 | sort_queued_samples(); | ||
1023 | |||
1024 | cursor = all_samples; | ||
1025 | while (cursor) { | ||
1026 | event = (void *)&cursor->data; | ||
1027 | cursor = cursor->next; | ||
1028 | process_sample_event(event, session); | ||
1029 | } | ||
1030 | } | ||
1031 | |||
1032 | static struct perf_event_ops event_ops = { | 929 | static struct perf_event_ops event_ops = { |
1033 | .comm = process_comm_event, | 930 | .comm = process_comm_event, |
1034 | .fork = process_fork_event, | 931 | .fork = process_fork_event, |
1035 | .exit = process_exit_event, | 932 | .exit = process_exit_event, |
1036 | .sample = queue_sample_event, | 933 | .sample = process_sample_event, |
934 | .ordered_samples = true, | ||
1037 | }; | 935 | }; |
1038 | 936 | ||
1039 | static int __cmd_timechart(void) | 937 | static int __cmd_timechart(void) |
1040 | { | 938 | { |
1041 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); | 939 | struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false); |
1042 | int ret = -EINVAL; | 940 | int ret = -EINVAL; |
1043 | 941 | ||
1044 | if (session == NULL) | 942 | if (session == NULL) |
@@ -1051,8 +949,6 @@ static int __cmd_timechart(void) | |||
1051 | if (ret) | 949 | if (ret) |
1052 | goto out_delete; | 950 | goto out_delete; |
1053 | 951 | ||
1054 | process_samples(session); | ||
1055 | |||
1056 | end_sample_processing(); | 952 | end_sample_processing(); |
1057 | 953 | ||
1058 | sort_pids(); | 954 | sort_pids(); |
@@ -1075,7 +971,6 @@ static const char *record_args[] = { | |||
1075 | "record", | 971 | "record", |
1076 | "-a", | 972 | "-a", |
1077 | "-R", | 973 | "-R", |
1078 | "-M", | ||
1079 | "-f", | 974 | "-f", |
1080 | "-c", "1", | 975 | "-c", "1", |
1081 | "-e", "power:power_start", | 976 | "-e", "power:power_start", |
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 1f529321607e..397290a0a76e 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c | |||
@@ -55,9 +55,9 @@ | |||
55 | #include <linux/unistd.h> | 55 | #include <linux/unistd.h> |
56 | #include <linux/types.h> | 56 | #include <linux/types.h> |
57 | 57 | ||
58 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; | 58 | static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; |
59 | 59 | ||
60 | static int system_wide = 0; | 60 | static bool system_wide = false; |
61 | 61 | ||
62 | static int default_interval = 0; | 62 | static int default_interval = 0; |
63 | 63 | ||
@@ -65,18 +65,21 @@ static int count_filter = 5; | |||
65 | static int print_entries; | 65 | static int print_entries; |
66 | 66 | ||
67 | static int target_pid = -1; | 67 | static int target_pid = -1; |
68 | static int inherit = 0; | 68 | static int target_tid = -1; |
69 | static pid_t *all_tids = NULL; | ||
70 | static int thread_num = 0; | ||
71 | static bool inherit = false; | ||
69 | static int profile_cpu = -1; | 72 | static int profile_cpu = -1; |
70 | static int nr_cpus = 0; | 73 | static int nr_cpus = 0; |
71 | static unsigned int realtime_prio = 0; | 74 | static int realtime_prio = 0; |
72 | static int group = 0; | 75 | static bool group = false; |
73 | static unsigned int page_size; | 76 | static unsigned int page_size; |
74 | static unsigned int mmap_pages = 16; | 77 | static unsigned int mmap_pages = 16; |
75 | static int freq = 1000; /* 1 KHz */ | 78 | static int freq = 1000; /* 1 KHz */ |
76 | 79 | ||
77 | static int delay_secs = 2; | 80 | static int delay_secs = 2; |
78 | static int zero = 0; | 81 | static bool zero = false; |
79 | static int dump_symtab = 0; | 82 | static bool dump_symtab = false; |
80 | 83 | ||
81 | static bool hide_kernel_symbols = false; | 84 | static bool hide_kernel_symbols = false; |
82 | static bool hide_user_symbols = false; | 85 | static bool hide_user_symbols = false; |
@@ -93,7 +96,7 @@ struct source_line { | |||
93 | struct source_line *next; | 96 | struct source_line *next; |
94 | }; | 97 | }; |
95 | 98 | ||
96 | static char *sym_filter = NULL; | 99 | static const char *sym_filter = NULL; |
97 | struct sym_entry *sym_filter_entry = NULL; | 100 | struct sym_entry *sym_filter_entry = NULL; |
98 | struct sym_entry *sym_filter_entry_sched = NULL; | 101 | struct sym_entry *sym_filter_entry_sched = NULL; |
99 | static int sym_pcnt_filter = 5; | 102 | static int sym_pcnt_filter = 5; |
@@ -133,7 +136,7 @@ static inline struct symbol *sym_entry__symbol(struct sym_entry *self) | |||
133 | return ((void *)self) + symbol_conf.priv_size; | 136 | return ((void *)self) + symbol_conf.priv_size; |
134 | } | 137 | } |
135 | 138 | ||
136 | static void get_term_dimensions(struct winsize *ws) | 139 | void get_term_dimensions(struct winsize *ws) |
137 | { | 140 | { |
138 | char *s = getenv("LINES"); | 141 | char *s = getenv("LINES"); |
139 | 142 | ||
@@ -169,7 +172,7 @@ static void sig_winch_handler(int sig __used) | |||
169 | update_print_entries(&winsize); | 172 | update_print_entries(&winsize); |
170 | } | 173 | } |
171 | 174 | ||
172 | static void parse_source(struct sym_entry *syme) | 175 | static int parse_source(struct sym_entry *syme) |
173 | { | 176 | { |
174 | struct symbol *sym; | 177 | struct symbol *sym; |
175 | struct sym_entry_source *source; | 178 | struct sym_entry_source *source; |
@@ -180,12 +183,21 @@ static void parse_source(struct sym_entry *syme) | |||
180 | u64 len; | 183 | u64 len; |
181 | 184 | ||
182 | if (!syme) | 185 | if (!syme) |
183 | return; | 186 | return -1; |
187 | |||
188 | sym = sym_entry__symbol(syme); | ||
189 | map = syme->map; | ||
190 | |||
191 | /* | ||
192 | * We can't annotate with just /proc/kallsyms | ||
193 | */ | ||
194 | if (map->dso->origin == DSO__ORIG_KERNEL) | ||
195 | return -1; | ||
184 | 196 | ||
185 | if (syme->src == NULL) { | 197 | if (syme->src == NULL) { |
186 | syme->src = zalloc(sizeof(*source)); | 198 | syme->src = zalloc(sizeof(*source)); |
187 | if (syme->src == NULL) | 199 | if (syme->src == NULL) |
188 | return; | 200 | return -1; |
189 | pthread_mutex_init(&syme->src->lock, NULL); | 201 | pthread_mutex_init(&syme->src->lock, NULL); |
190 | } | 202 | } |
191 | 203 | ||
@@ -195,9 +207,6 @@ static void parse_source(struct sym_entry *syme) | |||
195 | pthread_mutex_lock(&source->lock); | 207 | pthread_mutex_lock(&source->lock); |
196 | goto out_assign; | 208 | goto out_assign; |
197 | } | 209 | } |
198 | |||
199 | sym = sym_entry__symbol(syme); | ||
200 | map = syme->map; | ||
201 | path = map->dso->long_name; | 210 | path = map->dso->long_name; |
202 | 211 | ||
203 | len = sym->end - sym->start; | 212 | len = sym->end - sym->start; |
@@ -209,7 +218,7 @@ static void parse_source(struct sym_entry *syme) | |||
209 | 218 | ||
210 | file = popen(command, "r"); | 219 | file = popen(command, "r"); |
211 | if (!file) | 220 | if (!file) |
212 | return; | 221 | return -1; |
213 | 222 | ||
214 | pthread_mutex_lock(&source->lock); | 223 | pthread_mutex_lock(&source->lock); |
215 | source->lines_tail = &source->lines; | 224 | source->lines_tail = &source->lines; |
@@ -245,6 +254,7 @@ static void parse_source(struct sym_entry *syme) | |||
245 | out_assign: | 254 | out_assign: |
246 | sym_filter_entry = syme; | 255 | sym_filter_entry = syme; |
247 | pthread_mutex_unlock(&source->lock); | 256 | pthread_mutex_unlock(&source->lock); |
257 | return 0; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | static void __zero_source_counters(struct sym_entry *syme) | 260 | static void __zero_source_counters(struct sym_entry *syme) |
@@ -410,7 +420,9 @@ static double sym_weight(const struct sym_entry *sym) | |||
410 | } | 420 | } |
411 | 421 | ||
412 | static long samples; | 422 | static long samples; |
413 | static long userspace_samples; | 423 | static long kernel_samples, us_samples; |
424 | static long exact_samples; | ||
425 | static long guest_us_samples, guest_kernel_samples; | ||
414 | static const char CONSOLE_CLEAR[] = "[H[2J"; | 426 | static const char CONSOLE_CLEAR[] = "[H[2J"; |
415 | 427 | ||
416 | static void __list_insert_active_sym(struct sym_entry *syme) | 428 | static void __list_insert_active_sym(struct sym_entry *syme) |
@@ -450,7 +462,11 @@ static void print_sym_table(void) | |||
450 | int printed = 0, j; | 462 | int printed = 0, j; |
451 | int counter, snap = !display_weighted ? sym_counter : 0; | 463 | int counter, snap = !display_weighted ? sym_counter : 0; |
452 | float samples_per_sec = samples/delay_secs; | 464 | float samples_per_sec = samples/delay_secs; |
453 | float ksamples_per_sec = (samples-userspace_samples)/delay_secs; | 465 | float ksamples_per_sec = kernel_samples/delay_secs; |
466 | float us_samples_per_sec = (us_samples)/delay_secs; | ||
467 | float guest_kernel_samples_per_sec = (guest_kernel_samples)/delay_secs; | ||
468 | float guest_us_samples_per_sec = (guest_us_samples)/delay_secs; | ||
469 | float esamples_percent = (100.0*exact_samples)/samples; | ||
454 | float sum_ksamples = 0.0; | 470 | float sum_ksamples = 0.0; |
455 | struct sym_entry *syme, *n; | 471 | struct sym_entry *syme, *n; |
456 | struct rb_root tmp = RB_ROOT; | 472 | struct rb_root tmp = RB_ROOT; |
@@ -458,7 +474,8 @@ static void print_sym_table(void) | |||
458 | int sym_width = 0, dso_width = 0, dso_short_width = 0; | 474 | int sym_width = 0, dso_width = 0, dso_short_width = 0; |
459 | const int win_width = winsize.ws_col - 1; | 475 | const int win_width = winsize.ws_col - 1; |
460 | 476 | ||
461 | samples = userspace_samples = 0; | 477 | samples = us_samples = kernel_samples = exact_samples = 0; |
478 | guest_kernel_samples = guest_us_samples = 0; | ||
462 | 479 | ||
463 | /* Sort the active symbols */ | 480 | /* Sort the active symbols */ |
464 | pthread_mutex_lock(&active_symbols_lock); | 481 | pthread_mutex_lock(&active_symbols_lock); |
@@ -489,9 +506,30 @@ static void print_sym_table(void) | |||
489 | puts(CONSOLE_CLEAR); | 506 | puts(CONSOLE_CLEAR); |
490 | 507 | ||
491 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); | 508 | printf("%-*.*s\n", win_width, win_width, graph_dotted_line); |
492 | printf( " PerfTop:%8.0f irqs/sec kernel:%4.1f%% [", | 509 | if (!perf_guest) { |
493 | samples_per_sec, | 510 | printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%%" |
494 | 100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec))); | 511 | " exact: %4.1f%% [", |
512 | samples_per_sec, | ||
513 | 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) / | ||
514 | samples_per_sec)), | ||
515 | esamples_percent); | ||
516 | } else { | ||
517 | printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%" | ||
518 | " guest kernel:%4.1f%% guest us:%4.1f%%" | ||
519 | " exact: %4.1f%% [", | ||
520 | samples_per_sec, | ||
521 | 100.0 - (100.0 * ((samples_per_sec-ksamples_per_sec) / | ||
522 | samples_per_sec)), | ||
523 | 100.0 - (100.0 * ((samples_per_sec-us_samples_per_sec) / | ||
524 | samples_per_sec)), | ||
525 | 100.0 - (100.0 * ((samples_per_sec - | ||
526 | guest_kernel_samples_per_sec) / | ||
527 | samples_per_sec)), | ||
528 | 100.0 - (100.0 * ((samples_per_sec - | ||
529 | guest_us_samples_per_sec) / | ||
530 | samples_per_sec)), | ||
531 | esamples_percent); | ||
532 | } | ||
495 | 533 | ||
496 | if (nr_counters == 1 || !display_weighted) { | 534 | if (nr_counters == 1 || !display_weighted) { |
497 | printf("%Ld", (u64)attrs[0].sample_period); | 535 | printf("%Ld", (u64)attrs[0].sample_period); |
@@ -514,13 +552,15 @@ static void print_sym_table(void) | |||
514 | 552 | ||
515 | if (target_pid != -1) | 553 | if (target_pid != -1) |
516 | printf(" (target_pid: %d", target_pid); | 554 | printf(" (target_pid: %d", target_pid); |
555 | else if (target_tid != -1) | ||
556 | printf(" (target_tid: %d", target_tid); | ||
517 | else | 557 | else |
518 | printf(" (all"); | 558 | printf(" (all"); |
519 | 559 | ||
520 | if (profile_cpu != -1) | 560 | if (profile_cpu != -1) |
521 | printf(", cpu: %d)\n", profile_cpu); | 561 | printf(", cpu: %d)\n", profile_cpu); |
522 | else { | 562 | else { |
523 | if (target_pid != -1) | 563 | if (target_tid != -1) |
524 | printf(")\n"); | 564 | printf(")\n"); |
525 | else | 565 | else |
526 | printf(", %d CPUs)\n", nr_cpus); | 566 | printf(", %d CPUs)\n", nr_cpus); |
@@ -582,7 +622,6 @@ static void print_sym_table(void) | |||
582 | 622 | ||
583 | syme = rb_entry(nd, struct sym_entry, rb_node); | 623 | syme = rb_entry(nd, struct sym_entry, rb_node); |
584 | sym = sym_entry__symbol(syme); | 624 | sym = sym_entry__symbol(syme); |
585 | |||
586 | if (++printed > print_entries || (int)syme->snap_count < count_filter) | 625 | if (++printed > print_entries || (int)syme->snap_count < count_filter) |
587 | continue; | 626 | continue; |
588 | 627 | ||
@@ -746,7 +785,7 @@ static int key_mapped(int c) | |||
746 | return 0; | 785 | return 0; |
747 | } | 786 | } |
748 | 787 | ||
749 | static void handle_keypress(int c) | 788 | static void handle_keypress(struct perf_session *session, int c) |
750 | { | 789 | { |
751 | if (!key_mapped(c)) { | 790 | if (!key_mapped(c)) { |
752 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; | 791 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
@@ -815,7 +854,7 @@ static void handle_keypress(int c) | |||
815 | case 'Q': | 854 | case 'Q': |
816 | printf("exiting.\n"); | 855 | printf("exiting.\n"); |
817 | if (dump_symtab) | 856 | if (dump_symtab) |
818 | dsos__fprintf(stderr); | 857 | perf_session__fprintf_dsos(session, stderr); |
819 | exit(0); | 858 | exit(0); |
820 | case 's': | 859 | case 's': |
821 | prompt_symbol(&sym_filter_entry, "Enter details symbol"); | 860 | prompt_symbol(&sym_filter_entry, "Enter details symbol"); |
@@ -839,7 +878,7 @@ static void handle_keypress(int c) | |||
839 | display_weighted = ~display_weighted; | 878 | display_weighted = ~display_weighted; |
840 | break; | 879 | break; |
841 | case 'z': | 880 | case 'z': |
842 | zero = ~zero; | 881 | zero = !zero; |
843 | break; | 882 | break; |
844 | default: | 883 | default: |
845 | break; | 884 | break; |
@@ -851,6 +890,7 @@ static void *display_thread(void *arg __used) | |||
851 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; | 890 | struct pollfd stdin_poll = { .fd = 0, .events = POLLIN }; |
852 | struct termios tc, save; | 891 | struct termios tc, save; |
853 | int delay_msecs, c; | 892 | int delay_msecs, c; |
893 | struct perf_session *session = (struct perf_session *) arg; | ||
854 | 894 | ||
855 | tcgetattr(0, &save); | 895 | tcgetattr(0, &save); |
856 | tc = save; | 896 | tc = save; |
@@ -871,7 +911,7 @@ repeat: | |||
871 | c = getc(stdin); | 911 | c = getc(stdin); |
872 | tcsetattr(0, TCSAFLUSH, &save); | 912 | tcsetattr(0, TCSAFLUSH, &save); |
873 | 913 | ||
874 | handle_keypress(c); | 914 | handle_keypress(session, c); |
875 | goto repeat; | 915 | goto repeat; |
876 | 916 | ||
877 | return NULL; | 917 | return NULL; |
@@ -942,24 +982,48 @@ static void event__process_sample(const event_t *self, | |||
942 | u64 ip = self->ip.ip; | 982 | u64 ip = self->ip.ip; |
943 | struct sym_entry *syme; | 983 | struct sym_entry *syme; |
944 | struct addr_location al; | 984 | struct addr_location al; |
985 | struct machine *machine; | ||
945 | u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 986 | u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
946 | 987 | ||
947 | ++samples; | 988 | ++samples; |
948 | 989 | ||
949 | switch (origin) { | 990 | switch (origin) { |
950 | case PERF_RECORD_MISC_USER: | 991 | case PERF_RECORD_MISC_USER: |
951 | ++userspace_samples; | 992 | ++us_samples; |
952 | if (hide_user_symbols) | 993 | if (hide_user_symbols) |
953 | return; | 994 | return; |
995 | machine = perf_session__find_host_machine(session); | ||
954 | break; | 996 | break; |
955 | case PERF_RECORD_MISC_KERNEL: | 997 | case PERF_RECORD_MISC_KERNEL: |
998 | ++kernel_samples; | ||
956 | if (hide_kernel_symbols) | 999 | if (hide_kernel_symbols) |
957 | return; | 1000 | return; |
1001 | machine = perf_session__find_host_machine(session); | ||
1002 | break; | ||
1003 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
1004 | ++guest_kernel_samples; | ||
1005 | machine = perf_session__find_machine(session, self->ip.pid); | ||
958 | break; | 1006 | break; |
1007 | case PERF_RECORD_MISC_GUEST_USER: | ||
1008 | ++guest_us_samples; | ||
1009 | /* | ||
1010 | * TODO: we don't process guest user from host side | ||
1011 | * except simple counting. | ||
1012 | */ | ||
1013 | return; | ||
959 | default: | 1014 | default: |
960 | return; | 1015 | return; |
961 | } | 1016 | } |
962 | 1017 | ||
1018 | if (!machine && perf_guest) { | ||
1019 | pr_err("Can't find guest [%d]'s kernel information\n", | ||
1020 | self->ip.pid); | ||
1021 | return; | ||
1022 | } | ||
1023 | |||
1024 | if (self->header.misc & PERF_RECORD_MISC_EXACT_IP) | ||
1025 | exact_samples++; | ||
1026 | |||
963 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || | 1027 | if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 || |
964 | al.filtered) | 1028 | al.filtered) |
965 | return; | 1029 | return; |
@@ -976,7 +1040,7 @@ static void event__process_sample(const event_t *self, | |||
976 | * --hide-kernel-symbols, even if the user specifies an | 1040 | * --hide-kernel-symbols, even if the user specifies an |
977 | * invalid --vmlinux ;-) | 1041 | * invalid --vmlinux ;-) |
978 | */ | 1042 | */ |
979 | if (al.map == session->vmlinux_maps[MAP__FUNCTION] && | 1043 | if (al.map == machine->vmlinux_maps[MAP__FUNCTION] && |
980 | RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) { | 1044 | RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) { |
981 | pr_err("The %s file can't be used\n", | 1045 | pr_err("The %s file can't be used\n", |
982 | symbol_conf.vmlinux_name); | 1046 | symbol_conf.vmlinux_name); |
@@ -990,7 +1054,17 @@ static void event__process_sample(const event_t *self, | |||
990 | if (sym_filter_entry_sched) { | 1054 | if (sym_filter_entry_sched) { |
991 | sym_filter_entry = sym_filter_entry_sched; | 1055 | sym_filter_entry = sym_filter_entry_sched; |
992 | sym_filter_entry_sched = NULL; | 1056 | sym_filter_entry_sched = NULL; |
993 | parse_source(sym_filter_entry); | 1057 | if (parse_source(sym_filter_entry) < 0) { |
1058 | struct symbol *sym = sym_entry__symbol(sym_filter_entry); | ||
1059 | |||
1060 | pr_err("Can't annotate %s", sym->name); | ||
1061 | if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) { | ||
1062 | pr_err(": No vmlinux file was found in the path:\n"); | ||
1063 | vmlinux_path__fprintf(stderr); | ||
1064 | } else | ||
1065 | pr_err(".\n"); | ||
1066 | exit(1); | ||
1067 | } | ||
994 | } | 1068 | } |
995 | 1069 | ||
996 | syme = symbol__priv(al.sym); | 1070 | syme = symbol__priv(al.sym); |
@@ -1106,16 +1180,21 @@ static void perf_session__mmap_read_counter(struct perf_session *self, | |||
1106 | md->prev = old; | 1180 | md->prev = old; |
1107 | } | 1181 | } |
1108 | 1182 | ||
1109 | static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS]; | 1183 | static struct pollfd *event_array; |
1110 | static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 1184 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; |
1111 | 1185 | ||
1112 | static void perf_session__mmap_read(struct perf_session *self) | 1186 | static void perf_session__mmap_read(struct perf_session *self) |
1113 | { | 1187 | { |
1114 | int i, counter; | 1188 | int i, counter, thread_index; |
1115 | 1189 | ||
1116 | for (i = 0; i < nr_cpus; i++) { | 1190 | for (i = 0; i < nr_cpus; i++) { |
1117 | for (counter = 0; counter < nr_counters; counter++) | 1191 | for (counter = 0; counter < nr_counters; counter++) |
1118 | perf_session__mmap_read_counter(self, &mmap_array[i][counter]); | 1192 | for (thread_index = 0; |
1193 | thread_index < thread_num; | ||
1194 | thread_index++) { | ||
1195 | perf_session__mmap_read_counter(self, | ||
1196 | &mmap_array[i][counter][thread_index]); | ||
1197 | } | ||
1119 | } | 1198 | } |
1120 | } | 1199 | } |
1121 | 1200 | ||
@@ -1126,9 +1205,10 @@ static void start_counter(int i, int counter) | |||
1126 | { | 1205 | { |
1127 | struct perf_event_attr *attr; | 1206 | struct perf_event_attr *attr; |
1128 | int cpu; | 1207 | int cpu; |
1208 | int thread_index; | ||
1129 | 1209 | ||
1130 | cpu = profile_cpu; | 1210 | cpu = profile_cpu; |
1131 | if (target_pid == -1 && profile_cpu == -1) | 1211 | if (target_tid == -1 && profile_cpu == -1) |
1132 | cpu = cpumap[i]; | 1212 | cpu = cpumap[i]; |
1133 | 1213 | ||
1134 | attr = attrs + counter; | 1214 | attr = attrs + counter; |
@@ -1144,55 +1224,58 @@ static void start_counter(int i, int counter) | |||
1144 | attr->inherit = (cpu < 0) && inherit; | 1224 | attr->inherit = (cpu < 0) && inherit; |
1145 | attr->mmap = 1; | 1225 | attr->mmap = 1; |
1146 | 1226 | ||
1227 | for (thread_index = 0; thread_index < thread_num; thread_index++) { | ||
1147 | try_again: | 1228 | try_again: |
1148 | fd[i][counter] = sys_perf_event_open(attr, target_pid, cpu, group_fd, 0); | 1229 | fd[i][counter][thread_index] = sys_perf_event_open(attr, |
1149 | 1230 | all_tids[thread_index], cpu, group_fd, 0); | |
1150 | if (fd[i][counter] < 0) { | 1231 | |
1151 | int err = errno; | 1232 | if (fd[i][counter][thread_index] < 0) { |
1233 | int err = errno; | ||
1234 | |||
1235 | if (err == EPERM || err == EACCES) | ||
1236 | die("No permission - are you root?\n"); | ||
1237 | /* | ||
1238 | * If it's cycles then fall back to hrtimer | ||
1239 | * based cpu-clock-tick sw counter, which | ||
1240 | * is always available even if no PMU support: | ||
1241 | */ | ||
1242 | if (attr->type == PERF_TYPE_HARDWARE | ||
1243 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | ||
1244 | |||
1245 | if (verbose) | ||
1246 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | ||
1247 | |||
1248 | attr->type = PERF_TYPE_SOFTWARE; | ||
1249 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | ||
1250 | goto try_again; | ||
1251 | } | ||
1252 | printf("\n"); | ||
1253 | error("perfcounter syscall returned with %d (%s)\n", | ||
1254 | fd[i][counter][thread_index], strerror(err)); | ||
1255 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | ||
1256 | exit(-1); | ||
1257 | } | ||
1258 | assert(fd[i][counter][thread_index] >= 0); | ||
1259 | fcntl(fd[i][counter][thread_index], F_SETFL, O_NONBLOCK); | ||
1152 | 1260 | ||
1153 | if (err == EPERM || err == EACCES) | ||
1154 | die("No permission - are you root?\n"); | ||
1155 | /* | 1261 | /* |
1156 | * If it's cycles then fall back to hrtimer | 1262 | * First counter acts as the group leader: |
1157 | * based cpu-clock-tick sw counter, which | ||
1158 | * is always available even if no PMU support: | ||
1159 | */ | 1263 | */ |
1160 | if (attr->type == PERF_TYPE_HARDWARE | 1264 | if (group && group_fd == -1) |
1161 | && attr->config == PERF_COUNT_HW_CPU_CYCLES) { | 1265 | group_fd = fd[i][counter][thread_index]; |
1162 | 1266 | ||
1163 | if (verbose) | 1267 | event_array[nr_poll].fd = fd[i][counter][thread_index]; |
1164 | warning(" ... trying to fall back to cpu-clock-ticks\n"); | 1268 | event_array[nr_poll].events = POLLIN; |
1165 | 1269 | nr_poll++; | |
1166 | attr->type = PERF_TYPE_SOFTWARE; | 1270 | |
1167 | attr->config = PERF_COUNT_SW_CPU_CLOCK; | 1271 | mmap_array[i][counter][thread_index].counter = counter; |
1168 | goto try_again; | 1272 | mmap_array[i][counter][thread_index].prev = 0; |
1169 | } | 1273 | mmap_array[i][counter][thread_index].mask = mmap_pages*page_size - 1; |
1170 | printf("\n"); | 1274 | mmap_array[i][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, |
1171 | error("perfcounter syscall returned with %d (%s)\n", | 1275 | PROT_READ, MAP_SHARED, fd[i][counter][thread_index], 0); |
1172 | fd[i][counter], strerror(err)); | 1276 | if (mmap_array[i][counter][thread_index].base == MAP_FAILED) |
1173 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 1277 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); |
1174 | exit(-1); | ||
1175 | } | 1278 | } |
1176 | assert(fd[i][counter] >= 0); | ||
1177 | fcntl(fd[i][counter], F_SETFL, O_NONBLOCK); | ||
1178 | |||
1179 | /* | ||
1180 | * First counter acts as the group leader: | ||
1181 | */ | ||
1182 | if (group && group_fd == -1) | ||
1183 | group_fd = fd[i][counter]; | ||
1184 | |||
1185 | event_array[nr_poll].fd = fd[i][counter]; | ||
1186 | event_array[nr_poll].events = POLLIN; | ||
1187 | nr_poll++; | ||
1188 | |||
1189 | mmap_array[i][counter].counter = counter; | ||
1190 | mmap_array[i][counter].prev = 0; | ||
1191 | mmap_array[i][counter].mask = mmap_pages*page_size - 1; | ||
1192 | mmap_array[i][counter].base = mmap(NULL, (mmap_pages+1)*page_size, | ||
1193 | PROT_READ, MAP_SHARED, fd[i][counter], 0); | ||
1194 | if (mmap_array[i][counter].base == MAP_FAILED) | ||
1195 | die("failed to mmap with %d (%s)\n", errno, strerror(errno)); | ||
1196 | } | 1279 | } |
1197 | 1280 | ||
1198 | static int __cmd_top(void) | 1281 | static int __cmd_top(void) |
@@ -1204,12 +1287,12 @@ static int __cmd_top(void) | |||
1204 | * FIXME: perf_session__new should allow passing a O_MMAP, so that all this | 1287 | * FIXME: perf_session__new should allow passing a O_MMAP, so that all this |
1205 | * mmap reading, etc is encapsulated in it. Use O_WRONLY for now. | 1288 | * mmap reading, etc is encapsulated in it. Use O_WRONLY for now. |
1206 | */ | 1289 | */ |
1207 | struct perf_session *session = perf_session__new(NULL, O_WRONLY, false); | 1290 | struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false); |
1208 | if (session == NULL) | 1291 | if (session == NULL) |
1209 | return -ENOMEM; | 1292 | return -ENOMEM; |
1210 | 1293 | ||
1211 | if (target_pid != -1) | 1294 | if (target_tid != -1) |
1212 | event__synthesize_thread(target_pid, event__process, session); | 1295 | event__synthesize_thread(target_tid, event__process, session); |
1213 | else | 1296 | else |
1214 | event__synthesize_threads(event__process, session); | 1297 | event__synthesize_threads(event__process, session); |
1215 | 1298 | ||
@@ -1220,11 +1303,11 @@ static int __cmd_top(void) | |||
1220 | } | 1303 | } |
1221 | 1304 | ||
1222 | /* Wait for a minimal set of events before starting the snapshot */ | 1305 | /* Wait for a minimal set of events before starting the snapshot */ |
1223 | poll(event_array, nr_poll, 100); | 1306 | poll(&event_array[0], nr_poll, 100); |
1224 | 1307 | ||
1225 | perf_session__mmap_read(session); | 1308 | perf_session__mmap_read(session); |
1226 | 1309 | ||
1227 | if (pthread_create(&thread, NULL, display_thread, NULL)) { | 1310 | if (pthread_create(&thread, NULL, display_thread, session)) { |
1228 | printf("Could not create display thread.\n"); | 1311 | printf("Could not create display thread.\n"); |
1229 | exit(-1); | 1312 | exit(-1); |
1230 | } | 1313 | } |
@@ -1263,7 +1346,9 @@ static const struct option options[] = { | |||
1263 | OPT_INTEGER('c', "count", &default_interval, | 1346 | OPT_INTEGER('c', "count", &default_interval, |
1264 | "event period to sample"), | 1347 | "event period to sample"), |
1265 | OPT_INTEGER('p', "pid", &target_pid, | 1348 | OPT_INTEGER('p', "pid", &target_pid, |
1266 | "profile events on existing pid"), | 1349 | "profile events on existing process id"), |
1350 | OPT_INTEGER('t', "tid", &target_tid, | ||
1351 | "profile events on existing thread id"), | ||
1267 | OPT_BOOLEAN('a', "all-cpus", &system_wide, | 1352 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
1268 | "system-wide collection from all CPUs"), | 1353 | "system-wide collection from all CPUs"), |
1269 | OPT_INTEGER('C', "CPU", &profile_cpu, | 1354 | OPT_INTEGER('C', "CPU", &profile_cpu, |
@@ -1272,8 +1357,7 @@ static const struct option options[] = { | |||
1272 | "file", "vmlinux pathname"), | 1357 | "file", "vmlinux pathname"), |
1273 | OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols, | 1358 | OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols, |
1274 | "hide kernel symbols"), | 1359 | "hide kernel symbols"), |
1275 | OPT_INTEGER('m', "mmap-pages", &mmap_pages, | 1360 | OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), |
1276 | "number of mmap data pages"), | ||
1277 | OPT_INTEGER('r', "realtime", &realtime_prio, | 1361 | OPT_INTEGER('r', "realtime", &realtime_prio, |
1278 | "collect data with this RT SCHED_FIFO priority"), | 1362 | "collect data with this RT SCHED_FIFO priority"), |
1279 | OPT_INTEGER('d', "delay", &delay_secs, | 1363 | OPT_INTEGER('d', "delay", &delay_secs, |
@@ -1296,7 +1380,7 @@ static const struct option options[] = { | |||
1296 | "display this many functions"), | 1380 | "display this many functions"), |
1297 | OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols, | 1381 | OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols, |
1298 | "hide user symbols"), | 1382 | "hide user symbols"), |
1299 | OPT_BOOLEAN('v', "verbose", &verbose, | 1383 | OPT_INCR('v', "verbose", &verbose, |
1300 | "be more verbose (show counter open errors, etc)"), | 1384 | "be more verbose (show counter open errors, etc)"), |
1301 | OPT_END() | 1385 | OPT_END() |
1302 | }; | 1386 | }; |
@@ -1304,6 +1388,7 @@ static const struct option options[] = { | |||
1304 | int cmd_top(int argc, const char **argv, const char *prefix __used) | 1388 | int cmd_top(int argc, const char **argv, const char *prefix __used) |
1305 | { | 1389 | { |
1306 | int counter; | 1390 | int counter; |
1391 | int i,j; | ||
1307 | 1392 | ||
1308 | page_size = sysconf(_SC_PAGE_SIZE); | 1393 | page_size = sysconf(_SC_PAGE_SIZE); |
1309 | 1394 | ||
@@ -1311,8 +1396,39 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) | |||
1311 | if (argc) | 1396 | if (argc) |
1312 | usage_with_options(top_usage, options); | 1397 | usage_with_options(top_usage, options); |
1313 | 1398 | ||
1399 | if (target_pid != -1) { | ||
1400 | target_tid = target_pid; | ||
1401 | thread_num = find_all_tid(target_pid, &all_tids); | ||
1402 | if (thread_num <= 0) { | ||
1403 | fprintf(stderr, "Can't find all threads of pid %d\n", | ||
1404 | target_pid); | ||
1405 | usage_with_options(top_usage, options); | ||
1406 | } | ||
1407 | } else { | ||
1408 | all_tids=malloc(sizeof(pid_t)); | ||
1409 | if (!all_tids) | ||
1410 | return -ENOMEM; | ||
1411 | |||
1412 | all_tids[0] = target_tid; | ||
1413 | thread_num = 1; | ||
1414 | } | ||
1415 | |||
1416 | for (i = 0; i < MAX_NR_CPUS; i++) { | ||
1417 | for (j = 0; j < MAX_COUNTERS; j++) { | ||
1418 | fd[i][j] = malloc(sizeof(int)*thread_num); | ||
1419 | mmap_array[i][j] = zalloc( | ||
1420 | sizeof(struct mmap_data)*thread_num); | ||
1421 | if (!fd[i][j] || !mmap_array[i][j]) | ||
1422 | return -ENOMEM; | ||
1423 | } | ||
1424 | } | ||
1425 | event_array = malloc( | ||
1426 | sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num); | ||
1427 | if (!event_array) | ||
1428 | return -ENOMEM; | ||
1429 | |||
1314 | /* CPU and PID are mutually exclusive */ | 1430 | /* CPU and PID are mutually exclusive */ |
1315 | if (target_pid != -1 && profile_cpu != -1) { | 1431 | if (target_tid > 0 && profile_cpu != -1) { |
1316 | printf("WARNING: PID switch overriding CPU\n"); | 1432 | printf("WARNING: PID switch overriding CPU\n"); |
1317 | sleep(1); | 1433 | sleep(1); |
1318 | profile_cpu = -1; | 1434 | profile_cpu = -1; |
@@ -1353,7 +1469,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) | |||
1353 | attrs[counter].sample_period = default_interval; | 1469 | attrs[counter].sample_period = default_interval; |
1354 | } | 1470 | } |
1355 | 1471 | ||
1356 | if (target_pid != -1 || profile_cpu != -1) | 1472 | if (target_tid != -1 || profile_cpu != -1) |
1357 | nr_cpus = 1; | 1473 | nr_cpus = 1; |
1358 | else | 1474 | else |
1359 | nr_cpus = read_cpu_map(); | 1475 | nr_cpus = read_cpu_map(); |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 407041d20de0..dddf3f01b5ab 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -11,6 +11,8 @@ | |||
11 | 11 | ||
12 | static char const *script_name; | 12 | static char const *script_name; |
13 | static char const *generate_script_lang; | 13 | static char const *generate_script_lang; |
14 | static bool debug_ordering; | ||
15 | static u64 last_timestamp; | ||
14 | 16 | ||
15 | static int default_start_script(const char *script __unused, | 17 | static int default_start_script(const char *script __unused, |
16 | int argc __unused, | 18 | int argc __unused, |
@@ -51,6 +53,8 @@ static void setup_scripting(void) | |||
51 | 53 | ||
52 | static int cleanup_scripting(void) | 54 | static int cleanup_scripting(void) |
53 | { | 55 | { |
56 | pr_debug("\nperf trace script stopped\n"); | ||
57 | |||
54 | return scripting_ops->stop_script(); | 58 | return scripting_ops->stop_script(); |
55 | } | 59 | } |
56 | 60 | ||
@@ -87,6 +91,14 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
87 | } | 91 | } |
88 | 92 | ||
89 | if (session->sample_type & PERF_SAMPLE_RAW) { | 93 | if (session->sample_type & PERF_SAMPLE_RAW) { |
94 | if (debug_ordering) { | ||
95 | if (data.time < last_timestamp) { | ||
96 | pr_err("Samples misordered, previous: %llu " | ||
97 | "this: %llu\n", last_timestamp, | ||
98 | data.time); | ||
99 | } | ||
100 | last_timestamp = data.time; | ||
101 | } | ||
90 | /* | 102 | /* |
91 | * FIXME: better resolve from pid from the struct trace_entry | 103 | * FIXME: better resolve from pid from the struct trace_entry |
92 | * field, although it should be the same than this perf | 104 | * field, although it should be the same than this perf |
@@ -97,17 +109,31 @@ static int process_sample_event(event_t *event, struct perf_session *session) | |||
97 | data.time, thread->comm); | 109 | data.time, thread->comm); |
98 | } | 110 | } |
99 | 111 | ||
100 | session->events_stats.total += data.period; | 112 | session->hists.stats.total_period += data.period; |
101 | return 0; | 113 | return 0; |
102 | } | 114 | } |
103 | 115 | ||
104 | static struct perf_event_ops event_ops = { | 116 | static struct perf_event_ops event_ops = { |
105 | .sample = process_sample_event, | 117 | .sample = process_sample_event, |
106 | .comm = event__process_comm, | 118 | .comm = event__process_comm, |
119 | .attr = event__process_attr, | ||
120 | .event_type = event__process_event_type, | ||
121 | .tracing_data = event__process_tracing_data, | ||
122 | .build_id = event__process_build_id, | ||
123 | .ordered_samples = true, | ||
107 | }; | 124 | }; |
108 | 125 | ||
126 | extern volatile int session_done; | ||
127 | |||
128 | static void sig_handler(int sig __unused) | ||
129 | { | ||
130 | session_done = 1; | ||
131 | } | ||
132 | |||
109 | static int __cmd_trace(struct perf_session *session) | 133 | static int __cmd_trace(struct perf_session *session) |
110 | { | 134 | { |
135 | signal(SIGINT, sig_handler); | ||
136 | |||
111 | return perf_session__process_events(session, &event_ops); | 137 | return perf_session__process_events(session, &event_ops); |
112 | } | 138 | } |
113 | 139 | ||
@@ -505,7 +531,7 @@ static const char * const trace_usage[] = { | |||
505 | static const struct option options[] = { | 531 | static const struct option options[] = { |
506 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 532 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
507 | "dump raw trace in ASCII"), | 533 | "dump raw trace in ASCII"), |
508 | OPT_BOOLEAN('v', "verbose", &verbose, | 534 | OPT_INCR('v', "verbose", &verbose, |
509 | "be more verbose (show symbol address, etc)"), | 535 | "be more verbose (show symbol address, etc)"), |
510 | OPT_BOOLEAN('L', "Latency", &latency_format, | 536 | OPT_BOOLEAN('L', "Latency", &latency_format, |
511 | "show latency attributes (irqs/preemption disabled, etc)"), | 537 | "show latency attributes (irqs/preemption disabled, etc)"), |
@@ -518,6 +544,8 @@ static const struct option options[] = { | |||
518 | "generate perf-trace.xx script in specified language"), | 544 | "generate perf-trace.xx script in specified language"), |
519 | OPT_STRING('i', "input", &input_name, "file", | 545 | OPT_STRING('i', "input", &input_name, "file", |
520 | "input file name"), | 546 | "input file name"), |
547 | OPT_BOOLEAN('d', "debug-ordering", &debug_ordering, | ||
548 | "check that samples time ordering is monotonic"), | ||
521 | 549 | ||
522 | OPT_END() | 550 | OPT_END() |
523 | }; | 551 | }; |
@@ -548,6 +576,65 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
548 | suffix = REPORT_SUFFIX; | 576 | suffix = REPORT_SUFFIX; |
549 | } | 577 | } |
550 | 578 | ||
579 | if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) { | ||
580 | char *record_script_path, *report_script_path; | ||
581 | int live_pipe[2]; | ||
582 | pid_t pid; | ||
583 | |||
584 | record_script_path = get_script_path(argv[1], RECORD_SUFFIX); | ||
585 | if (!record_script_path) { | ||
586 | fprintf(stderr, "record script not found\n"); | ||
587 | return -1; | ||
588 | } | ||
589 | |||
590 | report_script_path = get_script_path(argv[1], REPORT_SUFFIX); | ||
591 | if (!report_script_path) { | ||
592 | fprintf(stderr, "report script not found\n"); | ||
593 | return -1; | ||
594 | } | ||
595 | |||
596 | if (pipe(live_pipe) < 0) { | ||
597 | perror("failed to create pipe"); | ||
598 | exit(-1); | ||
599 | } | ||
600 | |||
601 | pid = fork(); | ||
602 | if (pid < 0) { | ||
603 | perror("failed to fork"); | ||
604 | exit(-1); | ||
605 | } | ||
606 | |||
607 | if (!pid) { | ||
608 | dup2(live_pipe[1], 1); | ||
609 | close(live_pipe[0]); | ||
610 | |||
611 | __argv = malloc(5 * sizeof(const char *)); | ||
612 | __argv[0] = "/bin/sh"; | ||
613 | __argv[1] = record_script_path; | ||
614 | __argv[2] = "-o"; | ||
615 | __argv[3] = "-"; | ||
616 | __argv[4] = NULL; | ||
617 | |||
618 | execvp("/bin/sh", (char **)__argv); | ||
619 | exit(-1); | ||
620 | } | ||
621 | |||
622 | dup2(live_pipe[0], 0); | ||
623 | close(live_pipe[1]); | ||
624 | |||
625 | __argv = malloc((argc + 3) * sizeof(const char *)); | ||
626 | __argv[0] = "/bin/sh"; | ||
627 | __argv[1] = report_script_path; | ||
628 | for (i = 2; i < argc; i++) | ||
629 | __argv[i] = argv[i]; | ||
630 | __argv[i++] = "-i"; | ||
631 | __argv[i++] = "-"; | ||
632 | __argv[i++] = NULL; | ||
633 | |||
634 | execvp("/bin/sh", (char **)__argv); | ||
635 | exit(-1); | ||
636 | } | ||
637 | |||
551 | if (suffix) { | 638 | if (suffix) { |
552 | script_path = get_script_path(argv[2], suffix); | 639 | script_path = get_script_path(argv[2], suffix); |
553 | if (!script_path) { | 640 | if (!script_path) { |
@@ -576,11 +663,12 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
576 | if (!script_name) | 663 | if (!script_name) |
577 | setup_pager(); | 664 | setup_pager(); |
578 | 665 | ||
579 | session = perf_session__new(input_name, O_RDONLY, 0); | 666 | session = perf_session__new(input_name, O_RDONLY, 0, false); |
580 | if (session == NULL) | 667 | if (session == NULL) |
581 | return -ENOMEM; | 668 | return -ENOMEM; |
582 | 669 | ||
583 | if (!perf_session__has_traces(session, "record -R")) | 670 | if (strcmp(input_name, "-") && |
671 | !perf_session__has_traces(session, "record -R")) | ||
584 | return -EINVAL; | 672 | return -EINVAL; |
585 | 673 | ||
586 | if (generate_script_lang) { | 674 | if (generate_script_lang) { |
@@ -617,6 +705,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used) | |||
617 | err = scripting_ops->start_script(script_name, argc, argv); | 705 | err = scripting_ops->start_script(script_name, argc, argv); |
618 | if (err) | 706 | if (err) |
619 | goto out; | 707 | goto out; |
708 | pr_debug("perf trace started with script %s\n\n", script_name); | ||
620 | } | 709 | } |
621 | 710 | ||
622 | err = __cmd_trace(session); | 711 | err = __cmd_trace(session); |
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 10fe49e7048a..921245b28583 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h | |||
@@ -32,5 +32,8 @@ extern int cmd_version(int argc, const char **argv, const char *prefix); | |||
32 | extern int cmd_probe(int argc, const char **argv, const char *prefix); | 32 | extern int cmd_probe(int argc, const char **argv, const char *prefix); |
33 | extern int cmd_kmem(int argc, const char **argv, const char *prefix); | 33 | extern int cmd_kmem(int argc, const char **argv, const char *prefix); |
34 | extern int cmd_lock(int argc, const char **argv, const char *prefix); | 34 | extern int cmd_lock(int argc, const char **argv, const char *prefix); |
35 | extern int cmd_kvm(int argc, const char **argv, const char *prefix); | ||
36 | extern int cmd_test(int argc, const char **argv, const char *prefix); | ||
37 | extern int cmd_inject(int argc, const char **argv, const char *prefix); | ||
35 | 38 | ||
36 | #endif | 39 | #endif |
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt index db6ee94d4a8e..949d77fc0b97 100644 --- a/tools/perf/command-list.txt +++ b/tools/perf/command-list.txt | |||
@@ -8,6 +8,7 @@ perf-bench mainporcelain common | |||
8 | perf-buildid-cache mainporcelain common | 8 | perf-buildid-cache mainporcelain common |
9 | perf-buildid-list mainporcelain common | 9 | perf-buildid-list mainporcelain common |
10 | perf-diff mainporcelain common | 10 | perf-diff mainporcelain common |
11 | perf-inject mainporcelain common | ||
11 | perf-list mainporcelain common | 12 | perf-list mainporcelain common |
12 | perf-sched mainporcelain common | 13 | perf-sched mainporcelain common |
13 | perf-record mainporcelain common | 14 | perf-record mainporcelain common |
@@ -19,3 +20,5 @@ perf-trace mainporcelain common | |||
19 | perf-probe mainporcelain common | 20 | perf-probe mainporcelain common |
20 | perf-kmem mainporcelain common | 21 | perf-kmem mainporcelain common |
21 | perf-lock mainporcelain common | 22 | perf-lock mainporcelain common |
23 | perf-kvm mainporcelain common | ||
24 | perf-test mainporcelain common | ||
diff --git a/tools/perf/perf-archive.sh b/tools/perf/perf-archive.sh index 910468e6e01c..2e7a4f417e20 100644 --- a/tools/perf/perf-archive.sh +++ b/tools/perf/perf-archive.sh | |||
@@ -30,4 +30,7 @@ done | |||
30 | 30 | ||
31 | tar cfj $PERF_DATA.tar.bz2 -C $DEBUGDIR -T $MANIFEST | 31 | tar cfj $PERF_DATA.tar.bz2 -C $DEBUGDIR -T $MANIFEST |
32 | rm -f $MANIFEST $BUILDIDS | 32 | rm -f $MANIFEST $BUILDIDS |
33 | echo -e "Now please run:\n" | ||
34 | echo -e "$ tar xvf $PERF_DATA.tar.bz2 -C ~/.debug\n" | ||
35 | echo "wherever you need to run 'perf report' on." | ||
33 | exit 0 | 36 | exit 0 |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index cd32c200cdb3..08e0e5d2b50e 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -13,9 +13,10 @@ | |||
13 | #include "util/quote.h" | 13 | #include "util/quote.h" |
14 | #include "util/run-command.h" | 14 | #include "util/run-command.h" |
15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
16 | #include "util/string.h" | ||
17 | #include "util/debugfs.h" | 16 | #include "util/debugfs.h" |
18 | 17 | ||
18 | bool use_browser; | ||
19 | |||
19 | const char perf_usage_string[] = | 20 | const char perf_usage_string[] = |
20 | "perf [--version] [--help] COMMAND [ARGS]"; | 21 | "perf [--version] [--help] COMMAND [ARGS]"; |
21 | 22 | ||
@@ -262,6 +263,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
262 | set_debugfs_path(); | 263 | set_debugfs_path(); |
263 | 264 | ||
264 | status = p->fn(argc, argv, prefix); | 265 | status = p->fn(argc, argv, prefix); |
266 | exit_browser(status); | ||
267 | |||
265 | if (status) | 268 | if (status) |
266 | return status & 0xff; | 269 | return status & 0xff; |
267 | 270 | ||
@@ -304,6 +307,9 @@ static void handle_internal_command(int argc, const char **argv) | |||
304 | { "probe", cmd_probe, 0 }, | 307 | { "probe", cmd_probe, 0 }, |
305 | { "kmem", cmd_kmem, 0 }, | 308 | { "kmem", cmd_kmem, 0 }, |
306 | { "lock", cmd_lock, 0 }, | 309 | { "lock", cmd_lock, 0 }, |
310 | { "kvm", cmd_kvm, 0 }, | ||
311 | { "test", cmd_test, 0 }, | ||
312 | { "inject", cmd_inject, 0 }, | ||
307 | }; | 313 | }; |
308 | unsigned int i; | 314 | unsigned int i; |
309 | static const char ext[] = STRIP_EXTENSION; | 315 | static const char ext[] = STRIP_EXTENSION; |
diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 6fb379bc1d1f..ef7aa0a0c526 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h | |||
@@ -1,6 +1,10 @@ | |||
1 | #ifndef _PERF_PERF_H | 1 | #ifndef _PERF_PERF_H |
2 | #define _PERF_PERF_H | 2 | #define _PERF_PERF_H |
3 | 3 | ||
4 | struct winsize; | ||
5 | |||
6 | void get_term_dimensions(struct winsize *ws); | ||
7 | |||
4 | #if defined(__i386__) | 8 | #if defined(__i386__) |
5 | #include "../../arch/x86/include/asm/unistd.h" | 9 | #include "../../arch/x86/include/asm/unistd.h" |
6 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") | 10 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") |
@@ -76,6 +80,7 @@ | |||
76 | 80 | ||
77 | #include "../../include/linux/perf_event.h" | 81 | #include "../../include/linux/perf_event.h" |
78 | #include "util/types.h" | 82 | #include "util/types.h" |
83 | #include <stdbool.h> | ||
79 | 84 | ||
80 | /* | 85 | /* |
81 | * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all | 86 | * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all |
@@ -102,8 +107,6 @@ static inline unsigned long long rdclock(void) | |||
102 | #define __user | 107 | #define __user |
103 | #define asmlinkage | 108 | #define asmlinkage |
104 | 109 | ||
105 | #define __used __attribute__((__unused__)) | ||
106 | |||
107 | #define unlikely(x) __builtin_expect(!!(x), 0) | 110 | #define unlikely(x) __builtin_expect(!!(x), 0) |
108 | #define min(x, y) ({ \ | 111 | #define min(x, y) ({ \ |
109 | typeof(x) _min1 = (x); \ | 112 | typeof(x) _min1 = (x); \ |
@@ -129,4 +132,6 @@ struct ip_callchain { | |||
129 | u64 ips[0]; | 132 | u64 ips[0]; |
130 | }; | 133 | }; |
131 | 134 | ||
135 | extern bool perf_host, perf_guest; | ||
136 | |||
132 | #endif | 137 | #endif |
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm index f869c48dc9b0..d94b40c8ac85 100644 --- a/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm +++ b/tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm | |||
@@ -15,6 +15,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||
15 | 15 | ||
16 | our @EXPORT = qw( | 16 | our @EXPORT = qw( |
17 | avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs | 17 | avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs |
18 | clear_term | ||
18 | ); | 19 | ); |
19 | 20 | ||
20 | our $VERSION = '0.01'; | 21 | our $VERSION = '0.01'; |
@@ -55,6 +56,11 @@ sub nsecs_str { | |||
55 | return $str; | 56 | return $str; |
56 | } | 57 | } |
57 | 58 | ||
59 | sub clear_term | ||
60 | { | ||
61 | print "\x1b[H\x1b[2J"; | ||
62 | } | ||
63 | |||
58 | 1; | 64 | 1; |
59 | __END__ | 65 | __END__ |
60 | =head1 NAME | 66 | =head1 NAME |
diff --git a/tools/perf/scripts/perl/bin/check-perf-trace-record b/tools/perf/scripts/perl/bin/check-perf-trace-record index e6cb1474f8e8..423ad6aed056 100644 --- a/tools/perf/scripts/perl/bin/check-perf-trace-record +++ b/tools/perf/scripts/perl/bin/check-perf-trace-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree | 2 | perf record -a -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree |
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-record b/tools/perf/scripts/perl/bin/failed-syscalls-record index f8885d389e6f..eb5846bcb565 100644 --- a/tools/perf/scripts/perl/bin/failed-syscalls-record +++ b/tools/perf/scripts/perl/bin/failed-syscalls-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit | 2 | perf record -a -e raw_syscalls:sys_exit $@ |
diff --git a/tools/perf/scripts/perl/bin/failed-syscalls-report b/tools/perf/scripts/perl/bin/failed-syscalls-report index 8bfc660e5056..e3a5e55d54ff 100644 --- a/tools/perf/scripts/perl/bin/failed-syscalls-report +++ b/tools/perf/scripts/perl/bin/failed-syscalls-report | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide failed syscalls | 2 | # description: system-wide failed syscalls |
3 | # args: [comm] | 3 | # args: [comm] |
4 | perf trace -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $1 | 4 | if [ $# -gt 0 ] ; then |
5 | if ! expr match "$1" "-" > /dev/null ; then | ||
6 | comm=$1 | ||
7 | shift | ||
8 | fi | ||
9 | fi | ||
10 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $comm | ||
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-record b/tools/perf/scripts/perl/bin/rw-by-file-record index b25056ebf963..5bfaae5a6cba 100644 --- a/tools/perf/scripts/perl/bin/rw-by-file-record +++ b/tools/perf/scripts/perl/bin/rw-by-file-record | |||
@@ -1,2 +1,3 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_enter_write | 2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@ |
3 | |||
diff --git a/tools/perf/scripts/perl/bin/rw-by-file-report b/tools/perf/scripts/perl/bin/rw-by-file-report index eddb9ccce6a5..d83070b7eeb5 100644 --- a/tools/perf/scripts/perl/bin/rw-by-file-report +++ b/tools/perf/scripts/perl/bin/rw-by-file-report | |||
@@ -1,7 +1,13 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: r/w activity for a program, by file | 2 | # description: r/w activity for a program, by file |
3 | # args: <comm> | 3 | # args: <comm> |
4 | perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $1 | 4 | if [ $# -lt 1 ] ; then |
5 | echo "usage: rw-by-file <comm>" | ||
6 | exit | ||
7 | fi | ||
8 | comm=$1 | ||
9 | shift | ||
10 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $comm | ||
5 | 11 | ||
6 | 12 | ||
7 | 13 | ||
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-record b/tools/perf/scripts/perl/bin/rw-by-pid-record index 8903979c5b6c..6e0b2f7755ac 100644 --- a/tools/perf/scripts/perl/bin/rw-by-pid-record +++ b/tools/perf/scripts/perl/bin/rw-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write | 2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ |
diff --git a/tools/perf/scripts/perl/bin/rw-by-pid-report b/tools/perf/scripts/perl/bin/rw-by-pid-report index 7f44c25cc857..7ef46983f62f 100644 --- a/tools/perf/scripts/perl/bin/rw-by-pid-report +++ b/tools/perf/scripts/perl/bin/rw-by-pid-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide r/w activity | 2 | # description: system-wide r/w activity |
3 | perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl | 3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/perl/bin/rwtop-record b/tools/perf/scripts/perl/bin/rwtop-record new file mode 100644 index 000000000000..6e0b2f7755ac --- /dev/null +++ b/tools/perf/scripts/perl/bin/rwtop-record | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/bash | ||
2 | perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@ | ||
diff --git a/tools/perf/scripts/perl/bin/rwtop-report b/tools/perf/scripts/perl/bin/rwtop-report new file mode 100644 index 000000000000..93e698cd3f38 --- /dev/null +++ b/tools/perf/scripts/perl/bin/rwtop-report | |||
@@ -0,0 +1,23 @@ | |||
1 | #!/bin/bash | ||
2 | # description: system-wide r/w top | ||
3 | # args: [interval] | ||
4 | n_args=0 | ||
5 | for i in "$@" | ||
6 | do | ||
7 | if expr match "$i" "-" > /dev/null ; then | ||
8 | break | ||
9 | fi | ||
10 | n_args=$(( $n_args + 1 )) | ||
11 | done | ||
12 | if [ "$n_args" -gt 1 ] ; then | ||
13 | echo "usage: rwtop-report [interval]" | ||
14 | exit | ||
15 | fi | ||
16 | if [ "$n_args" -gt 0 ] ; then | ||
17 | interval=$1 | ||
18 | shift | ||
19 | fi | ||
20 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/rwtop.pl $interval | ||
21 | |||
22 | |||
23 | |||
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-record b/tools/perf/scripts/perl/bin/wakeup-latency-record index 6abedda911a4..9f2acaaae9f0 100644 --- a/tools/perf/scripts/perl/bin/wakeup-latency-record +++ b/tools/perf/scripts/perl/bin/wakeup-latency-record | |||
@@ -1,5 +1,5 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e sched:sched_switch -e sched:sched_wakeup | 2 | perf record -a -e sched:sched_switch -e sched:sched_wakeup $@ |
3 | 3 | ||
4 | 4 | ||
5 | 5 | ||
diff --git a/tools/perf/scripts/perl/bin/wakeup-latency-report b/tools/perf/scripts/perl/bin/wakeup-latency-report index fce3adcb3249..a0d898f9ca1d 100644 --- a/tools/perf/scripts/perl/bin/wakeup-latency-report +++ b/tools/perf/scripts/perl/bin/wakeup-latency-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide min/max/avg wakeup latency | 2 | # description: system-wide min/max/avg wakeup latency |
3 | perf trace -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl | 3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-record b/tools/perf/scripts/perl/bin/workqueue-stats-record index fce6637b19ba..85301f2471ff 100644 --- a/tools/perf/scripts/perl/bin/workqueue-stats-record +++ b/tools/perf/scripts/perl/bin/workqueue-stats-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion | 2 | perf record -a -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@ |
diff --git a/tools/perf/scripts/perl/bin/workqueue-stats-report b/tools/perf/scripts/perl/bin/workqueue-stats-report index 71cfbd182fb9..35081132ef97 100644 --- a/tools/perf/scripts/perl/bin/workqueue-stats-report +++ b/tools/perf/scripts/perl/bin/workqueue-stats-report | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: workqueue stats (ins/exe/create/destroy) | 2 | # description: workqueue stats (ins/exe/create/destroy) |
3 | perf trace -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl | 3 | perf trace $@ -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl |
4 | 4 | ||
5 | 5 | ||
6 | 6 | ||
diff --git a/tools/perf/scripts/perl/failed-syscalls.pl b/tools/perf/scripts/perl/failed-syscalls.pl index c18e7e27a84b..94bc25a347eb 100644 --- a/tools/perf/scripts/perl/failed-syscalls.pl +++ b/tools/perf/scripts/perl/failed-syscalls.pl | |||
@@ -11,6 +11,8 @@ use Perf::Trace::Core; | |||
11 | use Perf::Trace::Context; | 11 | use Perf::Trace::Context; |
12 | use Perf::Trace::Util; | 12 | use Perf::Trace::Util; |
13 | 13 | ||
14 | my $for_comm = shift; | ||
15 | |||
14 | my %failed_syscalls; | 16 | my %failed_syscalls; |
15 | 17 | ||
16 | sub raw_syscalls::sys_exit | 18 | sub raw_syscalls::sys_exit |
@@ -33,6 +35,8 @@ sub trace_end | |||
33 | 35 | ||
34 | foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}} | 36 | foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}} |
35 | keys %failed_syscalls) { | 37 | keys %failed_syscalls) { |
36 | printf("%-20s %10s\n", $comm, $failed_syscalls{$comm}); | 38 | next if ($for_comm && $comm ne $for_comm); |
39 | |||
40 | printf("%-20s %10s\n", $comm, $failed_syscalls{$comm}); | ||
37 | } | 41 | } |
38 | } | 42 | } |
diff --git a/tools/perf/scripts/perl/rw-by-pid.pl b/tools/perf/scripts/perl/rw-by-pid.pl index da601fae1a00..9db23c9daf55 100644 --- a/tools/perf/scripts/perl/rw-by-pid.pl +++ b/tools/perf/scripts/perl/rw-by-pid.pl | |||
@@ -79,12 +79,12 @@ sub trace_end | |||
79 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", | 79 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", |
80 | "-----------", "----------", "----------"); | 80 | "-----------", "----------", "----------"); |
81 | 81 | ||
82 | foreach my $pid (sort {$reads{$b}{bytes_read} <=> | 82 | foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> |
83 | $reads{$a}{bytes_read}} keys %reads) { | 83 | ($reads{$a}{bytes_read} || 0) } keys %reads) { |
84 | my $comm = $reads{$pid}{comm}; | 84 | my $comm = $reads{$pid}{comm} || ""; |
85 | my $total_reads = $reads{$pid}{total_reads}; | 85 | my $total_reads = $reads{$pid}{total_reads} || 0; |
86 | my $bytes_requested = $reads{$pid}{bytes_requested}; | 86 | my $bytes_requested = $reads{$pid}{bytes_requested} || 0; |
87 | my $bytes_read = $reads{$pid}{bytes_read}; | 87 | my $bytes_read = $reads{$pid}{bytes_read} || 0; |
88 | 88 | ||
89 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, | 89 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, |
90 | $total_reads, $bytes_requested, $bytes_read); | 90 | $total_reads, $bytes_requested, $bytes_read); |
@@ -96,16 +96,23 @@ sub trace_end | |||
96 | printf("%6s %20s %6s %10s\n", "------", "--------------------", | 96 | printf("%6s %20s %6s %10s\n", "------", "--------------------", |
97 | "------", "----------"); | 97 | "------", "----------"); |
98 | 98 | ||
99 | foreach my $pid (keys %reads) { | 99 | my @errcounts = (); |
100 | my $comm = $reads{$pid}{comm}; | ||
101 | foreach my $err (sort {$reads{$b}{comm} cmp $reads{$a}{comm}} | ||
102 | keys %{$reads{$pid}{errors}}) { | ||
103 | my $errors = $reads{$pid}{errors}{$err}; | ||
104 | 100 | ||
105 | printf("%6d %-20s %6d %10s\n", $pid, $comm, $err, $errors); | 101 | foreach my $pid (keys %reads) { |
102 | foreach my $error (keys %{$reads{$pid}{errors}}) { | ||
103 | my $comm = $reads{$pid}{comm} || ""; | ||
104 | my $errcount = $reads{$pid}{errors}{$error} || 0; | ||
105 | push @errcounts, [$pid, $comm, $error, $errcount]; | ||
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts; | ||
110 | |||
111 | for my $i (0 .. $#errcounts) { | ||
112 | printf("%6d %-20s %6d %10s\n", $errcounts[$i][0], | ||
113 | $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]); | ||
114 | } | ||
115 | |||
109 | printf("\nwrite counts by pid:\n\n"); | 116 | printf("\nwrite counts by pid:\n\n"); |
110 | 117 | ||
111 | printf("%6s %20s %10s %10s\n", "pid", "comm", | 118 | printf("%6s %20s %10s %10s\n", "pid", "comm", |
@@ -113,11 +120,11 @@ sub trace_end | |||
113 | printf("%6s %-20s %10s %10s\n", "------", "--------------------", | 120 | printf("%6s %-20s %10s %10s\n", "------", "--------------------", |
114 | "-----------", "----------"); | 121 | "-----------", "----------"); |
115 | 122 | ||
116 | foreach my $pid (sort {$writes{$b}{bytes_written} <=> | 123 | foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> |
117 | $writes{$a}{bytes_written}} keys %writes) { | 124 | ($writes{$a}{bytes_written} || 0)} keys %writes) { |
118 | my $comm = $writes{$pid}{comm}; | 125 | my $comm = $writes{$pid}{comm} || ""; |
119 | my $total_writes = $writes{$pid}{total_writes}; | 126 | my $total_writes = $writes{$pid}{total_writes} || 0; |
120 | my $bytes_written = $writes{$pid}{bytes_written}; | 127 | my $bytes_written = $writes{$pid}{bytes_written} || 0; |
121 | 128 | ||
122 | printf("%6s %-20s %10s %10s\n", $pid, $comm, | 129 | printf("%6s %-20s %10s %10s\n", $pid, $comm, |
123 | $total_writes, $bytes_written); | 130 | $total_writes, $bytes_written); |
@@ -129,16 +136,23 @@ sub trace_end | |||
129 | printf("%6s %20s %6s %10s\n", "------", "--------------------", | 136 | printf("%6s %20s %6s %10s\n", "------", "--------------------", |
130 | "------", "----------"); | 137 | "------", "----------"); |
131 | 138 | ||
132 | foreach my $pid (keys %writes) { | 139 | @errcounts = (); |
133 | my $comm = $writes{$pid}{comm}; | ||
134 | foreach my $err (sort {$writes{$b}{comm} cmp $writes{$a}{comm}} | ||
135 | keys %{$writes{$pid}{errors}}) { | ||
136 | my $errors = $writes{$pid}{errors}{$err}; | ||
137 | 140 | ||
138 | printf("%6d %-20s %6d %10s\n", $pid, $comm, $err, $errors); | 141 | foreach my $pid (keys %writes) { |
142 | foreach my $error (keys %{$writes{$pid}{errors}}) { | ||
143 | my $comm = $writes{$pid}{comm} || ""; | ||
144 | my $errcount = $writes{$pid}{errors}{$error} || 0; | ||
145 | push @errcounts, [$pid, $comm, $error, $errcount]; | ||
139 | } | 146 | } |
140 | } | 147 | } |
141 | 148 | ||
149 | @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts; | ||
150 | |||
151 | for my $i (0 .. $#errcounts) { | ||
152 | printf("%6d %-20s %6d %10s\n", $errcounts[$i][0], | ||
153 | $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]); | ||
154 | } | ||
155 | |||
142 | print_unhandled(); | 156 | print_unhandled(); |
143 | } | 157 | } |
144 | 158 | ||
diff --git a/tools/perf/scripts/perl/rwtop.pl b/tools/perf/scripts/perl/rwtop.pl new file mode 100644 index 000000000000..4bb3ecd33472 --- /dev/null +++ b/tools/perf/scripts/perl/rwtop.pl | |||
@@ -0,0 +1,199 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | |||
5 | # read/write top | ||
6 | # | ||
7 | # Periodically displays system-wide r/w call activity, broken down by | ||
8 | # pid. If an [interval] arg is specified, the display will be | ||
9 | # refreshed every [interval] seconds. The default interval is 3 | ||
10 | # seconds. | ||
11 | |||
12 | use 5.010000; | ||
13 | use strict; | ||
14 | use warnings; | ||
15 | |||
16 | use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib"; | ||
17 | use lib "./Perf-Trace-Util/lib"; | ||
18 | use Perf::Trace::Core; | ||
19 | use Perf::Trace::Util; | ||
20 | |||
21 | my $default_interval = 3; | ||
22 | my $nlines = 20; | ||
23 | my $print_thread; | ||
24 | my $print_pending = 0; | ||
25 | |||
26 | my %reads; | ||
27 | my %writes; | ||
28 | |||
29 | my $interval = shift; | ||
30 | if (!$interval) { | ||
31 | $interval = $default_interval; | ||
32 | } | ||
33 | |||
34 | sub syscalls::sys_exit_read | ||
35 | { | ||
36 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
37 | $common_pid, $common_comm, | ||
38 | $nr, $ret) = @_; | ||
39 | |||
40 | print_check(); | ||
41 | |||
42 | if ($ret > 0) { | ||
43 | $reads{$common_pid}{bytes_read} += $ret; | ||
44 | } else { | ||
45 | if (!defined ($reads{$common_pid}{bytes_read})) { | ||
46 | $reads{$common_pid}{bytes_read} = 0; | ||
47 | } | ||
48 | $reads{$common_pid}{errors}{$ret}++; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | sub syscalls::sys_enter_read | ||
53 | { | ||
54 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
55 | $common_pid, $common_comm, | ||
56 | $nr, $fd, $buf, $count) = @_; | ||
57 | |||
58 | print_check(); | ||
59 | |||
60 | $reads{$common_pid}{bytes_requested} += $count; | ||
61 | $reads{$common_pid}{total_reads}++; | ||
62 | $reads{$common_pid}{comm} = $common_comm; | ||
63 | } | ||
64 | |||
65 | sub syscalls::sys_exit_write | ||
66 | { | ||
67 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
68 | $common_pid, $common_comm, | ||
69 | $nr, $ret) = @_; | ||
70 | |||
71 | print_check(); | ||
72 | |||
73 | if ($ret <= 0) { | ||
74 | $writes{$common_pid}{errors}{$ret}++; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | sub syscalls::sys_enter_write | ||
79 | { | ||
80 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
81 | $common_pid, $common_comm, | ||
82 | $nr, $fd, $buf, $count) = @_; | ||
83 | |||
84 | print_check(); | ||
85 | |||
86 | $writes{$common_pid}{bytes_written} += $count; | ||
87 | $writes{$common_pid}{total_writes}++; | ||
88 | $writes{$common_pid}{comm} = $common_comm; | ||
89 | } | ||
90 | |||
91 | sub trace_begin | ||
92 | { | ||
93 | $SIG{ALRM} = \&set_print_pending; | ||
94 | alarm 1; | ||
95 | } | ||
96 | |||
97 | sub trace_end | ||
98 | { | ||
99 | print_unhandled(); | ||
100 | print_totals(); | ||
101 | } | ||
102 | |||
103 | sub print_check() | ||
104 | { | ||
105 | if ($print_pending == 1) { | ||
106 | $print_pending = 0; | ||
107 | print_totals(); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | sub set_print_pending() | ||
112 | { | ||
113 | $print_pending = 1; | ||
114 | alarm $interval; | ||
115 | } | ||
116 | |||
117 | sub print_totals | ||
118 | { | ||
119 | my $count; | ||
120 | |||
121 | $count = 0; | ||
122 | |||
123 | clear_term(); | ||
124 | |||
125 | printf("\nread counts by pid:\n\n"); | ||
126 | |||
127 | printf("%6s %20s %10s %10s %10s\n", "pid", "comm", | ||
128 | "# reads", "bytes_req", "bytes_read"); | ||
129 | printf("%6s %-20s %10s %10s %10s\n", "------", "--------------------", | ||
130 | "----------", "----------", "----------"); | ||
131 | |||
132 | foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=> | ||
133 | ($reads{$a}{bytes_read} || 0) } keys %reads) { | ||
134 | my $comm = $reads{$pid}{comm} || ""; | ||
135 | my $total_reads = $reads{$pid}{total_reads} || 0; | ||
136 | my $bytes_requested = $reads{$pid}{bytes_requested} || 0; | ||
137 | my $bytes_read = $reads{$pid}{bytes_read} || 0; | ||
138 | |||
139 | printf("%6s %-20s %10s %10s %10s\n", $pid, $comm, | ||
140 | $total_reads, $bytes_requested, $bytes_read); | ||
141 | |||
142 | if (++$count == $nlines) { | ||
143 | last; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | $count = 0; | ||
148 | |||
149 | printf("\nwrite counts by pid:\n\n"); | ||
150 | |||
151 | printf("%6s %20s %10s %13s\n", "pid", "comm", | ||
152 | "# writes", "bytes_written"); | ||
153 | printf("%6s %-20s %10s %13s\n", "------", "--------------------", | ||
154 | "----------", "-------------"); | ||
155 | |||
156 | foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=> | ||
157 | ($writes{$a}{bytes_written} || 0)} keys %writes) { | ||
158 | my $comm = $writes{$pid}{comm} || ""; | ||
159 | my $total_writes = $writes{$pid}{total_writes} || 0; | ||
160 | my $bytes_written = $writes{$pid}{bytes_written} || 0; | ||
161 | |||
162 | printf("%6s %-20s %10s %13s\n", $pid, $comm, | ||
163 | $total_writes, $bytes_written); | ||
164 | |||
165 | if (++$count == $nlines) { | ||
166 | last; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | %reads = (); | ||
171 | %writes = (); | ||
172 | } | ||
173 | |||
174 | my %unhandled; | ||
175 | |||
176 | sub print_unhandled | ||
177 | { | ||
178 | if ((scalar keys %unhandled) == 0) { | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | print "\nunhandled events:\n\n"; | ||
183 | |||
184 | printf("%-40s %10s\n", "event", "count"); | ||
185 | printf("%-40s %10s\n", "----------------------------------------", | ||
186 | "-----------"); | ||
187 | |||
188 | foreach my $event_name (keys %unhandled) { | ||
189 | printf("%-40s %10d\n", $event_name, $unhandled{$event_name}); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | sub trace_unhandled | ||
194 | { | ||
195 | my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs, | ||
196 | $common_pid, $common_comm) = @_; | ||
197 | |||
198 | $unhandled{$event_name}++; | ||
199 | } | ||
diff --git a/tools/perf/scripts/perl/wakeup-latency.pl b/tools/perf/scripts/perl/wakeup-latency.pl index ed58ef284e23..d9143dcec6c6 100644 --- a/tools/perf/scripts/perl/wakeup-latency.pl +++ b/tools/perf/scripts/perl/wakeup-latency.pl | |||
@@ -22,8 +22,8 @@ my %last_wakeup; | |||
22 | 22 | ||
23 | my $max_wakeup_latency; | 23 | my $max_wakeup_latency; |
24 | my $min_wakeup_latency; | 24 | my $min_wakeup_latency; |
25 | my $total_wakeup_latency; | 25 | my $total_wakeup_latency = 0; |
26 | my $total_wakeups; | 26 | my $total_wakeups = 0; |
27 | 27 | ||
28 | sub sched::sched_switch | 28 | sub sched::sched_switch |
29 | { | 29 | { |
@@ -67,8 +67,12 @@ sub trace_end | |||
67 | { | 67 | { |
68 | printf("wakeup_latency stats:\n\n"); | 68 | printf("wakeup_latency stats:\n\n"); |
69 | print "total_wakeups: $total_wakeups\n"; | 69 | print "total_wakeups: $total_wakeups\n"; |
70 | printf("avg_wakeup_latency (ns): %u\n", | 70 | if ($total_wakeups) { |
71 | avg($total_wakeup_latency, $total_wakeups)); | 71 | printf("avg_wakeup_latency (ns): %u\n", |
72 | avg($total_wakeup_latency, $total_wakeups)); | ||
73 | } else { | ||
74 | printf("avg_wakeup_latency (ns): N/A\n"); | ||
75 | } | ||
72 | printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency); | 76 | printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency); |
73 | printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency); | 77 | printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency); |
74 | 78 | ||
diff --git a/tools/perf/scripts/perl/workqueue-stats.pl b/tools/perf/scripts/perl/workqueue-stats.pl index 511302c8a494..b84b12699b70 100644 --- a/tools/perf/scripts/perl/workqueue-stats.pl +++ b/tools/perf/scripts/perl/workqueue-stats.pl | |||
@@ -71,9 +71,9 @@ sub trace_end | |||
71 | printf("%3s %6s %6s\t%-20s\n", "---", "---", "----", "----"); | 71 | printf("%3s %6s %6s\t%-20s\n", "---", "---", "----", "----"); |
72 | foreach my $pidhash (@cpus) { | 72 | foreach my $pidhash (@cpus) { |
73 | while ((my $pid, my $wqhash) = each %$pidhash) { | 73 | while ((my $pid, my $wqhash) = each %$pidhash) { |
74 | my $ins = $$wqhash{'inserted'}; | 74 | my $ins = $$wqhash{'inserted'} || 0; |
75 | my $exe = $$wqhash{'executed'}; | 75 | my $exe = $$wqhash{'executed'} || 0; |
76 | my $comm = $$wqhash{'comm'}; | 76 | my $comm = $$wqhash{'comm'} || ""; |
77 | if ($ins || $exe) { | 77 | if ($ins || $exe) { |
78 | printf("%3u %6u %6u\t%-20s\n", $cpu, $ins, $exe, $comm); | 78 | printf("%3u %6u %6u\t%-20s\n", $cpu, $ins, $exe, $comm); |
79 | } | 79 | } |
@@ -87,9 +87,9 @@ sub trace_end | |||
87 | printf("%3s %6s %6s\t%-20s\n", "---", "-------", "---------", "----"); | 87 | printf("%3s %6s %6s\t%-20s\n", "---", "-------", "---------", "----"); |
88 | foreach my $pidhash (@cpus) { | 88 | foreach my $pidhash (@cpus) { |
89 | while ((my $pid, my $wqhash) = each %$pidhash) { | 89 | while ((my $pid, my $wqhash) = each %$pidhash) { |
90 | my $created = $$wqhash{'created'}; | 90 | my $created = $$wqhash{'created'} || 0; |
91 | my $destroyed = $$wqhash{'destroyed'}; | 91 | my $destroyed = $$wqhash{'destroyed'} || 0; |
92 | my $comm = $$wqhash{'comm'}; | 92 | my $comm = $$wqhash{'comm'} || ""; |
93 | if ($created || $destroyed) { | 93 | if ($created || $destroyed) { |
94 | printf("%3u %6u %6u\t%-20s\n", $cpu, $created, $destroyed, | 94 | printf("%3u %6u %6u\t%-20s\n", $cpu, $created, $destroyed, |
95 | $comm); | 95 | $comm); |
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py index 83e91435ed09..9689bc0acd9f 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | |||
@@ -23,3 +23,6 @@ def nsecs_nsecs(nsecs): | |||
23 | def nsecs_str(nsecs): | 23 | def nsecs_str(nsecs): |
24 | str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), | 24 | str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), |
25 | return str | 25 | return str |
26 | |||
27 | def clear_term(): | ||
28 | print("\x1b[H\x1b[2J") | ||
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record index f8885d389e6f..eb5846bcb565 100644 --- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit | 2 | perf record -a -e raw_syscalls:sys_exit $@ |
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report index 1e0c0a860c87..30293545fcc2 100644 --- a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide failed syscalls, by pid | 2 | # description: system-wide failed syscalls, by pid |
3 | # args: [comm] | 3 | # args: [comm] |
4 | perf trace -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $1 | 4 | if [ $# -gt 0 ] ; then |
5 | if ! expr match "$1" "-" > /dev/null ; then | ||
6 | comm=$1 | ||
7 | shift | ||
8 | fi | ||
9 | fi | ||
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $comm | ||
diff --git a/tools/perf/scripts/python/bin/sctop-record b/tools/perf/scripts/python/bin/sctop-record new file mode 100644 index 000000000000..1fc5998b721d --- /dev/null +++ b/tools/perf/scripts/python/bin/sctop-record | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/bash | ||
2 | perf record -a -e raw_syscalls:sys_enter $@ | ||
diff --git a/tools/perf/scripts/python/bin/sctop-report b/tools/perf/scripts/python/bin/sctop-report new file mode 100644 index 000000000000..b01c842ae7b4 --- /dev/null +++ b/tools/perf/scripts/python/bin/sctop-report | |||
@@ -0,0 +1,24 @@ | |||
1 | #!/bin/bash | ||
2 | # description: syscall top | ||
3 | # args: [comm] [interval] | ||
4 | n_args=0 | ||
5 | for i in "$@" | ||
6 | do | ||
7 | if expr match "$i" "-" > /dev/null ; then | ||
8 | break | ||
9 | fi | ||
10 | n_args=$(( $n_args + 1 )) | ||
11 | done | ||
12 | if [ "$n_args" -gt 2 ] ; then | ||
13 | echo "usage: sctop-report [comm] [interval]" | ||
14 | exit | ||
15 | fi | ||
16 | if [ "$n_args" -gt 1 ] ; then | ||
17 | comm=$1 | ||
18 | interval=$2 | ||
19 | shift 2 | ||
20 | elif [ "$n_args" -gt 0 ] ; then | ||
21 | interval=$1 | ||
22 | shift | ||
23 | fi | ||
24 | perf trace $@ -s ~/libexec/perf-core/scripts/python/sctop.py $comm $interval | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record index 45a8c50359da..1fc5998b721d 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter | 2 | perf record -a -e raw_syscalls:sys_enter $@ |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report index f8044d192271..9e9d8ddd72ce 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide syscall counts, by pid | 2 | # description: system-wide syscall counts, by pid |
3 | # args: [comm] | 3 | # args: [comm] |
4 | perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $1 | 4 | if [ $# -gt 0 ] ; then |
5 | if ! expr match "$1" "-" > /dev/null ; then | ||
6 | comm=$1 | ||
7 | shift | ||
8 | fi | ||
9 | fi | ||
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $comm | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-record b/tools/perf/scripts/python/bin/syscall-counts-record index 45a8c50359da..1fc5998b721d 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-record +++ b/tools/perf/scripts/python/bin/syscall-counts-record | |||
@@ -1,2 +1,2 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter | 2 | perf record -a -e raw_syscalls:sys_enter $@ |
diff --git a/tools/perf/scripts/python/bin/syscall-counts-report b/tools/perf/scripts/python/bin/syscall-counts-report index a366aa61612f..dc076b618796 100644 --- a/tools/perf/scripts/python/bin/syscall-counts-report +++ b/tools/perf/scripts/python/bin/syscall-counts-report | |||
@@ -1,4 +1,10 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # description: system-wide syscall counts | 2 | # description: system-wide syscall counts |
3 | # args: [comm] | 3 | # args: [comm] |
4 | perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts.py $1 | 4 | if [ $# -gt 0 ] ; then |
5 | if ! expr match "$1" "-" > /dev/null ; then | ||
6 | comm=$1 | ||
7 | shift | ||
8 | fi | ||
9 | fi | ||
10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts.py $comm | ||
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py new file mode 100644 index 000000000000..6cafad40c296 --- /dev/null +++ b/tools/perf/scripts/python/sctop.py | |||
@@ -0,0 +1,78 @@ | |||
1 | # system call top | ||
2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
3 | # Licensed under the terms of the GNU GPL License version 2 | ||
4 | # | ||
5 | # Periodically displays system-wide system call totals, broken down by | ||
6 | # syscall. If a [comm] arg is specified, only syscalls called by | ||
7 | # [comm] are displayed. If an [interval] arg is specified, the display | ||
8 | # will be refreshed every [interval] seconds. The default interval is | ||
9 | # 3 seconds. | ||
10 | |||
11 | import thread | ||
12 | import time | ||
13 | import os | ||
14 | import sys | ||
15 | |||
16 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
17 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
18 | |||
19 | from perf_trace_context import * | ||
20 | from Core import * | ||
21 | from Util import * | ||
22 | |||
23 | usage = "perf trace -s syscall-counts.py [comm] [interval]\n"; | ||
24 | |||
25 | for_comm = None | ||
26 | default_interval = 3 | ||
27 | interval = default_interval | ||
28 | |||
29 | if len(sys.argv) > 3: | ||
30 | sys.exit(usage) | ||
31 | |||
32 | if len(sys.argv) > 2: | ||
33 | for_comm = sys.argv[1] | ||
34 | interval = int(sys.argv[2]) | ||
35 | elif len(sys.argv) > 1: | ||
36 | try: | ||
37 | interval = int(sys.argv[1]) | ||
38 | except ValueError: | ||
39 | for_comm = sys.argv[1] | ||
40 | interval = default_interval | ||
41 | |||
42 | syscalls = autodict() | ||
43 | |||
44 | def trace_begin(): | ||
45 | thread.start_new_thread(print_syscall_totals, (interval,)) | ||
46 | pass | ||
47 | |||
48 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | ||
49 | common_secs, common_nsecs, common_pid, common_comm, | ||
50 | id, args): | ||
51 | if for_comm is not None: | ||
52 | if common_comm != for_comm: | ||
53 | return | ||
54 | try: | ||
55 | syscalls[id] += 1 | ||
56 | except TypeError: | ||
57 | syscalls[id] = 1 | ||
58 | |||
59 | def print_syscall_totals(interval): | ||
60 | while 1: | ||
61 | clear_term() | ||
62 | if for_comm is not None: | ||
63 | print "\nsyscall events for %s:\n\n" % (for_comm), | ||
64 | else: | ||
65 | print "\nsyscall events:\n\n", | ||
66 | |||
67 | print "%-40s %10s\n" % ("event", "count"), | ||
68 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
69 | "----------"), | ||
70 | |||
71 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | ||
72 | reverse = True): | ||
73 | try: | ||
74 | print "%-40d %10d\n" % (id, val), | ||
75 | except TypeError: | ||
76 | pass | ||
77 | syscalls.clear() | ||
78 | time.sleep(interval) | ||
diff --git a/tools/perf/util/PERF-VERSION-GEN b/tools/perf/util/PERF-VERSION-GEN index 54552a00a117..49ece7921914 100755 --- a/tools/perf/util/PERF-VERSION-GEN +++ b/tools/perf/util/PERF-VERSION-GEN | |||
@@ -1,6 +1,10 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | GVF=PERF-VERSION-FILE | 3 | if [ $# -eq 1 ] ; then |
4 | OUTPUT=$1 | ||
5 | fi | ||
6 | |||
7 | GVF=${OUTPUT}PERF-VERSION-FILE | ||
4 | DEF_VER=v0.0.2.PERF | 8 | DEF_VER=v0.0.2.PERF |
5 | 9 | ||
6 | LF=' | 10 | LF=' |
diff --git a/tools/perf/util/bitmap.c b/tools/perf/util/bitmap.c new file mode 100644 index 000000000000..5e230acae1e9 --- /dev/null +++ b/tools/perf/util/bitmap.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * From lib/bitmap.c | ||
3 | * Helper functions for bitmap.h. | ||
4 | * | ||
5 | * This source code is licensed under the GNU General Public License, | ||
6 | * Version 2. See the file COPYING for more details. | ||
7 | */ | ||
8 | #include <linux/bitmap.h> | ||
9 | |||
10 | int __bitmap_weight(const unsigned long *bitmap, int bits) | ||
11 | { | ||
12 | int k, w = 0, lim = bits/BITS_PER_LONG; | ||
13 | |||
14 | for (k = 0; k < lim; k++) | ||
15 | w += hweight_long(bitmap[k]); | ||
16 | |||
17 | if (bits % BITS_PER_LONG) | ||
18 | w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); | ||
19 | |||
20 | return w; | ||
21 | } | ||
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 04904b35ba81..0f60a3906808 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -24,7 +24,7 @@ static int build_id__mark_dso_hit(event_t *event, struct perf_session *session) | |||
24 | } | 24 | } |
25 | 25 | ||
26 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, | 26 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, |
27 | event->ip.ip, &al); | 27 | event->ip.pid, event->ip.ip, &al); |
28 | 28 | ||
29 | if (al.map != NULL) | 29 | if (al.map != NULL) |
30 | al.map->dso->hit = 1; | 30 | al.map->dso->hit = 1; |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 918eb376abe3..4b9aab7f0405 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __PERF_CACHE_H | 1 | #ifndef __PERF_CACHE_H |
2 | #define __PERF_CACHE_H | 2 | #define __PERF_CACHE_H |
3 | 3 | ||
4 | #include <stdbool.h> | ||
4 | #include "util.h" | 5 | #include "util.h" |
5 | #include "strbuf.h" | 6 | #include "strbuf.h" |
6 | #include "../perf.h" | 7 | #include "../perf.h" |
@@ -69,6 +70,19 @@ extern const char *pager_program; | |||
69 | extern int pager_in_use(void); | 70 | extern int pager_in_use(void); |
70 | extern int pager_use_color; | 71 | extern int pager_use_color; |
71 | 72 | ||
73 | extern bool use_browser; | ||
74 | |||
75 | #ifdef NO_NEWT_SUPPORT | ||
76 | static inline void setup_browser(void) | ||
77 | { | ||
78 | setup_pager(); | ||
79 | } | ||
80 | static inline void exit_browser(bool wait_for_ok __used) {} | ||
81 | #else | ||
82 | void setup_browser(void); | ||
83 | void exit_browser(bool wait_for_ok); | ||
84 | #endif | ||
85 | |||
72 | extern const char *editor_program; | 86 | extern const char *editor_program; |
73 | extern const char *excludes_file; | 87 | extern const char *excludes_file; |
74 | 88 | ||
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index b3b71258272a..21a52e0a4435 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2009, Frederic Weisbecker <fweisbec@gmail.com> | 2 | * Copyright (C) 2009-2010, Frederic Weisbecker <fweisbec@gmail.com> |
3 | * | 3 | * |
4 | * Handle the callchains from the stream in an ad-hoc radix tree and then | 4 | * Handle the callchains from the stream in an ad-hoc radix tree and then |
5 | * sort them in an rbtree. | 5 | * sort them in an rbtree. |
@@ -17,6 +17,13 @@ | |||
17 | 17 | ||
18 | #include "callchain.h" | 18 | #include "callchain.h" |
19 | 19 | ||
20 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event) | ||
21 | { | ||
22 | unsigned int chain_size = event->header.size; | ||
23 | chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event; | ||
24 | return chain->nr * sizeof(u64) <= chain_size; | ||
25 | } | ||
26 | |||
20 | #define chain_for_each_child(child, parent) \ | 27 | #define chain_for_each_child(child, parent) \ |
21 | list_for_each_entry(child, &parent->children, brothers) | 28 | list_for_each_entry(child, &parent->children, brothers) |
22 | 29 | ||
@@ -160,7 +167,7 @@ create_child(struct callchain_node *parent, bool inherit_children) | |||
160 | { | 167 | { |
161 | struct callchain_node *new; | 168 | struct callchain_node *new; |
162 | 169 | ||
163 | new = malloc(sizeof(*new)); | 170 | new = zalloc(sizeof(*new)); |
164 | if (!new) { | 171 | if (!new) { |
165 | perror("not enough memory to create child for code path tree"); | 172 | perror("not enough memory to create child for code path tree"); |
166 | return NULL; | 173 | return NULL; |
@@ -183,25 +190,36 @@ create_child(struct callchain_node *parent, bool inherit_children) | |||
183 | return new; | 190 | return new; |
184 | } | 191 | } |
185 | 192 | ||
193 | |||
194 | struct resolved_ip { | ||
195 | u64 ip; | ||
196 | struct map_symbol ms; | ||
197 | }; | ||
198 | |||
199 | struct resolved_chain { | ||
200 | u64 nr; | ||
201 | struct resolved_ip ips[0]; | ||
202 | }; | ||
203 | |||
204 | |||
186 | /* | 205 | /* |
187 | * Fill the node with callchain values | 206 | * Fill the node with callchain values |
188 | */ | 207 | */ |
189 | static void | 208 | static void |
190 | fill_node(struct callchain_node *node, struct ip_callchain *chain, | 209 | fill_node(struct callchain_node *node, struct resolved_chain *chain, int start) |
191 | int start, struct symbol **syms) | ||
192 | { | 210 | { |
193 | unsigned int i; | 211 | unsigned int i; |
194 | 212 | ||
195 | for (i = start; i < chain->nr; i++) { | 213 | for (i = start; i < chain->nr; i++) { |
196 | struct callchain_list *call; | 214 | struct callchain_list *call; |
197 | 215 | ||
198 | call = malloc(sizeof(*call)); | 216 | call = zalloc(sizeof(*call)); |
199 | if (!call) { | 217 | if (!call) { |
200 | perror("not enough memory for the code path tree"); | 218 | perror("not enough memory for the code path tree"); |
201 | return; | 219 | return; |
202 | } | 220 | } |
203 | call->ip = chain->ips[i]; | 221 | call->ip = chain->ips[i].ip; |
204 | call->sym = syms[i]; | 222 | call->ms = chain->ips[i].ms; |
205 | list_add_tail(&call->list, &node->val); | 223 | list_add_tail(&call->list, &node->val); |
206 | } | 224 | } |
207 | node->val_nr = chain->nr - start; | 225 | node->val_nr = chain->nr - start; |
@@ -210,13 +228,13 @@ fill_node(struct callchain_node *node, struct ip_callchain *chain, | |||
210 | } | 228 | } |
211 | 229 | ||
212 | static void | 230 | static void |
213 | add_child(struct callchain_node *parent, struct ip_callchain *chain, | 231 | add_child(struct callchain_node *parent, struct resolved_chain *chain, |
214 | int start, struct symbol **syms) | 232 | int start) |
215 | { | 233 | { |
216 | struct callchain_node *new; | 234 | struct callchain_node *new; |
217 | 235 | ||
218 | new = create_child(parent, false); | 236 | new = create_child(parent, false); |
219 | fill_node(new, chain, start, syms); | 237 | fill_node(new, chain, start); |
220 | 238 | ||
221 | new->children_hit = 0; | 239 | new->children_hit = 0; |
222 | new->hit = 1; | 240 | new->hit = 1; |
@@ -228,9 +246,8 @@ add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
228 | * Then create another child to host the given callchain of new branch | 246 | * Then create another child to host the given callchain of new branch |
229 | */ | 247 | */ |
230 | static void | 248 | static void |
231 | split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | 249 | split_add_child(struct callchain_node *parent, struct resolved_chain *chain, |
232 | struct callchain_list *to_split, int idx_parents, int idx_local, | 250 | struct callchain_list *to_split, int idx_parents, int idx_local) |
233 | struct symbol **syms) | ||
234 | { | 251 | { |
235 | struct callchain_node *new; | 252 | struct callchain_node *new; |
236 | struct list_head *old_tail; | 253 | struct list_head *old_tail; |
@@ -257,7 +274,7 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
257 | /* create a new child for the new branch if any */ | 274 | /* create a new child for the new branch if any */ |
258 | if (idx_total < chain->nr) { | 275 | if (idx_total < chain->nr) { |
259 | parent->hit = 0; | 276 | parent->hit = 0; |
260 | add_child(parent, chain, idx_total, syms); | 277 | add_child(parent, chain, idx_total); |
261 | parent->children_hit++; | 278 | parent->children_hit++; |
262 | } else { | 279 | } else { |
263 | parent->hit = 1; | 280 | parent->hit = 1; |
@@ -265,32 +282,33 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain, | |||
265 | } | 282 | } |
266 | 283 | ||
267 | static int | 284 | static int |
268 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | 285 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, |
269 | unsigned int start, struct symbol **syms); | 286 | unsigned int start); |
270 | 287 | ||
271 | static void | 288 | static void |
272 | __append_chain_children(struct callchain_node *root, struct ip_callchain *chain, | 289 | __append_chain_children(struct callchain_node *root, |
273 | struct symbol **syms, unsigned int start) | 290 | struct resolved_chain *chain, |
291 | unsigned int start) | ||
274 | { | 292 | { |
275 | struct callchain_node *rnode; | 293 | struct callchain_node *rnode; |
276 | 294 | ||
277 | /* lookup in childrens */ | 295 | /* lookup in childrens */ |
278 | chain_for_each_child(rnode, root) { | 296 | chain_for_each_child(rnode, root) { |
279 | unsigned int ret = __append_chain(rnode, chain, start, syms); | 297 | unsigned int ret = __append_chain(rnode, chain, start); |
280 | 298 | ||
281 | if (!ret) | 299 | if (!ret) |
282 | goto inc_children_hit; | 300 | goto inc_children_hit; |
283 | } | 301 | } |
284 | /* nothing in children, add to the current node */ | 302 | /* nothing in children, add to the current node */ |
285 | add_child(root, chain, start, syms); | 303 | add_child(root, chain, start); |
286 | 304 | ||
287 | inc_children_hit: | 305 | inc_children_hit: |
288 | root->children_hit++; | 306 | root->children_hit++; |
289 | } | 307 | } |
290 | 308 | ||
291 | static int | 309 | static int |
292 | __append_chain(struct callchain_node *root, struct ip_callchain *chain, | 310 | __append_chain(struct callchain_node *root, struct resolved_chain *chain, |
293 | unsigned int start, struct symbol **syms) | 311 | unsigned int start) |
294 | { | 312 | { |
295 | struct callchain_list *cnode; | 313 | struct callchain_list *cnode; |
296 | unsigned int i = start; | 314 | unsigned int i = start; |
@@ -302,13 +320,19 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
302 | * anywhere inside a function. | 320 | * anywhere inside a function. |
303 | */ | 321 | */ |
304 | list_for_each_entry(cnode, &root->val, list) { | 322 | list_for_each_entry(cnode, &root->val, list) { |
323 | struct symbol *sym; | ||
324 | |||
305 | if (i == chain->nr) | 325 | if (i == chain->nr) |
306 | break; | 326 | break; |
307 | if (cnode->sym && syms[i]) { | 327 | |
308 | if (cnode->sym->start != syms[i]->start) | 328 | sym = chain->ips[i].ms.sym; |
329 | |||
330 | if (cnode->ms.sym && sym) { | ||
331 | if (cnode->ms.sym->start != sym->start) | ||
309 | break; | 332 | break; |
310 | } else if (cnode->ip != chain->ips[i]) | 333 | } else if (cnode->ip != chain->ips[i].ip) |
311 | break; | 334 | break; |
335 | |||
312 | if (!found) | 336 | if (!found) |
313 | found = true; | 337 | found = true; |
314 | i++; | 338 | i++; |
@@ -320,7 +344,7 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
320 | 344 | ||
321 | /* we match only a part of the node. Split it and add the new chain */ | 345 | /* we match only a part of the node. Split it and add the new chain */ |
322 | if (i - start < root->val_nr) { | 346 | if (i - start < root->val_nr) { |
323 | split_add_child(root, chain, cnode, start, i - start, syms); | 347 | split_add_child(root, chain, cnode, start, i - start); |
324 | return 0; | 348 | return 0; |
325 | } | 349 | } |
326 | 350 | ||
@@ -331,15 +355,50 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain, | |||
331 | } | 355 | } |
332 | 356 | ||
333 | /* We match the node and still have a part remaining */ | 357 | /* We match the node and still have a part remaining */ |
334 | __append_chain_children(root, chain, syms, i); | 358 | __append_chain_children(root, chain, i); |
335 | 359 | ||
336 | return 0; | 360 | return 0; |
337 | } | 361 | } |
338 | 362 | ||
339 | void append_chain(struct callchain_node *root, struct ip_callchain *chain, | 363 | static void filter_context(struct ip_callchain *old, struct resolved_chain *new, |
340 | struct symbol **syms) | 364 | struct map_symbol *syms) |
341 | { | 365 | { |
366 | int i, j = 0; | ||
367 | |||
368 | for (i = 0; i < (int)old->nr; i++) { | ||
369 | if (old->ips[i] >= PERF_CONTEXT_MAX) | ||
370 | continue; | ||
371 | |||
372 | new->ips[j].ip = old->ips[i]; | ||
373 | new->ips[j].ms = syms[i]; | ||
374 | j++; | ||
375 | } | ||
376 | |||
377 | new->nr = j; | ||
378 | } | ||
379 | |||
380 | |||
381 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, | ||
382 | struct map_symbol *syms) | ||
383 | { | ||
384 | struct resolved_chain *filtered; | ||
385 | |||
342 | if (!chain->nr) | 386 | if (!chain->nr) |
343 | return; | 387 | return 0; |
344 | __append_chain_children(root, chain, syms, 0); | 388 | |
389 | filtered = zalloc(sizeof(*filtered) + | ||
390 | chain->nr * sizeof(struct resolved_ip)); | ||
391 | if (!filtered) | ||
392 | return -ENOMEM; | ||
393 | |||
394 | filter_context(chain, filtered, syms); | ||
395 | |||
396 | if (!filtered->nr) | ||
397 | goto end; | ||
398 | |||
399 | __append_chain_children(root, filtered, 0); | ||
400 | end: | ||
401 | free(filtered); | ||
402 | |||
403 | return 0; | ||
345 | } | 404 | } |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index ad4626de4c2b..1cba1f5504e7 100644 --- a/tools/perf/util/callchain.h +++ b/tools/perf/util/callchain.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include "../perf.h" | 4 | #include "../perf.h" |
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include "event.h" | ||
7 | #include "util.h" | 8 | #include "util.h" |
8 | #include "symbol.h" | 9 | #include "symbol.h" |
9 | 10 | ||
@@ -33,13 +34,14 @@ typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_node *, | |||
33 | 34 | ||
34 | struct callchain_param { | 35 | struct callchain_param { |
35 | enum chain_mode mode; | 36 | enum chain_mode mode; |
37 | u32 print_limit; | ||
36 | double min_percent; | 38 | double min_percent; |
37 | sort_chain_func_t sort; | 39 | sort_chain_func_t sort; |
38 | }; | 40 | }; |
39 | 41 | ||
40 | struct callchain_list { | 42 | struct callchain_list { |
41 | u64 ip; | 43 | u64 ip; |
42 | struct symbol *sym; | 44 | struct map_symbol ms; |
43 | struct list_head list; | 45 | struct list_head list; |
44 | }; | 46 | }; |
45 | 47 | ||
@@ -56,6 +58,8 @@ static inline u64 cumul_hits(struct callchain_node *node) | |||
56 | } | 58 | } |
57 | 59 | ||
58 | int register_callchain_param(struct callchain_param *param); | 60 | int register_callchain_param(struct callchain_param *param); |
59 | void append_chain(struct callchain_node *root, struct ip_callchain *chain, | 61 | int append_chain(struct callchain_node *root, struct ip_callchain *chain, |
60 | struct symbol **syms); | 62 | struct map_symbol *syms); |
63 | |||
64 | bool ip_callchain__valid(struct ip_callchain *chain, event_t *event); | ||
61 | #endif /* __PERF_CALLCHAIN_H */ | 65 | #endif /* __PERF_CALLCHAIN_H */ |
diff --git a/tools/perf/util/color.c b/tools/perf/util/color.c index e88bca55a599..e191eb9a667f 100644 --- a/tools/perf/util/color.c +++ b/tools/perf/util/color.c | |||
@@ -166,6 +166,31 @@ int perf_color_default_config(const char *var, const char *value, void *cb) | |||
166 | return perf_default_config(var, value, cb); | 166 | return perf_default_config(var, value, cb); |
167 | } | 167 | } |
168 | 168 | ||
169 | static int __color_vsnprintf(char *bf, size_t size, const char *color, | ||
170 | const char *fmt, va_list args, const char *trail) | ||
171 | { | ||
172 | int r = 0; | ||
173 | |||
174 | /* | ||
175 | * Auto-detect: | ||
176 | */ | ||
177 | if (perf_use_color_default < 0) { | ||
178 | if (isatty(1) || pager_in_use()) | ||
179 | perf_use_color_default = 1; | ||
180 | else | ||
181 | perf_use_color_default = 0; | ||
182 | } | ||
183 | |||
184 | if (perf_use_color_default && *color) | ||
185 | r += snprintf(bf, size, "%s", color); | ||
186 | r += vsnprintf(bf + r, size - r, fmt, args); | ||
187 | if (perf_use_color_default && *color) | ||
188 | r += snprintf(bf + r, size - r, "%s", PERF_COLOR_RESET); | ||
189 | if (trail) | ||
190 | r += snprintf(bf + r, size - r, "%s", trail); | ||
191 | return r; | ||
192 | } | ||
193 | |||
169 | static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, | 194 | static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, |
170 | va_list args, const char *trail) | 195 | va_list args, const char *trail) |
171 | { | 196 | { |
@@ -191,11 +216,28 @@ static int __color_vfprintf(FILE *fp, const char *color, const char *fmt, | |||
191 | return r; | 216 | return r; |
192 | } | 217 | } |
193 | 218 | ||
219 | int color_vsnprintf(char *bf, size_t size, const char *color, | ||
220 | const char *fmt, va_list args) | ||
221 | { | ||
222 | return __color_vsnprintf(bf, size, color, fmt, args, NULL); | ||
223 | } | ||
224 | |||
194 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) | 225 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args) |
195 | { | 226 | { |
196 | return __color_vfprintf(fp, color, fmt, args, NULL); | 227 | return __color_vfprintf(fp, color, fmt, args, NULL); |
197 | } | 228 | } |
198 | 229 | ||
230 | int color_snprintf(char *bf, size_t size, const char *color, | ||
231 | const char *fmt, ...) | ||
232 | { | ||
233 | va_list args; | ||
234 | int r; | ||
235 | |||
236 | va_start(args, fmt); | ||
237 | r = color_vsnprintf(bf, size, color, fmt, args); | ||
238 | va_end(args); | ||
239 | return r; | ||
240 | } | ||
199 | 241 | ||
200 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) | 242 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) |
201 | { | 243 | { |
@@ -274,3 +316,9 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent) | |||
274 | 316 | ||
275 | return r; | 317 | return r; |
276 | } | 318 | } |
319 | |||
320 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent) | ||
321 | { | ||
322 | const char *color = get_percent_color(percent); | ||
323 | return color_snprintf(bf, size, color, fmt, percent); | ||
324 | } | ||
diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index 24e8809210bb..dea082b79602 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h | |||
@@ -32,10 +32,14 @@ int perf_color_default_config(const char *var, const char *value, void *cb); | |||
32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); | 32 | int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty); |
33 | void color_parse(const char *value, const char *var, char *dst); | 33 | void color_parse(const char *value, const char *var, char *dst); |
34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); | 34 | void color_parse_mem(const char *value, int len, const char *var, char *dst); |
35 | int color_vsnprintf(char *bf, size_t size, const char *color, | ||
36 | const char *fmt, va_list args); | ||
35 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); | 37 | int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args); |
36 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); | 38 | int color_fprintf(FILE *fp, const char *color, const char *fmt, ...); |
39 | int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...); | ||
37 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); | 40 | int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...); |
38 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); | 41 | int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf); |
42 | int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent); | ||
39 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); | 43 | int percent_color_fprintf(FILE *fp, const char *fmt, double percent); |
40 | const char *get_percent_color(double percent); | 44 | const char *get_percent_color(double percent); |
41 | 45 | ||
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 0905600c3851..dd824cf3b628 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -6,13 +6,14 @@ | |||
6 | #include <stdarg.h> | 6 | #include <stdarg.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | 8 | ||
9 | #include "cache.h" | ||
9 | #include "color.h" | 10 | #include "color.h" |
10 | #include "event.h" | 11 | #include "event.h" |
11 | #include "debug.h" | 12 | #include "debug.h" |
12 | #include "util.h" | 13 | #include "util.h" |
13 | 14 | ||
14 | int verbose = 0; | 15 | int verbose = 0; |
15 | int dump_trace = 0; | 16 | bool dump_trace = false; |
16 | 17 | ||
17 | int eprintf(int level, const char *fmt, ...) | 18 | int eprintf(int level, const char *fmt, ...) |
18 | { | 19 | { |
@@ -21,7 +22,10 @@ int eprintf(int level, const char *fmt, ...) | |||
21 | 22 | ||
22 | if (verbose >= level) { | 23 | if (verbose >= level) { |
23 | va_start(args, fmt); | 24 | va_start(args, fmt); |
24 | ret = vfprintf(stderr, fmt, args); | 25 | if (use_browser) |
26 | ret = browser__show_help(fmt, args); | ||
27 | else | ||
28 | ret = vfprintf(stderr, fmt, args); | ||
25 | va_end(args); | 29 | va_end(args); |
26 | } | 30 | } |
27 | 31 | ||
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index c6c24c522dea..047ac3324ebe 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -2,14 +2,38 @@ | |||
2 | #ifndef __PERF_DEBUG_H | 2 | #ifndef __PERF_DEBUG_H |
3 | #define __PERF_DEBUG_H | 3 | #define __PERF_DEBUG_H |
4 | 4 | ||
5 | #include <stdbool.h> | ||
5 | #include "event.h" | 6 | #include "event.h" |
6 | 7 | ||
7 | extern int verbose; | 8 | extern int verbose; |
8 | extern int dump_trace; | 9 | extern bool dump_trace; |
9 | 10 | ||
10 | int eprintf(int level, | ||
11 | const char *fmt, ...) __attribute__((format(printf, 2, 3))); | ||
12 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | 11 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
13 | void trace_event(event_t *event); | 12 | void trace_event(event_t *event); |
14 | 13 | ||
14 | struct ui_progress; | ||
15 | |||
16 | #ifdef NO_NEWT_SUPPORT | ||
17 | static inline int browser__show_help(const char *format __used, va_list ap __used) | ||
18 | { | ||
19 | return 0; | ||
20 | } | ||
21 | |||
22 | static inline struct ui_progress *ui_progress__new(const char *title __used, | ||
23 | u64 total __used) | ||
24 | { | ||
25 | return (struct ui_progress *)1; | ||
26 | } | ||
27 | |||
28 | static inline void ui_progress__update(struct ui_progress *self __used, | ||
29 | u64 curr __used) {} | ||
30 | |||
31 | static inline void ui_progress__delete(struct ui_progress *self __used) {} | ||
32 | #else | ||
33 | int browser__show_help(const char *format, va_list ap); | ||
34 | struct ui_progress *ui_progress__new(const char *title, u64 total); | ||
35 | void ui_progress__update(struct ui_progress *self, u64 curr); | ||
36 | void ui_progress__delete(struct ui_progress *self); | ||
37 | #endif | ||
38 | |||
15 | #endif /* __PERF_DEBUG_H */ | 39 | #endif /* __PERF_DEBUG_H */ |
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 705ec63548b4..50771b5813ee 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -7,6 +7,23 @@ | |||
7 | #include "strlist.h" | 7 | #include "strlist.h" |
8 | #include "thread.h" | 8 | #include "thread.h" |
9 | 9 | ||
10 | const char *event__name[] = { | ||
11 | [0] = "TOTAL", | ||
12 | [PERF_RECORD_MMAP] = "MMAP", | ||
13 | [PERF_RECORD_LOST] = "LOST", | ||
14 | [PERF_RECORD_COMM] = "COMM", | ||
15 | [PERF_RECORD_EXIT] = "EXIT", | ||
16 | [PERF_RECORD_THROTTLE] = "THROTTLE", | ||
17 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", | ||
18 | [PERF_RECORD_FORK] = "FORK", | ||
19 | [PERF_RECORD_READ] = "READ", | ||
20 | [PERF_RECORD_SAMPLE] = "SAMPLE", | ||
21 | [PERF_RECORD_HEADER_ATTR] = "ATTR", | ||
22 | [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE", | ||
23 | [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA", | ||
24 | [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID", | ||
25 | }; | ||
26 | |||
10 | static pid_t event__synthesize_comm(pid_t pid, int full, | 27 | static pid_t event__synthesize_comm(pid_t pid, int full, |
11 | event__handler_t process, | 28 | event__handler_t process, |
12 | struct perf_session *session) | 29 | struct perf_session *session) |
@@ -112,7 +129,11 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
112 | event_t ev = { | 129 | event_t ev = { |
113 | .header = { | 130 | .header = { |
114 | .type = PERF_RECORD_MMAP, | 131 | .type = PERF_RECORD_MMAP, |
115 | .misc = 0, /* Just like the kernel, see kernel/perf_event.c __perf_event_mmap */ | 132 | /* |
133 | * Just like the kernel, see __perf_event_mmap | ||
134 | * in kernel/perf_event.c | ||
135 | */ | ||
136 | .misc = PERF_RECORD_MISC_USER, | ||
116 | }, | 137 | }, |
117 | }; | 138 | }; |
118 | int n; | 139 | int n; |
@@ -130,6 +151,7 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
130 | continue; | 151 | continue; |
131 | pbf += n + 3; | 152 | pbf += n + 3; |
132 | if (*pbf == 'x') { /* vm_exec */ | 153 | if (*pbf == 'x') { /* vm_exec */ |
154 | u64 vm_pgoff; | ||
133 | char *execname = strchr(bf, '/'); | 155 | char *execname = strchr(bf, '/'); |
134 | 156 | ||
135 | /* Catch VDSO */ | 157 | /* Catch VDSO */ |
@@ -139,6 +161,14 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
139 | if (execname == NULL) | 161 | if (execname == NULL) |
140 | continue; | 162 | continue; |
141 | 163 | ||
164 | pbf += 3; | ||
165 | n = hex2u64(pbf, &vm_pgoff); | ||
166 | /* pgoff is in bytes, not pages */ | ||
167 | if (n >= 0) | ||
168 | ev.mmap.pgoff = vm_pgoff << getpagesize(); | ||
169 | else | ||
170 | ev.mmap.pgoff = 0; | ||
171 | |||
142 | size = strlen(execname); | 172 | size = strlen(execname); |
143 | execname[size - 1] = '\0'; /* Remove \n */ | 173 | execname[size - 1] = '\0'; /* Remove \n */ |
144 | memcpy(ev.mmap.filename, execname, size); | 174 | memcpy(ev.mmap.filename, execname, size); |
@@ -158,11 +188,23 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid, | |||
158 | } | 188 | } |
159 | 189 | ||
160 | int event__synthesize_modules(event__handler_t process, | 190 | int event__synthesize_modules(event__handler_t process, |
161 | struct perf_session *session) | 191 | struct perf_session *session, |
192 | struct machine *machine) | ||
162 | { | 193 | { |
163 | struct rb_node *nd; | 194 | struct rb_node *nd; |
195 | struct map_groups *kmaps = &machine->kmaps; | ||
196 | u16 misc; | ||
197 | |||
198 | /* | ||
199 | * kernel uses 0 for user space maps, see kernel/perf_event.c | ||
200 | * __perf_event_mmap | ||
201 | */ | ||
202 | if (machine__is_host(machine)) | ||
203 | misc = PERF_RECORD_MISC_KERNEL; | ||
204 | else | ||
205 | misc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
164 | 206 | ||
165 | for (nd = rb_first(&session->kmaps.maps[MAP__FUNCTION]); | 207 | for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]); |
166 | nd; nd = rb_next(nd)) { | 208 | nd; nd = rb_next(nd)) { |
167 | event_t ev; | 209 | event_t ev; |
168 | size_t size; | 210 | size_t size; |
@@ -173,12 +215,13 @@ int event__synthesize_modules(event__handler_t process, | |||
173 | 215 | ||
174 | size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); | 216 | size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64)); |
175 | memset(&ev, 0, sizeof(ev)); | 217 | memset(&ev, 0, sizeof(ev)); |
176 | ev.mmap.header.misc = 1; /* kernel uses 0 for user space maps, see kernel/perf_event.c __perf_event_mmap */ | 218 | ev.mmap.header.misc = misc; |
177 | ev.mmap.header.type = PERF_RECORD_MMAP; | 219 | ev.mmap.header.type = PERF_RECORD_MMAP; |
178 | ev.mmap.header.size = (sizeof(ev.mmap) - | 220 | ev.mmap.header.size = (sizeof(ev.mmap) - |
179 | (sizeof(ev.mmap.filename) - size)); | 221 | (sizeof(ev.mmap.filename) - size)); |
180 | ev.mmap.start = pos->start; | 222 | ev.mmap.start = pos->start; |
181 | ev.mmap.len = pos->end - pos->start; | 223 | ev.mmap.len = pos->end - pos->start; |
224 | ev.mmap.pid = machine->pid; | ||
182 | 225 | ||
183 | memcpy(ev.mmap.filename, pos->dso->long_name, | 226 | memcpy(ev.mmap.filename, pos->dso->long_name, |
184 | pos->dso->long_name_len + 1); | 227 | pos->dso->long_name_len + 1); |
@@ -241,13 +284,18 @@ static int find_symbol_cb(void *arg, const char *name, char type, u64 start) | |||
241 | 284 | ||
242 | int event__synthesize_kernel_mmap(event__handler_t process, | 285 | int event__synthesize_kernel_mmap(event__handler_t process, |
243 | struct perf_session *session, | 286 | struct perf_session *session, |
287 | struct machine *machine, | ||
244 | const char *symbol_name) | 288 | const char *symbol_name) |
245 | { | 289 | { |
246 | size_t size; | 290 | size_t size; |
291 | const char *filename, *mmap_name; | ||
292 | char path[PATH_MAX]; | ||
293 | char name_buff[PATH_MAX]; | ||
294 | struct map *map; | ||
295 | |||
247 | event_t ev = { | 296 | event_t ev = { |
248 | .header = { | 297 | .header = { |
249 | .type = PERF_RECORD_MMAP, | 298 | .type = PERF_RECORD_MMAP, |
250 | .misc = 1, /* kernel uses 0 for user space maps, see kernel/perf_event.c __perf_event_mmap */ | ||
251 | }, | 299 | }, |
252 | }; | 300 | }; |
253 | /* | 301 | /* |
@@ -257,16 +305,37 @@ int event__synthesize_kernel_mmap(event__handler_t process, | |||
257 | */ | 305 | */ |
258 | struct process_symbol_args args = { .name = symbol_name, }; | 306 | struct process_symbol_args args = { .name = symbol_name, }; |
259 | 307 | ||
260 | if (kallsyms__parse("/proc/kallsyms", &args, find_symbol_cb) <= 0) | 308 | mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff)); |
309 | if (machine__is_host(machine)) { | ||
310 | /* | ||
311 | * kernel uses PERF_RECORD_MISC_USER for user space maps, | ||
312 | * see kernel/perf_event.c __perf_event_mmap | ||
313 | */ | ||
314 | ev.header.misc = PERF_RECORD_MISC_KERNEL; | ||
315 | filename = "/proc/kallsyms"; | ||
316 | } else { | ||
317 | ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
318 | if (machine__is_default_guest(machine)) | ||
319 | filename = (char *) symbol_conf.default_guest_kallsyms; | ||
320 | else { | ||
321 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); | ||
322 | filename = path; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0) | ||
261 | return -ENOENT; | 327 | return -ENOENT; |
262 | 328 | ||
329 | map = machine->vmlinux_maps[MAP__FUNCTION]; | ||
263 | size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename), | 330 | size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename), |
264 | "[kernel.kallsyms.%s]", symbol_name) + 1; | 331 | "%s%s", mmap_name, symbol_name) + 1; |
265 | size = ALIGN(size, sizeof(u64)); | 332 | size = ALIGN(size, sizeof(u64)); |
266 | ev.mmap.header.size = (sizeof(ev.mmap) - (sizeof(ev.mmap.filename) - size)); | 333 | ev.mmap.header.size = (sizeof(ev.mmap) - |
334 | (sizeof(ev.mmap.filename) - size)); | ||
267 | ev.mmap.pgoff = args.start; | 335 | ev.mmap.pgoff = args.start; |
268 | ev.mmap.start = session->vmlinux_maps[MAP__FUNCTION]->start; | 336 | ev.mmap.start = map->start; |
269 | ev.mmap.len = session->vmlinux_maps[MAP__FUNCTION]->end - ev.mmap.start ; | 337 | ev.mmap.len = map->end - ev.mmap.start; |
338 | ev.mmap.pid = machine->pid; | ||
270 | 339 | ||
271 | return process(&ev, session); | 340 | return process(&ev, session); |
272 | } | 341 | } |
@@ -316,26 +385,54 @@ int event__process_comm(event_t *self, struct perf_session *session) | |||
316 | int event__process_lost(event_t *self, struct perf_session *session) | 385 | int event__process_lost(event_t *self, struct perf_session *session) |
317 | { | 386 | { |
318 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); | 387 | dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost); |
319 | session->events_stats.lost += self->lost.lost; | 388 | session->hists.stats.total_lost += self->lost.lost; |
320 | return 0; | 389 | return 0; |
321 | } | 390 | } |
322 | 391 | ||
323 | int event__process_mmap(event_t *self, struct perf_session *session) | 392 | static void event_set_kernel_mmap_len(struct map **maps, event_t *self) |
393 | { | ||
394 | maps[MAP__FUNCTION]->start = self->mmap.start; | ||
395 | maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len; | ||
396 | /* | ||
397 | * Be a bit paranoid here, some perf.data file came with | ||
398 | * a zero sized synthesized MMAP event for the kernel. | ||
399 | */ | ||
400 | if (maps[MAP__FUNCTION]->end == 0) | ||
401 | maps[MAP__FUNCTION]->end = ~0UL; | ||
402 | } | ||
403 | |||
404 | static int event__process_kernel_mmap(event_t *self, | ||
405 | struct perf_session *session) | ||
324 | { | 406 | { |
325 | struct thread *thread; | ||
326 | struct map *map; | 407 | struct map *map; |
408 | char kmmap_prefix[PATH_MAX]; | ||
409 | struct machine *machine; | ||
410 | enum dso_kernel_type kernel_type; | ||
411 | bool is_kernel_mmap; | ||
412 | |||
413 | machine = perf_session__findnew_machine(session, self->mmap.pid); | ||
414 | if (!machine) { | ||
415 | pr_err("Can't find id %d's machine\n", self->mmap.pid); | ||
416 | goto out_problem; | ||
417 | } | ||
327 | 418 | ||
328 | dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n", | 419 | machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix)); |
329 | self->mmap.pid, self->mmap.tid, self->mmap.start, | 420 | if (machine__is_host(machine)) |
330 | self->mmap.len, self->mmap.pgoff, self->mmap.filename); | 421 | kernel_type = DSO_TYPE_KERNEL; |
422 | else | ||
423 | kernel_type = DSO_TYPE_GUEST_KERNEL; | ||
331 | 424 | ||
332 | if (self->mmap.pid == 0) { | 425 | is_kernel_mmap = memcmp(self->mmap.filename, |
333 | static const char kmmap_prefix[] = "[kernel.kallsyms."; | 426 | kmmap_prefix, |
427 | strlen(kmmap_prefix)) == 0; | ||
428 | if (self->mmap.filename[0] == '/' || | ||
429 | (!is_kernel_mmap && self->mmap.filename[0] == '[')) { | ||
334 | 430 | ||
335 | if (self->mmap.filename[0] == '/') { | 431 | char short_module_name[1024]; |
336 | char short_module_name[1024]; | 432 | char *name, *dot; |
337 | char *name = strrchr(self->mmap.filename, '/'), *dot; | ||
338 | 433 | ||
434 | if (self->mmap.filename[0] == '/') { | ||
435 | name = strrchr(self->mmap.filename, '/'); | ||
339 | if (name == NULL) | 436 | if (name == NULL) |
340 | goto out_problem; | 437 | goto out_problem; |
341 | 438 | ||
@@ -343,58 +440,84 @@ int event__process_mmap(event_t *self, struct perf_session *session) | |||
343 | dot = strrchr(name, '.'); | 440 | dot = strrchr(name, '.'); |
344 | if (dot == NULL) | 441 | if (dot == NULL) |
345 | goto out_problem; | 442 | goto out_problem; |
346 | |||
347 | snprintf(short_module_name, sizeof(short_module_name), | 443 | snprintf(short_module_name, sizeof(short_module_name), |
348 | "[%.*s]", (int)(dot - name), name); | 444 | "[%.*s]", (int)(dot - name), name); |
349 | strxfrchar(short_module_name, '-', '_'); | 445 | strxfrchar(short_module_name, '-', '_'); |
350 | 446 | } else | |
351 | map = perf_session__new_module_map(session, | 447 | strcpy(short_module_name, self->mmap.filename); |
352 | self->mmap.start, | 448 | |
353 | self->mmap.filename); | 449 | map = machine__new_module(machine, self->mmap.start, |
354 | if (map == NULL) | 450 | self->mmap.filename); |
355 | goto out_problem; | 451 | if (map == NULL) |
356 | 452 | goto out_problem; | |
357 | name = strdup(short_module_name); | 453 | |
358 | if (name == NULL) | 454 | name = strdup(short_module_name); |
359 | goto out_problem; | 455 | if (name == NULL) |
360 | 456 | goto out_problem; | |
361 | map->dso->short_name = name; | 457 | |
362 | map->end = map->start + self->mmap.len; | 458 | map->dso->short_name = name; |
363 | } else if (memcmp(self->mmap.filename, kmmap_prefix, | 459 | map->end = map->start + self->mmap.len; |
364 | sizeof(kmmap_prefix) - 1) == 0) { | 460 | } else if (is_kernel_mmap) { |
365 | const char *symbol_name = (self->mmap.filename + | 461 | const char *symbol_name = (self->mmap.filename + |
366 | sizeof(kmmap_prefix) - 1); | 462 | strlen(kmmap_prefix)); |
463 | /* | ||
464 | * Should be there already, from the build-id table in | ||
465 | * the header. | ||
466 | */ | ||
467 | struct dso *kernel = __dsos__findnew(&machine->kernel_dsos, | ||
468 | kmmap_prefix); | ||
469 | if (kernel == NULL) | ||
470 | goto out_problem; | ||
471 | |||
472 | kernel->kernel = kernel_type; | ||
473 | if (__machine__create_kernel_maps(machine, kernel) < 0) | ||
474 | goto out_problem; | ||
475 | |||
476 | event_set_kernel_mmap_len(machine->vmlinux_maps, self); | ||
477 | perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, | ||
478 | symbol_name, | ||
479 | self->mmap.pgoff); | ||
480 | if (machine__is_default_guest(machine)) { | ||
367 | /* | 481 | /* |
368 | * Should be there already, from the build-id table in | 482 | * preload dso of guest kernel and modules |
369 | * the header. | ||
370 | */ | 483 | */ |
371 | struct dso *kernel = __dsos__findnew(&dsos__kernel, | 484 | dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION], |
372 | "[kernel.kallsyms]"); | 485 | NULL); |
373 | if (kernel == NULL) | 486 | } |
374 | goto out_problem; | 487 | } |
375 | 488 | return 0; | |
376 | kernel->kernel = 1; | 489 | out_problem: |
377 | if (__perf_session__create_kernel_maps(session, kernel) < 0) | 490 | return -1; |
378 | goto out_problem; | 491 | } |
379 | 492 | ||
380 | session->vmlinux_maps[MAP__FUNCTION]->start = self->mmap.start; | 493 | int event__process_mmap(event_t *self, struct perf_session *session) |
381 | session->vmlinux_maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len; | 494 | { |
382 | /* | 495 | struct machine *machine; |
383 | * Be a bit paranoid here, some perf.data file came with | 496 | struct thread *thread; |
384 | * a zero sized synthesized MMAP event for the kernel. | 497 | struct map *map; |
385 | */ | 498 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
386 | if (session->vmlinux_maps[MAP__FUNCTION]->end == 0) | 499 | int ret = 0; |
387 | session->vmlinux_maps[MAP__FUNCTION]->end = ~0UL; | ||
388 | 500 | ||
389 | perf_session__set_kallsyms_ref_reloc_sym(session, symbol_name, | 501 | dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n", |
390 | self->mmap.pgoff); | 502 | self->mmap.pid, self->mmap.tid, self->mmap.start, |
391 | } | 503 | self->mmap.len, self->mmap.pgoff, self->mmap.filename); |
504 | |||
505 | if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || | ||
506 | cpumode == PERF_RECORD_MISC_KERNEL) { | ||
507 | ret = event__process_kernel_mmap(self, session); | ||
508 | if (ret < 0) | ||
509 | goto out_problem; | ||
392 | return 0; | 510 | return 0; |
393 | } | 511 | } |
394 | 512 | ||
513 | machine = perf_session__find_host_machine(session); | ||
514 | if (machine == NULL) | ||
515 | goto out_problem; | ||
395 | thread = perf_session__findnew(session, self->mmap.pid); | 516 | thread = perf_session__findnew(session, self->mmap.pid); |
396 | map = map__new(&self->mmap, MAP__FUNCTION, | 517 | map = map__new(&machine->user_dsos, self->mmap.start, |
397 | session->cwd, session->cwdlen); | 518 | self->mmap.len, self->mmap.pgoff, |
519 | self->mmap.pid, self->mmap.filename, | ||
520 | MAP__FUNCTION, session->cwd, session->cwdlen); | ||
398 | 521 | ||
399 | if (thread == NULL || map == NULL) | 522 | if (thread == NULL || map == NULL) |
400 | goto out_problem; | 523 | goto out_problem; |
@@ -434,22 +557,56 @@ int event__process_task(event_t *self, struct perf_session *session) | |||
434 | 557 | ||
435 | void thread__find_addr_map(struct thread *self, | 558 | void thread__find_addr_map(struct thread *self, |
436 | struct perf_session *session, u8 cpumode, | 559 | struct perf_session *session, u8 cpumode, |
437 | enum map_type type, u64 addr, | 560 | enum map_type type, pid_t pid, u64 addr, |
438 | struct addr_location *al) | 561 | struct addr_location *al) |
439 | { | 562 | { |
440 | struct map_groups *mg = &self->mg; | 563 | struct map_groups *mg = &self->mg; |
564 | struct machine *machine = NULL; | ||
441 | 565 | ||
442 | al->thread = self; | 566 | al->thread = self; |
443 | al->addr = addr; | 567 | al->addr = addr; |
568 | al->cpumode = cpumode; | ||
569 | al->filtered = false; | ||
444 | 570 | ||
445 | if (cpumode == PERF_RECORD_MISC_KERNEL) { | 571 | if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { |
446 | al->level = 'k'; | 572 | al->level = 'k'; |
447 | mg = &session->kmaps; | 573 | machine = perf_session__find_host_machine(session); |
448 | } else if (cpumode == PERF_RECORD_MISC_USER) | 574 | if (machine == NULL) { |
575 | al->map = NULL; | ||
576 | return; | ||
577 | } | ||
578 | mg = &machine->kmaps; | ||
579 | } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { | ||
449 | al->level = '.'; | 580 | al->level = '.'; |
450 | else { | 581 | machine = perf_session__find_host_machine(session); |
451 | al->level = 'H'; | 582 | } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { |
583 | al->level = 'g'; | ||
584 | machine = perf_session__find_machine(session, pid); | ||
585 | if (machine == NULL) { | ||
586 | al->map = NULL; | ||
587 | return; | ||
588 | } | ||
589 | mg = &machine->kmaps; | ||
590 | } else { | ||
591 | /* | ||
592 | * 'u' means guest os user space. | ||
593 | * TODO: We don't support guest user space. Might support late. | ||
594 | */ | ||
595 | if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) | ||
596 | al->level = 'u'; | ||
597 | else | ||
598 | al->level = 'H'; | ||
452 | al->map = NULL; | 599 | al->map = NULL; |
600 | |||
601 | if ((cpumode == PERF_RECORD_MISC_GUEST_USER || | ||
602 | cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && | ||
603 | !perf_guest) | ||
604 | al->filtered = true; | ||
605 | if ((cpumode == PERF_RECORD_MISC_USER || | ||
606 | cpumode == PERF_RECORD_MISC_KERNEL) && | ||
607 | !perf_host) | ||
608 | al->filtered = true; | ||
609 | |||
453 | return; | 610 | return; |
454 | } | 611 | } |
455 | try_again: | 612 | try_again: |
@@ -464,8 +621,10 @@ try_again: | |||
464 | * "[vdso]" dso, but for now lets use the old trick of looking | 621 | * "[vdso]" dso, but for now lets use the old trick of looking |
465 | * in the whole kernel symbol list. | 622 | * in the whole kernel symbol list. |
466 | */ | 623 | */ |
467 | if ((long long)al->addr < 0 && mg != &session->kmaps) { | 624 | if ((long long)al->addr < 0 && |
468 | mg = &session->kmaps; | 625 | cpumode == PERF_RECORD_MISC_KERNEL && |
626 | machine && mg != &machine->kmaps) { | ||
627 | mg = &machine->kmaps; | ||
469 | goto try_again; | 628 | goto try_again; |
470 | } | 629 | } |
471 | } else | 630 | } else |
@@ -474,11 +633,11 @@ try_again: | |||
474 | 633 | ||
475 | void thread__find_addr_location(struct thread *self, | 634 | void thread__find_addr_location(struct thread *self, |
476 | struct perf_session *session, u8 cpumode, | 635 | struct perf_session *session, u8 cpumode, |
477 | enum map_type type, u64 addr, | 636 | enum map_type type, pid_t pid, u64 addr, |
478 | struct addr_location *al, | 637 | struct addr_location *al, |
479 | symbol_filter_t filter) | 638 | symbol_filter_t filter) |
480 | { | 639 | { |
481 | thread__find_addr_map(self, session, cpumode, type, addr, al); | 640 | thread__find_addr_map(self, session, cpumode, type, pid, addr, al); |
482 | if (al->map != NULL) | 641 | if (al->map != NULL) |
483 | al->sym = map__find_symbol(al->map, al->addr, filter); | 642 | al->sym = map__find_symbol(al->map, al->addr, filter); |
484 | else | 643 | else |
@@ -490,8 +649,10 @@ static void dso__calc_col_width(struct dso *self) | |||
490 | if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && | 649 | if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
491 | (!symbol_conf.dso_list || | 650 | (!symbol_conf.dso_list || |
492 | strlist__has_entry(symbol_conf.dso_list, self->name))) { | 651 | strlist__has_entry(symbol_conf.dso_list, self->name))) { |
493 | unsigned int slen = strlen(self->name); | 652 | u16 slen = self->short_name_len; |
494 | if (slen > dsos__col_width) | 653 | if (verbose) |
654 | slen = self->long_name_len; | ||
655 | if (dsos__col_width < slen) | ||
495 | dsos__col_width = slen; | 656 | dsos__col_width = slen; |
496 | } | 657 | } |
497 | 658 | ||
@@ -512,31 +673,55 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
512 | goto out_filtered; | 673 | goto out_filtered; |
513 | 674 | ||
514 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | 675 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); |
676 | /* | ||
677 | * Have we already created the kernel maps for the host machine? | ||
678 | * | ||
679 | * This should have happened earlier, when we processed the kernel MMAP | ||
680 | * events, but for older perf.data files there was no such thing, so do | ||
681 | * it now. | ||
682 | */ | ||
683 | if (cpumode == PERF_RECORD_MISC_KERNEL && | ||
684 | session->host_machine.vmlinux_maps[MAP__FUNCTION] == NULL) | ||
685 | machine__create_kernel_maps(&session->host_machine); | ||
515 | 686 | ||
516 | thread__find_addr_location(thread, session, cpumode, MAP__FUNCTION, | 687 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, |
517 | self->ip.ip, al, filter); | 688 | self->ip.pid, self->ip.ip, al); |
518 | dump_printf(" ...... dso: %s\n", | 689 | dump_printf(" ...... dso: %s\n", |
519 | al->map ? al->map->dso->long_name : | 690 | al->map ? al->map->dso->long_name : |
520 | al->level == 'H' ? "[hypervisor]" : "<not found>"); | 691 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
521 | /* | 692 | al->sym = NULL; |
522 | * We have to do this here as we may have a dso with no symbol hit that | 693 | |
523 | * has a name longer than the ones with symbols sampled. | 694 | if (al->map) { |
524 | */ | 695 | if (symbol_conf.dso_list && |
525 | if (al->map && !sort_dso.elide && !al->map->dso->slen_calculated) | 696 | (!al->map || !al->map->dso || |
526 | dso__calc_col_width(al->map->dso); | 697 | !(strlist__has_entry(symbol_conf.dso_list, |
527 | 698 | al->map->dso->short_name) || | |
528 | if (symbol_conf.dso_list && | 699 | (al->map->dso->short_name != al->map->dso->long_name && |
529 | (!al->map || !al->map->dso || | 700 | strlist__has_entry(symbol_conf.dso_list, |
530 | !(strlist__has_entry(symbol_conf.dso_list, al->map->dso->short_name) || | 701 | al->map->dso->long_name))))) |
531 | (al->map->dso->short_name != al->map->dso->long_name && | 702 | goto out_filtered; |
532 | strlist__has_entry(symbol_conf.dso_list, al->map->dso->long_name))))) | 703 | /* |
533 | goto out_filtered; | 704 | * We have to do this here as we may have a dso with no symbol |
705 | * hit that has a name longer than the ones with symbols | ||
706 | * sampled. | ||
707 | */ | ||
708 | if (!sort_dso.elide && !al->map->dso->slen_calculated) | ||
709 | dso__calc_col_width(al->map->dso); | ||
710 | |||
711 | al->sym = map__find_symbol(al->map, al->addr, filter); | ||
712 | } else { | ||
713 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; | ||
714 | |||
715 | if (dsos__col_width < unresolved_col_width && | ||
716 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && | ||
717 | !symbol_conf.dso_list) | ||
718 | dsos__col_width = unresolved_col_width; | ||
719 | } | ||
534 | 720 | ||
535 | if (symbol_conf.sym_list && al->sym && | 721 | if (symbol_conf.sym_list && al->sym && |
536 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) | 722 | !strlist__has_entry(symbol_conf.sym_list, al->sym->name)) |
537 | goto out_filtered; | 723 | goto out_filtered; |
538 | 724 | ||
539 | al->filtered = false; | ||
540 | return 0; | 725 | return 0; |
541 | 726 | ||
542 | out_filtered: | 727 | out_filtered: |
@@ -570,6 +755,7 @@ int event__parse_sample(event_t *event, u64 type, struct sample_data *data) | |||
570 | array++; | 755 | array++; |
571 | } | 756 | } |
572 | 757 | ||
758 | data->id = -1ULL; | ||
573 | if (type & PERF_SAMPLE_ID) { | 759 | if (type & PERF_SAMPLE_ID) { |
574 | data->id = *array; | 760 | data->id = *array; |
575 | array++; | 761 | array++; |
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index a33b94952e34..8577085db067 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h | |||
@@ -68,21 +68,54 @@ struct sample_data { | |||
68 | u64 addr; | 68 | u64 addr; |
69 | u64 id; | 69 | u64 id; |
70 | u64 stream_id; | 70 | u64 stream_id; |
71 | u32 cpu; | ||
72 | u64 period; | 71 | u64 period; |
73 | struct ip_callchain *callchain; | 72 | u32 cpu; |
74 | u32 raw_size; | 73 | u32 raw_size; |
75 | void *raw_data; | 74 | void *raw_data; |
75 | struct ip_callchain *callchain; | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | #define BUILD_ID_SIZE 20 | 78 | #define BUILD_ID_SIZE 20 |
79 | 79 | ||
80 | struct build_id_event { | 80 | struct build_id_event { |
81 | struct perf_event_header header; | 81 | struct perf_event_header header; |
82 | pid_t pid; | ||
82 | u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))]; | 83 | u8 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))]; |
83 | char filename[]; | 84 | char filename[]; |
84 | }; | 85 | }; |
85 | 86 | ||
87 | enum perf_user_event_type { /* above any possible kernel type */ | ||
88 | PERF_RECORD_HEADER_ATTR = 64, | ||
89 | PERF_RECORD_HEADER_EVENT_TYPE = 65, | ||
90 | PERF_RECORD_HEADER_TRACING_DATA = 66, | ||
91 | PERF_RECORD_HEADER_BUILD_ID = 67, | ||
92 | PERF_RECORD_FINISHED_ROUND = 68, | ||
93 | PERF_RECORD_HEADER_MAX | ||
94 | }; | ||
95 | |||
96 | struct attr_event { | ||
97 | struct perf_event_header header; | ||
98 | struct perf_event_attr attr; | ||
99 | u64 id[]; | ||
100 | }; | ||
101 | |||
102 | #define MAX_EVENT_NAME 64 | ||
103 | |||
104 | struct perf_trace_event_type { | ||
105 | u64 event_id; | ||
106 | char name[MAX_EVENT_NAME]; | ||
107 | }; | ||
108 | |||
109 | struct event_type_event { | ||
110 | struct perf_event_header header; | ||
111 | struct perf_trace_event_type event_type; | ||
112 | }; | ||
113 | |||
114 | struct tracing_data_event { | ||
115 | struct perf_event_header header; | ||
116 | u32 size; | ||
117 | }; | ||
118 | |||
86 | typedef union event_union { | 119 | typedef union event_union { |
87 | struct perf_event_header header; | 120 | struct perf_event_header header; |
88 | struct ip_event ip; | 121 | struct ip_event ip; |
@@ -92,22 +125,12 @@ typedef union event_union { | |||
92 | struct lost_event lost; | 125 | struct lost_event lost; |
93 | struct read_event read; | 126 | struct read_event read; |
94 | struct sample_event sample; | 127 | struct sample_event sample; |
128 | struct attr_event attr; | ||
129 | struct event_type_event event_type; | ||
130 | struct tracing_data_event tracing_data; | ||
131 | struct build_id_event build_id; | ||
95 | } event_t; | 132 | } event_t; |
96 | 133 | ||
97 | struct events_stats { | ||
98 | u64 total; | ||
99 | u64 lost; | ||
100 | }; | ||
101 | |||
102 | struct event_stat_id { | ||
103 | struct rb_node rb_node; | ||
104 | struct rb_root hists; | ||
105 | struct events_stats stats; | ||
106 | u64 config; | ||
107 | u64 event_stream; | ||
108 | u32 type; | ||
109 | }; | ||
110 | |||
111 | void event__print_totals(void); | 134 | void event__print_totals(void); |
112 | 135 | ||
113 | struct perf_session; | 136 | struct perf_session; |
@@ -119,10 +142,13 @@ int event__synthesize_thread(pid_t pid, event__handler_t process, | |||
119 | void event__synthesize_threads(event__handler_t process, | 142 | void event__synthesize_threads(event__handler_t process, |
120 | struct perf_session *session); | 143 | struct perf_session *session); |
121 | int event__synthesize_kernel_mmap(event__handler_t process, | 144 | int event__synthesize_kernel_mmap(event__handler_t process, |
122 | struct perf_session *session, | 145 | struct perf_session *session, |
123 | const char *symbol_name); | 146 | struct machine *machine, |
147 | const char *symbol_name); | ||
148 | |||
124 | int event__synthesize_modules(event__handler_t process, | 149 | int event__synthesize_modules(event__handler_t process, |
125 | struct perf_session *session); | 150 | struct perf_session *session, |
151 | struct machine *machine); | ||
126 | 152 | ||
127 | int event__process_comm(event_t *self, struct perf_session *session); | 153 | int event__process_comm(event_t *self, struct perf_session *session); |
128 | int event__process_lost(event_t *self, struct perf_session *session); | 154 | int event__process_lost(event_t *self, struct perf_session *session); |
@@ -134,4 +160,6 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session, | |||
134 | struct addr_location *al, symbol_filter_t filter); | 160 | struct addr_location *al, symbol_filter_t filter); |
135 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data); | 161 | int event__parse_sample(event_t *event, u64 type, struct sample_data *data); |
136 | 162 | ||
163 | extern const char *event__name[]; | ||
164 | |||
137 | #endif /* __PERF_RECORD_H */ | 165 | #endif /* __PERF_RECORD_H */ |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 6c9aa16ee51f..8847bec64c54 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -99,13 +99,6 @@ int perf_header__add_attr(struct perf_header *self, | |||
99 | return 0; | 99 | return 0; |
100 | } | 100 | } |
101 | 101 | ||
102 | #define MAX_EVENT_NAME 64 | ||
103 | |||
104 | struct perf_trace_event_type { | ||
105 | u64 event_id; | ||
106 | char name[MAX_EVENT_NAME]; | ||
107 | }; | ||
108 | |||
109 | static int event_count; | 102 | static int event_count; |
110 | static struct perf_trace_event_type *events; | 103 | static struct perf_trace_event_type *events; |
111 | 104 | ||
@@ -197,7 +190,8 @@ static int write_padded(int fd, const void *bf, size_t count, | |||
197 | continue; \ | 190 | continue; \ |
198 | else | 191 | else |
199 | 192 | ||
200 | static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd) | 193 | static int __dsos__write_buildid_table(struct list_head *head, pid_t pid, |
194 | u16 misc, int fd) | ||
201 | { | 195 | { |
202 | struct dso *pos; | 196 | struct dso *pos; |
203 | 197 | ||
@@ -212,6 +206,7 @@ static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd) | |||
212 | len = ALIGN(len, NAME_ALIGN); | 206 | len = ALIGN(len, NAME_ALIGN); |
213 | memset(&b, 0, sizeof(b)); | 207 | memset(&b, 0, sizeof(b)); |
214 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); | 208 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); |
209 | b.pid = pid; | ||
215 | b.header.misc = misc; | 210 | b.header.misc = misc; |
216 | b.header.size = sizeof(b) + len; | 211 | b.header.size = sizeof(b) + len; |
217 | err = do_write(fd, &b, sizeof(b)); | 212 | err = do_write(fd, &b, sizeof(b)); |
@@ -226,13 +221,32 @@ static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd) | |||
226 | return 0; | 221 | return 0; |
227 | } | 222 | } |
228 | 223 | ||
229 | static int dsos__write_buildid_table(int fd) | 224 | static int dsos__write_buildid_table(struct perf_header *header, int fd) |
230 | { | 225 | { |
231 | int err = __dsos__write_buildid_table(&dsos__kernel, | 226 | struct perf_session *session = container_of(header, |
232 | PERF_RECORD_MISC_KERNEL, fd); | 227 | struct perf_session, header); |
233 | if (err == 0) | 228 | struct rb_node *nd; |
234 | err = __dsos__write_buildid_table(&dsos__user, | 229 | int err = 0; |
235 | PERF_RECORD_MISC_USER, fd); | 230 | u16 kmisc, umisc; |
231 | |||
232 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | ||
233 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | ||
234 | if (machine__is_host(pos)) { | ||
235 | kmisc = PERF_RECORD_MISC_KERNEL; | ||
236 | umisc = PERF_RECORD_MISC_USER; | ||
237 | } else { | ||
238 | kmisc = PERF_RECORD_MISC_GUEST_KERNEL; | ||
239 | umisc = PERF_RECORD_MISC_GUEST_USER; | ||
240 | } | ||
241 | |||
242 | err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid, | ||
243 | kmisc, fd); | ||
244 | if (err == 0) | ||
245 | err = __dsos__write_buildid_table(&pos->user_dsos, | ||
246 | pos->pid, umisc, fd); | ||
247 | if (err) | ||
248 | break; | ||
249 | } | ||
236 | return err; | 250 | return err; |
237 | } | 251 | } |
238 | 252 | ||
@@ -349,9 +363,12 @@ static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir) | |||
349 | return err; | 363 | return err; |
350 | } | 364 | } |
351 | 365 | ||
352 | static int dsos__cache_build_ids(void) | 366 | static int dsos__cache_build_ids(struct perf_header *self) |
353 | { | 367 | { |
354 | int err_kernel, err_user; | 368 | struct perf_session *session = container_of(self, |
369 | struct perf_session, header); | ||
370 | struct rb_node *nd; | ||
371 | int ret = 0; | ||
355 | char debugdir[PATH_MAX]; | 372 | char debugdir[PATH_MAX]; |
356 | 373 | ||
357 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), | 374 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), |
@@ -360,9 +377,28 @@ static int dsos__cache_build_ids(void) | |||
360 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) | 377 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) |
361 | return -1; | 378 | return -1; |
362 | 379 | ||
363 | err_kernel = __dsos__cache_build_ids(&dsos__kernel, debugdir); | 380 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { |
364 | err_user = __dsos__cache_build_ids(&dsos__user, debugdir); | 381 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
365 | return err_kernel || err_user ? -1 : 0; | 382 | ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir); |
383 | ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir); | ||
384 | } | ||
385 | return ret ? -1 : 0; | ||
386 | } | ||
387 | |||
388 | static bool dsos__read_build_ids(struct perf_header *self, bool with_hits) | ||
389 | { | ||
390 | bool ret = false; | ||
391 | struct perf_session *session = container_of(self, | ||
392 | struct perf_session, header); | ||
393 | struct rb_node *nd; | ||
394 | |||
395 | for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { | ||
396 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | ||
397 | ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits); | ||
398 | ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits); | ||
399 | } | ||
400 | |||
401 | return ret; | ||
366 | } | 402 | } |
367 | 403 | ||
368 | static int perf_header__adds_write(struct perf_header *self, int fd) | 404 | static int perf_header__adds_write(struct perf_header *self, int fd) |
@@ -373,7 +409,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd) | |||
373 | u64 sec_start; | 409 | u64 sec_start; |
374 | int idx = 0, err; | 410 | int idx = 0, err; |
375 | 411 | ||
376 | if (dsos__read_build_ids(true)) | 412 | if (dsos__read_build_ids(self, true)) |
377 | perf_header__set_feat(self, HEADER_BUILD_ID); | 413 | perf_header__set_feat(self, HEADER_BUILD_ID); |
378 | 414 | ||
379 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); | 415 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
@@ -400,7 +436,6 @@ static int perf_header__adds_write(struct perf_header *self, int fd) | |||
400 | trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset; | 436 | trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset; |
401 | } | 437 | } |
402 | 438 | ||
403 | |||
404 | if (perf_header__has_feat(self, HEADER_BUILD_ID)) { | 439 | if (perf_header__has_feat(self, HEADER_BUILD_ID)) { |
405 | struct perf_file_section *buildid_sec; | 440 | struct perf_file_section *buildid_sec; |
406 | 441 | ||
@@ -408,14 +443,14 @@ static int perf_header__adds_write(struct perf_header *self, int fd) | |||
408 | 443 | ||
409 | /* Write build-ids */ | 444 | /* Write build-ids */ |
410 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); | 445 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); |
411 | err = dsos__write_buildid_table(fd); | 446 | err = dsos__write_buildid_table(self, fd); |
412 | if (err < 0) { | 447 | if (err < 0) { |
413 | pr_debug("failed to write buildid table\n"); | 448 | pr_debug("failed to write buildid table\n"); |
414 | goto out_free; | 449 | goto out_free; |
415 | } | 450 | } |
416 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - | 451 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - |
417 | buildid_sec->offset; | 452 | buildid_sec->offset; |
418 | dsos__cache_build_ids(); | 453 | dsos__cache_build_ids(self); |
419 | } | 454 | } |
420 | 455 | ||
421 | lseek(fd, sec_start, SEEK_SET); | 456 | lseek(fd, sec_start, SEEK_SET); |
@@ -427,6 +462,25 @@ out_free: | |||
427 | return err; | 462 | return err; |
428 | } | 463 | } |
429 | 464 | ||
465 | int perf_header__write_pipe(int fd) | ||
466 | { | ||
467 | struct perf_pipe_file_header f_header; | ||
468 | int err; | ||
469 | |||
470 | f_header = (struct perf_pipe_file_header){ | ||
471 | .magic = PERF_MAGIC, | ||
472 | .size = sizeof(f_header), | ||
473 | }; | ||
474 | |||
475 | err = do_write(fd, &f_header, sizeof(f_header)); | ||
476 | if (err < 0) { | ||
477 | pr_debug("failed to write perf pipe header\n"); | ||
478 | return err; | ||
479 | } | ||
480 | |||
481 | return 0; | ||
482 | } | ||
483 | |||
430 | int perf_header__write(struct perf_header *self, int fd, bool at_exit) | 484 | int perf_header__write(struct perf_header *self, int fd, bool at_exit) |
431 | { | 485 | { |
432 | struct perf_file_header f_header; | 486 | struct perf_file_header f_header; |
@@ -518,25 +572,10 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit) | |||
518 | return 0; | 572 | return 0; |
519 | } | 573 | } |
520 | 574 | ||
521 | static int do_read(int fd, void *buf, size_t size) | ||
522 | { | ||
523 | while (size) { | ||
524 | int ret = read(fd, buf, size); | ||
525 | |||
526 | if (ret <= 0) | ||
527 | return -1; | ||
528 | |||
529 | size -= ret; | ||
530 | buf += ret; | ||
531 | } | ||
532 | |||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | static int perf_header__getbuffer64(struct perf_header *self, | 575 | static int perf_header__getbuffer64(struct perf_header *self, |
537 | int fd, void *buf, size_t size) | 576 | int fd, void *buf, size_t size) |
538 | { | 577 | { |
539 | if (do_read(fd, buf, size)) | 578 | if (do_read(fd, buf, size) <= 0) |
540 | return -1; | 579 | return -1; |
541 | 580 | ||
542 | if (self->needs_swap) | 581 | if (self->needs_swap) |
@@ -592,7 +631,7 @@ int perf_file_header__read(struct perf_file_header *self, | |||
592 | { | 631 | { |
593 | lseek(fd, 0, SEEK_SET); | 632 | lseek(fd, 0, SEEK_SET); |
594 | 633 | ||
595 | if (do_read(fd, self, sizeof(*self)) || | 634 | if (do_read(fd, self, sizeof(*self)) <= 0 || |
596 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) | 635 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) |
597 | return -1; | 636 | return -1; |
598 | 637 | ||
@@ -636,6 +675,93 @@ int perf_file_header__read(struct perf_file_header *self, | |||
636 | return 0; | 675 | return 0; |
637 | } | 676 | } |
638 | 677 | ||
678 | static int __event_process_build_id(struct build_id_event *bev, | ||
679 | char *filename, | ||
680 | struct perf_session *session) | ||
681 | { | ||
682 | int err = -1; | ||
683 | struct list_head *head; | ||
684 | struct machine *machine; | ||
685 | u16 misc; | ||
686 | struct dso *dso; | ||
687 | enum dso_kernel_type dso_type; | ||
688 | |||
689 | machine = perf_session__findnew_machine(session, bev->pid); | ||
690 | if (!machine) | ||
691 | goto out; | ||
692 | |||
693 | misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
694 | |||
695 | switch (misc) { | ||
696 | case PERF_RECORD_MISC_KERNEL: | ||
697 | dso_type = DSO_TYPE_KERNEL; | ||
698 | head = &machine->kernel_dsos; | ||
699 | break; | ||
700 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
701 | dso_type = DSO_TYPE_GUEST_KERNEL; | ||
702 | head = &machine->kernel_dsos; | ||
703 | break; | ||
704 | case PERF_RECORD_MISC_USER: | ||
705 | case PERF_RECORD_MISC_GUEST_USER: | ||
706 | dso_type = DSO_TYPE_USER; | ||
707 | head = &machine->user_dsos; | ||
708 | break; | ||
709 | default: | ||
710 | goto out; | ||
711 | } | ||
712 | |||
713 | dso = __dsos__findnew(head, filename); | ||
714 | if (dso != NULL) { | ||
715 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; | ||
716 | |||
717 | dso__set_build_id(dso, &bev->build_id); | ||
718 | |||
719 | if (filename[0] == '[') | ||
720 | dso->kernel = dso_type; | ||
721 | |||
722 | build_id__sprintf(dso->build_id, sizeof(dso->build_id), | ||
723 | sbuild_id); | ||
724 | pr_debug("build id event received for %s: %s\n", | ||
725 | dso->long_name, sbuild_id); | ||
726 | } | ||
727 | |||
728 | err = 0; | ||
729 | out: | ||
730 | return err; | ||
731 | } | ||
732 | |||
733 | static int perf_header__read_build_ids(struct perf_header *self, | ||
734 | int input, u64 offset, u64 size) | ||
735 | { | ||
736 | struct perf_session *session = container_of(self, | ||
737 | struct perf_session, header); | ||
738 | struct build_id_event bev; | ||
739 | char filename[PATH_MAX]; | ||
740 | u64 limit = offset + size; | ||
741 | int err = -1; | ||
742 | |||
743 | while (offset < limit) { | ||
744 | ssize_t len; | ||
745 | |||
746 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) | ||
747 | goto out; | ||
748 | |||
749 | if (self->needs_swap) | ||
750 | perf_event_header__bswap(&bev.header); | ||
751 | |||
752 | len = bev.header.size - sizeof(bev); | ||
753 | if (read(input, filename, len) != len) | ||
754 | goto out; | ||
755 | |||
756 | __event_process_build_id(&bev, filename, session); | ||
757 | |||
758 | offset += bev.header.size; | ||
759 | } | ||
760 | err = 0; | ||
761 | out: | ||
762 | return err; | ||
763 | } | ||
764 | |||
639 | static int perf_file_section__process(struct perf_file_section *self, | 765 | static int perf_file_section__process(struct perf_file_section *self, |
640 | struct perf_header *ph, | 766 | struct perf_header *ph, |
641 | int feat, int fd) | 767 | int feat, int fd) |
@@ -648,7 +774,7 @@ static int perf_file_section__process(struct perf_file_section *self, | |||
648 | 774 | ||
649 | switch (feat) { | 775 | switch (feat) { |
650 | case HEADER_TRACE_INFO: | 776 | case HEADER_TRACE_INFO: |
651 | trace_report(fd); | 777 | trace_report(fd, false); |
652 | break; | 778 | break; |
653 | 779 | ||
654 | case HEADER_BUILD_ID: | 780 | case HEADER_BUILD_ID: |
@@ -662,13 +788,56 @@ static int perf_file_section__process(struct perf_file_section *self, | |||
662 | return 0; | 788 | return 0; |
663 | } | 789 | } |
664 | 790 | ||
665 | int perf_header__read(struct perf_header *self, int fd) | 791 | static int perf_file_header__read_pipe(struct perf_pipe_file_header *self, |
792 | struct perf_header *ph, int fd, | ||
793 | bool repipe) | ||
794 | { | ||
795 | if (do_read(fd, self, sizeof(*self)) <= 0 || | ||
796 | memcmp(&self->magic, __perf_magic, sizeof(self->magic))) | ||
797 | return -1; | ||
798 | |||
799 | if (repipe && do_write(STDOUT_FILENO, self, sizeof(*self)) < 0) | ||
800 | return -1; | ||
801 | |||
802 | if (self->size != sizeof(*self)) { | ||
803 | u64 size = bswap_64(self->size); | ||
804 | |||
805 | if (size != sizeof(*self)) | ||
806 | return -1; | ||
807 | |||
808 | ph->needs_swap = true; | ||
809 | } | ||
810 | |||
811 | return 0; | ||
812 | } | ||
813 | |||
814 | static int perf_header__read_pipe(struct perf_session *session, int fd) | ||
666 | { | 815 | { |
816 | struct perf_header *self = &session->header; | ||
817 | struct perf_pipe_file_header f_header; | ||
818 | |||
819 | if (perf_file_header__read_pipe(&f_header, self, fd, | ||
820 | session->repipe) < 0) { | ||
821 | pr_debug("incompatible file format\n"); | ||
822 | return -EINVAL; | ||
823 | } | ||
824 | |||
825 | session->fd = fd; | ||
826 | |||
827 | return 0; | ||
828 | } | ||
829 | |||
830 | int perf_header__read(struct perf_session *session, int fd) | ||
831 | { | ||
832 | struct perf_header *self = &session->header; | ||
667 | struct perf_file_header f_header; | 833 | struct perf_file_header f_header; |
668 | struct perf_file_attr f_attr; | 834 | struct perf_file_attr f_attr; |
669 | u64 f_id; | 835 | u64 f_id; |
670 | int nr_attrs, nr_ids, i, j; | 836 | int nr_attrs, nr_ids, i, j; |
671 | 837 | ||
838 | if (session->fd_pipe) | ||
839 | return perf_header__read_pipe(session, fd); | ||
840 | |||
672 | if (perf_file_header__read(&f_header, self, fd) < 0) { | 841 | if (perf_file_header__read(&f_header, self, fd) < 0) { |
673 | pr_debug("incompatible file format\n"); | 842 | pr_debug("incompatible file format\n"); |
674 | return -EINVAL; | 843 | return -EINVAL; |
@@ -753,6 +922,14 @@ perf_header__find_attr(u64 id, struct perf_header *header) | |||
753 | { | 922 | { |
754 | int i; | 923 | int i; |
755 | 924 | ||
925 | /* | ||
926 | * We set id to -1 if the data file doesn't contain sample | ||
927 | * ids. Check for this and avoid walking through the entire | ||
928 | * list of ids which may be large. | ||
929 | */ | ||
930 | if (id == -1ULL) | ||
931 | return NULL; | ||
932 | |||
756 | for (i = 0; i < header->attrs; i++) { | 933 | for (i = 0; i < header->attrs; i++) { |
757 | struct perf_header_attr *attr = header->attr[i]; | 934 | struct perf_header_attr *attr = header->attr[i]; |
758 | int j; | 935 | int j; |
@@ -765,3 +942,231 @@ perf_header__find_attr(u64 id, struct perf_header *header) | |||
765 | 942 | ||
766 | return NULL; | 943 | return NULL; |
767 | } | 944 | } |
945 | |||
946 | int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, | ||
947 | event__handler_t process, | ||
948 | struct perf_session *session) | ||
949 | { | ||
950 | event_t *ev; | ||
951 | size_t size; | ||
952 | int err; | ||
953 | |||
954 | size = sizeof(struct perf_event_attr); | ||
955 | size = ALIGN(size, sizeof(u64)); | ||
956 | size += sizeof(struct perf_event_header); | ||
957 | size += ids * sizeof(u64); | ||
958 | |||
959 | ev = malloc(size); | ||
960 | |||
961 | ev->attr.attr = *attr; | ||
962 | memcpy(ev->attr.id, id, ids * sizeof(u64)); | ||
963 | |||
964 | ev->attr.header.type = PERF_RECORD_HEADER_ATTR; | ||
965 | ev->attr.header.size = size; | ||
966 | |||
967 | err = process(ev, session); | ||
968 | |||
969 | free(ev); | ||
970 | |||
971 | return err; | ||
972 | } | ||
973 | |||
974 | int event__synthesize_attrs(struct perf_header *self, | ||
975 | event__handler_t process, | ||
976 | struct perf_session *session) | ||
977 | { | ||
978 | struct perf_header_attr *attr; | ||
979 | int i, err = 0; | ||
980 | |||
981 | for (i = 0; i < self->attrs; i++) { | ||
982 | attr = self->attr[i]; | ||
983 | |||
984 | err = event__synthesize_attr(&attr->attr, attr->ids, attr->id, | ||
985 | process, session); | ||
986 | if (err) { | ||
987 | pr_debug("failed to create perf header attribute\n"); | ||
988 | return err; | ||
989 | } | ||
990 | } | ||
991 | |||
992 | return err; | ||
993 | } | ||
994 | |||
995 | int event__process_attr(event_t *self, struct perf_session *session) | ||
996 | { | ||
997 | struct perf_header_attr *attr; | ||
998 | unsigned int i, ids, n_ids; | ||
999 | |||
1000 | attr = perf_header_attr__new(&self->attr.attr); | ||
1001 | if (attr == NULL) | ||
1002 | return -ENOMEM; | ||
1003 | |||
1004 | ids = self->header.size; | ||
1005 | ids -= (void *)&self->attr.id - (void *)self; | ||
1006 | n_ids = ids / sizeof(u64); | ||
1007 | |||
1008 | for (i = 0; i < n_ids; i++) { | ||
1009 | if (perf_header_attr__add_id(attr, self->attr.id[i]) < 0) { | ||
1010 | perf_header_attr__delete(attr); | ||
1011 | return -ENOMEM; | ||
1012 | } | ||
1013 | } | ||
1014 | |||
1015 | if (perf_header__add_attr(&session->header, attr) < 0) { | ||
1016 | perf_header_attr__delete(attr); | ||
1017 | return -ENOMEM; | ||
1018 | } | ||
1019 | |||
1020 | perf_session__update_sample_type(session); | ||
1021 | |||
1022 | return 0; | ||
1023 | } | ||
1024 | |||
1025 | int event__synthesize_event_type(u64 event_id, char *name, | ||
1026 | event__handler_t process, | ||
1027 | struct perf_session *session) | ||
1028 | { | ||
1029 | event_t ev; | ||
1030 | size_t size = 0; | ||
1031 | int err = 0; | ||
1032 | |||
1033 | memset(&ev, 0, sizeof(ev)); | ||
1034 | |||
1035 | ev.event_type.event_type.event_id = event_id; | ||
1036 | memset(ev.event_type.event_type.name, 0, MAX_EVENT_NAME); | ||
1037 | strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1); | ||
1038 | |||
1039 | ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE; | ||
1040 | size = strlen(name); | ||
1041 | size = ALIGN(size, sizeof(u64)); | ||
1042 | ev.event_type.header.size = sizeof(ev.event_type) - | ||
1043 | (sizeof(ev.event_type.event_type.name) - size); | ||
1044 | |||
1045 | err = process(&ev, session); | ||
1046 | |||
1047 | return err; | ||
1048 | } | ||
1049 | |||
1050 | int event__synthesize_event_types(event__handler_t process, | ||
1051 | struct perf_session *session) | ||
1052 | { | ||
1053 | struct perf_trace_event_type *type; | ||
1054 | int i, err = 0; | ||
1055 | |||
1056 | for (i = 0; i < event_count; i++) { | ||
1057 | type = &events[i]; | ||
1058 | |||
1059 | err = event__synthesize_event_type(type->event_id, type->name, | ||
1060 | process, session); | ||
1061 | if (err) { | ||
1062 | pr_debug("failed to create perf header event type\n"); | ||
1063 | return err; | ||
1064 | } | ||
1065 | } | ||
1066 | |||
1067 | return err; | ||
1068 | } | ||
1069 | |||
1070 | int event__process_event_type(event_t *self, | ||
1071 | struct perf_session *session __unused) | ||
1072 | { | ||
1073 | if (perf_header__push_event(self->event_type.event_type.event_id, | ||
1074 | self->event_type.event_type.name) < 0) | ||
1075 | return -ENOMEM; | ||
1076 | |||
1077 | return 0; | ||
1078 | } | ||
1079 | |||
1080 | int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs, | ||
1081 | int nb_events, | ||
1082 | event__handler_t process, | ||
1083 | struct perf_session *session __unused) | ||
1084 | { | ||
1085 | event_t ev; | ||
1086 | ssize_t size = 0, aligned_size = 0, padding; | ||
1087 | int err = 0; | ||
1088 | |||
1089 | memset(&ev, 0, sizeof(ev)); | ||
1090 | |||
1091 | ev.tracing_data.header.type = PERF_RECORD_HEADER_TRACING_DATA; | ||
1092 | size = read_tracing_data_size(fd, pattrs, nb_events); | ||
1093 | if (size <= 0) | ||
1094 | return size; | ||
1095 | aligned_size = ALIGN(size, sizeof(u64)); | ||
1096 | padding = aligned_size - size; | ||
1097 | ev.tracing_data.header.size = sizeof(ev.tracing_data); | ||
1098 | ev.tracing_data.size = aligned_size; | ||
1099 | |||
1100 | process(&ev, session); | ||
1101 | |||
1102 | err = read_tracing_data(fd, pattrs, nb_events); | ||
1103 | write_padded(fd, NULL, 0, padding); | ||
1104 | |||
1105 | return aligned_size; | ||
1106 | } | ||
1107 | |||
1108 | int event__process_tracing_data(event_t *self, | ||
1109 | struct perf_session *session) | ||
1110 | { | ||
1111 | ssize_t size_read, padding, size = self->tracing_data.size; | ||
1112 | off_t offset = lseek(session->fd, 0, SEEK_CUR); | ||
1113 | char buf[BUFSIZ]; | ||
1114 | |||
1115 | /* setup for reading amidst mmap */ | ||
1116 | lseek(session->fd, offset + sizeof(struct tracing_data_event), | ||
1117 | SEEK_SET); | ||
1118 | |||
1119 | size_read = trace_report(session->fd, session->repipe); | ||
1120 | |||
1121 | padding = ALIGN(size_read, sizeof(u64)) - size_read; | ||
1122 | |||
1123 | if (read(session->fd, buf, padding) < 0) | ||
1124 | die("reading input file"); | ||
1125 | if (session->repipe) { | ||
1126 | int retw = write(STDOUT_FILENO, buf, padding); | ||
1127 | if (retw <= 0 || retw != padding) | ||
1128 | die("repiping tracing data padding"); | ||
1129 | } | ||
1130 | |||
1131 | if (size_read + padding != size) | ||
1132 | die("tracing data size mismatch"); | ||
1133 | |||
1134 | return size_read + padding; | ||
1135 | } | ||
1136 | |||
1137 | int event__synthesize_build_id(struct dso *pos, u16 misc, | ||
1138 | event__handler_t process, | ||
1139 | struct machine *machine, | ||
1140 | struct perf_session *session) | ||
1141 | { | ||
1142 | event_t ev; | ||
1143 | size_t len; | ||
1144 | int err = 0; | ||
1145 | |||
1146 | if (!pos->hit) | ||
1147 | return err; | ||
1148 | |||
1149 | memset(&ev, 0, sizeof(ev)); | ||
1150 | |||
1151 | len = pos->long_name_len + 1; | ||
1152 | len = ALIGN(len, NAME_ALIGN); | ||
1153 | memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id)); | ||
1154 | ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID; | ||
1155 | ev.build_id.header.misc = misc; | ||
1156 | ev.build_id.pid = machine->pid; | ||
1157 | ev.build_id.header.size = sizeof(ev.build_id) + len; | ||
1158 | memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); | ||
1159 | |||
1160 | err = process(&ev, session); | ||
1161 | |||
1162 | return err; | ||
1163 | } | ||
1164 | |||
1165 | int event__process_build_id(event_t *self, | ||
1166 | struct perf_session *session) | ||
1167 | { | ||
1168 | __event_process_build_id(&self->build_id, | ||
1169 | self->build_id.filename, | ||
1170 | session); | ||
1171 | return 0; | ||
1172 | } | ||
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 82a6af72d4cc..402ac2454cf8 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h | |||
@@ -39,6 +39,11 @@ struct perf_file_header { | |||
39 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); | 39 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
40 | }; | 40 | }; |
41 | 41 | ||
42 | struct perf_pipe_file_header { | ||
43 | u64 magic; | ||
44 | u64 size; | ||
45 | }; | ||
46 | |||
42 | struct perf_header; | 47 | struct perf_header; |
43 | 48 | ||
44 | int perf_file_header__read(struct perf_file_header *self, | 49 | int perf_file_header__read(struct perf_file_header *self, |
@@ -47,21 +52,22 @@ int perf_file_header__read(struct perf_file_header *self, | |||
47 | struct perf_header { | 52 | struct perf_header { |
48 | int frozen; | 53 | int frozen; |
49 | int attrs, size; | 54 | int attrs, size; |
55 | bool needs_swap; | ||
50 | struct perf_header_attr **attr; | 56 | struct perf_header_attr **attr; |
51 | s64 attr_offset; | 57 | s64 attr_offset; |
52 | u64 data_offset; | 58 | u64 data_offset; |
53 | u64 data_size; | 59 | u64 data_size; |
54 | u64 event_offset; | 60 | u64 event_offset; |
55 | u64 event_size; | 61 | u64 event_size; |
56 | bool needs_swap; | ||
57 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); | 62 | DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); |
58 | }; | 63 | }; |
59 | 64 | ||
60 | int perf_header__init(struct perf_header *self); | 65 | int perf_header__init(struct perf_header *self); |
61 | void perf_header__exit(struct perf_header *self); | 66 | void perf_header__exit(struct perf_header *self); |
62 | 67 | ||
63 | int perf_header__read(struct perf_header *self, int fd); | 68 | int perf_header__read(struct perf_session *session, int fd); |
64 | int perf_header__write(struct perf_header *self, int fd, bool at_exit); | 69 | int perf_header__write(struct perf_header *self, int fd, bool at_exit); |
70 | int perf_header__write_pipe(int fd); | ||
65 | 71 | ||
66 | int perf_header__add_attr(struct perf_header *self, | 72 | int perf_header__add_attr(struct perf_header *self, |
67 | struct perf_header_attr *attr); | 73 | struct perf_header_attr *attr); |
@@ -89,4 +95,33 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, | |||
89 | const char *name, bool is_kallsyms); | 95 | const char *name, bool is_kallsyms); |
90 | int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); | 96 | int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); |
91 | 97 | ||
98 | int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id, | ||
99 | event__handler_t process, | ||
100 | struct perf_session *session); | ||
101 | int event__synthesize_attrs(struct perf_header *self, | ||
102 | event__handler_t process, | ||
103 | struct perf_session *session); | ||
104 | int event__process_attr(event_t *self, struct perf_session *session); | ||
105 | |||
106 | int event__synthesize_event_type(u64 event_id, char *name, | ||
107 | event__handler_t process, | ||
108 | struct perf_session *session); | ||
109 | int event__synthesize_event_types(event__handler_t process, | ||
110 | struct perf_session *session); | ||
111 | int event__process_event_type(event_t *self, | ||
112 | struct perf_session *session); | ||
113 | |||
114 | int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs, | ||
115 | int nb_events, | ||
116 | event__handler_t process, | ||
117 | struct perf_session *session); | ||
118 | int event__process_tracing_data(event_t *self, | ||
119 | struct perf_session *session); | ||
120 | |||
121 | int event__synthesize_build_id(struct dso *pos, u16 misc, | ||
122 | event__handler_t process, | ||
123 | struct machine *machine, | ||
124 | struct perf_session *session); | ||
125 | int event__process_build_id(event_t *self, struct perf_session *session); | ||
126 | |||
92 | #endif /* __PERF_HEADER_H */ | 127 | #endif /* __PERF_HEADER_H */ |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 2be33c7dbf03..9a71c94f057a 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include "util.h" | ||
1 | #include "hist.h" | 2 | #include "hist.h" |
2 | #include "session.h" | 3 | #include "session.h" |
3 | #include "sort.h" | 4 | #include "sort.h" |
@@ -8,25 +9,69 @@ struct callchain_param callchain_param = { | |||
8 | .min_percent = 0.5 | 9 | .min_percent = 0.5 |
9 | }; | 10 | }; |
10 | 11 | ||
12 | static void hist_entry__add_cpumode_period(struct hist_entry *self, | ||
13 | unsigned int cpumode, u64 period) | ||
14 | { | ||
15 | switch (cpumode) { | ||
16 | case PERF_RECORD_MISC_KERNEL: | ||
17 | self->period_sys += period; | ||
18 | break; | ||
19 | case PERF_RECORD_MISC_USER: | ||
20 | self->period_us += period; | ||
21 | break; | ||
22 | case PERF_RECORD_MISC_GUEST_KERNEL: | ||
23 | self->period_guest_sys += period; | ||
24 | break; | ||
25 | case PERF_RECORD_MISC_GUEST_USER: | ||
26 | self->period_guest_us += period; | ||
27 | break; | ||
28 | default: | ||
29 | break; | ||
30 | } | ||
31 | } | ||
32 | |||
11 | /* | 33 | /* |
12 | * histogram, sorted on item, collects counts | 34 | * histogram, sorted on item, collects periods |
13 | */ | 35 | */ |
14 | 36 | ||
15 | struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | 37 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
16 | struct addr_location *al, | 38 | { |
17 | struct symbol *sym_parent, | 39 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0; |
18 | u64 count, bool *hit) | 40 | struct hist_entry *self = malloc(sizeof(*self) + callchain_size); |
41 | |||
42 | if (self != NULL) { | ||
43 | *self = *template; | ||
44 | self->nr_events = 1; | ||
45 | if (symbol_conf.use_callchain) | ||
46 | callchain_init(self->callchain); | ||
47 | } | ||
48 | |||
49 | return self; | ||
50 | } | ||
51 | |||
52 | static void hists__inc_nr_entries(struct hists *self, struct hist_entry *entry) | ||
19 | { | 53 | { |
20 | struct rb_node **p = &hists->rb_node; | 54 | if (entry->ms.sym && self->max_sym_namelen < entry->ms.sym->namelen) |
55 | self->max_sym_namelen = entry->ms.sym->namelen; | ||
56 | ++self->nr_entries; | ||
57 | } | ||
58 | |||
59 | struct hist_entry *__hists__add_entry(struct hists *self, | ||
60 | struct addr_location *al, | ||
61 | struct symbol *sym_parent, u64 period) | ||
62 | { | ||
63 | struct rb_node **p = &self->entries.rb_node; | ||
21 | struct rb_node *parent = NULL; | 64 | struct rb_node *parent = NULL; |
22 | struct hist_entry *he; | 65 | struct hist_entry *he; |
23 | struct hist_entry entry = { | 66 | struct hist_entry entry = { |
24 | .thread = al->thread, | 67 | .thread = al->thread, |
25 | .map = al->map, | 68 | .ms = { |
26 | .sym = al->sym, | 69 | .map = al->map, |
70 | .sym = al->sym, | ||
71 | }, | ||
27 | .ip = al->addr, | 72 | .ip = al->addr, |
28 | .level = al->level, | 73 | .level = al->level, |
29 | .count = count, | 74 | .period = period, |
30 | .parent = sym_parent, | 75 | .parent = sym_parent, |
31 | }; | 76 | }; |
32 | int cmp; | 77 | int cmp; |
@@ -38,8 +83,9 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | |||
38 | cmp = hist_entry__cmp(&entry, he); | 83 | cmp = hist_entry__cmp(&entry, he); |
39 | 84 | ||
40 | if (!cmp) { | 85 | if (!cmp) { |
41 | *hit = true; | 86 | he->period += period; |
42 | return he; | 87 | ++he->nr_events; |
88 | goto out; | ||
43 | } | 89 | } |
44 | 90 | ||
45 | if (cmp < 0) | 91 | if (cmp < 0) |
@@ -48,13 +94,14 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | |||
48 | p = &(*p)->rb_right; | 94 | p = &(*p)->rb_right; |
49 | } | 95 | } |
50 | 96 | ||
51 | he = malloc(sizeof(*he)); | 97 | he = hist_entry__new(&entry); |
52 | if (!he) | 98 | if (!he) |
53 | return NULL; | 99 | return NULL; |
54 | *he = entry; | ||
55 | rb_link_node(&he->rb_node, parent, p); | 100 | rb_link_node(&he->rb_node, parent, p); |
56 | rb_insert_color(&he->rb_node, hists); | 101 | rb_insert_color(&he->rb_node, &self->entries); |
57 | *hit = false; | 102 | hists__inc_nr_entries(self, he); |
103 | out: | ||
104 | hist_entry__add_cpumode_period(he, al->cpumode, period); | ||
58 | return he; | 105 | return he; |
59 | } | 106 | } |
60 | 107 | ||
@@ -65,7 +112,7 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | |||
65 | int64_t cmp = 0; | 112 | int64_t cmp = 0; |
66 | 113 | ||
67 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 114 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
68 | cmp = se->cmp(left, right); | 115 | cmp = se->se_cmp(left, right); |
69 | if (cmp) | 116 | if (cmp) |
70 | break; | 117 | break; |
71 | } | 118 | } |
@@ -82,7 +129,7 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | |||
82 | list_for_each_entry(se, &hist_entry__sort_list, list) { | 129 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
83 | int64_t (*f)(struct hist_entry *, struct hist_entry *); | 130 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
84 | 131 | ||
85 | f = se->collapse ?: se->cmp; | 132 | f = se->se_collapse ?: se->se_cmp; |
86 | 133 | ||
87 | cmp = f(left, right); | 134 | cmp = f(left, right); |
88 | if (cmp) | 135 | if (cmp) |
@@ -101,7 +148,7 @@ void hist_entry__free(struct hist_entry *he) | |||
101 | * collapse the histogram | 148 | * collapse the histogram |
102 | */ | 149 | */ |
103 | 150 | ||
104 | static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | 151 | static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he) |
105 | { | 152 | { |
106 | struct rb_node **p = &root->rb_node; | 153 | struct rb_node **p = &root->rb_node; |
107 | struct rb_node *parent = NULL; | 154 | struct rb_node *parent = NULL; |
@@ -115,9 +162,9 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
115 | cmp = hist_entry__collapse(iter, he); | 162 | cmp = hist_entry__collapse(iter, he); |
116 | 163 | ||
117 | if (!cmp) { | 164 | if (!cmp) { |
118 | iter->count += he->count; | 165 | iter->period += he->period; |
119 | hist_entry__free(he); | 166 | hist_entry__free(he); |
120 | return; | 167 | return false; |
121 | } | 168 | } |
122 | 169 | ||
123 | if (cmp < 0) | 170 | if (cmp < 0) |
@@ -128,9 +175,10 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he) | |||
128 | 175 | ||
129 | rb_link_node(&he->rb_node, parent, p); | 176 | rb_link_node(&he->rb_node, parent, p); |
130 | rb_insert_color(&he->rb_node, root); | 177 | rb_insert_color(&he->rb_node, root); |
178 | return true; | ||
131 | } | 179 | } |
132 | 180 | ||
133 | void perf_session__collapse_resort(struct rb_root *hists) | 181 | void hists__collapse_resort(struct hists *self) |
134 | { | 182 | { |
135 | struct rb_root tmp; | 183 | struct rb_root tmp; |
136 | struct rb_node *next; | 184 | struct rb_node *next; |
@@ -140,72 +188,77 @@ void perf_session__collapse_resort(struct rb_root *hists) | |||
140 | return; | 188 | return; |
141 | 189 | ||
142 | tmp = RB_ROOT; | 190 | tmp = RB_ROOT; |
143 | next = rb_first(hists); | 191 | next = rb_first(&self->entries); |
192 | self->nr_entries = 0; | ||
193 | self->max_sym_namelen = 0; | ||
144 | 194 | ||
145 | while (next) { | 195 | while (next) { |
146 | n = rb_entry(next, struct hist_entry, rb_node); | 196 | n = rb_entry(next, struct hist_entry, rb_node); |
147 | next = rb_next(&n->rb_node); | 197 | next = rb_next(&n->rb_node); |
148 | 198 | ||
149 | rb_erase(&n->rb_node, hists); | 199 | rb_erase(&n->rb_node, &self->entries); |
150 | collapse__insert_entry(&tmp, n); | 200 | if (collapse__insert_entry(&tmp, n)) |
201 | hists__inc_nr_entries(self, n); | ||
151 | } | 202 | } |
152 | 203 | ||
153 | *hists = tmp; | 204 | self->entries = tmp; |
154 | } | 205 | } |
155 | 206 | ||
156 | /* | 207 | /* |
157 | * reverse the map, sort on count. | 208 | * reverse the map, sort on period. |
158 | */ | 209 | */ |
159 | 210 | ||
160 | static void perf_session__insert_output_hist_entry(struct rb_root *root, | 211 | static void __hists__insert_output_entry(struct rb_root *entries, |
161 | struct hist_entry *he, | 212 | struct hist_entry *he, |
162 | u64 min_callchain_hits) | 213 | u64 min_callchain_hits) |
163 | { | 214 | { |
164 | struct rb_node **p = &root->rb_node; | 215 | struct rb_node **p = &entries->rb_node; |
165 | struct rb_node *parent = NULL; | 216 | struct rb_node *parent = NULL; |
166 | struct hist_entry *iter; | 217 | struct hist_entry *iter; |
167 | 218 | ||
168 | if (symbol_conf.use_callchain) | 219 | if (symbol_conf.use_callchain) |
169 | callchain_param.sort(&he->sorted_chain, &he->callchain, | 220 | callchain_param.sort(&he->sorted_chain, he->callchain, |
170 | min_callchain_hits, &callchain_param); | 221 | min_callchain_hits, &callchain_param); |
171 | 222 | ||
172 | while (*p != NULL) { | 223 | while (*p != NULL) { |
173 | parent = *p; | 224 | parent = *p; |
174 | iter = rb_entry(parent, struct hist_entry, rb_node); | 225 | iter = rb_entry(parent, struct hist_entry, rb_node); |
175 | 226 | ||
176 | if (he->count > iter->count) | 227 | if (he->period > iter->period) |
177 | p = &(*p)->rb_left; | 228 | p = &(*p)->rb_left; |
178 | else | 229 | else |
179 | p = &(*p)->rb_right; | 230 | p = &(*p)->rb_right; |
180 | } | 231 | } |
181 | 232 | ||
182 | rb_link_node(&he->rb_node, parent, p); | 233 | rb_link_node(&he->rb_node, parent, p); |
183 | rb_insert_color(&he->rb_node, root); | 234 | rb_insert_color(&he->rb_node, entries); |
184 | } | 235 | } |
185 | 236 | ||
186 | void perf_session__output_resort(struct rb_root *hists, u64 total_samples) | 237 | void hists__output_resort(struct hists *self) |
187 | { | 238 | { |
188 | struct rb_root tmp; | 239 | struct rb_root tmp; |
189 | struct rb_node *next; | 240 | struct rb_node *next; |
190 | struct hist_entry *n; | 241 | struct hist_entry *n; |
191 | u64 min_callchain_hits; | 242 | u64 min_callchain_hits; |
192 | 243 | ||
193 | min_callchain_hits = | 244 | min_callchain_hits = self->stats.total_period * (callchain_param.min_percent / 100); |
194 | total_samples * (callchain_param.min_percent / 100); | ||
195 | 245 | ||
196 | tmp = RB_ROOT; | 246 | tmp = RB_ROOT; |
197 | next = rb_first(hists); | 247 | next = rb_first(&self->entries); |
248 | |||
249 | self->nr_entries = 0; | ||
250 | self->max_sym_namelen = 0; | ||
198 | 251 | ||
199 | while (next) { | 252 | while (next) { |
200 | n = rb_entry(next, struct hist_entry, rb_node); | 253 | n = rb_entry(next, struct hist_entry, rb_node); |
201 | next = rb_next(&n->rb_node); | 254 | next = rb_next(&n->rb_node); |
202 | 255 | ||
203 | rb_erase(&n->rb_node, hists); | 256 | rb_erase(&n->rb_node, &self->entries); |
204 | perf_session__insert_output_hist_entry(&tmp, n, | 257 | __hists__insert_output_entry(&tmp, n, min_callchain_hits); |
205 | min_callchain_hits); | 258 | hists__inc_nr_entries(self, n); |
206 | } | 259 | } |
207 | 260 | ||
208 | *hists = tmp; | 261 | self->entries = tmp; |
209 | } | 262 | } |
210 | 263 | ||
211 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) | 264 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
@@ -237,7 +290,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, | |||
237 | } | 290 | } |
238 | 291 | ||
239 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | 292 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
240 | int depth, int depth_mask, int count, | 293 | int depth, int depth_mask, int period, |
241 | u64 total_samples, int hits, | 294 | u64 total_samples, int hits, |
242 | int left_margin) | 295 | int left_margin) |
243 | { | 296 | { |
@@ -250,7 +303,7 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | |||
250 | ret += fprintf(fp, "|"); | 303 | ret += fprintf(fp, "|"); |
251 | else | 304 | else |
252 | ret += fprintf(fp, " "); | 305 | ret += fprintf(fp, " "); |
253 | if (!count && i == depth - 1) { | 306 | if (!period && i == depth - 1) { |
254 | double percent; | 307 | double percent; |
255 | 308 | ||
256 | percent = hits * 100.0 / total_samples; | 309 | percent = hits * 100.0 / total_samples; |
@@ -258,8 +311,8 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, | |||
258 | } else | 311 | } else |
259 | ret += fprintf(fp, "%s", " "); | 312 | ret += fprintf(fp, "%s", " "); |
260 | } | 313 | } |
261 | if (chain->sym) | 314 | if (chain->ms.sym) |
262 | ret += fprintf(fp, "%s\n", chain->sym->name); | 315 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
263 | else | 316 | else |
264 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); | 317 | ret += fprintf(fp, "%p\n", (void *)(long)chain->ip); |
265 | 318 | ||
@@ -278,7 +331,7 @@ static void init_rem_hits(void) | |||
278 | } | 331 | } |
279 | 332 | ||
280 | strcpy(rem_sq_bracket->name, "[...]"); | 333 | strcpy(rem_sq_bracket->name, "[...]"); |
281 | rem_hits.sym = rem_sq_bracket; | 334 | rem_hits.ms.sym = rem_sq_bracket; |
282 | } | 335 | } |
283 | 336 | ||
284 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | 337 | static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, |
@@ -293,6 +346,7 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
293 | u64 remaining; | 346 | u64 remaining; |
294 | size_t ret = 0; | 347 | size_t ret = 0; |
295 | int i; | 348 | int i; |
349 | uint entries_printed = 0; | ||
296 | 350 | ||
297 | if (callchain_param.mode == CHAIN_GRAPH_REL) | 351 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
298 | new_total = self->children_hit; | 352 | new_total = self->children_hit; |
@@ -328,8 +382,6 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
328 | left_margin); | 382 | left_margin); |
329 | i = 0; | 383 | i = 0; |
330 | list_for_each_entry(chain, &child->val, list) { | 384 | list_for_each_entry(chain, &child->val, list) { |
331 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
332 | continue; | ||
333 | ret += ipchain__fprintf_graph(fp, chain, depth, | 385 | ret += ipchain__fprintf_graph(fp, chain, depth, |
334 | new_depth_mask, i++, | 386 | new_depth_mask, i++, |
335 | new_total, | 387 | new_total, |
@@ -341,6 +393,8 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
341 | new_depth_mask | (1 << depth), | 393 | new_depth_mask | (1 << depth), |
342 | left_margin); | 394 | left_margin); |
343 | node = next; | 395 | node = next; |
396 | if (++entries_printed == callchain_param.print_limit) | ||
397 | break; | ||
344 | } | 398 | } |
345 | 399 | ||
346 | if (callchain_param.mode == CHAIN_GRAPH_REL && | 400 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
@@ -366,11 +420,9 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
366 | bool printed = false; | 420 | bool printed = false; |
367 | int i = 0; | 421 | int i = 0; |
368 | int ret = 0; | 422 | int ret = 0; |
423 | u32 entries_printed = 0; | ||
369 | 424 | ||
370 | list_for_each_entry(chain, &self->val, list) { | 425 | list_for_each_entry(chain, &self->val, list) { |
371 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
372 | continue; | ||
373 | |||
374 | if (!i++ && sort__first_dimension == SORT_SYM) | 426 | if (!i++ && sort__first_dimension == SORT_SYM) |
375 | continue; | 427 | continue; |
376 | 428 | ||
@@ -385,10 +437,13 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self, | |||
385 | } else | 437 | } else |
386 | ret += callchain__fprintf_left_margin(fp, left_margin); | 438 | ret += callchain__fprintf_left_margin(fp, left_margin); |
387 | 439 | ||
388 | if (chain->sym) | 440 | if (chain->ms.sym) |
389 | ret += fprintf(fp, " %s\n", chain->sym->name); | 441 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
390 | else | 442 | else |
391 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); | 443 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
444 | |||
445 | if (++entries_printed == callchain_param.print_limit) | ||
446 | break; | ||
392 | } | 447 | } |
393 | 448 | ||
394 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); | 449 | ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin); |
@@ -411,8 +466,8 @@ static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self, | |||
411 | list_for_each_entry(chain, &self->val, list) { | 466 | list_for_each_entry(chain, &self->val, list) { |
412 | if (chain->ip >= PERF_CONTEXT_MAX) | 467 | if (chain->ip >= PERF_CONTEXT_MAX) |
413 | continue; | 468 | continue; |
414 | if (chain->sym) | 469 | if (chain->ms.sym) |
415 | ret += fprintf(fp, " %s\n", chain->sym->name); | 470 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
416 | else | 471 | else |
417 | ret += fprintf(fp, " %p\n", | 472 | ret += fprintf(fp, " %p\n", |
418 | (void *)(long)chain->ip); | 473 | (void *)(long)chain->ip); |
@@ -427,6 +482,7 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |||
427 | struct rb_node *rb_node; | 482 | struct rb_node *rb_node; |
428 | struct callchain_node *chain; | 483 | struct callchain_node *chain; |
429 | size_t ret = 0; | 484 | size_t ret = 0; |
485 | u32 entries_printed = 0; | ||
430 | 486 | ||
431 | rb_node = rb_first(&self->sorted_chain); | 487 | rb_node = rb_first(&self->sorted_chain); |
432 | while (rb_node) { | 488 | while (rb_node) { |
@@ -449,55 +505,88 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self, | |||
449 | break; | 505 | break; |
450 | } | 506 | } |
451 | ret += fprintf(fp, "\n"); | 507 | ret += fprintf(fp, "\n"); |
508 | if (++entries_printed == callchain_param.print_limit) | ||
509 | break; | ||
452 | rb_node = rb_next(rb_node); | 510 | rb_node = rb_next(rb_node); |
453 | } | 511 | } |
454 | 512 | ||
455 | return ret; | 513 | return ret; |
456 | } | 514 | } |
457 | 515 | ||
458 | static size_t hist_entry__fprintf(struct hist_entry *self, | 516 | int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size, |
459 | struct perf_session *pair_session, | 517 | struct hists *pair_hists, bool show_displacement, |
460 | bool show_displacement, | 518 | long displacement, bool color, u64 session_total) |
461 | long displacement, FILE *fp, | ||
462 | u64 session_total) | ||
463 | { | 519 | { |
464 | struct sort_entry *se; | 520 | struct sort_entry *se; |
465 | u64 count, total; | 521 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; |
466 | const char *sep = symbol_conf.field_sep; | 522 | const char *sep = symbol_conf.field_sep; |
467 | size_t ret; | 523 | int ret; |
468 | 524 | ||
469 | if (symbol_conf.exclude_other && !self->parent) | 525 | if (symbol_conf.exclude_other && !self->parent) |
470 | return 0; | 526 | return 0; |
471 | 527 | ||
472 | if (pair_session) { | 528 | if (pair_hists) { |
473 | count = self->pair ? self->pair->count : 0; | 529 | period = self->pair ? self->pair->period : 0; |
474 | total = pair_session->events_stats.total; | 530 | total = pair_hists->stats.total_period; |
531 | period_sys = self->pair ? self->pair->period_sys : 0; | ||
532 | period_us = self->pair ? self->pair->period_us : 0; | ||
533 | period_guest_sys = self->pair ? self->pair->period_guest_sys : 0; | ||
534 | period_guest_us = self->pair ? self->pair->period_guest_us : 0; | ||
475 | } else { | 535 | } else { |
476 | count = self->count; | 536 | period = self->period; |
477 | total = session_total; | 537 | total = session_total; |
538 | period_sys = self->period_sys; | ||
539 | period_us = self->period_us; | ||
540 | period_guest_sys = self->period_guest_sys; | ||
541 | period_guest_us = self->period_guest_us; | ||
478 | } | 542 | } |
479 | 543 | ||
480 | if (total) | 544 | if (total) { |
481 | ret = percent_color_fprintf(fp, sep ? "%.2f" : " %6.2f%%", | 545 | if (color) |
482 | (count * 100.0) / total); | 546 | ret = percent_color_snprintf(s, size, |
483 | else | 547 | sep ? "%.2f" : " %6.2f%%", |
484 | ret = fprintf(fp, sep ? "%lld" : "%12lld ", count); | 548 | (period * 100.0) / total); |
549 | else | ||
550 | ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%", | ||
551 | (period * 100.0) / total); | ||
552 | if (symbol_conf.show_cpu_utilization) { | ||
553 | ret += percent_color_snprintf(s + ret, size - ret, | ||
554 | sep ? "%.2f" : " %6.2f%%", | ||
555 | (period_sys * 100.0) / total); | ||
556 | ret += percent_color_snprintf(s + ret, size - ret, | ||
557 | sep ? "%.2f" : " %6.2f%%", | ||
558 | (period_us * 100.0) / total); | ||
559 | if (perf_guest) { | ||
560 | ret += percent_color_snprintf(s + ret, | ||
561 | size - ret, | ||
562 | sep ? "%.2f" : " %6.2f%%", | ||
563 | (period_guest_sys * 100.0) / | ||
564 | total); | ||
565 | ret += percent_color_snprintf(s + ret, | ||
566 | size - ret, | ||
567 | sep ? "%.2f" : " %6.2f%%", | ||
568 | (period_guest_us * 100.0) / | ||
569 | total); | ||
570 | } | ||
571 | } | ||
572 | } else | ||
573 | ret = snprintf(s, size, sep ? "%lld" : "%12lld ", period); | ||
485 | 574 | ||
486 | if (symbol_conf.show_nr_samples) { | 575 | if (symbol_conf.show_nr_samples) { |
487 | if (sep) | 576 | if (sep) |
488 | fprintf(fp, "%c%lld", *sep, count); | 577 | ret += snprintf(s + ret, size - ret, "%c%lld", *sep, period); |
489 | else | 578 | else |
490 | fprintf(fp, "%11lld", count); | 579 | ret += snprintf(s + ret, size - ret, "%11lld", period); |
491 | } | 580 | } |
492 | 581 | ||
493 | if (pair_session) { | 582 | if (pair_hists) { |
494 | char bf[32]; | 583 | char bf[32]; |
495 | double old_percent = 0, new_percent = 0, diff; | 584 | double old_percent = 0, new_percent = 0, diff; |
496 | 585 | ||
497 | if (total > 0) | 586 | if (total > 0) |
498 | old_percent = (count * 100.0) / total; | 587 | old_percent = (period * 100.0) / total; |
499 | if (session_total > 0) | 588 | if (session_total > 0) |
500 | new_percent = (self->count * 100.0) / session_total; | 589 | new_percent = (self->period * 100.0) / session_total; |
501 | 590 | ||
502 | diff = new_percent - old_percent; | 591 | diff = new_percent - old_percent; |
503 | 592 | ||
@@ -507,9 +596,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
507 | snprintf(bf, sizeof(bf), " "); | 596 | snprintf(bf, sizeof(bf), " "); |
508 | 597 | ||
509 | if (sep) | 598 | if (sep) |
510 | ret += fprintf(fp, "%c%s", *sep, bf); | 599 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
511 | else | 600 | else |
512 | ret += fprintf(fp, "%11.11s", bf); | 601 | ret += snprintf(s + ret, size - ret, "%11.11s", bf); |
513 | 602 | ||
514 | if (show_displacement) { | 603 | if (show_displacement) { |
515 | if (displacement) | 604 | if (displacement) |
@@ -518,9 +607,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
518 | snprintf(bf, sizeof(bf), " "); | 607 | snprintf(bf, sizeof(bf), " "); |
519 | 608 | ||
520 | if (sep) | 609 | if (sep) |
521 | fprintf(fp, "%c%s", *sep, bf); | 610 | ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf); |
522 | else | 611 | else |
523 | fprintf(fp, "%6.6s", bf); | 612 | ret += snprintf(s + ret, size - ret, "%6.6s", bf); |
524 | } | 613 | } |
525 | } | 614 | } |
526 | 615 | ||
@@ -528,33 +617,43 @@ static size_t hist_entry__fprintf(struct hist_entry *self, | |||
528 | if (se->elide) | 617 | if (se->elide) |
529 | continue; | 618 | continue; |
530 | 619 | ||
531 | fprintf(fp, "%s", sep ?: " "); | 620 | ret += snprintf(s + ret, size - ret, "%s", sep ?: " "); |
532 | ret += se->print(fp, self, se->width ? *se->width : 0); | 621 | ret += se->se_snprintf(self, s + ret, size - ret, |
622 | se->se_width ? *se->se_width : 0); | ||
533 | } | 623 | } |
534 | 624 | ||
535 | ret += fprintf(fp, "\n"); | 625 | return ret; |
626 | } | ||
536 | 627 | ||
537 | if (symbol_conf.use_callchain) { | 628 | int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists, |
538 | int left_margin = 0; | 629 | bool show_displacement, long displacement, FILE *fp, |
630 | u64 session_total) | ||
631 | { | ||
632 | char bf[512]; | ||
633 | hist_entry__snprintf(self, bf, sizeof(bf), pair_hists, | ||
634 | show_displacement, displacement, | ||
635 | true, session_total); | ||
636 | return fprintf(fp, "%s\n", bf); | ||
637 | } | ||
539 | 638 | ||
540 | if (sort__first_dimension == SORT_COMM) { | 639 | static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp, |
541 | se = list_first_entry(&hist_entry__sort_list, typeof(*se), | 640 | u64 session_total) |
542 | list); | 641 | { |
543 | left_margin = se->width ? *se->width : 0; | 642 | int left_margin = 0; |
544 | left_margin -= thread__comm_len(self->thread); | ||
545 | } | ||
546 | 643 | ||
547 | hist_entry_callchain__fprintf(fp, self, session_total, | 644 | if (sort__first_dimension == SORT_COMM) { |
548 | left_margin); | 645 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
646 | typeof(*se), list); | ||
647 | left_margin = se->se_width ? *se->se_width : 0; | ||
648 | left_margin -= thread__comm_len(self->thread); | ||
549 | } | 649 | } |
550 | 650 | ||
551 | return ret; | 651 | return hist_entry_callchain__fprintf(fp, self, session_total, |
652 | left_margin); | ||
552 | } | 653 | } |
553 | 654 | ||
554 | size_t perf_session__fprintf_hists(struct rb_root *hists, | 655 | size_t hists__fprintf(struct hists *self, struct hists *pair, |
555 | struct perf_session *pair, | 656 | bool show_displacement, FILE *fp) |
556 | bool show_displacement, FILE *fp, | ||
557 | u64 session_total) | ||
558 | { | 657 | { |
559 | struct sort_entry *se; | 658 | struct sort_entry *se; |
560 | struct rb_node *nd; | 659 | struct rb_node *nd; |
@@ -563,7 +662,7 @@ size_t perf_session__fprintf_hists(struct rb_root *hists, | |||
563 | long displacement = 0; | 662 | long displacement = 0; |
564 | unsigned int width; | 663 | unsigned int width; |
565 | const char *sep = symbol_conf.field_sep; | 664 | const char *sep = symbol_conf.field_sep; |
566 | char *col_width = symbol_conf.col_width_list_str; | 665 | const char *col_width = symbol_conf.col_width_list_str; |
567 | 666 | ||
568 | init_rem_hits(); | 667 | init_rem_hits(); |
569 | 668 | ||
@@ -576,6 +675,24 @@ size_t perf_session__fprintf_hists(struct rb_root *hists, | |||
576 | fputs(" Samples ", fp); | 675 | fputs(" Samples ", fp); |
577 | } | 676 | } |
578 | 677 | ||
678 | if (symbol_conf.show_cpu_utilization) { | ||
679 | if (sep) { | ||
680 | ret += fprintf(fp, "%csys", *sep); | ||
681 | ret += fprintf(fp, "%cus", *sep); | ||
682 | if (perf_guest) { | ||
683 | ret += fprintf(fp, "%cguest sys", *sep); | ||
684 | ret += fprintf(fp, "%cguest us", *sep); | ||
685 | } | ||
686 | } else { | ||
687 | ret += fprintf(fp, " sys "); | ||
688 | ret += fprintf(fp, " us "); | ||
689 | if (perf_guest) { | ||
690 | ret += fprintf(fp, " guest sys "); | ||
691 | ret += fprintf(fp, " guest us "); | ||
692 | } | ||
693 | } | ||
694 | } | ||
695 | |||
579 | if (pair) { | 696 | if (pair) { |
580 | if (sep) | 697 | if (sep) |
581 | ret += fprintf(fp, "%cDelta", *sep); | 698 | ret += fprintf(fp, "%cDelta", *sep); |
@@ -594,22 +711,22 @@ size_t perf_session__fprintf_hists(struct rb_root *hists, | |||
594 | if (se->elide) | 711 | if (se->elide) |
595 | continue; | 712 | continue; |
596 | if (sep) { | 713 | if (sep) { |
597 | fprintf(fp, "%c%s", *sep, se->header); | 714 | fprintf(fp, "%c%s", *sep, se->se_header); |
598 | continue; | 715 | continue; |
599 | } | 716 | } |
600 | width = strlen(se->header); | 717 | width = strlen(se->se_header); |
601 | if (se->width) { | 718 | if (se->se_width) { |
602 | if (symbol_conf.col_width_list_str) { | 719 | if (symbol_conf.col_width_list_str) { |
603 | if (col_width) { | 720 | if (col_width) { |
604 | *se->width = atoi(col_width); | 721 | *se->se_width = atoi(col_width); |
605 | col_width = strchr(col_width, ','); | 722 | col_width = strchr(col_width, ','); |
606 | if (col_width) | 723 | if (col_width) |
607 | ++col_width; | 724 | ++col_width; |
608 | } | 725 | } |
609 | } | 726 | } |
610 | width = *se->width = max(*se->width, width); | 727 | width = *se->se_width = max(*se->se_width, width); |
611 | } | 728 | } |
612 | fprintf(fp, " %*s", width, se->header); | 729 | fprintf(fp, " %*s", width, se->se_header); |
613 | } | 730 | } |
614 | fprintf(fp, "\n"); | 731 | fprintf(fp, "\n"); |
615 | 732 | ||
@@ -631,10 +748,10 @@ size_t perf_session__fprintf_hists(struct rb_root *hists, | |||
631 | continue; | 748 | continue; |
632 | 749 | ||
633 | fprintf(fp, " "); | 750 | fprintf(fp, " "); |
634 | if (se->width) | 751 | if (se->se_width) |
635 | width = *se->width; | 752 | width = *se->se_width; |
636 | else | 753 | else |
637 | width = strlen(se->header); | 754 | width = strlen(se->se_header); |
638 | for (i = 0; i < width; i++) | 755 | for (i = 0; i < width; i++) |
639 | fprintf(fp, "."); | 756 | fprintf(fp, "."); |
640 | } | 757 | } |
@@ -642,7 +759,7 @@ size_t perf_session__fprintf_hists(struct rb_root *hists, | |||
642 | fprintf(fp, "\n#\n"); | 759 | fprintf(fp, "\n#\n"); |
643 | 760 | ||
644 | print_entries: | 761 | print_entries: |
645 | for (nd = rb_first(hists); nd; nd = rb_next(nd)) { | 762 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { |
646 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | 763 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
647 | 764 | ||
648 | if (show_displacement) { | 765 | if (show_displacement) { |
@@ -654,10 +771,14 @@ print_entries: | |||
654 | ++position; | 771 | ++position; |
655 | } | 772 | } |
656 | ret += hist_entry__fprintf(h, pair, show_displacement, | 773 | ret += hist_entry__fprintf(h, pair, show_displacement, |
657 | displacement, fp, session_total); | 774 | displacement, fp, self->stats.total_period); |
658 | if (h->map == NULL && verbose > 1) { | 775 | |
776 | if (symbol_conf.use_callchain) | ||
777 | ret += hist_entry__fprintf_callchain(h, fp, self->stats.total_period); | ||
778 | |||
779 | if (h->ms.map == NULL && verbose > 1) { | ||
659 | __map_groups__fprintf_maps(&h->thread->mg, | 780 | __map_groups__fprintf_maps(&h->thread->mg, |
660 | MAP__FUNCTION, fp); | 781 | MAP__FUNCTION, verbose, fp); |
661 | fprintf(fp, "%.10s end\n", graph_dotted_line); | 782 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
662 | } | 783 | } |
663 | } | 784 | } |
@@ -666,3 +787,271 @@ print_entries: | |||
666 | 787 | ||
667 | return ret; | 788 | return ret; |
668 | } | 789 | } |
790 | |||
791 | enum hist_filter { | ||
792 | HIST_FILTER__DSO, | ||
793 | HIST_FILTER__THREAD, | ||
794 | }; | ||
795 | |||
796 | void hists__filter_by_dso(struct hists *self, const struct dso *dso) | ||
797 | { | ||
798 | struct rb_node *nd; | ||
799 | |||
800 | self->nr_entries = self->stats.total_period = 0; | ||
801 | self->stats.nr_events[PERF_RECORD_SAMPLE] = 0; | ||
802 | self->max_sym_namelen = 0; | ||
803 | |||
804 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | ||
805 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
806 | |||
807 | if (symbol_conf.exclude_other && !h->parent) | ||
808 | continue; | ||
809 | |||
810 | if (dso != NULL && (h->ms.map == NULL || h->ms.map->dso != dso)) { | ||
811 | h->filtered |= (1 << HIST_FILTER__DSO); | ||
812 | continue; | ||
813 | } | ||
814 | |||
815 | h->filtered &= ~(1 << HIST_FILTER__DSO); | ||
816 | if (!h->filtered) { | ||
817 | ++self->nr_entries; | ||
818 | self->stats.total_period += h->period; | ||
819 | self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; | ||
820 | if (h->ms.sym && | ||
821 | self->max_sym_namelen < h->ms.sym->namelen) | ||
822 | self->max_sym_namelen = h->ms.sym->namelen; | ||
823 | } | ||
824 | } | ||
825 | } | ||
826 | |||
827 | void hists__filter_by_thread(struct hists *self, const struct thread *thread) | ||
828 | { | ||
829 | struct rb_node *nd; | ||
830 | |||
831 | self->nr_entries = self->stats.total_period = 0; | ||
832 | self->stats.nr_events[PERF_RECORD_SAMPLE] = 0; | ||
833 | self->max_sym_namelen = 0; | ||
834 | |||
835 | for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) { | ||
836 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
837 | |||
838 | if (thread != NULL && h->thread != thread) { | ||
839 | h->filtered |= (1 << HIST_FILTER__THREAD); | ||
840 | continue; | ||
841 | } | ||
842 | h->filtered &= ~(1 << HIST_FILTER__THREAD); | ||
843 | if (!h->filtered) { | ||
844 | ++self->nr_entries; | ||
845 | self->stats.total_period += h->period; | ||
846 | self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; | ||
847 | if (h->ms.sym && | ||
848 | self->max_sym_namelen < h->ms.sym->namelen) | ||
849 | self->max_sym_namelen = h->ms.sym->namelen; | ||
850 | } | ||
851 | } | ||
852 | } | ||
853 | |||
854 | static int symbol__alloc_hist(struct symbol *self) | ||
855 | { | ||
856 | struct sym_priv *priv = symbol__priv(self); | ||
857 | const int size = (sizeof(*priv->hist) + | ||
858 | (self->end - self->start) * sizeof(u64)); | ||
859 | |||
860 | priv->hist = zalloc(size); | ||
861 | return priv->hist == NULL ? -1 : 0; | ||
862 | } | ||
863 | |||
864 | int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip) | ||
865 | { | ||
866 | unsigned int sym_size, offset; | ||
867 | struct symbol *sym = self->ms.sym; | ||
868 | struct sym_priv *priv; | ||
869 | struct sym_hist *h; | ||
870 | |||
871 | if (!sym || !self->ms.map) | ||
872 | return 0; | ||
873 | |||
874 | priv = symbol__priv(sym); | ||
875 | if (priv->hist == NULL && symbol__alloc_hist(sym) < 0) | ||
876 | return -ENOMEM; | ||
877 | |||
878 | sym_size = sym->end - sym->start; | ||
879 | offset = ip - sym->start; | ||
880 | |||
881 | pr_debug3("%s: ip=%#Lx\n", __func__, self->ms.map->unmap_ip(self->ms.map, ip)); | ||
882 | |||
883 | if (offset >= sym_size) | ||
884 | return 0; | ||
885 | |||
886 | h = priv->hist; | ||
887 | h->sum++; | ||
888 | h->ip[offset]++; | ||
889 | |||
890 | pr_debug3("%#Lx %s: period++ [ip: %#Lx, %#Lx] => %Ld\n", self->ms.sym->start, | ||
891 | self->ms.sym->name, ip, ip - self->ms.sym->start, h->ip[offset]); | ||
892 | return 0; | ||
893 | } | ||
894 | |||
895 | static struct objdump_line *objdump_line__new(s64 offset, char *line) | ||
896 | { | ||
897 | struct objdump_line *self = malloc(sizeof(*self)); | ||
898 | |||
899 | if (self != NULL) { | ||
900 | self->offset = offset; | ||
901 | self->line = line; | ||
902 | } | ||
903 | |||
904 | return self; | ||
905 | } | ||
906 | |||
907 | void objdump_line__free(struct objdump_line *self) | ||
908 | { | ||
909 | free(self->line); | ||
910 | free(self); | ||
911 | } | ||
912 | |||
913 | static void objdump__add_line(struct list_head *head, struct objdump_line *line) | ||
914 | { | ||
915 | list_add_tail(&line->node, head); | ||
916 | } | ||
917 | |||
918 | struct objdump_line *objdump__get_next_ip_line(struct list_head *head, | ||
919 | struct objdump_line *pos) | ||
920 | { | ||
921 | list_for_each_entry_continue(pos, head, node) | ||
922 | if (pos->offset >= 0) | ||
923 | return pos; | ||
924 | |||
925 | return NULL; | ||
926 | } | ||
927 | |||
928 | static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file, | ||
929 | struct list_head *head) | ||
930 | { | ||
931 | struct symbol *sym = self->ms.sym; | ||
932 | struct objdump_line *objdump_line; | ||
933 | char *line = NULL, *tmp, *tmp2, *c; | ||
934 | size_t line_len; | ||
935 | s64 line_ip, offset = -1; | ||
936 | |||
937 | if (getline(&line, &line_len, file) < 0) | ||
938 | return -1; | ||
939 | |||
940 | if (!line) | ||
941 | return -1; | ||
942 | |||
943 | while (line_len != 0 && isspace(line[line_len - 1])) | ||
944 | line[--line_len] = '\0'; | ||
945 | |||
946 | c = strchr(line, '\n'); | ||
947 | if (c) | ||
948 | *c = 0; | ||
949 | |||
950 | line_ip = -1; | ||
951 | |||
952 | /* | ||
953 | * Strip leading spaces: | ||
954 | */ | ||
955 | tmp = line; | ||
956 | while (*tmp) { | ||
957 | if (*tmp != ' ') | ||
958 | break; | ||
959 | tmp++; | ||
960 | } | ||
961 | |||
962 | if (*tmp) { | ||
963 | /* | ||
964 | * Parse hexa addresses followed by ':' | ||
965 | */ | ||
966 | line_ip = strtoull(tmp, &tmp2, 16); | ||
967 | if (*tmp2 != ':') | ||
968 | line_ip = -1; | ||
969 | } | ||
970 | |||
971 | if (line_ip != -1) { | ||
972 | u64 start = map__rip_2objdump(self->ms.map, sym->start); | ||
973 | offset = line_ip - start; | ||
974 | } | ||
975 | |||
976 | objdump_line = objdump_line__new(offset, line); | ||
977 | if (objdump_line == NULL) { | ||
978 | free(line); | ||
979 | return -1; | ||
980 | } | ||
981 | objdump__add_line(head, objdump_line); | ||
982 | |||
983 | return 0; | ||
984 | } | ||
985 | |||
986 | int hist_entry__annotate(struct hist_entry *self, struct list_head *head) | ||
987 | { | ||
988 | struct symbol *sym = self->ms.sym; | ||
989 | struct map *map = self->ms.map; | ||
990 | struct dso *dso = map->dso; | ||
991 | const char *filename = dso->long_name; | ||
992 | char command[PATH_MAX * 2]; | ||
993 | FILE *file; | ||
994 | u64 len; | ||
995 | |||
996 | if (!filename) | ||
997 | return -1; | ||
998 | |||
999 | if (dso->origin == DSO__ORIG_KERNEL) { | ||
1000 | if (dso->annotate_warned) | ||
1001 | return 0; | ||
1002 | dso->annotate_warned = 1; | ||
1003 | pr_err("Can't annotate %s: No vmlinux file was found in the " | ||
1004 | "path:\n", sym->name); | ||
1005 | vmlinux_path__fprintf(stderr); | ||
1006 | return -1; | ||
1007 | } | ||
1008 | |||
1009 | pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__, | ||
1010 | filename, sym->name, map->unmap_ip(map, sym->start), | ||
1011 | map->unmap_ip(map, sym->end)); | ||
1012 | |||
1013 | len = sym->end - sym->start; | ||
1014 | |||
1015 | pr_debug("annotating [%p] %30s : [%p] %30s\n", | ||
1016 | dso, dso->long_name, sym, sym->name); | ||
1017 | |||
1018 | snprintf(command, sizeof(command), | ||
1019 | "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s|expand", | ||
1020 | map__rip_2objdump(map, sym->start), | ||
1021 | map__rip_2objdump(map, sym->end), | ||
1022 | filename, filename); | ||
1023 | |||
1024 | pr_debug("Executing: %s\n", command); | ||
1025 | |||
1026 | file = popen(command, "r"); | ||
1027 | if (!file) | ||
1028 | return -1; | ||
1029 | |||
1030 | while (!feof(file)) | ||
1031 | if (hist_entry__parse_objdump_line(self, file, head) < 0) | ||
1032 | break; | ||
1033 | |||
1034 | pclose(file); | ||
1035 | return 0; | ||
1036 | } | ||
1037 | |||
1038 | void hists__inc_nr_events(struct hists *self, u32 type) | ||
1039 | { | ||
1040 | ++self->stats.nr_events[0]; | ||
1041 | ++self->stats.nr_events[type]; | ||
1042 | } | ||
1043 | |||
1044 | size_t hists__fprintf_nr_events(struct hists *self, FILE *fp) | ||
1045 | { | ||
1046 | int i; | ||
1047 | size_t ret = 0; | ||
1048 | |||
1049 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { | ||
1050 | if (!event__name[i]) | ||
1051 | continue; | ||
1052 | ret += fprintf(fp, "%10s events: %10d\n", | ||
1053 | event__name[i], self->stats.nr_events[i]); | ||
1054 | } | ||
1055 | |||
1056 | return ret; | ||
1057 | } | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 16f360cce5bf..6f17dcd8412c 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -6,24 +6,104 @@ | |||
6 | 6 | ||
7 | extern struct callchain_param callchain_param; | 7 | extern struct callchain_param callchain_param; |
8 | 8 | ||
9 | struct perf_session; | ||
10 | struct hist_entry; | 9 | struct hist_entry; |
11 | struct addr_location; | 10 | struct addr_location; |
12 | struct symbol; | 11 | struct symbol; |
13 | struct rb_root; | 12 | struct rb_root; |
14 | 13 | ||
15 | struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, | 14 | struct objdump_line { |
16 | struct addr_location *al, | 15 | struct list_head node; |
17 | struct symbol *parent, | 16 | s64 offset; |
18 | u64 count, bool *hit); | 17 | char *line; |
18 | }; | ||
19 | |||
20 | void objdump_line__free(struct objdump_line *self); | ||
21 | struct objdump_line *objdump__get_next_ip_line(struct list_head *head, | ||
22 | struct objdump_line *pos); | ||
23 | |||
24 | struct sym_hist { | ||
25 | u64 sum; | ||
26 | u64 ip[0]; | ||
27 | }; | ||
28 | |||
29 | struct sym_ext { | ||
30 | struct rb_node node; | ||
31 | double percent; | ||
32 | char *path; | ||
33 | }; | ||
34 | |||
35 | struct sym_priv { | ||
36 | struct sym_hist *hist; | ||
37 | struct sym_ext *ext; | ||
38 | }; | ||
39 | |||
40 | /* | ||
41 | * The kernel collects the number of events it couldn't send in a stretch and | ||
42 | * when possible sends this number in a PERF_RECORD_LOST event. The number of | ||
43 | * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while | ||
44 | * total_lost tells exactly how many events the kernel in fact lost, i.e. it is | ||
45 | * the sum of all struct lost_event.lost fields reported. | ||
46 | * | ||
47 | * The total_period is needed because by default auto-freq is used, so | ||
48 | * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get | ||
49 | * the total number of low level events, it is necessary to to sum all struct | ||
50 | * sample_event.period and stash the result in total_period. | ||
51 | */ | ||
52 | struct events_stats { | ||
53 | u64 total_period; | ||
54 | u64 total_lost; | ||
55 | u32 nr_events[PERF_RECORD_HEADER_MAX]; | ||
56 | u32 nr_unknown_events; | ||
57 | }; | ||
58 | |||
59 | struct hists { | ||
60 | struct rb_node rb_node; | ||
61 | struct rb_root entries; | ||
62 | u64 nr_entries; | ||
63 | struct events_stats stats; | ||
64 | u64 config; | ||
65 | u64 event_stream; | ||
66 | u32 type; | ||
67 | u32 max_sym_namelen; | ||
68 | }; | ||
69 | |||
70 | struct hist_entry *__hists__add_entry(struct hists *self, | ||
71 | struct addr_location *al, | ||
72 | struct symbol *parent, u64 period); | ||
19 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); | 73 | extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *); |
20 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); | 74 | extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *); |
75 | int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists, | ||
76 | bool show_displacement, long displacement, FILE *fp, | ||
77 | u64 total); | ||
78 | int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size, | ||
79 | struct hists *pair_hists, bool show_displacement, | ||
80 | long displacement, bool color, u64 total); | ||
21 | void hist_entry__free(struct hist_entry *); | 81 | void hist_entry__free(struct hist_entry *); |
22 | 82 | ||
23 | void perf_session__output_resort(struct rb_root *hists, u64 total_samples); | 83 | void hists__output_resort(struct hists *self); |
24 | void perf_session__collapse_resort(struct rb_root *hists); | 84 | void hists__collapse_resort(struct hists *self); |
25 | size_t perf_session__fprintf_hists(struct rb_root *hists, | 85 | |
26 | struct perf_session *pair, | 86 | void hists__inc_nr_events(struct hists *self, u32 type); |
27 | bool show_displacement, FILE *fp, | 87 | size_t hists__fprintf_nr_events(struct hists *self, FILE *fp); |
28 | u64 session_total); | 88 | |
89 | size_t hists__fprintf(struct hists *self, struct hists *pair, | ||
90 | bool show_displacement, FILE *fp); | ||
91 | |||
92 | int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip); | ||
93 | int hist_entry__annotate(struct hist_entry *self, struct list_head *head); | ||
94 | |||
95 | void hists__filter_by_dso(struct hists *self, const struct dso *dso); | ||
96 | void hists__filter_by_thread(struct hists *self, const struct thread *thread); | ||
97 | |||
98 | #ifdef NO_NEWT_SUPPORT | ||
99 | static inline int hists__browse(struct hists *self __used, | ||
100 | const char *helpline __used, | ||
101 | const char *input_name __used) | ||
102 | { | ||
103 | return 0; | ||
104 | } | ||
105 | #else | ||
106 | int hists__browse(struct hists *self, const char *helpline, | ||
107 | const char *input_name); | ||
108 | #endif | ||
29 | #endif /* __PERF_HIST_H */ | 109 | #endif /* __PERF_HIST_H */ |
diff --git a/tools/perf/util/hweight.c b/tools/perf/util/hweight.c new file mode 100644 index 000000000000..5c1d0d099f0d --- /dev/null +++ b/tools/perf/util/hweight.c | |||
@@ -0,0 +1,31 @@ | |||
1 | #include <linux/bitops.h> | ||
2 | |||
3 | /** | ||
4 | * hweightN - returns the hamming weight of a N-bit word | ||
5 | * @x: the word to weigh | ||
6 | * | ||
7 | * The Hamming Weight of a number is the total number of bits set in it. | ||
8 | */ | ||
9 | |||
10 | unsigned int hweight32(unsigned int w) | ||
11 | { | ||
12 | unsigned int res = w - ((w >> 1) & 0x55555555); | ||
13 | res = (res & 0x33333333) + ((res >> 2) & 0x33333333); | ||
14 | res = (res + (res >> 4)) & 0x0F0F0F0F; | ||
15 | res = res + (res >> 8); | ||
16 | return (res + (res >> 16)) & 0x000000FF; | ||
17 | } | ||
18 | |||
19 | unsigned long hweight64(__u64 w) | ||
20 | { | ||
21 | #if BITS_PER_LONG == 32 | ||
22 | return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w); | ||
23 | #elif BITS_PER_LONG == 64 | ||
24 | __u64 res = w - ((w >> 1) & 0x5555555555555555ul); | ||
25 | res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul); | ||
26 | res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful; | ||
27 | res = res + (res >> 8); | ||
28 | res = res + (res >> 16); | ||
29 | return (res + (res >> 32)) & 0x00000000000000FFul; | ||
30 | #endif | ||
31 | } | ||
diff --git a/tools/perf/util/include/asm/bitops.h b/tools/perf/util/include/asm/bitops.h deleted file mode 100644 index 58e9817ffae0..000000000000 --- a/tools/perf/util/include/asm/bitops.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef _PERF_ASM_BITOPS_H_ | ||
2 | #define _PERF_ASM_BITOPS_H_ | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | #include "../../types.h" | ||
6 | #include <linux/compiler.h> | ||
7 | |||
8 | /* CHECKME: Not sure both always match */ | ||
9 | #define BITS_PER_LONG __WORDSIZE | ||
10 | |||
11 | #include "../../../../include/asm-generic/bitops/__fls.h" | ||
12 | #include "../../../../include/asm-generic/bitops/fls.h" | ||
13 | #include "../../../../include/asm-generic/bitops/fls64.h" | ||
14 | #include "../../../../include/asm-generic/bitops/__ffs.h" | ||
15 | #include "../../../../include/asm-generic/bitops/ffz.h" | ||
16 | #include "../../../../include/asm-generic/bitops/hweight.h" | ||
17 | |||
18 | #endif | ||
diff --git a/tools/perf/util/include/asm/hweight.h b/tools/perf/util/include/asm/hweight.h new file mode 100644 index 000000000000..36cf26d434a5 --- /dev/null +++ b/tools/perf/util/include/asm/hweight.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef PERF_HWEIGHT_H | ||
2 | #define PERF_HWEIGHT_H | ||
3 | |||
4 | #include <linux/types.h> | ||
5 | unsigned int hweight32(unsigned int w); | ||
6 | unsigned long hweight64(__u64 w); | ||
7 | |||
8 | #endif /* PERF_HWEIGHT_H */ | ||
diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h new file mode 100644 index 000000000000..cf6727e99c44 --- /dev/null +++ b/tools/perf/util/include/dwarf-regs.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef _PERF_DWARF_REGS_H_ | ||
2 | #define _PERF_DWARF_REGS_H_ | ||
3 | |||
4 | #ifdef DWARF_SUPPORT | ||
5 | const char *get_arch_regstr(unsigned int n); | ||
6 | #endif | ||
7 | |||
8 | #endif | ||
diff --git a/tools/perf/util/include/linux/bitmap.h b/tools/perf/util/include/linux/bitmap.h index 94507639a8c4..eda4416efa0a 100644 --- a/tools/perf/util/include/linux/bitmap.h +++ b/tools/perf/util/include/linux/bitmap.h | |||
@@ -1,3 +1,35 @@ | |||
1 | #include "../../../../include/linux/bitmap.h" | 1 | #ifndef _PERF_BITOPS_H |
2 | #include "../../../../include/asm-generic/bitops/find.h" | 2 | #define _PERF_BITOPS_H |
3 | #include <linux/errno.h> | 3 | |
4 | #include <string.h> | ||
5 | #include <linux/bitops.h> | ||
6 | |||
7 | int __bitmap_weight(const unsigned long *bitmap, int bits); | ||
8 | |||
9 | #define BITMAP_LAST_WORD_MASK(nbits) \ | ||
10 | ( \ | ||
11 | ((nbits) % BITS_PER_LONG) ? \ | ||
12 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ | ||
13 | ) | ||
14 | |||
15 | #define small_const_nbits(nbits) \ | ||
16 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) | ||
17 | |||
18 | static inline void bitmap_zero(unsigned long *dst, int nbits) | ||
19 | { | ||
20 | if (small_const_nbits(nbits)) | ||
21 | *dst = 0UL; | ||
22 | else { | ||
23 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); | ||
24 | memset(dst, 0, len); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | static inline int bitmap_weight(const unsigned long *src, int nbits) | ||
29 | { | ||
30 | if (small_const_nbits(nbits)) | ||
31 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); | ||
32 | return __bitmap_weight(src, nbits); | ||
33 | } | ||
34 | |||
35 | #endif /* _PERF_BITOPS_H */ | ||
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h index 8d63116e9435..bb4ac2e05385 100644 --- a/tools/perf/util/include/linux/bitops.h +++ b/tools/perf/util/include/linux/bitops.h | |||
@@ -1,13 +1,12 @@ | |||
1 | #ifndef _PERF_LINUX_BITOPS_H_ | 1 | #ifndef _PERF_LINUX_BITOPS_H_ |
2 | #define _PERF_LINUX_BITOPS_H_ | 2 | #define _PERF_LINUX_BITOPS_H_ |
3 | 3 | ||
4 | #define __KERNEL__ | 4 | #include <linux/kernel.h> |
5 | #include <asm/hweight.h> | ||
5 | 6 | ||
6 | #define CONFIG_GENERIC_FIND_NEXT_BIT | 7 | #define BITS_PER_LONG __WORDSIZE |
7 | #define CONFIG_GENERIC_FIND_FIRST_BIT | 8 | #define BITS_PER_BYTE 8 |
8 | #include "../../../../include/linux/bitops.h" | 9 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
9 | |||
10 | #undef __KERNEL__ | ||
11 | 10 | ||
12 | static inline void set_bit(int nr, unsigned long *addr) | 11 | static inline void set_bit(int nr, unsigned long *addr) |
13 | { | 12 | { |
@@ -20,10 +19,9 @@ static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) | |||
20 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; | 19 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; |
21 | } | 20 | } |
22 | 21 | ||
23 | unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned | 22 | static inline unsigned long hweight_long(unsigned long w) |
24 | long size, unsigned long offset); | 23 | { |
25 | 24 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | |
26 | unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned | 25 | } |
27 | long size, unsigned long offset); | ||
28 | 26 | ||
29 | #endif | 27 | #endif |
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h index dfb0713ed47f..791f9dd27ebf 100644 --- a/tools/perf/util/include/linux/compiler.h +++ b/tools/perf/util/include/linux/compiler.h | |||
@@ -7,4 +7,6 @@ | |||
7 | #define __user | 7 | #define __user |
8 | #define __attribute_const__ | 8 | #define __attribute_const__ |
9 | 9 | ||
10 | #define __used __attribute__((__unused__)) | ||
11 | |||
10 | #endif | 12 | #endif |
diff --git a/tools/perf/util/include/linux/kernel.h b/tools/perf/util/include/linux/kernel.h index f2611655ab51..1eb804fd3fbf 100644 --- a/tools/perf/util/include/linux/kernel.h +++ b/tools/perf/util/include/linux/kernel.h | |||
@@ -28,6 +28,8 @@ | |||
28 | (type *)((char *)__mptr - offsetof(type, member)); }) | 28 | (type *)((char *)__mptr - offsetof(type, member)); }) |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | ||
32 | |||
31 | #ifndef max | 33 | #ifndef max |
32 | #define max(x, y) ({ \ | 34 | #define max(x, y) ({ \ |
33 | typeof(x) _max1 = (x); \ | 35 | typeof(x) _max1 = (x); \ |
@@ -85,16 +87,19 @@ simple_strtoul(const char *nptr, char **endptr, int base) | |||
85 | return strtoul(nptr, endptr, base); | 87 | return strtoul(nptr, endptr, base); |
86 | } | 88 | } |
87 | 89 | ||
90 | int eprintf(int level, | ||
91 | const char *fmt, ...) __attribute__((format(printf, 2, 3))); | ||
92 | |||
88 | #ifndef pr_fmt | 93 | #ifndef pr_fmt |
89 | #define pr_fmt(fmt) fmt | 94 | #define pr_fmt(fmt) fmt |
90 | #endif | 95 | #endif |
91 | 96 | ||
92 | #define pr_err(fmt, ...) \ | 97 | #define pr_err(fmt, ...) \ |
93 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 98 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
94 | #define pr_warning(fmt, ...) \ | 99 | #define pr_warning(fmt, ...) \ |
95 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 100 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
96 | #define pr_info(fmt, ...) \ | 101 | #define pr_info(fmt, ...) \ |
97 | do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0) | 102 | eprintf(0, pr_fmt(fmt), ##__VA_ARGS__) |
98 | #define pr_debug(fmt, ...) \ | 103 | #define pr_debug(fmt, ...) \ |
99 | eprintf(1, pr_fmt(fmt), ##__VA_ARGS__) | 104 | eprintf(1, pr_fmt(fmt), ##__VA_ARGS__) |
100 | #define pr_debugN(n, fmt, ...) \ | 105 | #define pr_debugN(n, fmt, ...) \ |
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index e509cd59c67d..e672f2fef65b 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -1,9 +1,11 @@ | |||
1 | #include "event.h" | ||
2 | #include "symbol.h" | 1 | #include "symbol.h" |
2 | #include <errno.h> | ||
3 | #include <limits.h> | ||
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #include <stdio.h> | 6 | #include <stdio.h> |
6 | #include "debug.h" | 7 | #include <unistd.h> |
8 | #include "map.h" | ||
7 | 9 | ||
8 | const char *map_type__name[MAP__NR_TYPES] = { | 10 | const char *map_type__name[MAP__NR_TYPES] = { |
9 | [MAP__FUNCTION] = "Functions", | 11 | [MAP__FUNCTION] = "Functions", |
@@ -36,15 +38,16 @@ void map__init(struct map *self, enum map_type type, | |||
36 | self->map_ip = map__map_ip; | 38 | self->map_ip = map__map_ip; |
37 | self->unmap_ip = map__unmap_ip; | 39 | self->unmap_ip = map__unmap_ip; |
38 | RB_CLEAR_NODE(&self->rb_node); | 40 | RB_CLEAR_NODE(&self->rb_node); |
41 | self->groups = NULL; | ||
39 | } | 42 | } |
40 | 43 | ||
41 | struct map *map__new(struct mmap_event *event, enum map_type type, | 44 | struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, |
42 | char *cwd, int cwdlen) | 45 | u64 pgoff, u32 pid, char *filename, |
46 | enum map_type type, char *cwd, int cwdlen) | ||
43 | { | 47 | { |
44 | struct map *self = malloc(sizeof(*self)); | 48 | struct map *self = malloc(sizeof(*self)); |
45 | 49 | ||
46 | if (self != NULL) { | 50 | if (self != NULL) { |
47 | const char *filename = event->filename; | ||
48 | char newfilename[PATH_MAX]; | 51 | char newfilename[PATH_MAX]; |
49 | struct dso *dso; | 52 | struct dso *dso; |
50 | int anon; | 53 | int anon; |
@@ -62,16 +65,15 @@ struct map *map__new(struct mmap_event *event, enum map_type type, | |||
62 | anon = is_anon_memory(filename); | 65 | anon = is_anon_memory(filename); |
63 | 66 | ||
64 | if (anon) { | 67 | if (anon) { |
65 | snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid); | 68 | snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid); |
66 | filename = newfilename; | 69 | filename = newfilename; |
67 | } | 70 | } |
68 | 71 | ||
69 | dso = dsos__findnew(filename); | 72 | dso = __dsos__findnew(dsos__list, filename); |
70 | if (dso == NULL) | 73 | if (dso == NULL) |
71 | goto out_delete; | 74 | goto out_delete; |
72 | 75 | ||
73 | map__init(self, type, event->start, event->start + event->len, | 76 | map__init(self, type, start, start + len, pgoff, dso); |
74 | event->pgoff, dso); | ||
75 | 77 | ||
76 | if (anon) { | 78 | if (anon) { |
77 | set_identity: | 79 | set_identity: |
@@ -235,3 +237,392 @@ u64 map__objdump_2ip(struct map *map, u64 addr) | |||
235 | map->unmap_ip(map, addr); /* RIP -> IP */ | 237 | map->unmap_ip(map, addr); /* RIP -> IP */ |
236 | return ip; | 238 | return ip; |
237 | } | 239 | } |
240 | |||
241 | void map_groups__init(struct map_groups *self) | ||
242 | { | ||
243 | int i; | ||
244 | for (i = 0; i < MAP__NR_TYPES; ++i) { | ||
245 | self->maps[i] = RB_ROOT; | ||
246 | INIT_LIST_HEAD(&self->removed_maps[i]); | ||
247 | } | ||
248 | self->machine = NULL; | ||
249 | } | ||
250 | |||
251 | void map_groups__flush(struct map_groups *self) | ||
252 | { | ||
253 | int type; | ||
254 | |||
255 | for (type = 0; type < MAP__NR_TYPES; type++) { | ||
256 | struct rb_root *root = &self->maps[type]; | ||
257 | struct rb_node *next = rb_first(root); | ||
258 | |||
259 | while (next) { | ||
260 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
261 | next = rb_next(&pos->rb_node); | ||
262 | rb_erase(&pos->rb_node, root); | ||
263 | /* | ||
264 | * We may have references to this map, for | ||
265 | * instance in some hist_entry instances, so | ||
266 | * just move them to a separate list. | ||
267 | */ | ||
268 | list_add_tail(&pos->node, &self->removed_maps[pos->type]); | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | |||
273 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
274 | enum map_type type, u64 addr, | ||
275 | struct map **mapp, | ||
276 | symbol_filter_t filter) | ||
277 | { | ||
278 | struct map *map = map_groups__find(self, type, addr); | ||
279 | |||
280 | if (map != NULL) { | ||
281 | if (mapp != NULL) | ||
282 | *mapp = map; | ||
283 | return map__find_symbol(map, map->map_ip(map, addr), filter); | ||
284 | } | ||
285 | |||
286 | return NULL; | ||
287 | } | ||
288 | |||
289 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, | ||
290 | enum map_type type, | ||
291 | const char *name, | ||
292 | struct map **mapp, | ||
293 | symbol_filter_t filter) | ||
294 | { | ||
295 | struct rb_node *nd; | ||
296 | |||
297 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
298 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
299 | struct symbol *sym = map__find_symbol_by_name(pos, name, filter); | ||
300 | |||
301 | if (sym == NULL) | ||
302 | continue; | ||
303 | if (mapp != NULL) | ||
304 | *mapp = pos; | ||
305 | return sym; | ||
306 | } | ||
307 | |||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
312 | enum map_type type, int verbose, FILE *fp) | ||
313 | { | ||
314 | size_t printed = fprintf(fp, "%s:\n", map_type__name[type]); | ||
315 | struct rb_node *nd; | ||
316 | |||
317 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
318 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
319 | printed += fprintf(fp, "Map:"); | ||
320 | printed += map__fprintf(pos, fp); | ||
321 | if (verbose > 2) { | ||
322 | printed += dso__fprintf(pos->dso, type, fp); | ||
323 | printed += fprintf(fp, "--\n"); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | return printed; | ||
328 | } | ||
329 | |||
330 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp) | ||
331 | { | ||
332 | size_t printed = 0, i; | ||
333 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
334 | printed += __map_groups__fprintf_maps(self, i, verbose, fp); | ||
335 | return printed; | ||
336 | } | ||
337 | |||
338 | static size_t __map_groups__fprintf_removed_maps(struct map_groups *self, | ||
339 | enum map_type type, | ||
340 | int verbose, FILE *fp) | ||
341 | { | ||
342 | struct map *pos; | ||
343 | size_t printed = 0; | ||
344 | |||
345 | list_for_each_entry(pos, &self->removed_maps[type], node) { | ||
346 | printed += fprintf(fp, "Map:"); | ||
347 | printed += map__fprintf(pos, fp); | ||
348 | if (verbose > 1) { | ||
349 | printed += dso__fprintf(pos->dso, type, fp); | ||
350 | printed += fprintf(fp, "--\n"); | ||
351 | } | ||
352 | } | ||
353 | return printed; | ||
354 | } | ||
355 | |||
356 | static size_t map_groups__fprintf_removed_maps(struct map_groups *self, | ||
357 | int verbose, FILE *fp) | ||
358 | { | ||
359 | size_t printed = 0, i; | ||
360 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
361 | printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp); | ||
362 | return printed; | ||
363 | } | ||
364 | |||
365 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp) | ||
366 | { | ||
367 | size_t printed = map_groups__fprintf_maps(self, verbose, fp); | ||
368 | printed += fprintf(fp, "Removed maps:\n"); | ||
369 | return printed + map_groups__fprintf_removed_maps(self, verbose, fp); | ||
370 | } | ||
371 | |||
372 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | ||
373 | int verbose, FILE *fp) | ||
374 | { | ||
375 | struct rb_root *root = &self->maps[map->type]; | ||
376 | struct rb_node *next = rb_first(root); | ||
377 | |||
378 | while (next) { | ||
379 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
380 | next = rb_next(&pos->rb_node); | ||
381 | |||
382 | if (!map__overlap(pos, map)) | ||
383 | continue; | ||
384 | |||
385 | if (verbose >= 2) { | ||
386 | fputs("overlapping maps:\n", fp); | ||
387 | map__fprintf(map, fp); | ||
388 | map__fprintf(pos, fp); | ||
389 | } | ||
390 | |||
391 | rb_erase(&pos->rb_node, root); | ||
392 | /* | ||
393 | * We may have references to this map, for instance in some | ||
394 | * hist_entry instances, so just move them to a separate | ||
395 | * list. | ||
396 | */ | ||
397 | list_add_tail(&pos->node, &self->removed_maps[map->type]); | ||
398 | /* | ||
399 | * Now check if we need to create new maps for areas not | ||
400 | * overlapped by the new map: | ||
401 | */ | ||
402 | if (map->start > pos->start) { | ||
403 | struct map *before = map__clone(pos); | ||
404 | |||
405 | if (before == NULL) | ||
406 | return -ENOMEM; | ||
407 | |||
408 | before->end = map->start - 1; | ||
409 | map_groups__insert(self, before); | ||
410 | if (verbose >= 2) | ||
411 | map__fprintf(before, fp); | ||
412 | } | ||
413 | |||
414 | if (map->end < pos->end) { | ||
415 | struct map *after = map__clone(pos); | ||
416 | |||
417 | if (after == NULL) | ||
418 | return -ENOMEM; | ||
419 | |||
420 | after->start = map->end + 1; | ||
421 | map_groups__insert(self, after); | ||
422 | if (verbose >= 2) | ||
423 | map__fprintf(after, fp); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | /* | ||
431 | * XXX This should not really _copy_ te maps, but refcount them. | ||
432 | */ | ||
433 | int map_groups__clone(struct map_groups *self, | ||
434 | struct map_groups *parent, enum map_type type) | ||
435 | { | ||
436 | struct rb_node *nd; | ||
437 | for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) { | ||
438 | struct map *map = rb_entry(nd, struct map, rb_node); | ||
439 | struct map *new = map__clone(map); | ||
440 | if (new == NULL) | ||
441 | return -ENOMEM; | ||
442 | map_groups__insert(self, new); | ||
443 | } | ||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | ||
448 | { | ||
449 | return ip + (s64)map->pgoff; | ||
450 | } | ||
451 | |||
452 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
453 | { | ||
454 | return ip - (s64)map->pgoff; | ||
455 | } | ||
456 | |||
457 | void map__reloc_vmlinux(struct map *self) | ||
458 | { | ||
459 | struct kmap *kmap = map__kmap(self); | ||
460 | s64 reloc; | ||
461 | |||
462 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
463 | return; | ||
464 | |||
465 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
466 | kmap->ref_reloc_sym->addr); | ||
467 | |||
468 | if (!reloc) | ||
469 | return; | ||
470 | |||
471 | self->map_ip = map__reloc_map_ip; | ||
472 | self->unmap_ip = map__reloc_unmap_ip; | ||
473 | self->pgoff = reloc; | ||
474 | } | ||
475 | |||
476 | void maps__insert(struct rb_root *maps, struct map *map) | ||
477 | { | ||
478 | struct rb_node **p = &maps->rb_node; | ||
479 | struct rb_node *parent = NULL; | ||
480 | const u64 ip = map->start; | ||
481 | struct map *m; | ||
482 | |||
483 | while (*p != NULL) { | ||
484 | parent = *p; | ||
485 | m = rb_entry(parent, struct map, rb_node); | ||
486 | if (ip < m->start) | ||
487 | p = &(*p)->rb_left; | ||
488 | else | ||
489 | p = &(*p)->rb_right; | ||
490 | } | ||
491 | |||
492 | rb_link_node(&map->rb_node, parent, p); | ||
493 | rb_insert_color(&map->rb_node, maps); | ||
494 | } | ||
495 | |||
496 | struct map *maps__find(struct rb_root *maps, u64 ip) | ||
497 | { | ||
498 | struct rb_node **p = &maps->rb_node; | ||
499 | struct rb_node *parent = NULL; | ||
500 | struct map *m; | ||
501 | |||
502 | while (*p != NULL) { | ||
503 | parent = *p; | ||
504 | m = rb_entry(parent, struct map, rb_node); | ||
505 | if (ip < m->start) | ||
506 | p = &(*p)->rb_left; | ||
507 | else if (ip > m->end) | ||
508 | p = &(*p)->rb_right; | ||
509 | else | ||
510 | return m; | ||
511 | } | ||
512 | |||
513 | return NULL; | ||
514 | } | ||
515 | |||
516 | int machine__init(struct machine *self, const char *root_dir, pid_t pid) | ||
517 | { | ||
518 | map_groups__init(&self->kmaps); | ||
519 | RB_CLEAR_NODE(&self->rb_node); | ||
520 | INIT_LIST_HEAD(&self->user_dsos); | ||
521 | INIT_LIST_HEAD(&self->kernel_dsos); | ||
522 | |||
523 | self->kmaps.machine = self; | ||
524 | self->pid = pid; | ||
525 | self->root_dir = strdup(root_dir); | ||
526 | return self->root_dir == NULL ? -ENOMEM : 0; | ||
527 | } | ||
528 | |||
529 | struct machine *machines__add(struct rb_root *self, pid_t pid, | ||
530 | const char *root_dir) | ||
531 | { | ||
532 | struct rb_node **p = &self->rb_node; | ||
533 | struct rb_node *parent = NULL; | ||
534 | struct machine *pos, *machine = malloc(sizeof(*machine)); | ||
535 | |||
536 | if (!machine) | ||
537 | return NULL; | ||
538 | |||
539 | if (machine__init(machine, root_dir, pid) != 0) { | ||
540 | free(machine); | ||
541 | return NULL; | ||
542 | } | ||
543 | |||
544 | while (*p != NULL) { | ||
545 | parent = *p; | ||
546 | pos = rb_entry(parent, struct machine, rb_node); | ||
547 | if (pid < pos->pid) | ||
548 | p = &(*p)->rb_left; | ||
549 | else | ||
550 | p = &(*p)->rb_right; | ||
551 | } | ||
552 | |||
553 | rb_link_node(&machine->rb_node, parent, p); | ||
554 | rb_insert_color(&machine->rb_node, self); | ||
555 | |||
556 | return machine; | ||
557 | } | ||
558 | |||
559 | struct machine *machines__find(struct rb_root *self, pid_t pid) | ||
560 | { | ||
561 | struct rb_node **p = &self->rb_node; | ||
562 | struct rb_node *parent = NULL; | ||
563 | struct machine *machine; | ||
564 | struct machine *default_machine = NULL; | ||
565 | |||
566 | while (*p != NULL) { | ||
567 | parent = *p; | ||
568 | machine = rb_entry(parent, struct machine, rb_node); | ||
569 | if (pid < machine->pid) | ||
570 | p = &(*p)->rb_left; | ||
571 | else if (pid > machine->pid) | ||
572 | p = &(*p)->rb_right; | ||
573 | else | ||
574 | return machine; | ||
575 | if (!machine->pid) | ||
576 | default_machine = machine; | ||
577 | } | ||
578 | |||
579 | return default_machine; | ||
580 | } | ||
581 | |||
582 | struct machine *machines__findnew(struct rb_root *self, pid_t pid) | ||
583 | { | ||
584 | char path[PATH_MAX]; | ||
585 | const char *root_dir; | ||
586 | struct machine *machine = machines__find(self, pid); | ||
587 | |||
588 | if (!machine || machine->pid != pid) { | ||
589 | if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) | ||
590 | root_dir = ""; | ||
591 | else { | ||
592 | if (!symbol_conf.guestmount) | ||
593 | goto out; | ||
594 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); | ||
595 | if (access(path, R_OK)) { | ||
596 | pr_err("Can't access file %s\n", path); | ||
597 | goto out; | ||
598 | } | ||
599 | root_dir = path; | ||
600 | } | ||
601 | machine = machines__add(self, pid, root_dir); | ||
602 | } | ||
603 | |||
604 | out: | ||
605 | return machine; | ||
606 | } | ||
607 | |||
608 | void machines__process(struct rb_root *self, machine__process_t process, void *data) | ||
609 | { | ||
610 | struct rb_node *nd; | ||
611 | |||
612 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { | ||
613 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | ||
614 | process(pos, data); | ||
615 | } | ||
616 | } | ||
617 | |||
618 | char *machine__mmap_name(struct machine *self, char *bf, size_t size) | ||
619 | { | ||
620 | if (machine__is_host(self)) | ||
621 | snprintf(bf, size, "[%s]", "kernel.kallsyms"); | ||
622 | else if (machine__is_default_guest(self)) | ||
623 | snprintf(bf, size, "[%s]", "guest.kernel.kallsyms"); | ||
624 | else | ||
625 | snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms", self->pid); | ||
626 | |||
627 | return bf; | ||
628 | } | ||
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index b756368076c6..f39134512829 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -4,7 +4,9 @@ | |||
4 | #include <linux/compiler.h> | 4 | #include <linux/compiler.h> |
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rbtree.h> | 6 | #include <linux/rbtree.h> |
7 | #include <linux/types.h> | 7 | #include <stdio.h> |
8 | #include <stdbool.h> | ||
9 | #include "types.h" | ||
8 | 10 | ||
9 | enum map_type { | 11 | enum map_type { |
10 | MAP__FUNCTION = 0, | 12 | MAP__FUNCTION = 0, |
@@ -18,6 +20,7 @@ extern const char *map_type__name[MAP__NR_TYPES]; | |||
18 | struct dso; | 20 | struct dso; |
19 | struct ref_reloc_sym; | 21 | struct ref_reloc_sym; |
20 | struct map_groups; | 22 | struct map_groups; |
23 | struct machine; | ||
21 | 24 | ||
22 | struct map { | 25 | struct map { |
23 | union { | 26 | union { |
@@ -27,6 +30,7 @@ struct map { | |||
27 | u64 start; | 30 | u64 start; |
28 | u64 end; | 31 | u64 end; |
29 | enum map_type type; | 32 | enum map_type type; |
33 | u32 priv; | ||
30 | u64 pgoff; | 34 | u64 pgoff; |
31 | 35 | ||
32 | /* ip -> dso rip */ | 36 | /* ip -> dso rip */ |
@@ -35,6 +39,7 @@ struct map { | |||
35 | u64 (*unmap_ip)(struct map *, u64); | 39 | u64 (*unmap_ip)(struct map *, u64); |
36 | 40 | ||
37 | struct dso *dso; | 41 | struct dso *dso; |
42 | struct map_groups *groups; | ||
38 | }; | 43 | }; |
39 | 44 | ||
40 | struct kmap { | 45 | struct kmap { |
@@ -42,6 +47,32 @@ struct kmap { | |||
42 | struct map_groups *kmaps; | 47 | struct map_groups *kmaps; |
43 | }; | 48 | }; |
44 | 49 | ||
50 | struct map_groups { | ||
51 | struct rb_root maps[MAP__NR_TYPES]; | ||
52 | struct list_head removed_maps[MAP__NR_TYPES]; | ||
53 | struct machine *machine; | ||
54 | }; | ||
55 | |||
56 | /* Native host kernel uses -1 as pid index in machine */ | ||
57 | #define HOST_KERNEL_ID (-1) | ||
58 | #define DEFAULT_GUEST_KERNEL_ID (0) | ||
59 | |||
60 | struct machine { | ||
61 | struct rb_node rb_node; | ||
62 | pid_t pid; | ||
63 | char *root_dir; | ||
64 | struct list_head user_dsos; | ||
65 | struct list_head kernel_dsos; | ||
66 | struct map_groups kmaps; | ||
67 | struct map *vmlinux_maps[MAP__NR_TYPES]; | ||
68 | }; | ||
69 | |||
70 | static inline | ||
71 | struct map *machine__kernel_map(struct machine *self, enum map_type type) | ||
72 | { | ||
73 | return self->vmlinux_maps[type]; | ||
74 | } | ||
75 | |||
45 | static inline struct kmap *map__kmap(struct map *self) | 76 | static inline struct kmap *map__kmap(struct map *self) |
46 | { | 77 | { |
47 | return (struct kmap *)(self + 1); | 78 | return (struct kmap *)(self + 1); |
@@ -68,14 +99,14 @@ u64 map__rip_2objdump(struct map *map, u64 rip); | |||
68 | u64 map__objdump_2ip(struct map *map, u64 addr); | 99 | u64 map__objdump_2ip(struct map *map, u64 addr); |
69 | 100 | ||
70 | struct symbol; | 101 | struct symbol; |
71 | struct mmap_event; | ||
72 | 102 | ||
73 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); | 103 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
74 | 104 | ||
75 | void map__init(struct map *self, enum map_type type, | 105 | void map__init(struct map *self, enum map_type type, |
76 | u64 start, u64 end, u64 pgoff, struct dso *dso); | 106 | u64 start, u64 end, u64 pgoff, struct dso *dso); |
77 | struct map *map__new(struct mmap_event *event, enum map_type, | 107 | struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, |
78 | char *cwd, int cwdlen); | 108 | u64 pgoff, u32 pid, char *filename, |
109 | enum map_type type, char *cwd, int cwdlen); | ||
79 | void map__delete(struct map *self); | 110 | void map__delete(struct map *self); |
80 | struct map *map__clone(struct map *self); | 111 | struct map *map__clone(struct map *self); |
81 | int map__overlap(struct map *l, struct map *r); | 112 | int map__overlap(struct map *l, struct map *r); |
@@ -91,4 +122,96 @@ void map__fixup_end(struct map *self); | |||
91 | 122 | ||
92 | void map__reloc_vmlinux(struct map *self); | 123 | void map__reloc_vmlinux(struct map *self); |
93 | 124 | ||
125 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
126 | enum map_type type, int verbose, FILE *fp); | ||
127 | void maps__insert(struct rb_root *maps, struct map *map); | ||
128 | struct map *maps__find(struct rb_root *maps, u64 addr); | ||
129 | void map_groups__init(struct map_groups *self); | ||
130 | int map_groups__clone(struct map_groups *self, | ||
131 | struct map_groups *parent, enum map_type type); | ||
132 | size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); | ||
133 | size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); | ||
134 | |||
135 | typedef void (*machine__process_t)(struct machine *self, void *data); | ||
136 | |||
137 | void machines__process(struct rb_root *self, machine__process_t process, void *data); | ||
138 | struct machine *machines__add(struct rb_root *self, pid_t pid, | ||
139 | const char *root_dir); | ||
140 | struct machine *machines__find_host(struct rb_root *self); | ||
141 | struct machine *machines__find(struct rb_root *self, pid_t pid); | ||
142 | struct machine *machines__findnew(struct rb_root *self, pid_t pid); | ||
143 | char *machine__mmap_name(struct machine *self, char *bf, size_t size); | ||
144 | int machine__init(struct machine *self, const char *root_dir, pid_t pid); | ||
145 | |||
146 | /* | ||
147 | * Default guest kernel is defined by parameter --guestkallsyms | ||
148 | * and --guestmodules | ||
149 | */ | ||
150 | static inline bool machine__is_default_guest(struct machine *self) | ||
151 | { | ||
152 | return self ? self->pid == DEFAULT_GUEST_KERNEL_ID : false; | ||
153 | } | ||
154 | |||
155 | static inline bool machine__is_host(struct machine *self) | ||
156 | { | ||
157 | return self ? self->pid == HOST_KERNEL_ID : false; | ||
158 | } | ||
159 | |||
160 | static inline void map_groups__insert(struct map_groups *self, struct map *map) | ||
161 | { | ||
162 | maps__insert(&self->maps[map->type], map); | ||
163 | map->groups = self; | ||
164 | } | ||
165 | |||
166 | static inline struct map *map_groups__find(struct map_groups *self, | ||
167 | enum map_type type, u64 addr) | ||
168 | { | ||
169 | return maps__find(&self->maps[type], addr); | ||
170 | } | ||
171 | |||
172 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
173 | enum map_type type, u64 addr, | ||
174 | struct map **mapp, | ||
175 | symbol_filter_t filter); | ||
176 | |||
177 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *self, | ||
178 | enum map_type type, | ||
179 | const char *name, | ||
180 | struct map **mapp, | ||
181 | symbol_filter_t filter); | ||
182 | |||
183 | static inline | ||
184 | struct symbol *machine__find_kernel_symbol(struct machine *self, | ||
185 | enum map_type type, u64 addr, | ||
186 | struct map **mapp, | ||
187 | symbol_filter_t filter) | ||
188 | { | ||
189 | return map_groups__find_symbol(&self->kmaps, type, addr, mapp, filter); | ||
190 | } | ||
191 | |||
192 | static inline | ||
193 | struct symbol *machine__find_kernel_function(struct machine *self, u64 addr, | ||
194 | struct map **mapp, | ||
195 | symbol_filter_t filter) | ||
196 | { | ||
197 | return machine__find_kernel_symbol(self, MAP__FUNCTION, addr, mapp, filter); | ||
198 | } | ||
199 | |||
200 | static inline | ||
201 | struct symbol *map_groups__find_function_by_name(struct map_groups *self, | ||
202 | const char *name, struct map **mapp, | ||
203 | symbol_filter_t filter) | ||
204 | { | ||
205 | return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter); | ||
206 | } | ||
207 | |||
208 | int map_groups__fixup_overlappings(struct map_groups *self, struct map *map, | ||
209 | int verbose, FILE *fp); | ||
210 | |||
211 | struct map *map_groups__find_by_name(struct map_groups *self, | ||
212 | enum map_type type, const char *name); | ||
213 | struct map *machine__new_module(struct machine *self, u64 start, const char *filename); | ||
214 | |||
215 | void map_groups__flush(struct map_groups *self); | ||
216 | |||
94 | #endif /* __PERF_MAP_H */ | 217 | #endif /* __PERF_MAP_H */ |
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c new file mode 100644 index 000000000000..ccb7c5bb269e --- /dev/null +++ b/tools/perf/util/newt.c | |||
@@ -0,0 +1,1084 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #include <stdio.h> | ||
3 | #undef _GNU_SOURCE | ||
4 | |||
5 | #include <slang.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <newt.h> | ||
8 | #include <sys/ttydefaults.h> | ||
9 | |||
10 | #include "cache.h" | ||
11 | #include "hist.h" | ||
12 | #include "pstack.h" | ||
13 | #include "session.h" | ||
14 | #include "sort.h" | ||
15 | #include "symbol.h" | ||
16 | |||
17 | #if SLANG_VERSION < 20104 | ||
18 | #define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args) | ||
19 | #define slsmg_write_nstring(msg, len) SLsmg_write_nstring((char *)msg, len) | ||
20 | #define sltt_set_color(obj, name, fg, bg) SLtt_set_color(obj,(char *)name,\ | ||
21 | (char *)fg, (char *)bg) | ||
22 | #else | ||
23 | #define slsmg_printf SLsmg_printf | ||
24 | #define slsmg_write_nstring SLsmg_write_nstring | ||
25 | #define sltt_set_color SLtt_set_color | ||
26 | #endif | ||
27 | |||
28 | struct ui_progress { | ||
29 | newtComponent form, scale; | ||
30 | }; | ||
31 | |||
32 | struct ui_progress *ui_progress__new(const char *title, u64 total) | ||
33 | { | ||
34 | struct ui_progress *self = malloc(sizeof(*self)); | ||
35 | |||
36 | if (self != NULL) { | ||
37 | int cols; | ||
38 | newtGetScreenSize(&cols, NULL); | ||
39 | cols -= 4; | ||
40 | newtCenteredWindow(cols, 1, title); | ||
41 | self->form = newtForm(NULL, NULL, 0); | ||
42 | if (self->form == NULL) | ||
43 | goto out_free_self; | ||
44 | self->scale = newtScale(0, 0, cols, total); | ||
45 | if (self->scale == NULL) | ||
46 | goto out_free_form; | ||
47 | newtFormAddComponent(self->form, self->scale); | ||
48 | newtRefresh(); | ||
49 | } | ||
50 | |||
51 | return self; | ||
52 | |||
53 | out_free_form: | ||
54 | newtFormDestroy(self->form); | ||
55 | out_free_self: | ||
56 | free(self); | ||
57 | return NULL; | ||
58 | } | ||
59 | |||
60 | void ui_progress__update(struct ui_progress *self, u64 curr) | ||
61 | { | ||
62 | newtScaleSet(self->scale, curr); | ||
63 | newtRefresh(); | ||
64 | } | ||
65 | |||
66 | void ui_progress__delete(struct ui_progress *self) | ||
67 | { | ||
68 | newtFormDestroy(self->form); | ||
69 | newtPopWindow(); | ||
70 | free(self); | ||
71 | } | ||
72 | |||
73 | static void ui_helpline__pop(void) | ||
74 | { | ||
75 | newtPopHelpLine(); | ||
76 | } | ||
77 | |||
78 | static void ui_helpline__push(const char *msg) | ||
79 | { | ||
80 | newtPushHelpLine(msg); | ||
81 | } | ||
82 | |||
83 | static void ui_helpline__vpush(const char *fmt, va_list ap) | ||
84 | { | ||
85 | char *s; | ||
86 | |||
87 | if (vasprintf(&s, fmt, ap) < 0) | ||
88 | vfprintf(stderr, fmt, ap); | ||
89 | else { | ||
90 | ui_helpline__push(s); | ||
91 | free(s); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | static void ui_helpline__fpush(const char *fmt, ...) | ||
96 | { | ||
97 | va_list ap; | ||
98 | |||
99 | va_start(ap, fmt); | ||
100 | ui_helpline__vpush(fmt, ap); | ||
101 | va_end(ap); | ||
102 | } | ||
103 | |||
104 | static void ui_helpline__puts(const char *msg) | ||
105 | { | ||
106 | ui_helpline__pop(); | ||
107 | ui_helpline__push(msg); | ||
108 | } | ||
109 | |||
110 | static char browser__last_msg[1024]; | ||
111 | |||
112 | int browser__show_help(const char *format, va_list ap) | ||
113 | { | ||
114 | int ret; | ||
115 | static int backlog; | ||
116 | |||
117 | ret = vsnprintf(browser__last_msg + backlog, | ||
118 | sizeof(browser__last_msg) - backlog, format, ap); | ||
119 | backlog += ret; | ||
120 | |||
121 | if (browser__last_msg[backlog - 1] == '\n') { | ||
122 | ui_helpline__puts(browser__last_msg); | ||
123 | newtRefresh(); | ||
124 | backlog = 0; | ||
125 | } | ||
126 | |||
127 | return ret; | ||
128 | } | ||
129 | |||
130 | static void newt_form__set_exit_keys(newtComponent self) | ||
131 | { | ||
132 | newtFormAddHotKey(self, NEWT_KEY_LEFT); | ||
133 | newtFormAddHotKey(self, NEWT_KEY_ESCAPE); | ||
134 | newtFormAddHotKey(self, 'Q'); | ||
135 | newtFormAddHotKey(self, 'q'); | ||
136 | newtFormAddHotKey(self, CTRL('c')); | ||
137 | } | ||
138 | |||
139 | static newtComponent newt_form__new(void) | ||
140 | { | ||
141 | newtComponent self = newtForm(NULL, NULL, 0); | ||
142 | if (self) | ||
143 | newt_form__set_exit_keys(self); | ||
144 | return self; | ||
145 | } | ||
146 | |||
147 | static int popup_menu(int argc, char * const argv[]) | ||
148 | { | ||
149 | struct newtExitStruct es; | ||
150 | int i, rc = -1, max_len = 5; | ||
151 | newtComponent listbox, form = newt_form__new(); | ||
152 | |||
153 | if (form == NULL) | ||
154 | return -1; | ||
155 | |||
156 | listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT); | ||
157 | if (listbox == NULL) | ||
158 | goto out_destroy_form; | ||
159 | |||
160 | newtFormAddComponent(form, listbox); | ||
161 | |||
162 | for (i = 0; i < argc; ++i) { | ||
163 | int len = strlen(argv[i]); | ||
164 | if (len > max_len) | ||
165 | max_len = len; | ||
166 | if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i)) | ||
167 | goto out_destroy_form; | ||
168 | } | ||
169 | |||
170 | newtCenteredWindow(max_len, argc, NULL); | ||
171 | newtFormRun(form, &es); | ||
172 | rc = newtListboxGetCurrent(listbox) - NULL; | ||
173 | if (es.reason == NEWT_EXIT_HOTKEY) | ||
174 | rc = -1; | ||
175 | newtPopWindow(); | ||
176 | out_destroy_form: | ||
177 | newtFormDestroy(form); | ||
178 | return rc; | ||
179 | } | ||
180 | |||
181 | static int ui__help_window(const char *text) | ||
182 | { | ||
183 | struct newtExitStruct es; | ||
184 | newtComponent tb, form = newt_form__new(); | ||
185 | int rc = -1; | ||
186 | int max_len = 0, nr_lines = 0; | ||
187 | const char *t; | ||
188 | |||
189 | if (form == NULL) | ||
190 | return -1; | ||
191 | |||
192 | t = text; | ||
193 | while (1) { | ||
194 | const char *sep = strchr(t, '\n'); | ||
195 | int len; | ||
196 | |||
197 | if (sep == NULL) | ||
198 | sep = strchr(t, '\0'); | ||
199 | len = sep - t; | ||
200 | if (max_len < len) | ||
201 | max_len = len; | ||
202 | ++nr_lines; | ||
203 | if (*sep == '\0') | ||
204 | break; | ||
205 | t = sep + 1; | ||
206 | } | ||
207 | |||
208 | tb = newtTextbox(0, 0, max_len, nr_lines, 0); | ||
209 | if (tb == NULL) | ||
210 | goto out_destroy_form; | ||
211 | |||
212 | newtTextboxSetText(tb, text); | ||
213 | newtFormAddComponent(form, tb); | ||
214 | newtCenteredWindow(max_len, nr_lines, NULL); | ||
215 | newtFormRun(form, &es); | ||
216 | newtPopWindow(); | ||
217 | rc = 0; | ||
218 | out_destroy_form: | ||
219 | newtFormDestroy(form); | ||
220 | return rc; | ||
221 | } | ||
222 | |||
223 | static bool dialog_yesno(const char *msg) | ||
224 | { | ||
225 | /* newtWinChoice should really be accepting const char pointers... */ | ||
226 | char yes[] = "Yes", no[] = "No"; | ||
227 | return newtWinChoice(NULL, yes, no, (char *)msg) == 1; | ||
228 | } | ||
229 | |||
230 | #define HE_COLORSET_TOP 50 | ||
231 | #define HE_COLORSET_MEDIUM 51 | ||
232 | #define HE_COLORSET_NORMAL 52 | ||
233 | #define HE_COLORSET_SELECTED 53 | ||
234 | #define HE_COLORSET_CODE 54 | ||
235 | |||
236 | static int ui_browser__percent_color(double percent, bool current) | ||
237 | { | ||
238 | if (current) | ||
239 | return HE_COLORSET_SELECTED; | ||
240 | if (percent >= MIN_RED) | ||
241 | return HE_COLORSET_TOP; | ||
242 | if (percent >= MIN_GREEN) | ||
243 | return HE_COLORSET_MEDIUM; | ||
244 | return HE_COLORSET_NORMAL; | ||
245 | } | ||
246 | |||
247 | struct ui_browser { | ||
248 | newtComponent form, sb; | ||
249 | u64 index, first_visible_entry_idx; | ||
250 | void *first_visible_entry, *entries; | ||
251 | u16 top, left, width, height; | ||
252 | void *priv; | ||
253 | u32 nr_entries; | ||
254 | }; | ||
255 | |||
256 | static void ui_browser__refresh_dimensions(struct ui_browser *self) | ||
257 | { | ||
258 | int cols, rows; | ||
259 | newtGetScreenSize(&cols, &rows); | ||
260 | |||
261 | if (self->width > cols - 4) | ||
262 | self->width = cols - 4; | ||
263 | self->height = rows - 5; | ||
264 | if (self->height > self->nr_entries) | ||
265 | self->height = self->nr_entries; | ||
266 | self->top = (rows - self->height) / 2; | ||
267 | self->left = (cols - self->width) / 2; | ||
268 | } | ||
269 | |||
270 | static void ui_browser__reset_index(struct ui_browser *self) | ||
271 | { | ||
272 | self->index = self->first_visible_entry_idx = 0; | ||
273 | self->first_visible_entry = NULL; | ||
274 | } | ||
275 | |||
276 | static int objdump_line__show(struct objdump_line *self, struct list_head *head, | ||
277 | int width, struct hist_entry *he, int len, | ||
278 | bool current_entry) | ||
279 | { | ||
280 | if (self->offset != -1) { | ||
281 | struct symbol *sym = he->ms.sym; | ||
282 | unsigned int hits = 0; | ||
283 | double percent = 0.0; | ||
284 | int color; | ||
285 | struct sym_priv *priv = symbol__priv(sym); | ||
286 | struct sym_ext *sym_ext = priv->ext; | ||
287 | struct sym_hist *h = priv->hist; | ||
288 | s64 offset = self->offset; | ||
289 | struct objdump_line *next = objdump__get_next_ip_line(head, self); | ||
290 | |||
291 | while (offset < (s64)len && | ||
292 | (next == NULL || offset < next->offset)) { | ||
293 | if (sym_ext) { | ||
294 | percent += sym_ext[offset].percent; | ||
295 | } else | ||
296 | hits += h->ip[offset]; | ||
297 | |||
298 | ++offset; | ||
299 | } | ||
300 | |||
301 | if (sym_ext == NULL && h->sum) | ||
302 | percent = 100.0 * hits / h->sum; | ||
303 | |||
304 | color = ui_browser__percent_color(percent, current_entry); | ||
305 | SLsmg_set_color(color); | ||
306 | slsmg_printf(" %7.2f ", percent); | ||
307 | if (!current_entry) | ||
308 | SLsmg_set_color(HE_COLORSET_CODE); | ||
309 | } else { | ||
310 | int color = ui_browser__percent_color(0, current_entry); | ||
311 | SLsmg_set_color(color); | ||
312 | slsmg_write_nstring(" ", 9); | ||
313 | } | ||
314 | |||
315 | SLsmg_write_char(':'); | ||
316 | slsmg_write_nstring(" ", 8); | ||
317 | if (!*self->line) | ||
318 | slsmg_write_nstring(" ", width - 18); | ||
319 | else | ||
320 | slsmg_write_nstring(self->line, width - 18); | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static int ui_browser__refresh_entries(struct ui_browser *self) | ||
326 | { | ||
327 | struct objdump_line *pos; | ||
328 | struct list_head *head = self->entries; | ||
329 | struct hist_entry *he = self->priv; | ||
330 | int row = 0; | ||
331 | int len = he->ms.sym->end - he->ms.sym->start; | ||
332 | |||
333 | if (self->first_visible_entry == NULL || self->first_visible_entry == self->entries) | ||
334 | self->first_visible_entry = head->next; | ||
335 | |||
336 | pos = list_entry(self->first_visible_entry, struct objdump_line, node); | ||
337 | |||
338 | list_for_each_entry_from(pos, head, node) { | ||
339 | bool current_entry = (self->first_visible_entry_idx + row) == self->index; | ||
340 | SLsmg_gotorc(self->top + row, self->left); | ||
341 | objdump_line__show(pos, head, self->width, | ||
342 | he, len, current_entry); | ||
343 | if (++row == self->height) | ||
344 | break; | ||
345 | } | ||
346 | |||
347 | SLsmg_set_color(HE_COLORSET_NORMAL); | ||
348 | SLsmg_fill_region(self->top + row, self->left, | ||
349 | self->height - row, self->width, ' '); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
354 | static int ui_browser__run(struct ui_browser *self, const char *title, | ||
355 | struct newtExitStruct *es) | ||
356 | { | ||
357 | if (self->form) { | ||
358 | newtFormDestroy(self->form); | ||
359 | newtPopWindow(); | ||
360 | } | ||
361 | |||
362 | ui_browser__refresh_dimensions(self); | ||
363 | newtCenteredWindow(self->width + 2, self->height, title); | ||
364 | self->form = newt_form__new(); | ||
365 | if (self->form == NULL) | ||
366 | return -1; | ||
367 | |||
368 | self->sb = newtVerticalScrollbar(self->width + 1, 0, self->height, | ||
369 | HE_COLORSET_NORMAL, | ||
370 | HE_COLORSET_SELECTED); | ||
371 | if (self->sb == NULL) | ||
372 | return -1; | ||
373 | |||
374 | newtFormAddHotKey(self->form, NEWT_KEY_UP); | ||
375 | newtFormAddHotKey(self->form, NEWT_KEY_DOWN); | ||
376 | newtFormAddHotKey(self->form, NEWT_KEY_PGUP); | ||
377 | newtFormAddHotKey(self->form, NEWT_KEY_PGDN); | ||
378 | newtFormAddHotKey(self->form, NEWT_KEY_HOME); | ||
379 | newtFormAddHotKey(self->form, NEWT_KEY_END); | ||
380 | |||
381 | if (ui_browser__refresh_entries(self) < 0) | ||
382 | return -1; | ||
383 | newtFormAddComponent(self->form, self->sb); | ||
384 | |||
385 | while (1) { | ||
386 | unsigned int offset; | ||
387 | |||
388 | newtFormRun(self->form, es); | ||
389 | |||
390 | if (es->reason != NEWT_EXIT_HOTKEY) | ||
391 | break; | ||
392 | switch (es->u.key) { | ||
393 | case NEWT_KEY_DOWN: | ||
394 | if (self->index == self->nr_entries - 1) | ||
395 | break; | ||
396 | ++self->index; | ||
397 | if (self->index == self->first_visible_entry_idx + self->height) { | ||
398 | struct list_head *pos = self->first_visible_entry; | ||
399 | ++self->first_visible_entry_idx; | ||
400 | self->first_visible_entry = pos->next; | ||
401 | } | ||
402 | break; | ||
403 | case NEWT_KEY_UP: | ||
404 | if (self->index == 0) | ||
405 | break; | ||
406 | --self->index; | ||
407 | if (self->index < self->first_visible_entry_idx) { | ||
408 | struct list_head *pos = self->first_visible_entry; | ||
409 | --self->first_visible_entry_idx; | ||
410 | self->first_visible_entry = pos->prev; | ||
411 | } | ||
412 | break; | ||
413 | case NEWT_KEY_PGDN: | ||
414 | if (self->first_visible_entry_idx + self->height > self->nr_entries - 1) | ||
415 | break; | ||
416 | |||
417 | offset = self->height; | ||
418 | if (self->index + offset > self->nr_entries - 1) | ||
419 | offset = self->nr_entries - 1 - self->index; | ||
420 | self->index += offset; | ||
421 | self->first_visible_entry_idx += offset; | ||
422 | |||
423 | while (offset--) { | ||
424 | struct list_head *pos = self->first_visible_entry; | ||
425 | self->first_visible_entry = pos->next; | ||
426 | } | ||
427 | |||
428 | break; | ||
429 | case NEWT_KEY_PGUP: | ||
430 | if (self->first_visible_entry_idx == 0) | ||
431 | break; | ||
432 | |||
433 | if (self->first_visible_entry_idx < self->height) | ||
434 | offset = self->first_visible_entry_idx; | ||
435 | else | ||
436 | offset = self->height; | ||
437 | |||
438 | self->index -= offset; | ||
439 | self->first_visible_entry_idx -= offset; | ||
440 | |||
441 | while (offset--) { | ||
442 | struct list_head *pos = self->first_visible_entry; | ||
443 | self->first_visible_entry = pos->prev; | ||
444 | } | ||
445 | break; | ||
446 | case NEWT_KEY_HOME: | ||
447 | ui_browser__reset_index(self); | ||
448 | break; | ||
449 | case NEWT_KEY_END: { | ||
450 | struct list_head *head = self->entries; | ||
451 | offset = self->height - 1; | ||
452 | |||
453 | if (offset > self->nr_entries) | ||
454 | offset = self->nr_entries; | ||
455 | |||
456 | self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset; | ||
457 | self->first_visible_entry = head->prev; | ||
458 | while (offset-- != 0) { | ||
459 | struct list_head *pos = self->first_visible_entry; | ||
460 | self->first_visible_entry = pos->prev; | ||
461 | } | ||
462 | } | ||
463 | break; | ||
464 | case NEWT_KEY_ESCAPE: | ||
465 | case NEWT_KEY_LEFT: | ||
466 | case CTRL('c'): | ||
467 | case 'Q': | ||
468 | case 'q': | ||
469 | return 0; | ||
470 | default: | ||
471 | continue; | ||
472 | } | ||
473 | if (ui_browser__refresh_entries(self) < 0) | ||
474 | return -1; | ||
475 | } | ||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | /* | ||
480 | * When debugging newt problems it was useful to be able to "unroll" | ||
481 | * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate | ||
482 | * a source file with the sequence of calls to these methods, to then | ||
483 | * tweak the arrays to get the intended results, so I'm keeping this code | ||
484 | * here, may be useful again in the future. | ||
485 | */ | ||
486 | #undef NEWT_DEBUG | ||
487 | |||
488 | static void newt_checkbox_tree__add(newtComponent tree, const char *str, | ||
489 | void *priv, int *indexes) | ||
490 | { | ||
491 | #ifdef NEWT_DEBUG | ||
492 | /* Print the newtCheckboxTreeAddArray to tinker with its index arrays */ | ||
493 | int i = 0, len = 40 - strlen(str); | ||
494 | |||
495 | fprintf(stderr, | ||
496 | "\tnewtCheckboxTreeAddItem(tree, %*.*s\"%s\", (void *)%p, 0, ", | ||
497 | len, len, " ", str, priv); | ||
498 | while (indexes[i] != NEWT_ARG_LAST) { | ||
499 | if (indexes[i] != NEWT_ARG_APPEND) | ||
500 | fprintf(stderr, " %d,", indexes[i]); | ||
501 | else | ||
502 | fprintf(stderr, " %s,", "NEWT_ARG_APPEND"); | ||
503 | ++i; | ||
504 | } | ||
505 | fprintf(stderr, " %s", " NEWT_ARG_LAST);\n"); | ||
506 | fflush(stderr); | ||
507 | #endif | ||
508 | newtCheckboxTreeAddArray(tree, str, priv, 0, indexes); | ||
509 | } | ||
510 | |||
511 | static char *callchain_list__sym_name(struct callchain_list *self, | ||
512 | char *bf, size_t bfsize) | ||
513 | { | ||
514 | if (self->ms.sym) | ||
515 | return self->ms.sym->name; | ||
516 | |||
517 | snprintf(bf, bfsize, "%#Lx", self->ip); | ||
518 | return bf; | ||
519 | } | ||
520 | |||
521 | static void __callchain__append_graph_browser(struct callchain_node *self, | ||
522 | newtComponent tree, u64 total, | ||
523 | int *indexes, int depth) | ||
524 | { | ||
525 | struct rb_node *node; | ||
526 | u64 new_total, remaining; | ||
527 | int idx = 0; | ||
528 | |||
529 | if (callchain_param.mode == CHAIN_GRAPH_REL) | ||
530 | new_total = self->children_hit; | ||
531 | else | ||
532 | new_total = total; | ||
533 | |||
534 | remaining = new_total; | ||
535 | node = rb_first(&self->rb_root); | ||
536 | while (node) { | ||
537 | struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); | ||
538 | struct rb_node *next = rb_next(node); | ||
539 | u64 cumul = cumul_hits(child); | ||
540 | struct callchain_list *chain; | ||
541 | int first = true, printed = 0; | ||
542 | int chain_idx = -1; | ||
543 | remaining -= cumul; | ||
544 | |||
545 | indexes[depth] = NEWT_ARG_APPEND; | ||
546 | indexes[depth + 1] = NEWT_ARG_LAST; | ||
547 | |||
548 | list_for_each_entry(chain, &child->val, list) { | ||
549 | char ipstr[BITS_PER_LONG / 4 + 1], | ||
550 | *alloc_str = NULL; | ||
551 | const char *str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
552 | |||
553 | if (first) { | ||
554 | double percent = cumul * 100.0 / new_total; | ||
555 | |||
556 | first = false; | ||
557 | if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0) | ||
558 | str = "Not enough memory!"; | ||
559 | else | ||
560 | str = alloc_str; | ||
561 | } else { | ||
562 | indexes[depth] = idx; | ||
563 | indexes[depth + 1] = NEWT_ARG_APPEND; | ||
564 | indexes[depth + 2] = NEWT_ARG_LAST; | ||
565 | ++chain_idx; | ||
566 | } | ||
567 | newt_checkbox_tree__add(tree, str, &chain->ms, indexes); | ||
568 | free(alloc_str); | ||
569 | ++printed; | ||
570 | } | ||
571 | |||
572 | indexes[depth] = idx; | ||
573 | if (chain_idx != -1) | ||
574 | indexes[depth + 1] = chain_idx; | ||
575 | if (printed != 0) | ||
576 | ++idx; | ||
577 | __callchain__append_graph_browser(child, tree, new_total, indexes, | ||
578 | depth + (chain_idx != -1 ? 2 : 1)); | ||
579 | node = next; | ||
580 | } | ||
581 | } | ||
582 | |||
583 | static void callchain__append_graph_browser(struct callchain_node *self, | ||
584 | newtComponent tree, u64 total, | ||
585 | int *indexes, int parent_idx) | ||
586 | { | ||
587 | struct callchain_list *chain; | ||
588 | int i = 0; | ||
589 | |||
590 | indexes[1] = NEWT_ARG_APPEND; | ||
591 | indexes[2] = NEWT_ARG_LAST; | ||
592 | |||
593 | list_for_each_entry(chain, &self->val, list) { | ||
594 | char ipstr[BITS_PER_LONG / 4 + 1], *str; | ||
595 | |||
596 | if (chain->ip >= PERF_CONTEXT_MAX) | ||
597 | continue; | ||
598 | |||
599 | if (!i++ && sort__first_dimension == SORT_SYM) | ||
600 | continue; | ||
601 | |||
602 | str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr)); | ||
603 | newt_checkbox_tree__add(tree, str, &chain->ms, indexes); | ||
604 | } | ||
605 | |||
606 | indexes[1] = parent_idx; | ||
607 | indexes[2] = NEWT_ARG_APPEND; | ||
608 | indexes[3] = NEWT_ARG_LAST; | ||
609 | __callchain__append_graph_browser(self, tree, total, indexes, 2); | ||
610 | } | ||
611 | |||
612 | static void hist_entry__append_callchain_browser(struct hist_entry *self, | ||
613 | newtComponent tree, u64 total, int parent_idx) | ||
614 | { | ||
615 | struct rb_node *rb_node; | ||
616 | int indexes[1024] = { [0] = parent_idx, }; | ||
617 | int idx = 0; | ||
618 | struct callchain_node *chain; | ||
619 | |||
620 | rb_node = rb_first(&self->sorted_chain); | ||
621 | while (rb_node) { | ||
622 | chain = rb_entry(rb_node, struct callchain_node, rb_node); | ||
623 | switch (callchain_param.mode) { | ||
624 | case CHAIN_FLAT: | ||
625 | break; | ||
626 | case CHAIN_GRAPH_ABS: /* falldown */ | ||
627 | case CHAIN_GRAPH_REL: | ||
628 | callchain__append_graph_browser(chain, tree, total, indexes, idx++); | ||
629 | break; | ||
630 | case CHAIN_NONE: | ||
631 | default: | ||
632 | break; | ||
633 | } | ||
634 | rb_node = rb_next(rb_node); | ||
635 | } | ||
636 | } | ||
637 | |||
638 | static size_t hist_entry__append_browser(struct hist_entry *self, | ||
639 | newtComponent tree, u64 total) | ||
640 | { | ||
641 | char s[256]; | ||
642 | size_t ret; | ||
643 | |||
644 | if (symbol_conf.exclude_other && !self->parent) | ||
645 | return 0; | ||
646 | |||
647 | ret = hist_entry__snprintf(self, s, sizeof(s), NULL, | ||
648 | false, 0, false, total); | ||
649 | if (symbol_conf.use_callchain) { | ||
650 | int indexes[2]; | ||
651 | |||
652 | indexes[0] = NEWT_ARG_APPEND; | ||
653 | indexes[1] = NEWT_ARG_LAST; | ||
654 | newt_checkbox_tree__add(tree, s, &self->ms, indexes); | ||
655 | } else | ||
656 | newtListboxAppendEntry(tree, s, &self->ms); | ||
657 | |||
658 | return ret; | ||
659 | } | ||
660 | |||
661 | static void hist_entry__annotate_browser(struct hist_entry *self) | ||
662 | { | ||
663 | struct ui_browser browser; | ||
664 | struct newtExitStruct es; | ||
665 | struct objdump_line *pos, *n; | ||
666 | LIST_HEAD(head); | ||
667 | |||
668 | if (self->ms.sym == NULL) | ||
669 | return; | ||
670 | |||
671 | if (hist_entry__annotate(self, &head) < 0) | ||
672 | return; | ||
673 | |||
674 | ui_helpline__push("Press <- or ESC to exit"); | ||
675 | |||
676 | memset(&browser, 0, sizeof(browser)); | ||
677 | browser.entries = &head; | ||
678 | browser.priv = self; | ||
679 | list_for_each_entry(pos, &head, node) { | ||
680 | size_t line_len = strlen(pos->line); | ||
681 | if (browser.width < line_len) | ||
682 | browser.width = line_len; | ||
683 | ++browser.nr_entries; | ||
684 | } | ||
685 | |||
686 | browser.width += 18; /* Percentage */ | ||
687 | ui_browser__run(&browser, self->ms.sym->name, &es); | ||
688 | newtFormDestroy(browser.form); | ||
689 | newtPopWindow(); | ||
690 | list_for_each_entry_safe(pos, n, &head, node) { | ||
691 | list_del(&pos->node); | ||
692 | objdump_line__free(pos); | ||
693 | } | ||
694 | ui_helpline__pop(); | ||
695 | } | ||
696 | |||
697 | static const void *newt__symbol_tree_get_current(newtComponent self) | ||
698 | { | ||
699 | if (symbol_conf.use_callchain) | ||
700 | return newtCheckboxTreeGetCurrent(self); | ||
701 | return newtListboxGetCurrent(self); | ||
702 | } | ||
703 | |||
704 | static void hist_browser__selection(newtComponent self, void *data) | ||
705 | { | ||
706 | const struct map_symbol **symbol_ptr = data; | ||
707 | *symbol_ptr = newt__symbol_tree_get_current(self); | ||
708 | } | ||
709 | |||
710 | struct hist_browser { | ||
711 | newtComponent form, tree; | ||
712 | const struct map_symbol *selection; | ||
713 | }; | ||
714 | |||
715 | static struct hist_browser *hist_browser__new(void) | ||
716 | { | ||
717 | struct hist_browser *self = malloc(sizeof(*self)); | ||
718 | |||
719 | if (self != NULL) | ||
720 | self->form = NULL; | ||
721 | |||
722 | return self; | ||
723 | } | ||
724 | |||
725 | static void hist_browser__delete(struct hist_browser *self) | ||
726 | { | ||
727 | newtFormDestroy(self->form); | ||
728 | newtPopWindow(); | ||
729 | free(self); | ||
730 | } | ||
731 | |||
732 | static int hist_browser__populate(struct hist_browser *self, struct hists *hists, | ||
733 | const char *title) | ||
734 | { | ||
735 | int max_len = 0, idx, cols, rows; | ||
736 | struct ui_progress *progress; | ||
737 | struct rb_node *nd; | ||
738 | u64 curr_hist = 0; | ||
739 | char seq[] = ".", unit; | ||
740 | char str[256]; | ||
741 | unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE]; | ||
742 | |||
743 | if (self->form) { | ||
744 | newtFormDestroy(self->form); | ||
745 | newtPopWindow(); | ||
746 | } | ||
747 | |||
748 | nr_events = convert_unit(nr_events, &unit); | ||
749 | snprintf(str, sizeof(str), "Events: %lu%c ", | ||
750 | nr_events, unit); | ||
751 | newtDrawRootText(0, 0, str); | ||
752 | |||
753 | newtGetScreenSize(NULL, &rows); | ||
754 | |||
755 | if (symbol_conf.use_callchain) | ||
756 | self->tree = newtCheckboxTreeMulti(0, 0, rows - 5, seq, | ||
757 | NEWT_FLAG_SCROLL); | ||
758 | else | ||
759 | self->tree = newtListbox(0, 0, rows - 5, | ||
760 | (NEWT_FLAG_SCROLL | | ||
761 | NEWT_FLAG_RETURNEXIT)); | ||
762 | |||
763 | newtComponentAddCallback(self->tree, hist_browser__selection, | ||
764 | &self->selection); | ||
765 | |||
766 | progress = ui_progress__new("Adding entries to the browser...", | ||
767 | hists->nr_entries); | ||
768 | if (progress == NULL) | ||
769 | return -1; | ||
770 | |||
771 | idx = 0; | ||
772 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | ||
773 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | ||
774 | int len; | ||
775 | |||
776 | if (h->filtered) | ||
777 | continue; | ||
778 | |||
779 | len = hist_entry__append_browser(h, self->tree, hists->stats.total_period); | ||
780 | if (len > max_len) | ||
781 | max_len = len; | ||
782 | if (symbol_conf.use_callchain) | ||
783 | hist_entry__append_callchain_browser(h, self->tree, | ||
784 | hists->stats.total_period, idx++); | ||
785 | ++curr_hist; | ||
786 | if (curr_hist % 5) | ||
787 | ui_progress__update(progress, curr_hist); | ||
788 | } | ||
789 | |||
790 | ui_progress__delete(progress); | ||
791 | |||
792 | newtGetScreenSize(&cols, &rows); | ||
793 | |||
794 | if (max_len > cols) | ||
795 | max_len = cols - 3; | ||
796 | |||
797 | if (!symbol_conf.use_callchain) | ||
798 | newtListboxSetWidth(self->tree, max_len); | ||
799 | |||
800 | newtCenteredWindow(max_len + (symbol_conf.use_callchain ? 5 : 0), | ||
801 | rows - 5, title); | ||
802 | self->form = newt_form__new(); | ||
803 | if (self->form == NULL) | ||
804 | return -1; | ||
805 | |||
806 | newtFormAddHotKey(self->form, 'A'); | ||
807 | newtFormAddHotKey(self->form, 'a'); | ||
808 | newtFormAddHotKey(self->form, 'D'); | ||
809 | newtFormAddHotKey(self->form, 'd'); | ||
810 | newtFormAddHotKey(self->form, 'T'); | ||
811 | newtFormAddHotKey(self->form, 't'); | ||
812 | newtFormAddHotKey(self->form, '?'); | ||
813 | newtFormAddHotKey(self->form, 'H'); | ||
814 | newtFormAddHotKey(self->form, 'h'); | ||
815 | newtFormAddHotKey(self->form, NEWT_KEY_F1); | ||
816 | newtFormAddHotKey(self->form, NEWT_KEY_RIGHT); | ||
817 | newtFormAddComponents(self->form, self->tree, NULL); | ||
818 | self->selection = newt__symbol_tree_get_current(self->tree); | ||
819 | |||
820 | return 0; | ||
821 | } | ||
822 | |||
823 | static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self) | ||
824 | { | ||
825 | int *indexes; | ||
826 | |||
827 | if (!symbol_conf.use_callchain) | ||
828 | goto out; | ||
829 | |||
830 | indexes = newtCheckboxTreeFindItem(self->tree, (void *)self->selection); | ||
831 | if (indexes) { | ||
832 | bool is_hist_entry = indexes[1] == NEWT_ARG_LAST; | ||
833 | free(indexes); | ||
834 | if (is_hist_entry) | ||
835 | goto out; | ||
836 | } | ||
837 | return NULL; | ||
838 | out: | ||
839 | return container_of(self->selection, struct hist_entry, ms); | ||
840 | } | ||
841 | |||
842 | static struct thread *hist_browser__selected_thread(struct hist_browser *self) | ||
843 | { | ||
844 | struct hist_entry *he = hist_browser__selected_entry(self); | ||
845 | return he ? he->thread : NULL; | ||
846 | } | ||
847 | |||
848 | static int hist_browser__title(char *bf, size_t size, const char *input_name, | ||
849 | const struct dso *dso, const struct thread *thread) | ||
850 | { | ||
851 | int printed = 0; | ||
852 | |||
853 | if (thread) | ||
854 | printed += snprintf(bf + printed, size - printed, | ||
855 | "Thread: %s(%d)", | ||
856 | (thread->comm_set ? thread->comm : ""), | ||
857 | thread->pid); | ||
858 | if (dso) | ||
859 | printed += snprintf(bf + printed, size - printed, | ||
860 | "%sDSO: %s", thread ? " " : "", | ||
861 | dso->short_name); | ||
862 | return printed ?: snprintf(bf, size, "Report: %s", input_name); | ||
863 | } | ||
864 | |||
865 | int hists__browse(struct hists *self, const char *helpline, const char *input_name) | ||
866 | { | ||
867 | struct hist_browser *browser = hist_browser__new(); | ||
868 | struct pstack *fstack = pstack__new(2); | ||
869 | const struct thread *thread_filter = NULL; | ||
870 | const struct dso *dso_filter = NULL; | ||
871 | struct newtExitStruct es; | ||
872 | char msg[160]; | ||
873 | int err = -1; | ||
874 | |||
875 | if (browser == NULL) | ||
876 | return -1; | ||
877 | |||
878 | fstack = pstack__new(2); | ||
879 | if (fstack == NULL) | ||
880 | goto out; | ||
881 | |||
882 | ui_helpline__push(helpline); | ||
883 | |||
884 | hist_browser__title(msg, sizeof(msg), input_name, | ||
885 | dso_filter, thread_filter); | ||
886 | if (hist_browser__populate(browser, self, msg) < 0) | ||
887 | goto out_free_stack; | ||
888 | |||
889 | while (1) { | ||
890 | const struct thread *thread; | ||
891 | const struct dso *dso; | ||
892 | char *options[16]; | ||
893 | int nr_options = 0, choice = 0, i, | ||
894 | annotate = -2, zoom_dso = -2, zoom_thread = -2; | ||
895 | |||
896 | newtFormRun(browser->form, &es); | ||
897 | |||
898 | thread = hist_browser__selected_thread(browser); | ||
899 | dso = browser->selection->map ? browser->selection->map->dso : NULL; | ||
900 | |||
901 | if (es.reason == NEWT_EXIT_HOTKEY) { | ||
902 | if (es.u.key == NEWT_KEY_F1) | ||
903 | goto do_help; | ||
904 | |||
905 | switch (toupper(es.u.key)) { | ||
906 | case 'A': | ||
907 | goto do_annotate; | ||
908 | case 'D': | ||
909 | goto zoom_dso; | ||
910 | case 'T': | ||
911 | goto zoom_thread; | ||
912 | case 'H': | ||
913 | case '?': | ||
914 | do_help: | ||
915 | ui__help_window("-> Zoom into DSO/Threads & Annotate current symbol\n" | ||
916 | "<- Zoom out\n" | ||
917 | "a Annotate current symbol\n" | ||
918 | "h/?/F1 Show this window\n" | ||
919 | "d Zoom into current DSO\n" | ||
920 | "t Zoom into current Thread\n" | ||
921 | "q/CTRL+C Exit browser"); | ||
922 | continue; | ||
923 | default:; | ||
924 | } | ||
925 | if (toupper(es.u.key) == 'Q' || | ||
926 | es.u.key == CTRL('c')) | ||
927 | break; | ||
928 | if (es.u.key == NEWT_KEY_ESCAPE) { | ||
929 | if (dialog_yesno("Do you really want to exit?")) | ||
930 | break; | ||
931 | else | ||
932 | continue; | ||
933 | } | ||
934 | |||
935 | if (es.u.key == NEWT_KEY_LEFT) { | ||
936 | const void *top; | ||
937 | |||
938 | if (pstack__empty(fstack)) | ||
939 | continue; | ||
940 | top = pstack__pop(fstack); | ||
941 | if (top == &dso_filter) | ||
942 | goto zoom_out_dso; | ||
943 | if (top == &thread_filter) | ||
944 | goto zoom_out_thread; | ||
945 | continue; | ||
946 | } | ||
947 | } | ||
948 | |||
949 | if (browser->selection->sym != NULL && | ||
950 | asprintf(&options[nr_options], "Annotate %s", | ||
951 | browser->selection->sym->name) > 0) | ||
952 | annotate = nr_options++; | ||
953 | |||
954 | if (thread != NULL && | ||
955 | asprintf(&options[nr_options], "Zoom %s %s(%d) thread", | ||
956 | (thread_filter ? "out of" : "into"), | ||
957 | (thread->comm_set ? thread->comm : ""), | ||
958 | thread->pid) > 0) | ||
959 | zoom_thread = nr_options++; | ||
960 | |||
961 | if (dso != NULL && | ||
962 | asprintf(&options[nr_options], "Zoom %s %s DSO", | ||
963 | (dso_filter ? "out of" : "into"), | ||
964 | (dso->kernel ? "the Kernel" : dso->short_name)) > 0) | ||
965 | zoom_dso = nr_options++; | ||
966 | |||
967 | options[nr_options++] = (char *)"Exit"; | ||
968 | |||
969 | choice = popup_menu(nr_options, options); | ||
970 | |||
971 | for (i = 0; i < nr_options - 1; ++i) | ||
972 | free(options[i]); | ||
973 | |||
974 | if (choice == nr_options - 1) | ||
975 | break; | ||
976 | |||
977 | if (choice == -1) | ||
978 | continue; | ||
979 | |||
980 | if (choice == annotate) { | ||
981 | struct hist_entry *he; | ||
982 | do_annotate: | ||
983 | if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) { | ||
984 | ui_helpline__puts("No vmlinux file found, can't " | ||
985 | "annotate with just a " | ||
986 | "kallsyms file"); | ||
987 | continue; | ||
988 | } | ||
989 | |||
990 | he = hist_browser__selected_entry(browser); | ||
991 | if (he == NULL) | ||
992 | continue; | ||
993 | |||
994 | hist_entry__annotate_browser(he); | ||
995 | } else if (choice == zoom_dso) { | ||
996 | zoom_dso: | ||
997 | if (dso_filter) { | ||
998 | pstack__remove(fstack, &dso_filter); | ||
999 | zoom_out_dso: | ||
1000 | ui_helpline__pop(); | ||
1001 | dso_filter = NULL; | ||
1002 | } else { | ||
1003 | if (dso == NULL) | ||
1004 | continue; | ||
1005 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"", | ||
1006 | dso->kernel ? "the Kernel" : dso->short_name); | ||
1007 | dso_filter = dso; | ||
1008 | pstack__push(fstack, &dso_filter); | ||
1009 | } | ||
1010 | hists__filter_by_dso(self, dso_filter); | ||
1011 | hist_browser__title(msg, sizeof(msg), input_name, | ||
1012 | dso_filter, thread_filter); | ||
1013 | if (hist_browser__populate(browser, self, msg) < 0) | ||
1014 | goto out; | ||
1015 | } else if (choice == zoom_thread) { | ||
1016 | zoom_thread: | ||
1017 | if (thread_filter) { | ||
1018 | pstack__remove(fstack, &thread_filter); | ||
1019 | zoom_out_thread: | ||
1020 | ui_helpline__pop(); | ||
1021 | thread_filter = NULL; | ||
1022 | } else { | ||
1023 | ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"", | ||
1024 | thread->comm_set ? thread->comm : "", | ||
1025 | thread->pid); | ||
1026 | thread_filter = thread; | ||
1027 | pstack__push(fstack, &thread_filter); | ||
1028 | } | ||
1029 | hists__filter_by_thread(self, thread_filter); | ||
1030 | hist_browser__title(msg, sizeof(msg), input_name, | ||
1031 | dso_filter, thread_filter); | ||
1032 | if (hist_browser__populate(browser, self, msg) < 0) | ||
1033 | goto out; | ||
1034 | } | ||
1035 | } | ||
1036 | err = 0; | ||
1037 | out_free_stack: | ||
1038 | pstack__delete(fstack); | ||
1039 | out: | ||
1040 | hist_browser__delete(browser); | ||
1041 | return err; | ||
1042 | } | ||
1043 | |||
1044 | static struct newtPercentTreeColors { | ||
1045 | const char *topColorFg, *topColorBg; | ||
1046 | const char *mediumColorFg, *mediumColorBg; | ||
1047 | const char *normalColorFg, *normalColorBg; | ||
1048 | const char *selColorFg, *selColorBg; | ||
1049 | const char *codeColorFg, *codeColorBg; | ||
1050 | } defaultPercentTreeColors = { | ||
1051 | "red", "lightgray", | ||
1052 | "green", "lightgray", | ||
1053 | "black", "lightgray", | ||
1054 | "lightgray", "magenta", | ||
1055 | "blue", "lightgray", | ||
1056 | }; | ||
1057 | |||
1058 | void setup_browser(void) | ||
1059 | { | ||
1060 | struct newtPercentTreeColors *c = &defaultPercentTreeColors; | ||
1061 | if (!isatty(1)) | ||
1062 | return; | ||
1063 | |||
1064 | use_browser = true; | ||
1065 | newtInit(); | ||
1066 | newtCls(); | ||
1067 | ui_helpline__puts(" "); | ||
1068 | sltt_set_color(HE_COLORSET_TOP, NULL, c->topColorFg, c->topColorBg); | ||
1069 | sltt_set_color(HE_COLORSET_MEDIUM, NULL, c->mediumColorFg, c->mediumColorBg); | ||
1070 | sltt_set_color(HE_COLORSET_NORMAL, NULL, c->normalColorFg, c->normalColorBg); | ||
1071 | sltt_set_color(HE_COLORSET_SELECTED, NULL, c->selColorFg, c->selColorBg); | ||
1072 | sltt_set_color(HE_COLORSET_CODE, NULL, c->codeColorFg, c->codeColorBg); | ||
1073 | } | ||
1074 | |||
1075 | void exit_browser(bool wait_for_ok) | ||
1076 | { | ||
1077 | if (use_browser) { | ||
1078 | if (wait_for_ok) { | ||
1079 | char title[] = "Fatal Error", ok[] = "Ok"; | ||
1080 | newtWinMessage(title, ok, browser__last_msg); | ||
1081 | } | ||
1082 | newtFinished(); | ||
1083 | } | ||
1084 | } | ||
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 05d0c5c2030c..9bf0f402ca73 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "parse-events.h" | 5 | #include "parse-events.h" |
6 | #include "exec_cmd.h" | 6 | #include "exec_cmd.h" |
7 | #include "string.h" | 7 | #include "string.h" |
8 | #include "symbol.h" | ||
8 | #include "cache.h" | 9 | #include "cache.h" |
9 | #include "header.h" | 10 | #include "header.h" |
10 | #include "debugfs.h" | 11 | #include "debugfs.h" |
@@ -409,7 +410,6 @@ static enum event_result | |||
409 | parse_single_tracepoint_event(char *sys_name, | 410 | parse_single_tracepoint_event(char *sys_name, |
410 | const char *evt_name, | 411 | const char *evt_name, |
411 | unsigned int evt_length, | 412 | unsigned int evt_length, |
412 | char *flags, | ||
413 | struct perf_event_attr *attr, | 413 | struct perf_event_attr *attr, |
414 | const char **strp) | 414 | const char **strp) |
415 | { | 415 | { |
@@ -418,14 +418,6 @@ parse_single_tracepoint_event(char *sys_name, | |||
418 | u64 id; | 418 | u64 id; |
419 | int fd; | 419 | int fd; |
420 | 420 | ||
421 | if (flags) { | ||
422 | if (!strncmp(flags, "record", strlen(flags))) { | ||
423 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
424 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
425 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | 421 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, |
430 | sys_name, evt_name); | 422 | sys_name, evt_name); |
431 | 423 | ||
@@ -444,6 +436,13 @@ parse_single_tracepoint_event(char *sys_name, | |||
444 | attr->type = PERF_TYPE_TRACEPOINT; | 436 | attr->type = PERF_TYPE_TRACEPOINT; |
445 | *strp = evt_name + evt_length; | 437 | *strp = evt_name + evt_length; |
446 | 438 | ||
439 | attr->sample_type |= PERF_SAMPLE_RAW; | ||
440 | attr->sample_type |= PERF_SAMPLE_TIME; | ||
441 | attr->sample_type |= PERF_SAMPLE_CPU; | ||
442 | |||
443 | attr->sample_period = 1; | ||
444 | |||
445 | |||
447 | return EVT_HANDLED; | 446 | return EVT_HANDLED; |
448 | } | 447 | } |
449 | 448 | ||
@@ -532,8 +531,7 @@ static enum event_result parse_tracepoint_event(const char **strp, | |||
532 | flags); | 531 | flags); |
533 | } else | 532 | } else |
534 | return parse_single_tracepoint_event(sys_name, evt_name, | 533 | return parse_single_tracepoint_event(sys_name, evt_name, |
535 | evt_length, flags, | 534 | evt_length, attr, strp); |
536 | attr, strp); | ||
537 | } | 535 | } |
538 | 536 | ||
539 | static enum event_result | 537 | static enum event_result |
@@ -690,19 +688,29 @@ static enum event_result | |||
690 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) | 688 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) |
691 | { | 689 | { |
692 | const char *str = *strp; | 690 | const char *str = *strp; |
693 | int eu = 1, ek = 1, eh = 1; | 691 | int exclude = 0; |
692 | int eu = 0, ek = 0, eh = 0, precise = 0; | ||
694 | 693 | ||
695 | if (*str++ != ':') | 694 | if (*str++ != ':') |
696 | return 0; | 695 | return 0; |
697 | while (*str) { | 696 | while (*str) { |
698 | if (*str == 'u') | 697 | if (*str == 'u') { |
698 | if (!exclude) | ||
699 | exclude = eu = ek = eh = 1; | ||
699 | eu = 0; | 700 | eu = 0; |
700 | else if (*str == 'k') | 701 | } else if (*str == 'k') { |
702 | if (!exclude) | ||
703 | exclude = eu = ek = eh = 1; | ||
701 | ek = 0; | 704 | ek = 0; |
702 | else if (*str == 'h') | 705 | } else if (*str == 'h') { |
706 | if (!exclude) | ||
707 | exclude = eu = ek = eh = 1; | ||
703 | eh = 0; | 708 | eh = 0; |
704 | else | 709 | } else if (*str == 'p') { |
710 | precise++; | ||
711 | } else | ||
705 | break; | 712 | break; |
713 | |||
706 | ++str; | 714 | ++str; |
707 | } | 715 | } |
708 | if (str >= *strp + 2) { | 716 | if (str >= *strp + 2) { |
@@ -710,6 +718,7 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr) | |||
710 | attr->exclude_user = eu; | 718 | attr->exclude_user = eu; |
711 | attr->exclude_kernel = ek; | 719 | attr->exclude_kernel = ek; |
712 | attr->exclude_hv = eh; | 720 | attr->exclude_hv = eh; |
721 | attr->precise_ip = precise; | ||
713 | return 1; | 722 | return 1; |
714 | } | 723 | } |
715 | return 0; | 724 | return 0; |
@@ -934,7 +943,8 @@ void print_events(void) | |||
934 | 943 | ||
935 | printf("\n"); | 944 | printf("\n"); |
936 | printf(" %-42s [%s]\n", | 945 | printf(" %-42s [%s]\n", |
937 | "rNNN", event_type_descriptors[PERF_TYPE_RAW]); | 946 | "rNNN (see 'perf list --help' on how to encode it)", |
947 | event_type_descriptors[PERF_TYPE_RAW]); | ||
938 | printf("\n"); | 948 | printf("\n"); |
939 | 949 | ||
940 | printf(" %-42s [%s]\n", | 950 | printf(" %-42s [%s]\n", |
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index b8c1f64bc935..fc4ab3fe877a 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h | |||
@@ -13,6 +13,7 @@ struct tracepoint_path { | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | extern struct tracepoint_path *tracepoint_id_to_path(u64 config); | 15 | extern struct tracepoint_path *tracepoint_id_to_path(u64 config); |
16 | extern bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events); | ||
16 | 17 | ||
17 | extern int nr_counters; | 18 | extern int nr_counters; |
18 | 19 | ||
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index efebd5b476b3..99d02aa57dbf 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -49,8 +49,9 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
49 | break; | 49 | break; |
50 | /* FALLTHROUGH */ | 50 | /* FALLTHROUGH */ |
51 | case OPTION_BOOLEAN: | 51 | case OPTION_BOOLEAN: |
52 | case OPTION_INCR: | ||
52 | case OPTION_BIT: | 53 | case OPTION_BIT: |
53 | case OPTION_SET_INT: | 54 | case OPTION_SET_UINT: |
54 | case OPTION_SET_PTR: | 55 | case OPTION_SET_PTR: |
55 | return opterror(opt, "takes no value", flags); | 56 | return opterror(opt, "takes no value", flags); |
56 | case OPTION_END: | 57 | case OPTION_END: |
@@ -58,7 +59,9 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
58 | case OPTION_GROUP: | 59 | case OPTION_GROUP: |
59 | case OPTION_STRING: | 60 | case OPTION_STRING: |
60 | case OPTION_INTEGER: | 61 | case OPTION_INTEGER: |
62 | case OPTION_UINTEGER: | ||
61 | case OPTION_LONG: | 63 | case OPTION_LONG: |
64 | case OPTION_U64: | ||
62 | default: | 65 | default: |
63 | break; | 66 | break; |
64 | } | 67 | } |
@@ -73,11 +76,15 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
73 | return 0; | 76 | return 0; |
74 | 77 | ||
75 | case OPTION_BOOLEAN: | 78 | case OPTION_BOOLEAN: |
79 | *(bool *)opt->value = unset ? false : true; | ||
80 | return 0; | ||
81 | |||
82 | case OPTION_INCR: | ||
76 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; | 83 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; |
77 | return 0; | 84 | return 0; |
78 | 85 | ||
79 | case OPTION_SET_INT: | 86 | case OPTION_SET_UINT: |
80 | *(int *)opt->value = unset ? 0 : opt->defval; | 87 | *(unsigned int *)opt->value = unset ? 0 : opt->defval; |
81 | return 0; | 88 | return 0; |
82 | 89 | ||
83 | case OPTION_SET_PTR: | 90 | case OPTION_SET_PTR: |
@@ -120,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
120 | return opterror(opt, "expects a numerical value", flags); | 127 | return opterror(opt, "expects a numerical value", flags); |
121 | return 0; | 128 | return 0; |
122 | 129 | ||
130 | case OPTION_UINTEGER: | ||
131 | if (unset) { | ||
132 | *(unsigned int *)opt->value = 0; | ||
133 | return 0; | ||
134 | } | ||
135 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
136 | *(unsigned int *)opt->value = opt->defval; | ||
137 | return 0; | ||
138 | } | ||
139 | if (get_arg(p, opt, flags, &arg)) | ||
140 | return -1; | ||
141 | *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); | ||
142 | if (*s) | ||
143 | return opterror(opt, "expects a numerical value", flags); | ||
144 | return 0; | ||
145 | |||
123 | case OPTION_LONG: | 146 | case OPTION_LONG: |
124 | if (unset) { | 147 | if (unset) { |
125 | *(long *)opt->value = 0; | 148 | *(long *)opt->value = 0; |
@@ -136,6 +159,22 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
136 | return opterror(opt, "expects a numerical value", flags); | 159 | return opterror(opt, "expects a numerical value", flags); |
137 | return 0; | 160 | return 0; |
138 | 161 | ||
162 | case OPTION_U64: | ||
163 | if (unset) { | ||
164 | *(u64 *)opt->value = 0; | ||
165 | return 0; | ||
166 | } | ||
167 | if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { | ||
168 | *(u64 *)opt->value = opt->defval; | ||
169 | return 0; | ||
170 | } | ||
171 | if (get_arg(p, opt, flags, &arg)) | ||
172 | return -1; | ||
173 | *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); | ||
174 | if (*s) | ||
175 | return opterror(opt, "expects a numerical value", flags); | ||
176 | return 0; | ||
177 | |||
139 | case OPTION_END: | 178 | case OPTION_END: |
140 | case OPTION_ARGUMENT: | 179 | case OPTION_ARGUMENT: |
141 | case OPTION_GROUP: | 180 | case OPTION_GROUP: |
@@ -441,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr, | |||
441 | switch (opts->type) { | 480 | switch (opts->type) { |
442 | case OPTION_ARGUMENT: | 481 | case OPTION_ARGUMENT: |
443 | break; | 482 | break; |
483 | case OPTION_LONG: | ||
484 | case OPTION_U64: | ||
444 | case OPTION_INTEGER: | 485 | case OPTION_INTEGER: |
486 | case OPTION_UINTEGER: | ||
445 | if (opts->flags & PARSE_OPT_OPTARG) | 487 | if (opts->flags & PARSE_OPT_OPTARG) |
446 | if (opts->long_name) | 488 | if (opts->long_name) |
447 | pos += fprintf(stderr, "[=<n>]"); | 489 | pos += fprintf(stderr, "[=<n>]"); |
@@ -473,14 +515,14 @@ int usage_with_options_internal(const char * const *usagestr, | |||
473 | pos += fprintf(stderr, " ..."); | 515 | pos += fprintf(stderr, " ..."); |
474 | } | 516 | } |
475 | break; | 517 | break; |
476 | default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ | 518 | default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */ |
477 | case OPTION_END: | 519 | case OPTION_END: |
478 | case OPTION_GROUP: | 520 | case OPTION_GROUP: |
479 | case OPTION_BIT: | 521 | case OPTION_BIT: |
480 | case OPTION_BOOLEAN: | 522 | case OPTION_BOOLEAN: |
481 | case OPTION_SET_INT: | 523 | case OPTION_INCR: |
524 | case OPTION_SET_UINT: | ||
482 | case OPTION_SET_PTR: | 525 | case OPTION_SET_PTR: |
483 | case OPTION_LONG: | ||
484 | break; | 526 | break; |
485 | } | 527 | } |
486 | 528 | ||
@@ -500,6 +542,7 @@ int usage_with_options_internal(const char * const *usagestr, | |||
500 | void usage_with_options(const char * const *usagestr, | 542 | void usage_with_options(const char * const *usagestr, |
501 | const struct option *opts) | 543 | const struct option *opts) |
502 | { | 544 | { |
545 | exit_browser(false); | ||
503 | usage_with_options_internal(usagestr, opts, 0); | 546 | usage_with_options_internal(usagestr, opts, 0); |
504 | exit(129); | 547 | exit(129); |
505 | } | 548 | } |
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index 948805af43c2..c7d72dce54b2 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h | |||
@@ -1,6 +1,9 @@ | |||
1 | #ifndef __PERF_PARSE_OPTIONS_H | 1 | #ifndef __PERF_PARSE_OPTIONS_H |
2 | #define __PERF_PARSE_OPTIONS_H | 2 | #define __PERF_PARSE_OPTIONS_H |
3 | 3 | ||
4 | #include <linux/kernel.h> | ||
5 | #include <stdbool.h> | ||
6 | |||
4 | enum parse_opt_type { | 7 | enum parse_opt_type { |
5 | /* special types */ | 8 | /* special types */ |
6 | OPTION_END, | 9 | OPTION_END, |
@@ -8,14 +11,17 @@ enum parse_opt_type { | |||
8 | OPTION_GROUP, | 11 | OPTION_GROUP, |
9 | /* options with no arguments */ | 12 | /* options with no arguments */ |
10 | OPTION_BIT, | 13 | OPTION_BIT, |
11 | OPTION_BOOLEAN, /* _INCR would have been a better name */ | 14 | OPTION_BOOLEAN, |
12 | OPTION_SET_INT, | 15 | OPTION_INCR, |
16 | OPTION_SET_UINT, | ||
13 | OPTION_SET_PTR, | 17 | OPTION_SET_PTR, |
14 | /* options with arguments (usually) */ | 18 | /* options with arguments (usually) */ |
15 | OPTION_STRING, | 19 | OPTION_STRING, |
16 | OPTION_INTEGER, | 20 | OPTION_INTEGER, |
17 | OPTION_LONG, | 21 | OPTION_LONG, |
18 | OPTION_CALLBACK, | 22 | OPTION_CALLBACK, |
23 | OPTION_U64, | ||
24 | OPTION_UINTEGER, | ||
19 | }; | 25 | }; |
20 | 26 | ||
21 | enum parse_opt_flags { | 27 | enum parse_opt_flags { |
@@ -73,7 +79,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); | |||
73 | * | 79 | * |
74 | * `defval`:: | 80 | * `defval`:: |
75 | * default value to fill (*->value) with for PARSE_OPT_OPTARG. | 81 | * default value to fill (*->value) with for PARSE_OPT_OPTARG. |
76 | * OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in | 82 | * OPTION_{BIT,SET_UINT,SET_PTR} store the {mask,integer,pointer} to put in |
77 | * the value when met. | 83 | * the value when met. |
78 | * CALLBACKS can use it like they want. | 84 | * CALLBACKS can use it like they want. |
79 | */ | 85 | */ |
@@ -90,16 +96,21 @@ struct option { | |||
90 | intptr_t defval; | 96 | intptr_t defval; |
91 | }; | 97 | }; |
92 | 98 | ||
99 | #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) | ||
100 | |||
93 | #define OPT_END() { .type = OPTION_END } | 101 | #define OPT_END() { .type = OPTION_END } |
94 | #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } | 102 | #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } |
95 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } | 103 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } |
96 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } | 104 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) } |
97 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 105 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) } |
98 | #define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } | 106 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } |
107 | #define OPT_SET_UINT(s, l, v, h, i) { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) } | ||
99 | #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } | 108 | #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } |
100 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 109 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } |
101 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 110 | #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } |
102 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } | 111 | #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } |
112 | #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } | ||
113 | #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } | ||
103 | #define OPT_DATE(s, l, v, h) \ | 114 | #define OPT_DATE(s, l, v, h) \ |
104 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } | 115 | { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } |
105 | #define OPT_CALLBACK(s, l, v, a, h, f) \ | 116 | #define OPT_CALLBACK(s, l, v, a, h, f) \ |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 7c004b6ef24f..914c67095d96 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -33,20 +33,27 @@ | |||
33 | #include <limits.h> | 33 | #include <limits.h> |
34 | 34 | ||
35 | #undef _GNU_SOURCE | 35 | #undef _GNU_SOURCE |
36 | #include "util.h" | ||
36 | #include "event.h" | 37 | #include "event.h" |
37 | #include "string.h" | 38 | #include "string.h" |
38 | #include "strlist.h" | 39 | #include "strlist.h" |
39 | #include "debug.h" | 40 | #include "debug.h" |
40 | #include "cache.h" | 41 | #include "cache.h" |
41 | #include "color.h" | 42 | #include "color.h" |
42 | #include "parse-events.h" /* For debugfs_path */ | 43 | #include "symbol.h" |
44 | #include "thread.h" | ||
45 | #include "debugfs.h" | ||
46 | #include "trace-event.h" /* For __unused */ | ||
43 | #include "probe-event.h" | 47 | #include "probe-event.h" |
48 | #include "probe-finder.h" | ||
44 | 49 | ||
45 | #define MAX_CMDLEN 256 | 50 | #define MAX_CMDLEN 256 |
46 | #define MAX_PROBE_ARGS 128 | 51 | #define MAX_PROBE_ARGS 128 |
47 | #define PERFPROBE_GROUP "probe" | 52 | #define PERFPROBE_GROUP "probe" |
48 | 53 | ||
49 | #define semantic_error(msg ...) die("Semantic error :" msg) | 54 | bool probe_event_dry_run; /* Dry run flag */ |
55 | |||
56 | #define semantic_error(msg ...) pr_err("Semantic error :" msg) | ||
50 | 57 | ||
51 | /* If there is no space to write, returns -E2BIG. */ | 58 | /* If there is no space to write, returns -E2BIG. */ |
52 | static int e_snprintf(char *str, size_t size, const char *format, ...) | 59 | static int e_snprintf(char *str, size_t size, const char *format, ...) |
@@ -64,7 +71,275 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
64 | return ret; | 71 | return ret; |
65 | } | 72 | } |
66 | 73 | ||
67 | void parse_line_range_desc(const char *arg, struct line_range *lr) | 74 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
75 | static struct machine machine; | ||
76 | |||
77 | /* Initialize symbol maps and path of vmlinux */ | ||
78 | static int init_vmlinux(void) | ||
79 | { | ||
80 | struct dso *kernel; | ||
81 | int ret; | ||
82 | |||
83 | symbol_conf.sort_by_name = true; | ||
84 | if (symbol_conf.vmlinux_name == NULL) | ||
85 | symbol_conf.try_vmlinux_path = true; | ||
86 | else | ||
87 | pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name); | ||
88 | ret = symbol__init(); | ||
89 | if (ret < 0) { | ||
90 | pr_debug("Failed to init symbol map.\n"); | ||
91 | goto out; | ||
92 | } | ||
93 | |||
94 | ret = machine__init(&machine, "/", 0); | ||
95 | if (ret < 0) | ||
96 | goto out; | ||
97 | |||
98 | kernel = dso__new_kernel(symbol_conf.vmlinux_name); | ||
99 | if (kernel == NULL) | ||
100 | die("Failed to create kernel dso."); | ||
101 | |||
102 | ret = __machine__create_kernel_maps(&machine, kernel); | ||
103 | if (ret < 0) | ||
104 | pr_debug("Failed to create kernel maps.\n"); | ||
105 | |||
106 | out: | ||
107 | if (ret < 0) | ||
108 | pr_warning("Failed to init vmlinux path.\n"); | ||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | #ifdef DWARF_SUPPORT | ||
113 | static int open_vmlinux(void) | ||
114 | { | ||
115 | if (map__load(machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) { | ||
116 | pr_debug("Failed to load kernel map.\n"); | ||
117 | return -EINVAL; | ||
118 | } | ||
119 | pr_debug("Try to open %s\n", machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name); | ||
120 | return open(machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name, O_RDONLY); | ||
121 | } | ||
122 | |||
123 | /* Convert trace point to probe point with debuginfo */ | ||
124 | static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, | ||
125 | struct perf_probe_point *pp) | ||
126 | { | ||
127 | struct symbol *sym; | ||
128 | int fd, ret = -ENOENT; | ||
129 | |||
130 | sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], | ||
131 | tp->symbol, NULL); | ||
132 | if (sym) { | ||
133 | fd = open_vmlinux(); | ||
134 | if (fd >= 0) { | ||
135 | ret = find_perf_probe_point(fd, | ||
136 | sym->start + tp->offset, pp); | ||
137 | close(fd); | ||
138 | } | ||
139 | } | ||
140 | if (ret <= 0) { | ||
141 | pr_debug("Failed to find corresponding probes from " | ||
142 | "debuginfo. Use kprobe event information.\n"); | ||
143 | pp->function = strdup(tp->symbol); | ||
144 | if (pp->function == NULL) | ||
145 | return -ENOMEM; | ||
146 | pp->offset = tp->offset; | ||
147 | } | ||
148 | pp->retprobe = tp->retprobe; | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | /* Try to find perf_probe_event with debuginfo */ | ||
154 | static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev, | ||
155 | struct kprobe_trace_event **tevs, | ||
156 | int max_tevs) | ||
157 | { | ||
158 | bool need_dwarf = perf_probe_event_need_dwarf(pev); | ||
159 | int fd, ntevs; | ||
160 | |||
161 | fd = open_vmlinux(); | ||
162 | if (fd < 0) { | ||
163 | if (need_dwarf) { | ||
164 | pr_warning("Failed to open debuginfo file.\n"); | ||
165 | return fd; | ||
166 | } | ||
167 | pr_debug("Could not open vmlinux. Try to use symbols.\n"); | ||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | /* Searching trace events corresponding to probe event */ | ||
172 | ntevs = find_kprobe_trace_events(fd, pev, tevs, max_tevs); | ||
173 | close(fd); | ||
174 | |||
175 | if (ntevs > 0) { /* Succeeded to find trace events */ | ||
176 | pr_debug("find %d kprobe_trace_events.\n", ntevs); | ||
177 | return ntevs; | ||
178 | } | ||
179 | |||
180 | if (ntevs == 0) { /* No error but failed to find probe point. */ | ||
181 | pr_warning("Probe point '%s' not found.\n", | ||
182 | synthesize_perf_probe_point(&pev->point)); | ||
183 | return -ENOENT; | ||
184 | } | ||
185 | /* Error path : ntevs < 0 */ | ||
186 | pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs); | ||
187 | if (ntevs == -EBADF) { | ||
188 | pr_warning("Warning: No dwarf info found in the vmlinux - " | ||
189 | "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n"); | ||
190 | if (!need_dwarf) { | ||
191 | pr_debug("Trying to use symbols.\nn"); | ||
192 | return 0; | ||
193 | } | ||
194 | } | ||
195 | return ntevs; | ||
196 | } | ||
197 | |||
198 | #define LINEBUF_SIZE 256 | ||
199 | #define NR_ADDITIONAL_LINES 2 | ||
200 | |||
201 | static int show_one_line(FILE *fp, int l, bool skip, bool show_num) | ||
202 | { | ||
203 | char buf[LINEBUF_SIZE]; | ||
204 | const char *color = PERF_COLOR_BLUE; | ||
205 | |||
206 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
207 | goto error; | ||
208 | if (!skip) { | ||
209 | if (show_num) | ||
210 | fprintf(stdout, "%7d %s", l, buf); | ||
211 | else | ||
212 | color_fprintf(stdout, color, " %s", buf); | ||
213 | } | ||
214 | |||
215 | while (strlen(buf) == LINEBUF_SIZE - 1 && | ||
216 | buf[LINEBUF_SIZE - 2] != '\n') { | ||
217 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
218 | goto error; | ||
219 | if (!skip) { | ||
220 | if (show_num) | ||
221 | fprintf(stdout, "%s", buf); | ||
222 | else | ||
223 | color_fprintf(stdout, color, "%s", buf); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | return 0; | ||
228 | error: | ||
229 | if (feof(fp)) | ||
230 | pr_warning("Source file is shorter than expected.\n"); | ||
231 | else | ||
232 | pr_warning("File read error: %s\n", strerror(errno)); | ||
233 | |||
234 | return -1; | ||
235 | } | ||
236 | |||
237 | /* | ||
238 | * Show line-range always requires debuginfo to find source file and | ||
239 | * line number. | ||
240 | */ | ||
241 | int show_line_range(struct line_range *lr) | ||
242 | { | ||
243 | int l = 1; | ||
244 | struct line_node *ln; | ||
245 | FILE *fp; | ||
246 | int fd, ret; | ||
247 | |||
248 | /* Search a line range */ | ||
249 | ret = init_vmlinux(); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | |||
253 | fd = open_vmlinux(); | ||
254 | if (fd < 0) { | ||
255 | pr_warning("Failed to open debuginfo file.\n"); | ||
256 | return fd; | ||
257 | } | ||
258 | |||
259 | ret = find_line_range(fd, lr); | ||
260 | close(fd); | ||
261 | if (ret == 0) { | ||
262 | pr_warning("Specified source line is not found.\n"); | ||
263 | return -ENOENT; | ||
264 | } else if (ret < 0) { | ||
265 | pr_warning("Debuginfo analysis failed. (%d)\n", ret); | ||
266 | return ret; | ||
267 | } | ||
268 | |||
269 | setup_pager(); | ||
270 | |||
271 | if (lr->function) | ||
272 | fprintf(stdout, "<%s:%d>\n", lr->function, | ||
273 | lr->start - lr->offset); | ||
274 | else | ||
275 | fprintf(stdout, "<%s:%d>\n", lr->file, lr->start); | ||
276 | |||
277 | fp = fopen(lr->path, "r"); | ||
278 | if (fp == NULL) { | ||
279 | pr_warning("Failed to open %s: %s\n", lr->path, | ||
280 | strerror(errno)); | ||
281 | return -errno; | ||
282 | } | ||
283 | /* Skip to starting line number */ | ||
284 | while (l < lr->start && ret >= 0) | ||
285 | ret = show_one_line(fp, l++, true, false); | ||
286 | if (ret < 0) | ||
287 | goto end; | ||
288 | |||
289 | list_for_each_entry(ln, &lr->line_list, list) { | ||
290 | while (ln->line > l && ret >= 0) | ||
291 | ret = show_one_line(fp, (l++) - lr->offset, | ||
292 | false, false); | ||
293 | if (ret >= 0) | ||
294 | ret = show_one_line(fp, (l++) - lr->offset, | ||
295 | false, true); | ||
296 | if (ret < 0) | ||
297 | goto end; | ||
298 | } | ||
299 | |||
300 | if (lr->end == INT_MAX) | ||
301 | lr->end = l + NR_ADDITIONAL_LINES; | ||
302 | while (l <= lr->end && !feof(fp) && ret >= 0) | ||
303 | ret = show_one_line(fp, (l++) - lr->offset, false, false); | ||
304 | end: | ||
305 | fclose(fp); | ||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | #else /* !DWARF_SUPPORT */ | ||
310 | |||
311 | static int convert_to_perf_probe_point(struct kprobe_trace_point *tp, | ||
312 | struct perf_probe_point *pp) | ||
313 | { | ||
314 | pp->function = strdup(tp->symbol); | ||
315 | if (pp->function == NULL) | ||
316 | return -ENOMEM; | ||
317 | pp->offset = tp->offset; | ||
318 | pp->retprobe = tp->retprobe; | ||
319 | |||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev, | ||
324 | struct kprobe_trace_event **tevs __unused, | ||
325 | int max_tevs __unused) | ||
326 | { | ||
327 | if (perf_probe_event_need_dwarf(pev)) { | ||
328 | pr_warning("Debuginfo-analysis is not supported.\n"); | ||
329 | return -ENOSYS; | ||
330 | } | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | int show_line_range(struct line_range *lr __unused) | ||
335 | { | ||
336 | pr_warning("Debuginfo-analysis is not supported.\n"); | ||
337 | return -ENOSYS; | ||
338 | } | ||
339 | |||
340 | #endif | ||
341 | |||
342 | int parse_line_range_desc(const char *arg, struct line_range *lr) | ||
68 | { | 343 | { |
69 | const char *ptr; | 344 | const char *ptr; |
70 | char *tmp; | 345 | char *tmp; |
@@ -75,29 +350,45 @@ void parse_line_range_desc(const char *arg, struct line_range *lr) | |||
75 | */ | 350 | */ |
76 | ptr = strchr(arg, ':'); | 351 | ptr = strchr(arg, ':'); |
77 | if (ptr) { | 352 | if (ptr) { |
78 | lr->start = (unsigned int)strtoul(ptr + 1, &tmp, 0); | 353 | lr->start = (int)strtoul(ptr + 1, &tmp, 0); |
79 | if (*tmp == '+') | 354 | if (*tmp == '+') { |
80 | lr->end = lr->start + (unsigned int)strtoul(tmp + 1, | 355 | lr->end = lr->start + (int)strtoul(tmp + 1, &tmp, 0); |
81 | &tmp, 0); | 356 | lr->end--; /* |
82 | else if (*tmp == '-') | 357 | * Adjust the number of lines here. |
83 | lr->end = (unsigned int)strtoul(tmp + 1, &tmp, 0); | 358 | * If the number of lines == 1, the |
359 | * the end of line should be equal to | ||
360 | * the start of line. | ||
361 | */ | ||
362 | } else if (*tmp == '-') | ||
363 | lr->end = (int)strtoul(tmp + 1, &tmp, 0); | ||
84 | else | 364 | else |
85 | lr->end = 0; | 365 | lr->end = INT_MAX; |
86 | pr_debug("Line range is %u to %u\n", lr->start, lr->end); | 366 | pr_debug("Line range is %d to %d\n", lr->start, lr->end); |
87 | if (lr->end && lr->start > lr->end) | 367 | if (lr->start > lr->end) { |
88 | semantic_error("Start line must be smaller" | 368 | semantic_error("Start line must be smaller" |
89 | " than end line."); | 369 | " than end line.\n"); |
90 | if (*tmp != '\0') | 370 | return -EINVAL; |
91 | semantic_error("Tailing with invalid character '%d'.", | 371 | } |
372 | if (*tmp != '\0') { | ||
373 | semantic_error("Tailing with invalid character '%d'.\n", | ||
92 | *tmp); | 374 | *tmp); |
375 | return -EINVAL; | ||
376 | } | ||
93 | tmp = strndup(arg, (ptr - arg)); | 377 | tmp = strndup(arg, (ptr - arg)); |
94 | } else | 378 | } else { |
95 | tmp = strdup(arg); | 379 | tmp = strdup(arg); |
380 | lr->end = INT_MAX; | ||
381 | } | ||
382 | |||
383 | if (tmp == NULL) | ||
384 | return -ENOMEM; | ||
96 | 385 | ||
97 | if (strchr(tmp, '.')) | 386 | if (strchr(tmp, '.')) |
98 | lr->file = tmp; | 387 | lr->file = tmp; |
99 | else | 388 | else |
100 | lr->function = tmp; | 389 | lr->function = tmp; |
390 | |||
391 | return 0; | ||
101 | } | 392 | } |
102 | 393 | ||
103 | /* Check the name is good for event/group */ | 394 | /* Check the name is good for event/group */ |
@@ -113,8 +404,9 @@ static bool check_event_name(const char *name) | |||
113 | } | 404 | } |
114 | 405 | ||
115 | /* Parse probepoint definition. */ | 406 | /* Parse probepoint definition. */ |
116 | static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | 407 | static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev) |
117 | { | 408 | { |
409 | struct perf_probe_point *pp = &pev->point; | ||
118 | char *ptr, *tmp; | 410 | char *ptr, *tmp; |
119 | char c, nc = 0; | 411 | char c, nc = 0; |
120 | /* | 412 | /* |
@@ -129,13 +421,19 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
129 | if (ptr && *ptr == '=') { /* Event name */ | 421 | if (ptr && *ptr == '=') { /* Event name */ |
130 | *ptr = '\0'; | 422 | *ptr = '\0'; |
131 | tmp = ptr + 1; | 423 | tmp = ptr + 1; |
132 | ptr = strchr(arg, ':'); | 424 | if (strchr(arg, ':')) { |
133 | if (ptr) /* Group name is not supported yet. */ | 425 | semantic_error("Group name is not supported yet.\n"); |
134 | semantic_error("Group name is not supported yet."); | 426 | return -ENOTSUP; |
135 | if (!check_event_name(arg)) | 427 | } |
428 | if (!check_event_name(arg)) { | ||
136 | semantic_error("%s is bad for event name -it must " | 429 | semantic_error("%s is bad for event name -it must " |
137 | "follow C symbol-naming rule.", arg); | 430 | "follow C symbol-naming rule.\n", arg); |
138 | pp->event = strdup(arg); | 431 | return -EINVAL; |
432 | } | ||
433 | pev->event = strdup(arg); | ||
434 | if (pev->event == NULL) | ||
435 | return -ENOMEM; | ||
436 | pev->group = NULL; | ||
139 | arg = tmp; | 437 | arg = tmp; |
140 | } | 438 | } |
141 | 439 | ||
@@ -145,12 +443,15 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
145 | *ptr++ = '\0'; | 443 | *ptr++ = '\0'; |
146 | } | 444 | } |
147 | 445 | ||
446 | tmp = strdup(arg); | ||
447 | if (tmp == NULL) | ||
448 | return -ENOMEM; | ||
449 | |||
148 | /* Check arg is function or file and copy it */ | 450 | /* Check arg is function or file and copy it */ |
149 | if (strchr(arg, '.')) /* File */ | 451 | if (strchr(tmp, '.')) /* File */ |
150 | pp->file = strdup(arg); | 452 | pp->file = tmp; |
151 | else /* Function */ | 453 | else /* Function */ |
152 | pp->function = strdup(arg); | 454 | pp->function = tmp; |
153 | DIE_IF(pp->file == NULL && pp->function == NULL); | ||
154 | 455 | ||
155 | /* Parse other options */ | 456 | /* Parse other options */ |
156 | while (ptr) { | 457 | while (ptr) { |
@@ -158,6 +459,8 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
158 | c = nc; | 459 | c = nc; |
159 | if (c == ';') { /* Lazy pattern must be the last part */ | 460 | if (c == ';') { /* Lazy pattern must be the last part */ |
160 | pp->lazy_line = strdup(arg); | 461 | pp->lazy_line = strdup(arg); |
462 | if (pp->lazy_line == NULL) | ||
463 | return -ENOMEM; | ||
161 | break; | 464 | break; |
162 | } | 465 | } |
163 | ptr = strpbrk(arg, ";:+@%"); | 466 | ptr = strpbrk(arg, ";:+@%"); |
@@ -168,266 +471,658 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp) | |||
168 | switch (c) { | 471 | switch (c) { |
169 | case ':': /* Line number */ | 472 | case ':': /* Line number */ |
170 | pp->line = strtoul(arg, &tmp, 0); | 473 | pp->line = strtoul(arg, &tmp, 0); |
171 | if (*tmp != '\0') | 474 | if (*tmp != '\0') { |
172 | semantic_error("There is non-digit char" | 475 | semantic_error("There is non-digit char" |
173 | " in line number."); | 476 | " in line number.\n"); |
477 | return -EINVAL; | ||
478 | } | ||
174 | break; | 479 | break; |
175 | case '+': /* Byte offset from a symbol */ | 480 | case '+': /* Byte offset from a symbol */ |
176 | pp->offset = strtoul(arg, &tmp, 0); | 481 | pp->offset = strtoul(arg, &tmp, 0); |
177 | if (*tmp != '\0') | 482 | if (*tmp != '\0') { |
178 | semantic_error("There is non-digit character" | 483 | semantic_error("There is non-digit character" |
179 | " in offset."); | 484 | " in offset.\n"); |
485 | return -EINVAL; | ||
486 | } | ||
180 | break; | 487 | break; |
181 | case '@': /* File name */ | 488 | case '@': /* File name */ |
182 | if (pp->file) | 489 | if (pp->file) { |
183 | semantic_error("SRC@SRC is not allowed."); | 490 | semantic_error("SRC@SRC is not allowed.\n"); |
491 | return -EINVAL; | ||
492 | } | ||
184 | pp->file = strdup(arg); | 493 | pp->file = strdup(arg); |
185 | DIE_IF(pp->file == NULL); | 494 | if (pp->file == NULL) |
495 | return -ENOMEM; | ||
186 | break; | 496 | break; |
187 | case '%': /* Probe places */ | 497 | case '%': /* Probe places */ |
188 | if (strcmp(arg, "return") == 0) { | 498 | if (strcmp(arg, "return") == 0) { |
189 | pp->retprobe = 1; | 499 | pp->retprobe = 1; |
190 | } else /* Others not supported yet */ | 500 | } else { /* Others not supported yet */ |
191 | semantic_error("%%%s is not supported.", arg); | 501 | semantic_error("%%%s is not supported.\n", arg); |
502 | return -ENOTSUP; | ||
503 | } | ||
192 | break; | 504 | break; |
193 | default: | 505 | default: /* Buggy case */ |
194 | DIE_IF("Program has a bug."); | 506 | pr_err("This program has a bug at %s:%d.\n", |
507 | __FILE__, __LINE__); | ||
508 | return -ENOTSUP; | ||
195 | break; | 509 | break; |
196 | } | 510 | } |
197 | } | 511 | } |
198 | 512 | ||
199 | /* Exclusion check */ | 513 | /* Exclusion check */ |
200 | if (pp->lazy_line && pp->line) | 514 | if (pp->lazy_line && pp->line) { |
201 | semantic_error("Lazy pattern can't be used with line number."); | 515 | semantic_error("Lazy pattern can't be used with line number."); |
516 | return -EINVAL; | ||
517 | } | ||
202 | 518 | ||
203 | if (pp->lazy_line && pp->offset) | 519 | if (pp->lazy_line && pp->offset) { |
204 | semantic_error("Lazy pattern can't be used with offset."); | 520 | semantic_error("Lazy pattern can't be used with offset."); |
521 | return -EINVAL; | ||
522 | } | ||
205 | 523 | ||
206 | if (pp->line && pp->offset) | 524 | if (pp->line && pp->offset) { |
207 | semantic_error("Offset can't be used with line number."); | 525 | semantic_error("Offset can't be used with line number."); |
526 | return -EINVAL; | ||
527 | } | ||
208 | 528 | ||
209 | if (!pp->line && !pp->lazy_line && pp->file && !pp->function) | 529 | if (!pp->line && !pp->lazy_line && pp->file && !pp->function) { |
210 | semantic_error("File always requires line number or " | 530 | semantic_error("File always requires line number or " |
211 | "lazy pattern."); | 531 | "lazy pattern."); |
532 | return -EINVAL; | ||
533 | } | ||
212 | 534 | ||
213 | if (pp->offset && !pp->function) | 535 | if (pp->offset && !pp->function) { |
214 | semantic_error("Offset requires an entry function."); | 536 | semantic_error("Offset requires an entry function."); |
537 | return -EINVAL; | ||
538 | } | ||
215 | 539 | ||
216 | if (pp->retprobe && !pp->function) | 540 | if (pp->retprobe && !pp->function) { |
217 | semantic_error("Return probe requires an entry function."); | 541 | semantic_error("Return probe requires an entry function."); |
542 | return -EINVAL; | ||
543 | } | ||
218 | 544 | ||
219 | if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) | 545 | if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) { |
220 | semantic_error("Offset/Line/Lazy pattern can't be used with " | 546 | semantic_error("Offset/Line/Lazy pattern can't be used with " |
221 | "return probe."); | 547 | "return probe."); |
548 | return -EINVAL; | ||
549 | } | ||
222 | 550 | ||
223 | pr_debug("symbol:%s file:%s line:%d offset:%d return:%d lazy:%s\n", | 551 | pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n", |
224 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, | 552 | pp->function, pp->file, pp->line, pp->offset, pp->retprobe, |
225 | pp->lazy_line); | 553 | pp->lazy_line); |
554 | return 0; | ||
226 | } | 555 | } |
227 | 556 | ||
228 | /* Parse perf-probe event definition */ | 557 | /* Parse perf-probe event argument */ |
229 | void parse_perf_probe_event(const char *str, struct probe_point *pp, | 558 | static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg) |
230 | bool *need_dwarf) | ||
231 | { | 559 | { |
232 | char **argv; | 560 | char *tmp; |
233 | int argc, i; | 561 | struct perf_probe_arg_field **fieldp; |
562 | |||
563 | pr_debug("parsing arg: %s into ", str); | ||
234 | 564 | ||
235 | *need_dwarf = false; | 565 | tmp = strchr(str, '='); |
566 | if (tmp) { | ||
567 | arg->name = strndup(str, tmp - str); | ||
568 | if (arg->name == NULL) | ||
569 | return -ENOMEM; | ||
570 | pr_debug("name:%s ", arg->name); | ||
571 | str = tmp + 1; | ||
572 | } | ||
236 | 573 | ||
237 | argv = argv_split(str, &argc); | 574 | tmp = strchr(str, ':'); |
238 | if (!argv) | 575 | if (tmp) { /* Type setting */ |
239 | die("argv_split failed."); | 576 | *tmp = '\0'; |
240 | if (argc > MAX_PROBE_ARGS + 1) | 577 | arg->type = strdup(tmp + 1); |
241 | semantic_error("Too many arguments"); | 578 | if (arg->type == NULL) |
579 | return -ENOMEM; | ||
580 | pr_debug("type:%s ", arg->type); | ||
581 | } | ||
242 | 582 | ||
583 | tmp = strpbrk(str, "-."); | ||
584 | if (!is_c_varname(str) || !tmp) { | ||
585 | /* A variable, register, symbol or special value */ | ||
586 | arg->var = strdup(str); | ||
587 | if (arg->var == NULL) | ||
588 | return -ENOMEM; | ||
589 | pr_debug("%s\n", arg->var); | ||
590 | return 0; | ||
591 | } | ||
592 | |||
593 | /* Structure fields */ | ||
594 | arg->var = strndup(str, tmp - str); | ||
595 | if (arg->var == NULL) | ||
596 | return -ENOMEM; | ||
597 | pr_debug("%s, ", arg->var); | ||
598 | fieldp = &arg->field; | ||
599 | |||
600 | do { | ||
601 | *fieldp = zalloc(sizeof(struct perf_probe_arg_field)); | ||
602 | if (*fieldp == NULL) | ||
603 | return -ENOMEM; | ||
604 | if (*tmp == '.') { | ||
605 | str = tmp + 1; | ||
606 | (*fieldp)->ref = false; | ||
607 | } else if (tmp[1] == '>') { | ||
608 | str = tmp + 2; | ||
609 | (*fieldp)->ref = true; | ||
610 | } else { | ||
611 | semantic_error("Argument parse error: %s\n", str); | ||
612 | return -EINVAL; | ||
613 | } | ||
614 | |||
615 | tmp = strpbrk(str, "-."); | ||
616 | if (tmp) { | ||
617 | (*fieldp)->name = strndup(str, tmp - str); | ||
618 | if ((*fieldp)->name == NULL) | ||
619 | return -ENOMEM; | ||
620 | pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref); | ||
621 | fieldp = &(*fieldp)->next; | ||
622 | } | ||
623 | } while (tmp); | ||
624 | (*fieldp)->name = strdup(str); | ||
625 | if ((*fieldp)->name == NULL) | ||
626 | return -ENOMEM; | ||
627 | pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref); | ||
628 | |||
629 | /* If no name is specified, set the last field name */ | ||
630 | if (!arg->name) { | ||
631 | arg->name = strdup((*fieldp)->name); | ||
632 | if (arg->name == NULL) | ||
633 | return -ENOMEM; | ||
634 | } | ||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | /* Parse perf-probe event command */ | ||
639 | int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev) | ||
640 | { | ||
641 | char **argv; | ||
642 | int argc, i, ret = 0; | ||
643 | |||
644 | argv = argv_split(cmd, &argc); | ||
645 | if (!argv) { | ||
646 | pr_debug("Failed to split arguments.\n"); | ||
647 | return -ENOMEM; | ||
648 | } | ||
649 | if (argc - 1 > MAX_PROBE_ARGS) { | ||
650 | semantic_error("Too many probe arguments (%d).\n", argc - 1); | ||
651 | ret = -ERANGE; | ||
652 | goto out; | ||
653 | } | ||
243 | /* Parse probe point */ | 654 | /* Parse probe point */ |
244 | parse_perf_probe_probepoint(argv[0], pp); | 655 | ret = parse_perf_probe_point(argv[0], pev); |
245 | if (pp->file || pp->line || pp->lazy_line) | 656 | if (ret < 0) |
246 | *need_dwarf = true; | 657 | goto out; |
247 | 658 | ||
248 | /* Copy arguments and ensure return probe has no C argument */ | 659 | /* Copy arguments and ensure return probe has no C argument */ |
249 | pp->nr_args = argc - 1; | 660 | pev->nargs = argc - 1; |
250 | pp->args = zalloc(sizeof(char *) * pp->nr_args); | 661 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); |
251 | for (i = 0; i < pp->nr_args; i++) { | 662 | if (pev->args == NULL) { |
252 | pp->args[i] = strdup(argv[i + 1]); | 663 | ret = -ENOMEM; |
253 | if (!pp->args[i]) | 664 | goto out; |
254 | die("Failed to copy argument."); | 665 | } |
255 | if (is_c_varname(pp->args[i])) { | 666 | for (i = 0; i < pev->nargs && ret >= 0; i++) { |
256 | if (pp->retprobe) | 667 | ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]); |
257 | semantic_error("You can't specify local" | 668 | if (ret >= 0 && |
258 | " variable for kretprobe"); | 669 | is_c_varname(pev->args[i].var) && pev->point.retprobe) { |
259 | *need_dwarf = true; | 670 | semantic_error("You can't specify local variable for" |
671 | " kretprobe.\n"); | ||
672 | ret = -EINVAL; | ||
260 | } | 673 | } |
261 | } | 674 | } |
262 | 675 | out: | |
263 | argv_free(argv); | 676 | argv_free(argv); |
677 | |||
678 | return ret; | ||
679 | } | ||
680 | |||
681 | /* Return true if this perf_probe_event requires debuginfo */ | ||
682 | bool perf_probe_event_need_dwarf(struct perf_probe_event *pev) | ||
683 | { | ||
684 | int i; | ||
685 | |||
686 | if (pev->point.file || pev->point.line || pev->point.lazy_line) | ||
687 | return true; | ||
688 | |||
689 | for (i = 0; i < pev->nargs; i++) | ||
690 | if (is_c_varname(pev->args[i].var)) | ||
691 | return true; | ||
692 | |||
693 | return false; | ||
264 | } | 694 | } |
265 | 695 | ||
266 | /* Parse kprobe_events event into struct probe_point */ | 696 | /* Parse kprobe_events event into struct probe_point */ |
267 | void parse_trace_kprobe_event(const char *str, struct probe_point *pp) | 697 | int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev) |
268 | { | 698 | { |
699 | struct kprobe_trace_point *tp = &tev->point; | ||
269 | char pr; | 700 | char pr; |
270 | char *p; | 701 | char *p; |
271 | int ret, i, argc; | 702 | int ret, i, argc; |
272 | char **argv; | 703 | char **argv; |
273 | 704 | ||
274 | pr_debug("Parsing kprobe_events: %s\n", str); | 705 | pr_debug("Parsing kprobe_events: %s\n", cmd); |
275 | argv = argv_split(str, &argc); | 706 | argv = argv_split(cmd, &argc); |
276 | if (!argv) | 707 | if (!argv) { |
277 | die("argv_split failed."); | 708 | pr_debug("Failed to split arguments.\n"); |
278 | if (argc < 2) | 709 | return -ENOMEM; |
279 | semantic_error("Too less arguments."); | 710 | } |
711 | if (argc < 2) { | ||
712 | semantic_error("Too few probe arguments.\n"); | ||
713 | ret = -ERANGE; | ||
714 | goto out; | ||
715 | } | ||
280 | 716 | ||
281 | /* Scan event and group name. */ | 717 | /* Scan event and group name. */ |
282 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", | 718 | ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]", |
283 | &pr, (float *)(void *)&pp->group, | 719 | &pr, (float *)(void *)&tev->group, |
284 | (float *)(void *)&pp->event); | 720 | (float *)(void *)&tev->event); |
285 | if (ret != 3) | 721 | if (ret != 3) { |
286 | semantic_error("Failed to parse event name: %s", argv[0]); | 722 | semantic_error("Failed to parse event name: %s\n", argv[0]); |
287 | pr_debug("Group:%s Event:%s probe:%c\n", pp->group, pp->event, pr); | 723 | ret = -EINVAL; |
724 | goto out; | ||
725 | } | ||
726 | pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr); | ||
288 | 727 | ||
289 | pp->retprobe = (pr == 'r'); | 728 | tp->retprobe = (pr == 'r'); |
290 | 729 | ||
291 | /* Scan function name and offset */ | 730 | /* Scan function name and offset */ |
292 | ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function, | 731 | ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol, |
293 | &pp->offset); | 732 | &tp->offset); |
294 | if (ret == 1) | 733 | if (ret == 1) |
295 | pp->offset = 0; | 734 | tp->offset = 0; |
296 | |||
297 | /* kprobe_events doesn't have this information */ | ||
298 | pp->line = 0; | ||
299 | pp->file = NULL; | ||
300 | 735 | ||
301 | pp->nr_args = argc - 2; | 736 | tev->nargs = argc - 2; |
302 | pp->args = zalloc(sizeof(char *) * pp->nr_args); | 737 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
303 | for (i = 0; i < pp->nr_args; i++) { | 738 | if (tev->args == NULL) { |
739 | ret = -ENOMEM; | ||
740 | goto out; | ||
741 | } | ||
742 | for (i = 0; i < tev->nargs; i++) { | ||
304 | p = strchr(argv[i + 2], '='); | 743 | p = strchr(argv[i + 2], '='); |
305 | if (p) /* We don't need which register is assigned. */ | 744 | if (p) /* We don't need which register is assigned. */ |
306 | *p = '\0'; | 745 | *p++ = '\0'; |
307 | pp->args[i] = strdup(argv[i + 2]); | 746 | else |
308 | if (!pp->args[i]) | 747 | p = argv[i + 2]; |
309 | die("Failed to copy argument."); | 748 | tev->args[i].name = strdup(argv[i + 2]); |
749 | /* TODO: parse regs and offset */ | ||
750 | tev->args[i].value = strdup(p); | ||
751 | if (tev->args[i].name == NULL || tev->args[i].value == NULL) { | ||
752 | ret = -ENOMEM; | ||
753 | goto out; | ||
754 | } | ||
310 | } | 755 | } |
311 | 756 | ret = 0; | |
757 | out: | ||
312 | argv_free(argv); | 758 | argv_free(argv); |
759 | return ret; | ||
313 | } | 760 | } |
314 | 761 | ||
315 | /* Synthesize only probe point (not argument) */ | 762 | /* Compose only probe arg */ |
316 | int synthesize_perf_probe_point(struct probe_point *pp) | 763 | int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len) |
317 | { | 764 | { |
318 | char *buf; | 765 | struct perf_probe_arg_field *field = pa->field; |
319 | char offs[64] = "", line[64] = ""; | ||
320 | int ret; | 766 | int ret; |
767 | char *tmp = buf; | ||
321 | 768 | ||
322 | pp->probes[0] = buf = zalloc(MAX_CMDLEN); | 769 | if (pa->name && pa->var) |
323 | pp->found = 1; | 770 | ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var); |
324 | if (!buf) | 771 | else |
325 | die("Failed to allocate memory by zalloc."); | 772 | ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var); |
773 | if (ret <= 0) | ||
774 | goto error; | ||
775 | tmp += ret; | ||
776 | len -= ret; | ||
777 | |||
778 | while (field) { | ||
779 | ret = e_snprintf(tmp, len, "%s%s", field->ref ? "->" : ".", | ||
780 | field->name); | ||
781 | if (ret <= 0) | ||
782 | goto error; | ||
783 | tmp += ret; | ||
784 | len -= ret; | ||
785 | field = field->next; | ||
786 | } | ||
787 | |||
788 | if (pa->type) { | ||
789 | ret = e_snprintf(tmp, len, ":%s", pa->type); | ||
790 | if (ret <= 0) | ||
791 | goto error; | ||
792 | tmp += ret; | ||
793 | len -= ret; | ||
794 | } | ||
795 | |||
796 | return tmp - buf; | ||
797 | error: | ||
798 | pr_debug("Failed to synthesize perf probe argument: %s", | ||
799 | strerror(-ret)); | ||
800 | return ret; | ||
801 | } | ||
802 | |||
803 | /* Compose only probe point (not argument) */ | ||
804 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp) | ||
805 | { | ||
806 | char *buf, *tmp; | ||
807 | char offs[32] = "", line[32] = "", file[32] = ""; | ||
808 | int ret, len; | ||
809 | |||
810 | buf = zalloc(MAX_CMDLEN); | ||
811 | if (buf == NULL) { | ||
812 | ret = -ENOMEM; | ||
813 | goto error; | ||
814 | } | ||
326 | if (pp->offset) { | 815 | if (pp->offset) { |
327 | ret = e_snprintf(offs, 64, "+%d", pp->offset); | 816 | ret = e_snprintf(offs, 32, "+%lu", pp->offset); |
328 | if (ret <= 0) | 817 | if (ret <= 0) |
329 | goto error; | 818 | goto error; |
330 | } | 819 | } |
331 | if (pp->line) { | 820 | if (pp->line) { |
332 | ret = e_snprintf(line, 64, ":%d", pp->line); | 821 | ret = e_snprintf(line, 32, ":%d", pp->line); |
822 | if (ret <= 0) | ||
823 | goto error; | ||
824 | } | ||
825 | if (pp->file) { | ||
826 | len = strlen(pp->file) - 31; | ||
827 | if (len < 0) | ||
828 | len = 0; | ||
829 | tmp = strchr(pp->file + len, '/'); | ||
830 | if (!tmp) | ||
831 | tmp = pp->file + len; | ||
832 | ret = e_snprintf(file, 32, "@%s", tmp + 1); | ||
333 | if (ret <= 0) | 833 | if (ret <= 0) |
334 | goto error; | 834 | goto error; |
335 | } | 835 | } |
336 | 836 | ||
337 | if (pp->function) | 837 | if (pp->function) |
338 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s", pp->function, | 838 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function, |
339 | offs, pp->retprobe ? "%return" : "", line); | 839 | offs, pp->retprobe ? "%return" : "", line, |
840 | file); | ||
340 | else | 841 | else |
341 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line); | 842 | ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line); |
342 | if (ret <= 0) { | 843 | if (ret <= 0) |
844 | goto error; | ||
845 | |||
846 | return buf; | ||
343 | error: | 847 | error: |
344 | free(pp->probes[0]); | 848 | pr_debug("Failed to synthesize perf probe point: %s", |
345 | pp->probes[0] = NULL; | 849 | strerror(-ret)); |
346 | pp->found = 0; | 850 | if (buf) |
347 | } | 851 | free(buf); |
348 | return ret; | 852 | return NULL; |
349 | } | 853 | } |
350 | 854 | ||
351 | int synthesize_perf_probe_event(struct probe_point *pp) | 855 | #if 0 |
856 | char *synthesize_perf_probe_command(struct perf_probe_event *pev) | ||
352 | { | 857 | { |
353 | char *buf; | 858 | char *buf; |
354 | int i, len, ret; | 859 | int i, len, ret; |
355 | 860 | ||
356 | len = synthesize_perf_probe_point(pp); | 861 | buf = synthesize_perf_probe_point(&pev->point); |
357 | if (len < 0) | 862 | if (!buf) |
358 | return 0; | 863 | return NULL; |
359 | 864 | ||
360 | buf = pp->probes[0]; | 865 | len = strlen(buf); |
361 | for (i = 0; i < pp->nr_args; i++) { | 866 | for (i = 0; i < pev->nargs; i++) { |
362 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", | 867 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", |
363 | pp->args[i]); | 868 | pev->args[i].name); |
364 | if (ret <= 0) | 869 | if (ret <= 0) { |
365 | goto error; | 870 | free(buf); |
871 | return NULL; | ||
872 | } | ||
366 | len += ret; | 873 | len += ret; |
367 | } | 874 | } |
368 | pp->found = 1; | ||
369 | 875 | ||
370 | return pp->found; | 876 | return buf; |
371 | error: | 877 | } |
372 | free(pp->probes[0]); | 878 | #endif |
373 | pp->probes[0] = NULL; | 879 | |
880 | static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref, | ||
881 | char **buf, size_t *buflen, | ||
882 | int depth) | ||
883 | { | ||
884 | int ret; | ||
885 | if (ref->next) { | ||
886 | depth = __synthesize_kprobe_trace_arg_ref(ref->next, buf, | ||
887 | buflen, depth + 1); | ||
888 | if (depth < 0) | ||
889 | goto out; | ||
890 | } | ||
891 | |||
892 | ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset); | ||
893 | if (ret < 0) | ||
894 | depth = ret; | ||
895 | else { | ||
896 | *buf += ret; | ||
897 | *buflen -= ret; | ||
898 | } | ||
899 | out: | ||
900 | return depth; | ||
374 | 901 | ||
375 | return ret; | ||
376 | } | 902 | } |
377 | 903 | ||
378 | int synthesize_trace_kprobe_event(struct probe_point *pp) | 904 | static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg, |
905 | char *buf, size_t buflen) | ||
379 | { | 906 | { |
907 | int ret, depth = 0; | ||
908 | char *tmp = buf; | ||
909 | |||
910 | /* Argument name or separator */ | ||
911 | if (arg->name) | ||
912 | ret = e_snprintf(buf, buflen, " %s=", arg->name); | ||
913 | else | ||
914 | ret = e_snprintf(buf, buflen, " "); | ||
915 | if (ret < 0) | ||
916 | return ret; | ||
917 | buf += ret; | ||
918 | buflen -= ret; | ||
919 | |||
920 | /* Dereferencing arguments */ | ||
921 | if (arg->ref) { | ||
922 | depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf, | ||
923 | &buflen, 1); | ||
924 | if (depth < 0) | ||
925 | return depth; | ||
926 | } | ||
927 | |||
928 | /* Print argument value */ | ||
929 | ret = e_snprintf(buf, buflen, "%s", arg->value); | ||
930 | if (ret < 0) | ||
931 | return ret; | ||
932 | buf += ret; | ||
933 | buflen -= ret; | ||
934 | |||
935 | /* Closing */ | ||
936 | while (depth--) { | ||
937 | ret = e_snprintf(buf, buflen, ")"); | ||
938 | if (ret < 0) | ||
939 | return ret; | ||
940 | buf += ret; | ||
941 | buflen -= ret; | ||
942 | } | ||
943 | /* Print argument type */ | ||
944 | if (arg->type) { | ||
945 | ret = e_snprintf(buf, buflen, ":%s", arg->type); | ||
946 | if (ret <= 0) | ||
947 | return ret; | ||
948 | buf += ret; | ||
949 | } | ||
950 | |||
951 | return buf - tmp; | ||
952 | } | ||
953 | |||
954 | char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev) | ||
955 | { | ||
956 | struct kprobe_trace_point *tp = &tev->point; | ||
380 | char *buf; | 957 | char *buf; |
381 | int i, len, ret; | 958 | int i, len, ret; |
382 | 959 | ||
383 | pp->probes[0] = buf = zalloc(MAX_CMDLEN); | 960 | buf = zalloc(MAX_CMDLEN); |
384 | if (!buf) | 961 | if (buf == NULL) |
385 | die("Failed to allocate memory by zalloc."); | 962 | return NULL; |
386 | ret = e_snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); | 963 | |
387 | if (ret <= 0) | 964 | len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu", |
965 | tp->retprobe ? 'r' : 'p', | ||
966 | tev->group, tev->event, | ||
967 | tp->symbol, tp->offset); | ||
968 | if (len <= 0) | ||
388 | goto error; | 969 | goto error; |
389 | len = ret; | ||
390 | 970 | ||
391 | for (i = 0; i < pp->nr_args; i++) { | 971 | for (i = 0; i < tev->nargs; i++) { |
392 | ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s", | 972 | ret = synthesize_kprobe_trace_arg(&tev->args[i], buf + len, |
393 | pp->args[i]); | 973 | MAX_CMDLEN - len); |
394 | if (ret <= 0) | 974 | if (ret <= 0) |
395 | goto error; | 975 | goto error; |
396 | len += ret; | 976 | len += ret; |
397 | } | 977 | } |
398 | pp->found = 1; | ||
399 | 978 | ||
400 | return pp->found; | 979 | return buf; |
401 | error: | 980 | error: |
402 | free(pp->probes[0]); | 981 | free(buf); |
403 | pp->probes[0] = NULL; | 982 | return NULL; |
983 | } | ||
984 | |||
985 | int convert_to_perf_probe_event(struct kprobe_trace_event *tev, | ||
986 | struct perf_probe_event *pev) | ||
987 | { | ||
988 | char buf[64] = ""; | ||
989 | int i, ret; | ||
990 | |||
991 | /* Convert event/group name */ | ||
992 | pev->event = strdup(tev->event); | ||
993 | pev->group = strdup(tev->group); | ||
994 | if (pev->event == NULL || pev->group == NULL) | ||
995 | return -ENOMEM; | ||
996 | |||
997 | /* Convert trace_point to probe_point */ | ||
998 | ret = convert_to_perf_probe_point(&tev->point, &pev->point); | ||
999 | if (ret < 0) | ||
1000 | return ret; | ||
1001 | |||
1002 | /* Convert trace_arg to probe_arg */ | ||
1003 | pev->nargs = tev->nargs; | ||
1004 | pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs); | ||
1005 | if (pev->args == NULL) | ||
1006 | return -ENOMEM; | ||
1007 | for (i = 0; i < tev->nargs && ret >= 0; i++) { | ||
1008 | if (tev->args[i].name) | ||
1009 | pev->args[i].name = strdup(tev->args[i].name); | ||
1010 | else { | ||
1011 | ret = synthesize_kprobe_trace_arg(&tev->args[i], | ||
1012 | buf, 64); | ||
1013 | pev->args[i].name = strdup(buf); | ||
1014 | } | ||
1015 | if (pev->args[i].name == NULL && ret >= 0) | ||
1016 | ret = -ENOMEM; | ||
1017 | } | ||
1018 | |||
1019 | if (ret < 0) | ||
1020 | clear_perf_probe_event(pev); | ||
404 | 1021 | ||
405 | return ret; | 1022 | return ret; |
406 | } | 1023 | } |
407 | 1024 | ||
408 | static int open_kprobe_events(int flags, int mode) | 1025 | void clear_perf_probe_event(struct perf_probe_event *pev) |
1026 | { | ||
1027 | struct perf_probe_point *pp = &pev->point; | ||
1028 | struct perf_probe_arg_field *field, *next; | ||
1029 | int i; | ||
1030 | |||
1031 | if (pev->event) | ||
1032 | free(pev->event); | ||
1033 | if (pev->group) | ||
1034 | free(pev->group); | ||
1035 | if (pp->file) | ||
1036 | free(pp->file); | ||
1037 | if (pp->function) | ||
1038 | free(pp->function); | ||
1039 | if (pp->lazy_line) | ||
1040 | free(pp->lazy_line); | ||
1041 | for (i = 0; i < pev->nargs; i++) { | ||
1042 | if (pev->args[i].name) | ||
1043 | free(pev->args[i].name); | ||
1044 | if (pev->args[i].var) | ||
1045 | free(pev->args[i].var); | ||
1046 | if (pev->args[i].type) | ||
1047 | free(pev->args[i].type); | ||
1048 | field = pev->args[i].field; | ||
1049 | while (field) { | ||
1050 | next = field->next; | ||
1051 | if (field->name) | ||
1052 | free(field->name); | ||
1053 | free(field); | ||
1054 | field = next; | ||
1055 | } | ||
1056 | } | ||
1057 | if (pev->args) | ||
1058 | free(pev->args); | ||
1059 | memset(pev, 0, sizeof(*pev)); | ||
1060 | } | ||
1061 | |||
1062 | void clear_kprobe_trace_event(struct kprobe_trace_event *tev) | ||
1063 | { | ||
1064 | struct kprobe_trace_arg_ref *ref, *next; | ||
1065 | int i; | ||
1066 | |||
1067 | if (tev->event) | ||
1068 | free(tev->event); | ||
1069 | if (tev->group) | ||
1070 | free(tev->group); | ||
1071 | if (tev->point.symbol) | ||
1072 | free(tev->point.symbol); | ||
1073 | for (i = 0; i < tev->nargs; i++) { | ||
1074 | if (tev->args[i].name) | ||
1075 | free(tev->args[i].name); | ||
1076 | if (tev->args[i].value) | ||
1077 | free(tev->args[i].value); | ||
1078 | if (tev->args[i].type) | ||
1079 | free(tev->args[i].type); | ||
1080 | ref = tev->args[i].ref; | ||
1081 | while (ref) { | ||
1082 | next = ref->next; | ||
1083 | free(ref); | ||
1084 | ref = next; | ||
1085 | } | ||
1086 | } | ||
1087 | if (tev->args) | ||
1088 | free(tev->args); | ||
1089 | memset(tev, 0, sizeof(*tev)); | ||
1090 | } | ||
1091 | |||
1092 | static int open_kprobe_events(bool readwrite) | ||
409 | { | 1093 | { |
410 | char buf[PATH_MAX]; | 1094 | char buf[PATH_MAX]; |
1095 | const char *__debugfs; | ||
411 | int ret; | 1096 | int ret; |
412 | 1097 | ||
413 | ret = e_snprintf(buf, PATH_MAX, "%s/../kprobe_events", debugfs_path); | 1098 | __debugfs = debugfs_find_mountpoint(); |
414 | if (ret < 0) | 1099 | if (__debugfs == NULL) { |
415 | die("Failed to make kprobe_events path."); | 1100 | pr_warning("Debugfs is not mounted.\n"); |
1101 | return -ENOENT; | ||
1102 | } | ||
1103 | |||
1104 | ret = e_snprintf(buf, PATH_MAX, "%stracing/kprobe_events", __debugfs); | ||
1105 | if (ret >= 0) { | ||
1106 | pr_debug("Opening %s write=%d\n", buf, readwrite); | ||
1107 | if (readwrite && !probe_event_dry_run) | ||
1108 | ret = open(buf, O_RDWR, O_APPEND); | ||
1109 | else | ||
1110 | ret = open(buf, O_RDONLY, 0); | ||
1111 | } | ||
416 | 1112 | ||
417 | ret = open(buf, flags, mode); | ||
418 | if (ret < 0) { | 1113 | if (ret < 0) { |
419 | if (errno == ENOENT) | 1114 | if (errno == ENOENT) |
420 | die("kprobe_events file does not exist -" | 1115 | pr_warning("kprobe_events file does not exist - please" |
421 | " please rebuild with CONFIG_KPROBE_EVENT."); | 1116 | " rebuild kernel with CONFIG_KPROBE_EVENT.\n"); |
422 | else | 1117 | else |
423 | die("Could not open kprobe_events file: %s", | 1118 | pr_warning("Failed to open kprobe_events file: %s\n", |
424 | strerror(errno)); | 1119 | strerror(errno)); |
425 | } | 1120 | } |
426 | return ret; | 1121 | return ret; |
427 | } | 1122 | } |
428 | 1123 | ||
429 | /* Get raw string list of current kprobe_events */ | 1124 | /* Get raw string list of current kprobe_events */ |
430 | static struct strlist *get_trace_kprobe_event_rawlist(int fd) | 1125 | static struct strlist *get_kprobe_trace_command_rawlist(int fd) |
431 | { | 1126 | { |
432 | int ret, idx; | 1127 | int ret, idx; |
433 | FILE *fp; | 1128 | FILE *fp; |
@@ -447,271 +1142,486 @@ static struct strlist *get_trace_kprobe_event_rawlist(int fd) | |||
447 | if (p[idx] == '\n') | 1142 | if (p[idx] == '\n') |
448 | p[idx] = '\0'; | 1143 | p[idx] = '\0'; |
449 | ret = strlist__add(sl, buf); | 1144 | ret = strlist__add(sl, buf); |
450 | if (ret < 0) | 1145 | if (ret < 0) { |
451 | die("strlist__add failed: %s", strerror(-ret)); | 1146 | pr_debug("strlist__add failed: %s\n", strerror(-ret)); |
1147 | strlist__delete(sl); | ||
1148 | return NULL; | ||
1149 | } | ||
452 | } | 1150 | } |
453 | fclose(fp); | 1151 | fclose(fp); |
454 | 1152 | ||
455 | return sl; | 1153 | return sl; |
456 | } | 1154 | } |
457 | 1155 | ||
458 | /* Free and zero clear probe_point */ | ||
459 | static void clear_probe_point(struct probe_point *pp) | ||
460 | { | ||
461 | int i; | ||
462 | |||
463 | if (pp->event) | ||
464 | free(pp->event); | ||
465 | if (pp->group) | ||
466 | free(pp->group); | ||
467 | if (pp->function) | ||
468 | free(pp->function); | ||
469 | if (pp->file) | ||
470 | free(pp->file); | ||
471 | if (pp->lazy_line) | ||
472 | free(pp->lazy_line); | ||
473 | for (i = 0; i < pp->nr_args; i++) | ||
474 | free(pp->args[i]); | ||
475 | if (pp->args) | ||
476 | free(pp->args); | ||
477 | for (i = 0; i < pp->found; i++) | ||
478 | free(pp->probes[i]); | ||
479 | memset(pp, 0, sizeof(*pp)); | ||
480 | } | ||
481 | |||
482 | /* Show an event */ | 1156 | /* Show an event */ |
483 | static void show_perf_probe_event(const char *event, const char *place, | 1157 | static int show_perf_probe_event(struct perf_probe_event *pev) |
484 | struct probe_point *pp) | ||
485 | { | 1158 | { |
486 | int i, ret; | 1159 | int i, ret; |
487 | char buf[128]; | 1160 | char buf[128]; |
1161 | char *place; | ||
1162 | |||
1163 | /* Synthesize only event probe point */ | ||
1164 | place = synthesize_perf_probe_point(&pev->point); | ||
1165 | if (!place) | ||
1166 | return -EINVAL; | ||
488 | 1167 | ||
489 | ret = e_snprintf(buf, 128, "%s:%s", pp->group, event); | 1168 | ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event); |
490 | if (ret < 0) | 1169 | if (ret < 0) |
491 | die("Failed to copy event: %s", strerror(-ret)); | 1170 | return ret; |
492 | printf(" %-40s (on %s", buf, place); | 1171 | |
1172 | printf(" %-20s (on %s", buf, place); | ||
493 | 1173 | ||
494 | if (pp->nr_args > 0) { | 1174 | if (pev->nargs > 0) { |
495 | printf(" with"); | 1175 | printf(" with"); |
496 | for (i = 0; i < pp->nr_args; i++) | 1176 | for (i = 0; i < pev->nargs; i++) { |
497 | printf(" %s", pp->args[i]); | 1177 | ret = synthesize_perf_probe_arg(&pev->args[i], |
1178 | buf, 128); | ||
1179 | if (ret < 0) | ||
1180 | break; | ||
1181 | printf(" %s", buf); | ||
1182 | } | ||
498 | } | 1183 | } |
499 | printf(")\n"); | 1184 | printf(")\n"); |
1185 | free(place); | ||
1186 | return ret; | ||
500 | } | 1187 | } |
501 | 1188 | ||
502 | /* List up current perf-probe events */ | 1189 | /* List up current perf-probe events */ |
503 | void show_perf_probe_events(void) | 1190 | int show_perf_probe_events(void) |
504 | { | 1191 | { |
505 | int fd; | 1192 | int fd, ret; |
506 | struct probe_point pp; | 1193 | struct kprobe_trace_event tev; |
1194 | struct perf_probe_event pev; | ||
507 | struct strlist *rawlist; | 1195 | struct strlist *rawlist; |
508 | struct str_node *ent; | 1196 | struct str_node *ent; |
509 | 1197 | ||
510 | setup_pager(); | 1198 | setup_pager(); |
511 | memset(&pp, 0, sizeof(pp)); | 1199 | ret = init_vmlinux(); |
1200 | if (ret < 0) | ||
1201 | return ret; | ||
1202 | |||
1203 | memset(&tev, 0, sizeof(tev)); | ||
1204 | memset(&pev, 0, sizeof(pev)); | ||
512 | 1205 | ||
513 | fd = open_kprobe_events(O_RDONLY, 0); | 1206 | fd = open_kprobe_events(false); |
514 | rawlist = get_trace_kprobe_event_rawlist(fd); | 1207 | if (fd < 0) |
1208 | return fd; | ||
1209 | |||
1210 | rawlist = get_kprobe_trace_command_rawlist(fd); | ||
515 | close(fd); | 1211 | close(fd); |
1212 | if (!rawlist) | ||
1213 | return -ENOENT; | ||
516 | 1214 | ||
517 | strlist__for_each(ent, rawlist) { | 1215 | strlist__for_each(ent, rawlist) { |
518 | parse_trace_kprobe_event(ent->s, &pp); | 1216 | ret = parse_kprobe_trace_command(ent->s, &tev); |
519 | /* Synthesize only event probe point */ | 1217 | if (ret >= 0) { |
520 | synthesize_perf_probe_point(&pp); | 1218 | ret = convert_to_perf_probe_event(&tev, &pev); |
521 | /* Show an event */ | 1219 | if (ret >= 0) |
522 | show_perf_probe_event(pp.event, pp.probes[0], &pp); | 1220 | ret = show_perf_probe_event(&pev); |
523 | clear_probe_point(&pp); | 1221 | } |
1222 | clear_perf_probe_event(&pev); | ||
1223 | clear_kprobe_trace_event(&tev); | ||
1224 | if (ret < 0) | ||
1225 | break; | ||
524 | } | 1226 | } |
525 | |||
526 | strlist__delete(rawlist); | 1227 | strlist__delete(rawlist); |
1228 | |||
1229 | return ret; | ||
527 | } | 1230 | } |
528 | 1231 | ||
529 | /* Get current perf-probe event names */ | 1232 | /* Get current perf-probe event names */ |
530 | static struct strlist *get_perf_event_names(int fd, bool include_group) | 1233 | static struct strlist *get_kprobe_trace_event_names(int fd, bool include_group) |
531 | { | 1234 | { |
532 | char buf[128]; | 1235 | char buf[128]; |
533 | struct strlist *sl, *rawlist; | 1236 | struct strlist *sl, *rawlist; |
534 | struct str_node *ent; | 1237 | struct str_node *ent; |
535 | struct probe_point pp; | 1238 | struct kprobe_trace_event tev; |
1239 | int ret = 0; | ||
536 | 1240 | ||
537 | memset(&pp, 0, sizeof(pp)); | 1241 | memset(&tev, 0, sizeof(tev)); |
538 | rawlist = get_trace_kprobe_event_rawlist(fd); | ||
539 | 1242 | ||
1243 | rawlist = get_kprobe_trace_command_rawlist(fd); | ||
540 | sl = strlist__new(true, NULL); | 1244 | sl = strlist__new(true, NULL); |
541 | strlist__for_each(ent, rawlist) { | 1245 | strlist__for_each(ent, rawlist) { |
542 | parse_trace_kprobe_event(ent->s, &pp); | 1246 | ret = parse_kprobe_trace_command(ent->s, &tev); |
1247 | if (ret < 0) | ||
1248 | break; | ||
543 | if (include_group) { | 1249 | if (include_group) { |
544 | if (e_snprintf(buf, 128, "%s:%s", pp.group, | 1250 | ret = e_snprintf(buf, 128, "%s:%s", tev.group, |
545 | pp.event) < 0) | 1251 | tev.event); |
546 | die("Failed to copy group:event name."); | 1252 | if (ret >= 0) |
547 | strlist__add(sl, buf); | 1253 | ret = strlist__add(sl, buf); |
548 | } else | 1254 | } else |
549 | strlist__add(sl, pp.event); | 1255 | ret = strlist__add(sl, tev.event); |
550 | clear_probe_point(&pp); | 1256 | clear_kprobe_trace_event(&tev); |
1257 | if (ret < 0) | ||
1258 | break; | ||
551 | } | 1259 | } |
552 | |||
553 | strlist__delete(rawlist); | 1260 | strlist__delete(rawlist); |
554 | 1261 | ||
1262 | if (ret < 0) { | ||
1263 | strlist__delete(sl); | ||
1264 | return NULL; | ||
1265 | } | ||
555 | return sl; | 1266 | return sl; |
556 | } | 1267 | } |
557 | 1268 | ||
558 | static void write_trace_kprobe_event(int fd, const char *buf) | 1269 | static int write_kprobe_trace_event(int fd, struct kprobe_trace_event *tev) |
559 | { | 1270 | { |
560 | int ret; | 1271 | int ret = 0; |
1272 | char *buf = synthesize_kprobe_trace_command(tev); | ||
1273 | |||
1274 | if (!buf) { | ||
1275 | pr_debug("Failed to synthesize kprobe trace event.\n"); | ||
1276 | return -EINVAL; | ||
1277 | } | ||
561 | 1278 | ||
562 | pr_debug("Writing event: %s\n", buf); | 1279 | pr_debug("Writing event: %s\n", buf); |
563 | ret = write(fd, buf, strlen(buf)); | 1280 | if (!probe_event_dry_run) { |
564 | if (ret <= 0) | 1281 | ret = write(fd, buf, strlen(buf)); |
565 | die("Failed to write event: %s", strerror(errno)); | 1282 | if (ret <= 0) |
1283 | pr_warning("Failed to write event: %s\n", | ||
1284 | strerror(errno)); | ||
1285 | } | ||
1286 | free(buf); | ||
1287 | return ret; | ||
566 | } | 1288 | } |
567 | 1289 | ||
568 | static void get_new_event_name(char *buf, size_t len, const char *base, | 1290 | static int get_new_event_name(char *buf, size_t len, const char *base, |
569 | struct strlist *namelist, bool allow_suffix) | 1291 | struct strlist *namelist, bool allow_suffix) |
570 | { | 1292 | { |
571 | int i, ret; | 1293 | int i, ret; |
572 | 1294 | ||
573 | /* Try no suffix */ | 1295 | /* Try no suffix */ |
574 | ret = e_snprintf(buf, len, "%s", base); | 1296 | ret = e_snprintf(buf, len, "%s", base); |
575 | if (ret < 0) | 1297 | if (ret < 0) { |
576 | die("snprintf() failed: %s", strerror(-ret)); | 1298 | pr_debug("snprintf() failed: %s\n", strerror(-ret)); |
1299 | return ret; | ||
1300 | } | ||
577 | if (!strlist__has_entry(namelist, buf)) | 1301 | if (!strlist__has_entry(namelist, buf)) |
578 | return; | 1302 | return 0; |
579 | 1303 | ||
580 | if (!allow_suffix) { | 1304 | if (!allow_suffix) { |
581 | pr_warning("Error: event \"%s\" already exists. " | 1305 | pr_warning("Error: event \"%s\" already exists. " |
582 | "(Use -f to force duplicates.)\n", base); | 1306 | "(Use -f to force duplicates.)\n", base); |
583 | die("Can't add new event."); | 1307 | return -EEXIST; |
584 | } | 1308 | } |
585 | 1309 | ||
586 | /* Try to add suffix */ | 1310 | /* Try to add suffix */ |
587 | for (i = 1; i < MAX_EVENT_INDEX; i++) { | 1311 | for (i = 1; i < MAX_EVENT_INDEX; i++) { |
588 | ret = e_snprintf(buf, len, "%s_%d", base, i); | 1312 | ret = e_snprintf(buf, len, "%s_%d", base, i); |
589 | if (ret < 0) | 1313 | if (ret < 0) { |
590 | die("snprintf() failed: %s", strerror(-ret)); | 1314 | pr_debug("snprintf() failed: %s\n", strerror(-ret)); |
1315 | return ret; | ||
1316 | } | ||
591 | if (!strlist__has_entry(namelist, buf)) | 1317 | if (!strlist__has_entry(namelist, buf)) |
592 | break; | 1318 | break; |
593 | } | 1319 | } |
594 | if (i == MAX_EVENT_INDEX) | 1320 | if (i == MAX_EVENT_INDEX) { |
595 | die("Too many events are on the same function."); | 1321 | pr_warning("Too many events are on the same function.\n"); |
1322 | ret = -ERANGE; | ||
1323 | } | ||
1324 | |||
1325 | return ret; | ||
596 | } | 1326 | } |
597 | 1327 | ||
598 | void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, | 1328 | static int __add_kprobe_trace_events(struct perf_probe_event *pev, |
599 | bool force_add) | 1329 | struct kprobe_trace_event *tevs, |
1330 | int ntevs, bool allow_suffix) | ||
600 | { | 1331 | { |
601 | int i, j, fd; | 1332 | int i, fd, ret; |
602 | struct probe_point *pp; | 1333 | struct kprobe_trace_event *tev = NULL; |
603 | char buf[MAX_CMDLEN]; | 1334 | char buf[64]; |
604 | char event[64]; | 1335 | const char *event, *group; |
605 | struct strlist *namelist; | 1336 | struct strlist *namelist; |
606 | bool allow_suffix; | ||
607 | 1337 | ||
608 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 1338 | fd = open_kprobe_events(true); |
1339 | if (fd < 0) | ||
1340 | return fd; | ||
609 | /* Get current event names */ | 1341 | /* Get current event names */ |
610 | namelist = get_perf_event_names(fd, false); | 1342 | namelist = get_kprobe_trace_event_names(fd, false); |
611 | 1343 | if (!namelist) { | |
612 | for (j = 0; j < nr_probes; j++) { | 1344 | pr_debug("Failed to get current event list.\n"); |
613 | pp = probes + j; | 1345 | return -EIO; |
614 | if (!pp->event) | 1346 | } |
615 | pp->event = strdup(pp->function); | 1347 | |
616 | if (!pp->group) | 1348 | ret = 0; |
617 | pp->group = strdup(PERFPROBE_GROUP); | 1349 | printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":"); |
618 | DIE_IF(!pp->event || !pp->group); | 1350 | for (i = 0; i < ntevs; i++) { |
619 | /* If force_add is true, suffix search is allowed */ | 1351 | tev = &tevs[i]; |
620 | allow_suffix = force_add; | 1352 | if (pev->event) |
621 | for (i = 0; i < pp->found; i++) { | 1353 | event = pev->event; |
622 | /* Get an unused new event name */ | 1354 | else |
623 | get_new_event_name(event, 64, pp->event, namelist, | 1355 | if (pev->point.function) |
624 | allow_suffix); | 1356 | event = pev->point.function; |
625 | snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n", | 1357 | else |
626 | pp->retprobe ? 'r' : 'p', | 1358 | event = tev->point.symbol; |
627 | pp->group, event, | 1359 | if (pev->group) |
628 | pp->probes[i]); | 1360 | group = pev->group; |
629 | write_trace_kprobe_event(fd, buf); | 1361 | else |
630 | printf("Added new event:\n"); | 1362 | group = PERFPROBE_GROUP; |
631 | /* Get the first parameter (probe-point) */ | 1363 | |
632 | sscanf(pp->probes[i], "%s", buf); | 1364 | /* Get an unused new event name */ |
633 | show_perf_probe_event(event, buf, pp); | 1365 | ret = get_new_event_name(buf, 64, event, |
634 | /* Add added event name to namelist */ | 1366 | namelist, allow_suffix); |
635 | strlist__add(namelist, event); | 1367 | if (ret < 0) |
636 | /* | 1368 | break; |
637 | * Probes after the first probe which comes from same | 1369 | event = buf; |
638 | * user input are always allowed to add suffix, because | 1370 | |
639 | * there might be several addresses corresponding to | 1371 | tev->event = strdup(event); |
640 | * one code line. | 1372 | tev->group = strdup(group); |
641 | */ | 1373 | if (tev->event == NULL || tev->group == NULL) { |
642 | allow_suffix = true; | 1374 | ret = -ENOMEM; |
1375 | break; | ||
643 | } | 1376 | } |
1377 | ret = write_kprobe_trace_event(fd, tev); | ||
1378 | if (ret < 0) | ||
1379 | break; | ||
1380 | /* Add added event name to namelist */ | ||
1381 | strlist__add(namelist, event); | ||
1382 | |||
1383 | /* Trick here - save current event/group */ | ||
1384 | event = pev->event; | ||
1385 | group = pev->group; | ||
1386 | pev->event = tev->event; | ||
1387 | pev->group = tev->group; | ||
1388 | show_perf_probe_event(pev); | ||
1389 | /* Trick here - restore current event/group */ | ||
1390 | pev->event = (char *)event; | ||
1391 | pev->group = (char *)group; | ||
1392 | |||
1393 | /* | ||
1394 | * Probes after the first probe which comes from same | ||
1395 | * user input are always allowed to add suffix, because | ||
1396 | * there might be several addresses corresponding to | ||
1397 | * one code line. | ||
1398 | */ | ||
1399 | allow_suffix = true; | ||
1400 | } | ||
1401 | |||
1402 | if (ret >= 0) { | ||
1403 | /* Show how to use the event. */ | ||
1404 | printf("\nYou can now use it on all perf tools, such as:\n\n"); | ||
1405 | printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group, | ||
1406 | tev->event); | ||
644 | } | 1407 | } |
645 | /* Show how to use the event. */ | ||
646 | printf("\nYou can now use it on all perf tools, such as:\n\n"); | ||
647 | printf("\tperf record -e %s:%s -a sleep 1\n\n", PERFPROBE_GROUP, event); | ||
648 | 1408 | ||
649 | strlist__delete(namelist); | 1409 | strlist__delete(namelist); |
650 | close(fd); | 1410 | close(fd); |
1411 | return ret; | ||
1412 | } | ||
1413 | |||
1414 | static int convert_to_kprobe_trace_events(struct perf_probe_event *pev, | ||
1415 | struct kprobe_trace_event **tevs, | ||
1416 | int max_tevs) | ||
1417 | { | ||
1418 | struct symbol *sym; | ||
1419 | int ret = 0, i; | ||
1420 | struct kprobe_trace_event *tev; | ||
1421 | |||
1422 | /* Convert perf_probe_event with debuginfo */ | ||
1423 | ret = try_to_find_kprobe_trace_events(pev, tevs, max_tevs); | ||
1424 | if (ret != 0) | ||
1425 | return ret; | ||
1426 | |||
1427 | /* Allocate trace event buffer */ | ||
1428 | tev = *tevs = zalloc(sizeof(struct kprobe_trace_event)); | ||
1429 | if (tev == NULL) | ||
1430 | return -ENOMEM; | ||
1431 | |||
1432 | /* Copy parameters */ | ||
1433 | tev->point.symbol = strdup(pev->point.function); | ||
1434 | if (tev->point.symbol == NULL) { | ||
1435 | ret = -ENOMEM; | ||
1436 | goto error; | ||
1437 | } | ||
1438 | tev->point.offset = pev->point.offset; | ||
1439 | tev->nargs = pev->nargs; | ||
1440 | if (tev->nargs) { | ||
1441 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) | ||
1442 | * tev->nargs); | ||
1443 | if (tev->args == NULL) { | ||
1444 | ret = -ENOMEM; | ||
1445 | goto error; | ||
1446 | } | ||
1447 | for (i = 0; i < tev->nargs; i++) { | ||
1448 | if (pev->args[i].name) { | ||
1449 | tev->args[i].name = strdup(pev->args[i].name); | ||
1450 | if (tev->args[i].name == NULL) { | ||
1451 | ret = -ENOMEM; | ||
1452 | goto error; | ||
1453 | } | ||
1454 | } | ||
1455 | tev->args[i].value = strdup(pev->args[i].var); | ||
1456 | if (tev->args[i].value == NULL) { | ||
1457 | ret = -ENOMEM; | ||
1458 | goto error; | ||
1459 | } | ||
1460 | if (pev->args[i].type) { | ||
1461 | tev->args[i].type = strdup(pev->args[i].type); | ||
1462 | if (tev->args[i].type == NULL) { | ||
1463 | ret = -ENOMEM; | ||
1464 | goto error; | ||
1465 | } | ||
1466 | } | ||
1467 | } | ||
1468 | } | ||
1469 | |||
1470 | /* Currently just checking function name from symbol map */ | ||
1471 | sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION], | ||
1472 | tev->point.symbol, NULL); | ||
1473 | if (!sym) { | ||
1474 | pr_warning("Kernel symbol \'%s\' not found.\n", | ||
1475 | tev->point.symbol); | ||
1476 | ret = -ENOENT; | ||
1477 | goto error; | ||
1478 | } | ||
1479 | |||
1480 | return 1; | ||
1481 | error: | ||
1482 | clear_kprobe_trace_event(tev); | ||
1483 | free(tev); | ||
1484 | *tevs = NULL; | ||
1485 | return ret; | ||
1486 | } | ||
1487 | |||
1488 | struct __event_package { | ||
1489 | struct perf_probe_event *pev; | ||
1490 | struct kprobe_trace_event *tevs; | ||
1491 | int ntevs; | ||
1492 | }; | ||
1493 | |||
1494 | int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | ||
1495 | bool force_add, int max_tevs) | ||
1496 | { | ||
1497 | int i, j, ret; | ||
1498 | struct __event_package *pkgs; | ||
1499 | |||
1500 | pkgs = zalloc(sizeof(struct __event_package) * npevs); | ||
1501 | if (pkgs == NULL) | ||
1502 | return -ENOMEM; | ||
1503 | |||
1504 | /* Init vmlinux path */ | ||
1505 | ret = init_vmlinux(); | ||
1506 | if (ret < 0) | ||
1507 | return ret; | ||
1508 | |||
1509 | /* Loop 1: convert all events */ | ||
1510 | for (i = 0; i < npevs; i++) { | ||
1511 | pkgs[i].pev = &pevs[i]; | ||
1512 | /* Convert with or without debuginfo */ | ||
1513 | ret = convert_to_kprobe_trace_events(pkgs[i].pev, | ||
1514 | &pkgs[i].tevs, max_tevs); | ||
1515 | if (ret < 0) | ||
1516 | goto end; | ||
1517 | pkgs[i].ntevs = ret; | ||
1518 | } | ||
1519 | |||
1520 | /* Loop 2: add all events */ | ||
1521 | for (i = 0; i < npevs && ret >= 0; i++) | ||
1522 | ret = __add_kprobe_trace_events(pkgs[i].pev, pkgs[i].tevs, | ||
1523 | pkgs[i].ntevs, force_add); | ||
1524 | end: | ||
1525 | /* Loop 3: cleanup trace events */ | ||
1526 | for (i = 0; i < npevs; i++) | ||
1527 | for (j = 0; j < pkgs[i].ntevs; j++) | ||
1528 | clear_kprobe_trace_event(&pkgs[i].tevs[j]); | ||
1529 | |||
1530 | return ret; | ||
651 | } | 1531 | } |
652 | 1532 | ||
653 | static void __del_trace_kprobe_event(int fd, struct str_node *ent) | 1533 | static int __del_trace_kprobe_event(int fd, struct str_node *ent) |
654 | { | 1534 | { |
655 | char *p; | 1535 | char *p; |
656 | char buf[128]; | 1536 | char buf[128]; |
1537 | int ret; | ||
657 | 1538 | ||
658 | /* Convert from perf-probe event to trace-kprobe event */ | 1539 | /* Convert from perf-probe event to trace-kprobe event */ |
659 | if (e_snprintf(buf, 128, "-:%s", ent->s) < 0) | 1540 | ret = e_snprintf(buf, 128, "-:%s", ent->s); |
660 | die("Failed to copy event."); | 1541 | if (ret < 0) |
1542 | goto error; | ||
1543 | |||
661 | p = strchr(buf + 2, ':'); | 1544 | p = strchr(buf + 2, ':'); |
662 | if (!p) | 1545 | if (!p) { |
663 | die("Internal error: %s should have ':' but not.", ent->s); | 1546 | pr_debug("Internal error: %s should have ':' but not.\n", |
1547 | ent->s); | ||
1548 | ret = -ENOTSUP; | ||
1549 | goto error; | ||
1550 | } | ||
664 | *p = '/'; | 1551 | *p = '/'; |
665 | 1552 | ||
666 | write_trace_kprobe_event(fd, buf); | 1553 | pr_debug("Writing event: %s\n", buf); |
1554 | ret = write(fd, buf, strlen(buf)); | ||
1555 | if (ret < 0) | ||
1556 | goto error; | ||
1557 | |||
667 | printf("Remove event: %s\n", ent->s); | 1558 | printf("Remove event: %s\n", ent->s); |
1559 | return 0; | ||
1560 | error: | ||
1561 | pr_warning("Failed to delete event: %s\n", strerror(-ret)); | ||
1562 | return ret; | ||
668 | } | 1563 | } |
669 | 1564 | ||
670 | static void del_trace_kprobe_event(int fd, const char *group, | 1565 | static int del_trace_kprobe_event(int fd, const char *group, |
671 | const char *event, struct strlist *namelist) | 1566 | const char *event, struct strlist *namelist) |
672 | { | 1567 | { |
673 | char buf[128]; | 1568 | char buf[128]; |
674 | struct str_node *ent, *n; | 1569 | struct str_node *ent, *n; |
675 | int found = 0; | 1570 | int found = 0, ret = 0; |
676 | 1571 | ||
677 | if (e_snprintf(buf, 128, "%s:%s", group, event) < 0) | 1572 | ret = e_snprintf(buf, 128, "%s:%s", group, event); |
678 | die("Failed to copy event."); | 1573 | if (ret < 0) { |
1574 | pr_err("Failed to copy event."); | ||
1575 | return ret; | ||
1576 | } | ||
679 | 1577 | ||
680 | if (strpbrk(buf, "*?")) { /* Glob-exp */ | 1578 | if (strpbrk(buf, "*?")) { /* Glob-exp */ |
681 | strlist__for_each_safe(ent, n, namelist) | 1579 | strlist__for_each_safe(ent, n, namelist) |
682 | if (strglobmatch(ent->s, buf)) { | 1580 | if (strglobmatch(ent->s, buf)) { |
683 | found++; | 1581 | found++; |
684 | __del_trace_kprobe_event(fd, ent); | 1582 | ret = __del_trace_kprobe_event(fd, ent); |
1583 | if (ret < 0) | ||
1584 | break; | ||
685 | strlist__remove(namelist, ent); | 1585 | strlist__remove(namelist, ent); |
686 | } | 1586 | } |
687 | } else { | 1587 | } else { |
688 | ent = strlist__find(namelist, buf); | 1588 | ent = strlist__find(namelist, buf); |
689 | if (ent) { | 1589 | if (ent) { |
690 | found++; | 1590 | found++; |
691 | __del_trace_kprobe_event(fd, ent); | 1591 | ret = __del_trace_kprobe_event(fd, ent); |
692 | strlist__remove(namelist, ent); | 1592 | if (ret >= 0) |
1593 | strlist__remove(namelist, ent); | ||
693 | } | 1594 | } |
694 | } | 1595 | } |
695 | if (found == 0) | 1596 | if (found == 0 && ret >= 0) |
696 | pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf); | 1597 | pr_info("Info: Event \"%s\" does not exist.\n", buf); |
1598 | |||
1599 | return ret; | ||
697 | } | 1600 | } |
698 | 1601 | ||
699 | void del_trace_kprobe_events(struct strlist *dellist) | 1602 | int del_perf_probe_events(struct strlist *dellist) |
700 | { | 1603 | { |
701 | int fd; | 1604 | int fd, ret = 0; |
702 | const char *group, *event; | 1605 | const char *group, *event; |
703 | char *p, *str; | 1606 | char *p, *str; |
704 | struct str_node *ent; | 1607 | struct str_node *ent; |
705 | struct strlist *namelist; | 1608 | struct strlist *namelist; |
706 | 1609 | ||
707 | fd = open_kprobe_events(O_RDWR, O_APPEND); | 1610 | fd = open_kprobe_events(true); |
1611 | if (fd < 0) | ||
1612 | return fd; | ||
1613 | |||
708 | /* Get current event names */ | 1614 | /* Get current event names */ |
709 | namelist = get_perf_event_names(fd, true); | 1615 | namelist = get_kprobe_trace_event_names(fd, true); |
1616 | if (namelist == NULL) | ||
1617 | return -EINVAL; | ||
710 | 1618 | ||
711 | strlist__for_each(ent, dellist) { | 1619 | strlist__for_each(ent, dellist) { |
712 | str = strdup(ent->s); | 1620 | str = strdup(ent->s); |
713 | if (!str) | 1621 | if (str == NULL) { |
714 | die("Failed to copy event."); | 1622 | ret = -ENOMEM; |
1623 | break; | ||
1624 | } | ||
715 | pr_debug("Parsing: %s\n", str); | 1625 | pr_debug("Parsing: %s\n", str); |
716 | p = strchr(str, ':'); | 1626 | p = strchr(str, ':'); |
717 | if (p) { | 1627 | if (p) { |
@@ -723,80 +1633,14 @@ void del_trace_kprobe_events(struct strlist *dellist) | |||
723 | event = str; | 1633 | event = str; |
724 | } | 1634 | } |
725 | pr_debug("Group: %s, Event: %s\n", group, event); | 1635 | pr_debug("Group: %s, Event: %s\n", group, event); |
726 | del_trace_kprobe_event(fd, group, event, namelist); | 1636 | ret = del_trace_kprobe_event(fd, group, event, namelist); |
727 | free(str); | 1637 | free(str); |
1638 | if (ret < 0) | ||
1639 | break; | ||
728 | } | 1640 | } |
729 | strlist__delete(namelist); | 1641 | strlist__delete(namelist); |
730 | close(fd); | 1642 | close(fd); |
731 | } | ||
732 | 1643 | ||
733 | #define LINEBUF_SIZE 256 | 1644 | return ret; |
734 | #define NR_ADDITIONAL_LINES 2 | ||
735 | |||
736 | static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num) | ||
737 | { | ||
738 | char buf[LINEBUF_SIZE]; | ||
739 | const char *color = PERF_COLOR_BLUE; | ||
740 | |||
741 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
742 | goto error; | ||
743 | if (!skip) { | ||
744 | if (show_num) | ||
745 | fprintf(stdout, "%7u %s", l, buf); | ||
746 | else | ||
747 | color_fprintf(stdout, color, " %s", buf); | ||
748 | } | ||
749 | |||
750 | while (strlen(buf) == LINEBUF_SIZE - 1 && | ||
751 | buf[LINEBUF_SIZE - 2] != '\n') { | ||
752 | if (fgets(buf, LINEBUF_SIZE, fp) == NULL) | ||
753 | goto error; | ||
754 | if (!skip) { | ||
755 | if (show_num) | ||
756 | fprintf(stdout, "%s", buf); | ||
757 | else | ||
758 | color_fprintf(stdout, color, "%s", buf); | ||
759 | } | ||
760 | } | ||
761 | return; | ||
762 | error: | ||
763 | if (feof(fp)) | ||
764 | die("Source file is shorter than expected."); | ||
765 | else | ||
766 | die("File read error: %s", strerror(errno)); | ||
767 | } | 1645 | } |
768 | 1646 | ||
769 | void show_line_range(struct line_range *lr) | ||
770 | { | ||
771 | unsigned int l = 1; | ||
772 | struct line_node *ln; | ||
773 | FILE *fp; | ||
774 | |||
775 | setup_pager(); | ||
776 | |||
777 | if (lr->function) | ||
778 | fprintf(stdout, "<%s:%d>\n", lr->function, | ||
779 | lr->start - lr->offset); | ||
780 | else | ||
781 | fprintf(stdout, "<%s:%d>\n", lr->file, lr->start); | ||
782 | |||
783 | fp = fopen(lr->path, "r"); | ||
784 | if (fp == NULL) | ||
785 | die("Failed to open %s: %s", lr->path, strerror(errno)); | ||
786 | /* Skip to starting line number */ | ||
787 | while (l < lr->start) | ||
788 | show_one_line(fp, l++, true, false); | ||
789 | |||
790 | list_for_each_entry(ln, &lr->line_list, list) { | ||
791 | while (ln->line > l) | ||
792 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
793 | show_one_line(fp, (l++) - lr->offset, false, true); | ||
794 | } | ||
795 | |||
796 | if (lr->end == INT_MAX) | ||
797 | lr->end = l + NR_ADDITIONAL_LINES; | ||
798 | while (l < lr->end && !feof(fp)) | ||
799 | show_one_line(fp, (l++) - lr->offset, false, false); | ||
800 | |||
801 | fclose(fp); | ||
802 | } | ||
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h index 711287d4baea..e9db1a214ca4 100644 --- a/tools/perf/util/probe-event.h +++ b/tools/perf/util/probe-event.h | |||
@@ -2,21 +2,125 @@ | |||
2 | #define _PROBE_EVENT_H | 2 | #define _PROBE_EVENT_H |
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "probe-finder.h" | ||
6 | #include "strlist.h" | 5 | #include "strlist.h" |
7 | 6 | ||
8 | extern void parse_line_range_desc(const char *arg, struct line_range *lr); | 7 | extern bool probe_event_dry_run; |
9 | extern void parse_perf_probe_event(const char *str, struct probe_point *pp, | 8 | |
10 | bool *need_dwarf); | 9 | /* kprobe-tracer tracing point */ |
11 | extern int synthesize_perf_probe_point(struct probe_point *pp); | 10 | struct kprobe_trace_point { |
12 | extern int synthesize_perf_probe_event(struct probe_point *pp); | 11 | char *symbol; /* Base symbol */ |
13 | extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp); | 12 | unsigned long offset; /* Offset from symbol */ |
14 | extern int synthesize_trace_kprobe_event(struct probe_point *pp); | 13 | bool retprobe; /* Return probe flag */ |
15 | extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes, | 14 | }; |
16 | bool force_add); | 15 | |
17 | extern void del_trace_kprobe_events(struct strlist *dellist); | 16 | /* kprobe-tracer tracing argument referencing offset */ |
18 | extern void show_perf_probe_events(void); | 17 | struct kprobe_trace_arg_ref { |
19 | extern void show_line_range(struct line_range *lr); | 18 | struct kprobe_trace_arg_ref *next; /* Next reference */ |
19 | long offset; /* Offset value */ | ||
20 | }; | ||
21 | |||
22 | /* kprobe-tracer tracing argument */ | ||
23 | struct kprobe_trace_arg { | ||
24 | char *name; /* Argument name */ | ||
25 | char *value; /* Base value */ | ||
26 | char *type; /* Type name */ | ||
27 | struct kprobe_trace_arg_ref *ref; /* Referencing offset */ | ||
28 | }; | ||
29 | |||
30 | /* kprobe-tracer tracing event (point + arg) */ | ||
31 | struct kprobe_trace_event { | ||
32 | char *event; /* Event name */ | ||
33 | char *group; /* Group name */ | ||
34 | struct kprobe_trace_point point; /* Trace point */ | ||
35 | int nargs; /* Number of args */ | ||
36 | struct kprobe_trace_arg *args; /* Arguments */ | ||
37 | }; | ||
38 | |||
39 | /* Perf probe probing point */ | ||
40 | struct perf_probe_point { | ||
41 | char *file; /* File path */ | ||
42 | char *function; /* Function name */ | ||
43 | int line; /* Line number */ | ||
44 | bool retprobe; /* Return probe flag */ | ||
45 | char *lazy_line; /* Lazy matching pattern */ | ||
46 | unsigned long offset; /* Offset from function entry */ | ||
47 | }; | ||
48 | |||
49 | /* Perf probe probing argument field chain */ | ||
50 | struct perf_probe_arg_field { | ||
51 | struct perf_probe_arg_field *next; /* Next field */ | ||
52 | char *name; /* Name of the field */ | ||
53 | bool ref; /* Referencing flag */ | ||
54 | }; | ||
55 | |||
56 | /* Perf probe probing argument */ | ||
57 | struct perf_probe_arg { | ||
58 | char *name; /* Argument name */ | ||
59 | char *var; /* Variable name */ | ||
60 | char *type; /* Type name */ | ||
61 | struct perf_probe_arg_field *field; /* Structure fields */ | ||
62 | }; | ||
63 | |||
64 | /* Perf probe probing event (point + arg) */ | ||
65 | struct perf_probe_event { | ||
66 | char *event; /* Event name */ | ||
67 | char *group; /* Group name */ | ||
68 | struct perf_probe_point point; /* Probe point */ | ||
69 | int nargs; /* Number of arguments */ | ||
70 | struct perf_probe_arg *args; /* Arguments */ | ||
71 | }; | ||
72 | |||
73 | |||
74 | /* Line number container */ | ||
75 | struct line_node { | ||
76 | struct list_head list; | ||
77 | int line; | ||
78 | }; | ||
79 | |||
80 | /* Line range */ | ||
81 | struct line_range { | ||
82 | char *file; /* File name */ | ||
83 | char *function; /* Function name */ | ||
84 | int start; /* Start line number */ | ||
85 | int end; /* End line number */ | ||
86 | int offset; /* Start line offset */ | ||
87 | char *path; /* Real path name */ | ||
88 | struct list_head line_list; /* Visible lines */ | ||
89 | }; | ||
90 | |||
91 | /* Command string to events */ | ||
92 | extern int parse_perf_probe_command(const char *cmd, | ||
93 | struct perf_probe_event *pev); | ||
94 | extern int parse_kprobe_trace_command(const char *cmd, | ||
95 | struct kprobe_trace_event *tev); | ||
96 | |||
97 | /* Events to command string */ | ||
98 | extern char *synthesize_perf_probe_command(struct perf_probe_event *pev); | ||
99 | extern char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev); | ||
100 | extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, | ||
101 | size_t len); | ||
102 | |||
103 | /* Check the perf_probe_event needs debuginfo */ | ||
104 | extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev); | ||
105 | |||
106 | /* Convert from kprobe_trace_event to perf_probe_event */ | ||
107 | extern int convert_to_perf_probe_event(struct kprobe_trace_event *tev, | ||
108 | struct perf_probe_event *pev); | ||
109 | |||
110 | /* Release event contents */ | ||
111 | extern void clear_perf_probe_event(struct perf_probe_event *pev); | ||
112 | extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev); | ||
113 | |||
114 | /* Command string to line-range */ | ||
115 | extern int parse_line_range_desc(const char *cmd, struct line_range *lr); | ||
116 | |||
117 | |||
118 | extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs, | ||
119 | bool force_add, int max_probe_points); | ||
120 | extern int del_perf_probe_events(struct strlist *dellist); | ||
121 | extern int show_perf_probe_events(void); | ||
122 | extern int show_line_range(struct line_range *lr); | ||
123 | |||
20 | 124 | ||
21 | /* Maximum index number of event-name postfix */ | 125 | /* Maximum index number of event-name postfix */ |
22 | #define MAX_EVENT_INDEX 1024 | 126 | #define MAX_EVENT_INDEX 1024 |
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index c171a243d05b..562b1443e785 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <stdarg.h> | 32 | #include <stdarg.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <dwarf-regs.h> | ||
34 | 35 | ||
35 | #include "string.h" | 36 | #include "string.h" |
36 | #include "event.h" | 37 | #include "event.h" |
@@ -38,57 +39,8 @@ | |||
38 | #include "util.h" | 39 | #include "util.h" |
39 | #include "probe-finder.h" | 40 | #include "probe-finder.h" |
40 | 41 | ||
41 | 42 | /* Kprobe tracer basic type is up to u64 */ | |
42 | /* | 43 | #define MAX_BASIC_TYPE_BITS 64 |
43 | * Generic dwarf analysis helpers | ||
44 | */ | ||
45 | |||
46 | #define X86_32_MAX_REGS 8 | ||
47 | const char *x86_32_regs_table[X86_32_MAX_REGS] = { | ||
48 | "%ax", | ||
49 | "%cx", | ||
50 | "%dx", | ||
51 | "%bx", | ||
52 | "$stack", /* Stack address instead of %sp */ | ||
53 | "%bp", | ||
54 | "%si", | ||
55 | "%di", | ||
56 | }; | ||
57 | |||
58 | #define X86_64_MAX_REGS 16 | ||
59 | const char *x86_64_regs_table[X86_64_MAX_REGS] = { | ||
60 | "%ax", | ||
61 | "%dx", | ||
62 | "%cx", | ||
63 | "%bx", | ||
64 | "%si", | ||
65 | "%di", | ||
66 | "%bp", | ||
67 | "%sp", | ||
68 | "%r8", | ||
69 | "%r9", | ||
70 | "%r10", | ||
71 | "%r11", | ||
72 | "%r12", | ||
73 | "%r13", | ||
74 | "%r14", | ||
75 | "%r15", | ||
76 | }; | ||
77 | |||
78 | /* TODO: switching by dwarf address size */ | ||
79 | #ifdef __x86_64__ | ||
80 | #define ARCH_MAX_REGS X86_64_MAX_REGS | ||
81 | #define arch_regs_table x86_64_regs_table | ||
82 | #else | ||
83 | #define ARCH_MAX_REGS X86_32_MAX_REGS | ||
84 | #define arch_regs_table x86_32_regs_table | ||
85 | #endif | ||
86 | |||
87 | /* Return architecture dependent register string (for kprobe-tracer) */ | ||
88 | static const char *get_arch_regstr(unsigned int n) | ||
89 | { | ||
90 | return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL; | ||
91 | } | ||
92 | 44 | ||
93 | /* | 45 | /* |
94 | * Compare the tail of two strings. | 46 | * Compare the tail of two strings. |
@@ -108,7 +60,7 @@ static int strtailcmp(const char *s1, const char *s2) | |||
108 | /* Line number list operations */ | 60 | /* Line number list operations */ |
109 | 61 | ||
110 | /* Add a line to line number list */ | 62 | /* Add a line to line number list */ |
111 | static void line_list__add_line(struct list_head *head, unsigned int line) | 63 | static int line_list__add_line(struct list_head *head, int line) |
112 | { | 64 | { |
113 | struct line_node *ln; | 65 | struct line_node *ln; |
114 | struct list_head *p; | 66 | struct list_head *p; |
@@ -119,21 +71,23 @@ static void line_list__add_line(struct list_head *head, unsigned int line) | |||
119 | p = &ln->list; | 71 | p = &ln->list; |
120 | goto found; | 72 | goto found; |
121 | } else if (ln->line == line) /* Already exist */ | 73 | } else if (ln->line == line) /* Already exist */ |
122 | return ; | 74 | return 1; |
123 | } | 75 | } |
124 | /* List is empty, or the smallest entry */ | 76 | /* List is empty, or the smallest entry */ |
125 | p = head; | 77 | p = head; |
126 | found: | 78 | found: |
127 | pr_debug("line list: add a line %u\n", line); | 79 | pr_debug("line list: add a line %u\n", line); |
128 | ln = zalloc(sizeof(struct line_node)); | 80 | ln = zalloc(sizeof(struct line_node)); |
129 | DIE_IF(ln == NULL); | 81 | if (ln == NULL) |
82 | return -ENOMEM; | ||
130 | ln->line = line; | 83 | ln->line = line; |
131 | INIT_LIST_HEAD(&ln->list); | 84 | INIT_LIST_HEAD(&ln->list); |
132 | list_add(&ln->list, p); | 85 | list_add(&ln->list, p); |
86 | return 0; | ||
133 | } | 87 | } |
134 | 88 | ||
135 | /* Check if the line in line number list */ | 89 | /* Check if the line in line number list */ |
136 | static int line_list__has_line(struct list_head *head, unsigned int line) | 90 | static int line_list__has_line(struct list_head *head, int line) |
137 | { | 91 | { |
138 | struct line_node *ln; | 92 | struct line_node *ln; |
139 | 93 | ||
@@ -184,9 +138,129 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname) | |||
184 | if (strtailcmp(src, fname) == 0) | 138 | if (strtailcmp(src, fname) == 0) |
185 | break; | 139 | break; |
186 | } | 140 | } |
141 | if (i == nfiles) | ||
142 | return NULL; | ||
187 | return src; | 143 | return src; |
188 | } | 144 | } |
189 | 145 | ||
146 | /* Compare diename and tname */ | ||
147 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | ||
148 | { | ||
149 | const char *name; | ||
150 | name = dwarf_diename(dw_die); | ||
151 | return name ? strcmp(tname, name) : -1; | ||
152 | } | ||
153 | |||
154 | /* Get type die, but skip qualifiers and typedef */ | ||
155 | static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem) | ||
156 | { | ||
157 | Dwarf_Attribute attr; | ||
158 | int tag; | ||
159 | |||
160 | do { | ||
161 | if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL || | ||
162 | dwarf_formref_die(&attr, die_mem) == NULL) | ||
163 | return NULL; | ||
164 | |||
165 | tag = dwarf_tag(die_mem); | ||
166 | vr_die = die_mem; | ||
167 | } while (tag == DW_TAG_const_type || | ||
168 | tag == DW_TAG_restrict_type || | ||
169 | tag == DW_TAG_volatile_type || | ||
170 | tag == DW_TAG_shared_type || | ||
171 | tag == DW_TAG_typedef); | ||
172 | |||
173 | return die_mem; | ||
174 | } | ||
175 | |||
176 | static bool die_is_signed_type(Dwarf_Die *tp_die) | ||
177 | { | ||
178 | Dwarf_Attribute attr; | ||
179 | Dwarf_Word ret; | ||
180 | |||
181 | if (dwarf_attr(tp_die, DW_AT_encoding, &attr) == NULL || | ||
182 | dwarf_formudata(&attr, &ret) != 0) | ||
183 | return false; | ||
184 | |||
185 | return (ret == DW_ATE_signed_char || ret == DW_ATE_signed || | ||
186 | ret == DW_ATE_signed_fixed); | ||
187 | } | ||
188 | |||
189 | static int die_get_byte_size(Dwarf_Die *tp_die) | ||
190 | { | ||
191 | Dwarf_Attribute attr; | ||
192 | Dwarf_Word ret; | ||
193 | |||
194 | if (dwarf_attr(tp_die, DW_AT_byte_size, &attr) == NULL || | ||
195 | dwarf_formudata(&attr, &ret) != 0) | ||
196 | return 0; | ||
197 | |||
198 | return (int)ret; | ||
199 | } | ||
200 | |||
201 | /* Get data_member_location offset */ | ||
202 | static int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs) | ||
203 | { | ||
204 | Dwarf_Attribute attr; | ||
205 | Dwarf_Op *expr; | ||
206 | size_t nexpr; | ||
207 | int ret; | ||
208 | |||
209 | if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL) | ||
210 | return -ENOENT; | ||
211 | |||
212 | if (dwarf_formudata(&attr, offs) != 0) { | ||
213 | /* DW_AT_data_member_location should be DW_OP_plus_uconst */ | ||
214 | ret = dwarf_getlocation(&attr, &expr, &nexpr); | ||
215 | if (ret < 0 || nexpr == 0) | ||
216 | return -ENOENT; | ||
217 | |||
218 | if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) { | ||
219 | pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n", | ||
220 | expr[0].atom, nexpr); | ||
221 | return -ENOTSUP; | ||
222 | } | ||
223 | *offs = (Dwarf_Word)expr[0].number; | ||
224 | } | ||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | /* Return values for die_find callbacks */ | ||
229 | enum { | ||
230 | DIE_FIND_CB_FOUND = 0, /* End of Search */ | ||
231 | DIE_FIND_CB_CHILD = 1, /* Search only children */ | ||
232 | DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ | ||
233 | DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ | ||
234 | }; | ||
235 | |||
236 | /* Search a child die */ | ||
237 | static Dwarf_Die *die_find_child(Dwarf_Die *rt_die, | ||
238 | int (*callback)(Dwarf_Die *, void *), | ||
239 | void *data, Dwarf_Die *die_mem) | ||
240 | { | ||
241 | Dwarf_Die child_die; | ||
242 | int ret; | ||
243 | |||
244 | ret = dwarf_child(rt_die, die_mem); | ||
245 | if (ret != 0) | ||
246 | return NULL; | ||
247 | |||
248 | do { | ||
249 | ret = callback(die_mem, data); | ||
250 | if (ret == DIE_FIND_CB_FOUND) | ||
251 | return die_mem; | ||
252 | |||
253 | if ((ret & DIE_FIND_CB_CHILD) && | ||
254 | die_find_child(die_mem, callback, data, &child_die)) { | ||
255 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
256 | return die_mem; | ||
257 | } | ||
258 | } while ((ret & DIE_FIND_CB_SIBLING) && | ||
259 | dwarf_siblingof(die_mem, die_mem) == 0); | ||
260 | |||
261 | return NULL; | ||
262 | } | ||
263 | |||
190 | struct __addr_die_search_param { | 264 | struct __addr_die_search_param { |
191 | Dwarf_Addr addr; | 265 | Dwarf_Addr addr; |
192 | Dwarf_Die *die_mem; | 266 | Dwarf_Die *die_mem; |
@@ -205,8 +279,8 @@ static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) | |||
205 | } | 279 | } |
206 | 280 | ||
207 | /* Search a real subprogram including this line, */ | 281 | /* Search a real subprogram including this line, */ |
208 | static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, | 282 | static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, |
209 | Dwarf_Die *die_mem) | 283 | Dwarf_Die *die_mem) |
210 | { | 284 | { |
211 | struct __addr_die_search_param ad; | 285 | struct __addr_die_search_param ad; |
212 | ad.addr = addr; | 286 | ad.addr = addr; |
@@ -218,77 +292,64 @@ static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr, | |||
218 | return die_mem; | 292 | return die_mem; |
219 | } | 293 | } |
220 | 294 | ||
221 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ | 295 | /* die_find callback for inline function search */ |
222 | static Dwarf_Die *die_get_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, | 296 | static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) |
223 | Dwarf_Die *die_mem) | ||
224 | { | 297 | { |
225 | Dwarf_Die child_die; | 298 | Dwarf_Addr *addr = data; |
226 | int ret; | ||
227 | 299 | ||
228 | ret = dwarf_child(sp_die, die_mem); | 300 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && |
229 | if (ret != 0) | 301 | dwarf_haspc(die_mem, *addr)) |
230 | return NULL; | 302 | return DIE_FIND_CB_FOUND; |
231 | 303 | ||
232 | do { | 304 | return DIE_FIND_CB_CONTINUE; |
233 | if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine && | ||
234 | dwarf_haspc(die_mem, addr)) | ||
235 | return die_mem; | ||
236 | |||
237 | if (die_get_inlinefunc(die_mem, addr, &child_die)) { | ||
238 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | ||
239 | return die_mem; | ||
240 | } | ||
241 | } while (dwarf_siblingof(die_mem, die_mem) == 0); | ||
242 | |||
243 | return NULL; | ||
244 | } | 305 | } |
245 | 306 | ||
246 | /* Compare diename and tname */ | 307 | /* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */ |
247 | static bool die_compare_name(Dwarf_Die *dw_die, const char *tname) | 308 | static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, |
309 | Dwarf_Die *die_mem) | ||
248 | { | 310 | { |
249 | const char *name; | 311 | return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem); |
250 | name = dwarf_diename(dw_die); | ||
251 | DIE_IF(name == NULL); | ||
252 | return strcmp(tname, name); | ||
253 | } | 312 | } |
254 | 313 | ||
255 | /* Get entry pc(or low pc, 1st entry of ranges) of the die */ | 314 | static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) |
256 | static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die) | ||
257 | { | 315 | { |
258 | Dwarf_Addr epc; | 316 | const char *name = data; |
259 | int ret; | 317 | int tag; |
260 | 318 | ||
261 | ret = dwarf_entrypc(dw_die, &epc); | 319 | tag = dwarf_tag(die_mem); |
262 | DIE_IF(ret == -1); | 320 | if ((tag == DW_TAG_formal_parameter || |
263 | return epc; | 321 | tag == DW_TAG_variable) && |
322 | (die_compare_name(die_mem, name) == 0)) | ||
323 | return DIE_FIND_CB_FOUND; | ||
324 | |||
325 | return DIE_FIND_CB_CONTINUE; | ||
264 | } | 326 | } |
265 | 327 | ||
266 | /* Get a variable die */ | 328 | /* Find a variable called 'name' */ |
267 | static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, | 329 | static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, |
268 | Dwarf_Die *die_mem) | 330 | Dwarf_Die *die_mem) |
269 | { | 331 | { |
270 | Dwarf_Die child_die; | 332 | return die_find_child(sp_die, __die_find_variable_cb, (void *)name, |
271 | int tag; | 333 | die_mem); |
272 | int ret; | 334 | } |
273 | 335 | ||
274 | ret = dwarf_child(sp_die, die_mem); | 336 | static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) |
275 | if (ret != 0) | 337 | { |
276 | return NULL; | 338 | const char *name = data; |
277 | 339 | ||
278 | do { | 340 | if ((dwarf_tag(die_mem) == DW_TAG_member) && |
279 | tag = dwarf_tag(die_mem); | 341 | (die_compare_name(die_mem, name) == 0)) |
280 | if ((tag == DW_TAG_formal_parameter || | 342 | return DIE_FIND_CB_FOUND; |
281 | tag == DW_TAG_variable) && | ||
282 | (die_compare_name(die_mem, name) == 0)) | ||
283 | return die_mem; | ||
284 | 343 | ||
285 | if (die_find_variable(die_mem, name, &child_die)) { | 344 | return DIE_FIND_CB_SIBLING; |
286 | memcpy(die_mem, &child_die, sizeof(Dwarf_Die)); | 345 | } |
287 | return die_mem; | ||
288 | } | ||
289 | } while (dwarf_siblingof(die_mem, die_mem) == 0); | ||
290 | 346 | ||
291 | return NULL; | 347 | /* Find a member called 'name' */ |
348 | static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, | ||
349 | Dwarf_Die *die_mem) | ||
350 | { | ||
351 | return die_find_child(st_die, __die_find_member_cb, (void *)name, | ||
352 | die_mem); | ||
292 | } | 353 | } |
293 | 354 | ||
294 | /* | 355 | /* |
@@ -296,19 +357,22 @@ static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name, | |||
296 | */ | 357 | */ |
297 | 358 | ||
298 | /* Show a location */ | 359 | /* Show a location */ |
299 | static void show_location(Dwarf_Op *op, struct probe_finder *pf) | 360 | static int convert_location(Dwarf_Op *op, struct probe_finder *pf) |
300 | { | 361 | { |
301 | unsigned int regn; | 362 | unsigned int regn; |
302 | Dwarf_Word offs = 0; | 363 | Dwarf_Word offs = 0; |
303 | int deref = 0, ret; | 364 | bool ref = false; |
304 | const char *regs; | 365 | const char *regs; |
366 | struct kprobe_trace_arg *tvar = pf->tvar; | ||
305 | 367 | ||
306 | /* TODO: support CFA */ | ||
307 | /* If this is based on frame buffer, set the offset */ | 368 | /* If this is based on frame buffer, set the offset */ |
308 | if (op->atom == DW_OP_fbreg) { | 369 | if (op->atom == DW_OP_fbreg) { |
309 | if (pf->fb_ops == NULL) | 370 | if (pf->fb_ops == NULL) { |
310 | die("The attribute of frame base is not supported.\n"); | 371 | pr_warning("The attribute of frame base is not " |
311 | deref = 1; | 372 | "supported.\n"); |
373 | return -ENOTSUP; | ||
374 | } | ||
375 | ref = true; | ||
312 | offs = op->number; | 376 | offs = op->number; |
313 | op = &pf->fb_ops[0]; | 377 | op = &pf->fb_ops[0]; |
314 | } | 378 | } |
@@ -316,35 +380,164 @@ static void show_location(Dwarf_Op *op, struct probe_finder *pf) | |||
316 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { | 380 | if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) { |
317 | regn = op->atom - DW_OP_breg0; | 381 | regn = op->atom - DW_OP_breg0; |
318 | offs += op->number; | 382 | offs += op->number; |
319 | deref = 1; | 383 | ref = true; |
320 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { | 384 | } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) { |
321 | regn = op->atom - DW_OP_reg0; | 385 | regn = op->atom - DW_OP_reg0; |
322 | } else if (op->atom == DW_OP_bregx) { | 386 | } else if (op->atom == DW_OP_bregx) { |
323 | regn = op->number; | 387 | regn = op->number; |
324 | offs += op->number2; | 388 | offs += op->number2; |
325 | deref = 1; | 389 | ref = true; |
326 | } else if (op->atom == DW_OP_regx) { | 390 | } else if (op->atom == DW_OP_regx) { |
327 | regn = op->number; | 391 | regn = op->number; |
328 | } else | 392 | } else { |
329 | die("DW_OP %d is not supported.", op->atom); | 393 | pr_warning("DW_OP %x is not supported.\n", op->atom); |
394 | return -ENOTSUP; | ||
395 | } | ||
330 | 396 | ||
331 | regs = get_arch_regstr(regn); | 397 | regs = get_arch_regstr(regn); |
332 | if (!regs) | 398 | if (!regs) { |
333 | die("%u exceeds max register number.", regn); | 399 | pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn); |
400 | return -ERANGE; | ||
401 | } | ||
402 | |||
403 | tvar->value = strdup(regs); | ||
404 | if (tvar->value == NULL) | ||
405 | return -ENOMEM; | ||
406 | |||
407 | if (ref) { | ||
408 | tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
409 | if (tvar->ref == NULL) | ||
410 | return -ENOMEM; | ||
411 | tvar->ref->offset = (long)offs; | ||
412 | } | ||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static int convert_variable_type(Dwarf_Die *vr_die, | ||
417 | struct kprobe_trace_arg *targ) | ||
418 | { | ||
419 | Dwarf_Die type; | ||
420 | char buf[16]; | ||
421 | int ret; | ||
422 | |||
423 | if (die_get_real_type(vr_die, &type) == NULL) { | ||
424 | pr_warning("Failed to get a type information of %s.\n", | ||
425 | dwarf_diename(vr_die)); | ||
426 | return -ENOENT; | ||
427 | } | ||
428 | |||
429 | ret = die_get_byte_size(&type) * 8; | ||
430 | if (ret) { | ||
431 | /* Check the bitwidth */ | ||
432 | if (ret > MAX_BASIC_TYPE_BITS) { | ||
433 | pr_info("%s exceeds max-bitwidth." | ||
434 | " Cut down to %d bits.\n", | ||
435 | dwarf_diename(&type), MAX_BASIC_TYPE_BITS); | ||
436 | ret = MAX_BASIC_TYPE_BITS; | ||
437 | } | ||
438 | |||
439 | ret = snprintf(buf, 16, "%c%d", | ||
440 | die_is_signed_type(&type) ? 's' : 'u', ret); | ||
441 | if (ret < 0 || ret >= 16) { | ||
442 | if (ret >= 16) | ||
443 | ret = -E2BIG; | ||
444 | pr_warning("Failed to convert variable type: %s\n", | ||
445 | strerror(-ret)); | ||
446 | return ret; | ||
447 | } | ||
448 | targ->type = strdup(buf); | ||
449 | if (targ->type == NULL) | ||
450 | return -ENOMEM; | ||
451 | } | ||
452 | return 0; | ||
453 | } | ||
454 | |||
455 | static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname, | ||
456 | struct perf_probe_arg_field *field, | ||
457 | struct kprobe_trace_arg_ref **ref_ptr, | ||
458 | Dwarf_Die *die_mem) | ||
459 | { | ||
460 | struct kprobe_trace_arg_ref *ref = *ref_ptr; | ||
461 | Dwarf_Die type; | ||
462 | Dwarf_Word offs; | ||
463 | int ret; | ||
464 | |||
465 | pr_debug("converting %s in %s\n", field->name, varname); | ||
466 | if (die_get_real_type(vr_die, &type) == NULL) { | ||
467 | pr_warning("Failed to get the type of %s.\n", varname); | ||
468 | return -ENOENT; | ||
469 | } | ||
470 | |||
471 | /* Check the pointer and dereference */ | ||
472 | if (dwarf_tag(&type) == DW_TAG_pointer_type) { | ||
473 | if (!field->ref) { | ||
474 | pr_err("Semantic error: %s must be referred by '->'\n", | ||
475 | field->name); | ||
476 | return -EINVAL; | ||
477 | } | ||
478 | /* Get the type pointed by this pointer */ | ||
479 | if (die_get_real_type(&type, &type) == NULL) { | ||
480 | pr_warning("Failed to get the type of %s.\n", varname); | ||
481 | return -ENOENT; | ||
482 | } | ||
483 | /* Verify it is a data structure */ | ||
484 | if (dwarf_tag(&type) != DW_TAG_structure_type) { | ||
485 | pr_warning("%s is not a data structure.\n", varname); | ||
486 | return -EINVAL; | ||
487 | } | ||
488 | |||
489 | ref = zalloc(sizeof(struct kprobe_trace_arg_ref)); | ||
490 | if (ref == NULL) | ||
491 | return -ENOMEM; | ||
492 | if (*ref_ptr) | ||
493 | (*ref_ptr)->next = ref; | ||
494 | else | ||
495 | *ref_ptr = ref; | ||
496 | } else { | ||
497 | /* Verify it is a data structure */ | ||
498 | if (dwarf_tag(&type) != DW_TAG_structure_type) { | ||
499 | pr_warning("%s is not a data structure.\n", varname); | ||
500 | return -EINVAL; | ||
501 | } | ||
502 | if (field->ref) { | ||
503 | pr_err("Semantic error: %s must be referred by '.'\n", | ||
504 | field->name); | ||
505 | return -EINVAL; | ||
506 | } | ||
507 | if (!ref) { | ||
508 | pr_warning("Structure on a register is not " | ||
509 | "supported yet.\n"); | ||
510 | return -ENOTSUP; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | if (die_find_member(&type, field->name, die_mem) == NULL) { | ||
515 | pr_warning("%s(tyep:%s) has no member %s.\n", varname, | ||
516 | dwarf_diename(&type), field->name); | ||
517 | return -EINVAL; | ||
518 | } | ||
334 | 519 | ||
335 | if (deref) | 520 | /* Get the offset of the field */ |
336 | ret = snprintf(pf->buf, pf->len, " %s=%+jd(%s)", | 521 | ret = die_get_data_member_location(die_mem, &offs); |
337 | pf->var, (intmax_t)offs, regs); | 522 | if (ret < 0) { |
523 | pr_warning("Failed to get the offset of %s.\n", field->name); | ||
524 | return ret; | ||
525 | } | ||
526 | ref->offset += (long)offs; | ||
527 | |||
528 | /* Converting next field */ | ||
529 | if (field->next) | ||
530 | return convert_variable_fields(die_mem, field->name, | ||
531 | field->next, &ref, die_mem); | ||
338 | else | 532 | else |
339 | ret = snprintf(pf->buf, pf->len, " %s=%s", pf->var, regs); | 533 | return 0; |
340 | DIE_IF(ret < 0); | ||
341 | DIE_IF(ret >= pf->len); | ||
342 | } | 534 | } |
343 | 535 | ||
344 | /* Show a variables in kprobe event format */ | 536 | /* Show a variables in kprobe event format */ |
345 | static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | 537 | static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf) |
346 | { | 538 | { |
347 | Dwarf_Attribute attr; | 539 | Dwarf_Attribute attr; |
540 | Dwarf_Die die_mem; | ||
348 | Dwarf_Op *expr; | 541 | Dwarf_Op *expr; |
349 | size_t nexpr; | 542 | size_t nexpr; |
350 | int ret; | 543 | int ret; |
@@ -356,142 +549,191 @@ static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf) | |||
356 | if (ret <= 0 || nexpr == 0) | 549 | if (ret <= 0 || nexpr == 0) |
357 | goto error; | 550 | goto error; |
358 | 551 | ||
359 | show_location(expr, pf); | 552 | ret = convert_location(expr, pf); |
553 | if (ret == 0 && pf->pvar->field) { | ||
554 | ret = convert_variable_fields(vr_die, pf->pvar->var, | ||
555 | pf->pvar->field, &pf->tvar->ref, | ||
556 | &die_mem); | ||
557 | vr_die = &die_mem; | ||
558 | } | ||
559 | if (ret == 0) { | ||
560 | if (pf->pvar->type) { | ||
561 | pf->tvar->type = strdup(pf->pvar->type); | ||
562 | if (pf->tvar->type == NULL) | ||
563 | ret = -ENOMEM; | ||
564 | } else | ||
565 | ret = convert_variable_type(vr_die, pf->tvar); | ||
566 | } | ||
360 | /* *expr will be cached in libdw. Don't free it. */ | 567 | /* *expr will be cached in libdw. Don't free it. */ |
361 | return ; | 568 | return ret; |
362 | error: | 569 | error: |
363 | /* TODO: Support const_value */ | 570 | /* TODO: Support const_value */ |
364 | die("Failed to find the location of %s at this address.\n" | 571 | pr_err("Failed to find the location of %s at this address.\n" |
365 | " Perhaps, it has been optimized out.", pf->var); | 572 | " Perhaps, it has been optimized out.\n", pf->pvar->var); |
573 | return -ENOENT; | ||
366 | } | 574 | } |
367 | 575 | ||
368 | /* Find a variable in a subprogram die */ | 576 | /* Find a variable in a subprogram die */ |
369 | static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) | 577 | static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf) |
370 | { | 578 | { |
371 | int ret; | ||
372 | Dwarf_Die vr_die; | 579 | Dwarf_Die vr_die; |
580 | char buf[32], *ptr; | ||
581 | int ret; | ||
373 | 582 | ||
374 | /* TODO: Support struct members and arrays */ | 583 | /* TODO: Support arrays */ |
375 | if (!is_c_varname(pf->var)) { | 584 | if (pf->pvar->name) |
376 | /* Output raw parameters */ | 585 | pf->tvar->name = strdup(pf->pvar->name); |
377 | ret = snprintf(pf->buf, pf->len, " %s", pf->var); | 586 | else { |
378 | DIE_IF(ret < 0); | 587 | ret = synthesize_perf_probe_arg(pf->pvar, buf, 32); |
379 | DIE_IF(ret >= pf->len); | 588 | if (ret < 0) |
380 | return ; | 589 | return ret; |
590 | ptr = strchr(buf, ':'); /* Change type separator to _ */ | ||
591 | if (ptr) | ||
592 | *ptr = '_'; | ||
593 | pf->tvar->name = strdup(buf); | ||
594 | } | ||
595 | if (pf->tvar->name == NULL) | ||
596 | return -ENOMEM; | ||
597 | |||
598 | if (!is_c_varname(pf->pvar->var)) { | ||
599 | /* Copy raw parameters */ | ||
600 | pf->tvar->value = strdup(pf->pvar->var); | ||
601 | if (pf->tvar->value == NULL) | ||
602 | return -ENOMEM; | ||
603 | else | ||
604 | return 0; | ||
381 | } | 605 | } |
382 | 606 | ||
383 | pr_debug("Searching '%s' variable in context.\n", pf->var); | 607 | pr_debug("Searching '%s' variable in context.\n", |
608 | pf->pvar->var); | ||
384 | /* Search child die for local variables and parameters. */ | 609 | /* Search child die for local variables and parameters. */ |
385 | if (!die_find_variable(sp_die, pf->var, &vr_die)) | 610 | if (!die_find_variable(sp_die, pf->pvar->var, &vr_die)) { |
386 | die("Failed to find '%s' in this function.", pf->var); | 611 | pr_warning("Failed to find '%s' in this function.\n", |
387 | 612 | pf->pvar->var); | |
388 | show_variable(&vr_die, pf); | 613 | return -ENOENT; |
614 | } | ||
615 | return convert_variable(&vr_die, pf); | ||
389 | } | 616 | } |
390 | 617 | ||
391 | /* Show a probe point to output buffer */ | 618 | /* Show a probe point to output buffer */ |
392 | static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) | 619 | static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf) |
393 | { | 620 | { |
394 | struct probe_point *pp = pf->pp; | 621 | struct kprobe_trace_event *tev; |
395 | Dwarf_Addr eaddr; | 622 | Dwarf_Addr eaddr; |
396 | Dwarf_Die die_mem; | 623 | Dwarf_Die die_mem; |
397 | const char *name; | 624 | const char *name; |
398 | char tmp[MAX_PROBE_BUFFER]; | 625 | int ret, i; |
399 | int ret, i, len; | ||
400 | Dwarf_Attribute fb_attr; | 626 | Dwarf_Attribute fb_attr; |
401 | size_t nops; | 627 | size_t nops; |
402 | 628 | ||
629 | if (pf->ntevs == pf->max_tevs) { | ||
630 | pr_warning("Too many( > %d) probe point found.\n", | ||
631 | pf->max_tevs); | ||
632 | return -ERANGE; | ||
633 | } | ||
634 | tev = &pf->tevs[pf->ntevs++]; | ||
635 | |||
403 | /* If no real subprogram, find a real one */ | 636 | /* If no real subprogram, find a real one */ |
404 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { | 637 | if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) { |
405 | sp_die = die_get_real_subprogram(&pf->cu_die, | 638 | sp_die = die_find_real_subprogram(&pf->cu_die, |
406 | pf->addr, &die_mem); | 639 | pf->addr, &die_mem); |
407 | if (!sp_die) | 640 | if (!sp_die) { |
408 | die("Probe point is not found in subprograms."); | 641 | pr_warning("Failed to find probe point in any " |
642 | "functions.\n"); | ||
643 | return -ENOENT; | ||
644 | } | ||
409 | } | 645 | } |
410 | 646 | ||
411 | /* Output name of probe point */ | 647 | /* Copy the name of probe point */ |
412 | name = dwarf_diename(sp_die); | 648 | name = dwarf_diename(sp_die); |
413 | if (name) { | 649 | if (name) { |
414 | dwarf_entrypc(sp_die, &eaddr); | 650 | if (dwarf_entrypc(sp_die, &eaddr) != 0) { |
415 | ret = snprintf(tmp, MAX_PROBE_BUFFER, "%s+%lu", name, | 651 | pr_warning("Failed to get entry pc of %s\n", |
416 | (unsigned long)(pf->addr - eaddr)); | 652 | dwarf_diename(sp_die)); |
417 | /* Copy the function name if possible */ | 653 | return -ENOENT; |
418 | if (!pp->function) { | ||
419 | pp->function = strdup(name); | ||
420 | pp->offset = (size_t)(pf->addr - eaddr); | ||
421 | } | 654 | } |
422 | } else { | 655 | tev->point.symbol = strdup(name); |
656 | if (tev->point.symbol == NULL) | ||
657 | return -ENOMEM; | ||
658 | tev->point.offset = (unsigned long)(pf->addr - eaddr); | ||
659 | } else | ||
423 | /* This function has no name. */ | 660 | /* This function has no name. */ |
424 | ret = snprintf(tmp, MAX_PROBE_BUFFER, "0x%jx", | 661 | tev->point.offset = (unsigned long)pf->addr; |
425 | (uintmax_t)pf->addr); | 662 | |
426 | if (!pp->function) { | 663 | pr_debug("Probe point found: %s+%lu\n", tev->point.symbol, |
427 | /* TODO: Use _stext */ | 664 | tev->point.offset); |
428 | pp->function = strdup(""); | ||
429 | pp->offset = (size_t)pf->addr; | ||
430 | } | ||
431 | } | ||
432 | DIE_IF(ret < 0); | ||
433 | DIE_IF(ret >= MAX_PROBE_BUFFER); | ||
434 | len = ret; | ||
435 | pr_debug("Probe point found: %s\n", tmp); | ||
436 | 665 | ||
437 | /* Get the frame base attribute/ops */ | 666 | /* Get the frame base attribute/ops */ |
438 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); | 667 | dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr); |
439 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); | 668 | ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1); |
440 | if (ret <= 0 || nops == 0) | 669 | if (ret <= 0 || nops == 0) { |
441 | pf->fb_ops = NULL; | 670 | pf->fb_ops = NULL; |
671 | } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa && | ||
672 | pf->cfi != NULL) { | ||
673 | Dwarf_Frame *frame; | ||
674 | if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 || | ||
675 | dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) { | ||
676 | pr_warning("Failed to get CFA on 0x%jx\n", | ||
677 | (uintmax_t)pf->addr); | ||
678 | return -ENOENT; | ||
679 | } | ||
680 | } | ||
442 | 681 | ||
443 | /* Find each argument */ | 682 | /* Find each argument */ |
444 | /* TODO: use dwarf_cfi_addrframe */ | 683 | tev->nargs = pf->pev->nargs; |
445 | for (i = 0; i < pp->nr_args; i++) { | 684 | tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs); |
446 | pf->var = pp->args[i]; | 685 | if (tev->args == NULL) |
447 | pf->buf = &tmp[len]; | 686 | return -ENOMEM; |
448 | pf->len = MAX_PROBE_BUFFER - len; | 687 | for (i = 0; i < pf->pev->nargs; i++) { |
449 | find_variable(sp_die, pf); | 688 | pf->pvar = &pf->pev->args[i]; |
450 | len += strlen(pf->buf); | 689 | pf->tvar = &tev->args[i]; |
690 | ret = find_variable(sp_die, pf); | ||
691 | if (ret != 0) | ||
692 | return ret; | ||
451 | } | 693 | } |
452 | 694 | ||
453 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ | 695 | /* *pf->fb_ops will be cached in libdw. Don't free it. */ |
454 | pf->fb_ops = NULL; | 696 | pf->fb_ops = NULL; |
455 | 697 | return 0; | |
456 | if (pp->found == MAX_PROBES) | ||
457 | die("Too many( > %d) probe point found.\n", MAX_PROBES); | ||
458 | |||
459 | pp->probes[pp->found] = strdup(tmp); | ||
460 | pp->found++; | ||
461 | } | 698 | } |
462 | 699 | ||
463 | /* Find probe point from its line number */ | 700 | /* Find probe point from its line number */ |
464 | static void find_probe_point_by_line(struct probe_finder *pf) | 701 | static int find_probe_point_by_line(struct probe_finder *pf) |
465 | { | 702 | { |
466 | Dwarf_Lines *lines; | 703 | Dwarf_Lines *lines; |
467 | Dwarf_Line *line; | 704 | Dwarf_Line *line; |
468 | size_t nlines, i; | 705 | size_t nlines, i; |
469 | Dwarf_Addr addr; | 706 | Dwarf_Addr addr; |
470 | int lineno; | 707 | int lineno; |
471 | int ret; | 708 | int ret = 0; |
472 | 709 | ||
473 | ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines); | 710 | if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) { |
474 | DIE_IF(ret != 0); | 711 | pr_warning("No source lines found in this CU.\n"); |
712 | return -ENOENT; | ||
713 | } | ||
475 | 714 | ||
476 | for (i = 0; i < nlines; i++) { | 715 | for (i = 0; i < nlines && ret == 0; i++) { |
477 | line = dwarf_onesrcline(lines, i); | 716 | line = dwarf_onesrcline(lines, i); |
478 | dwarf_lineno(line, &lineno); | 717 | if (dwarf_lineno(line, &lineno) != 0 || |
479 | if (lineno != pf->lno) | 718 | lineno != pf->lno) |
480 | continue; | 719 | continue; |
481 | 720 | ||
482 | /* TODO: Get fileno from line, but how? */ | 721 | /* TODO: Get fileno from line, but how? */ |
483 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) | 722 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) |
484 | continue; | 723 | continue; |
485 | 724 | ||
486 | ret = dwarf_lineaddr(line, &addr); | 725 | if (dwarf_lineaddr(line, &addr) != 0) { |
487 | DIE_IF(ret != 0); | 726 | pr_warning("Failed to get the address of the line.\n"); |
727 | return -ENOENT; | ||
728 | } | ||
488 | pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n", | 729 | pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n", |
489 | (int)i, lineno, (uintmax_t)addr); | 730 | (int)i, lineno, (uintmax_t)addr); |
490 | pf->addr = addr; | 731 | pf->addr = addr; |
491 | 732 | ||
492 | show_probe_point(NULL, pf); | 733 | ret = convert_probe_point(NULL, pf); |
493 | /* Continuing, because target line might be inlined. */ | 734 | /* Continuing, because target line might be inlined. */ |
494 | } | 735 | } |
736 | return ret; | ||
495 | } | 737 | } |
496 | 738 | ||
497 | /* Find lines which match lazy pattern */ | 739 | /* Find lines which match lazy pattern */ |
@@ -499,16 +741,27 @@ static int find_lazy_match_lines(struct list_head *head, | |||
499 | const char *fname, const char *pat) | 741 | const char *fname, const char *pat) |
500 | { | 742 | { |
501 | char *fbuf, *p1, *p2; | 743 | char *fbuf, *p1, *p2; |
502 | int fd, line, nlines = 0; | 744 | int fd, ret, line, nlines = 0; |
503 | struct stat st; | 745 | struct stat st; |
504 | 746 | ||
505 | fd = open(fname, O_RDONLY); | 747 | fd = open(fname, O_RDONLY); |
506 | if (fd < 0) | 748 | if (fd < 0) { |
507 | die("failed to open %s", fname); | 749 | pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); |
508 | DIE_IF(fstat(fd, &st) < 0); | 750 | return fd; |
509 | fbuf = malloc(st.st_size + 2); | 751 | } |
510 | DIE_IF(fbuf == NULL); | 752 | |
511 | DIE_IF(read(fd, fbuf, st.st_size) < 0); | 753 | ret = fstat(fd, &st); |
754 | if (ret < 0) { | ||
755 | pr_warning("Failed to get the size of %s: %s\n", | ||
756 | fname, strerror(errno)); | ||
757 | return ret; | ||
758 | } | ||
759 | fbuf = xmalloc(st.st_size + 2); | ||
760 | ret = read(fd, fbuf, st.st_size); | ||
761 | if (ret < 0) { | ||
762 | pr_warning("Failed to read %s: %s\n", fname, strerror(errno)); | ||
763 | return ret; | ||
764 | } | ||
512 | close(fd); | 765 | close(fd); |
513 | fbuf[st.st_size] = '\n'; /* Dummy line */ | 766 | fbuf[st.st_size] = '\n'; /* Dummy line */ |
514 | fbuf[st.st_size + 1] = '\0'; | 767 | fbuf[st.st_size + 1] = '\0'; |
@@ -528,7 +781,7 @@ static int find_lazy_match_lines(struct list_head *head, | |||
528 | } | 781 | } |
529 | 782 | ||
530 | /* Find probe points from lazy pattern */ | 783 | /* Find probe points from lazy pattern */ |
531 | static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | 784 | static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) |
532 | { | 785 | { |
533 | Dwarf_Lines *lines; | 786 | Dwarf_Lines *lines; |
534 | Dwarf_Line *line; | 787 | Dwarf_Line *line; |
@@ -536,37 +789,46 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
536 | Dwarf_Addr addr; | 789 | Dwarf_Addr addr; |
537 | Dwarf_Die die_mem; | 790 | Dwarf_Die die_mem; |
538 | int lineno; | 791 | int lineno; |
539 | int ret; | 792 | int ret = 0; |
540 | 793 | ||
541 | if (list_empty(&pf->lcache)) { | 794 | if (list_empty(&pf->lcache)) { |
542 | /* Matching lazy line pattern */ | 795 | /* Matching lazy line pattern */ |
543 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, | 796 | ret = find_lazy_match_lines(&pf->lcache, pf->fname, |
544 | pf->pp->lazy_line); | 797 | pf->pev->point.lazy_line); |
545 | if (ret <= 0) | 798 | if (ret == 0) { |
546 | die("No matched lines found in %s.", pf->fname); | 799 | pr_debug("No matched lines found in %s.\n", pf->fname); |
800 | return 0; | ||
801 | } else if (ret < 0) | ||
802 | return ret; | ||
547 | } | 803 | } |
548 | 804 | ||
549 | ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines); | 805 | if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) { |
550 | DIE_IF(ret != 0); | 806 | pr_warning("No source lines found in this CU.\n"); |
551 | for (i = 0; i < nlines; i++) { | 807 | return -ENOENT; |
808 | } | ||
809 | |||
810 | for (i = 0; i < nlines && ret >= 0; i++) { | ||
552 | line = dwarf_onesrcline(lines, i); | 811 | line = dwarf_onesrcline(lines, i); |
553 | 812 | ||
554 | dwarf_lineno(line, &lineno); | 813 | if (dwarf_lineno(line, &lineno) != 0 || |
555 | if (!line_list__has_line(&pf->lcache, lineno)) | 814 | !line_list__has_line(&pf->lcache, lineno)) |
556 | continue; | 815 | continue; |
557 | 816 | ||
558 | /* TODO: Get fileno from line, but how? */ | 817 | /* TODO: Get fileno from line, but how? */ |
559 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) | 818 | if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0) |
560 | continue; | 819 | continue; |
561 | 820 | ||
562 | ret = dwarf_lineaddr(line, &addr); | 821 | if (dwarf_lineaddr(line, &addr) != 0) { |
563 | DIE_IF(ret != 0); | 822 | pr_debug("Failed to get the address of line %d.\n", |
823 | lineno); | ||
824 | continue; | ||
825 | } | ||
564 | if (sp_die) { | 826 | if (sp_die) { |
565 | /* Address filtering 1: does sp_die include addr? */ | 827 | /* Address filtering 1: does sp_die include addr? */ |
566 | if (!dwarf_haspc(sp_die, addr)) | 828 | if (!dwarf_haspc(sp_die, addr)) |
567 | continue; | 829 | continue; |
568 | /* Address filtering 2: No child include addr? */ | 830 | /* Address filtering 2: No child include addr? */ |
569 | if (die_get_inlinefunc(sp_die, addr, &die_mem)) | 831 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
570 | continue; | 832 | continue; |
571 | } | 833 | } |
572 | 834 | ||
@@ -574,27 +836,44 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf) | |||
574 | (int)i, lineno, (unsigned long long)addr); | 836 | (int)i, lineno, (unsigned long long)addr); |
575 | pf->addr = addr; | 837 | pf->addr = addr; |
576 | 838 | ||
577 | show_probe_point(sp_die, pf); | 839 | ret = convert_probe_point(sp_die, pf); |
578 | /* Continuing, because target line might be inlined. */ | 840 | /* Continuing, because target line might be inlined. */ |
579 | } | 841 | } |
580 | /* TODO: deallocate lines, but how? */ | 842 | /* TODO: deallocate lines, but how? */ |
843 | return ret; | ||
581 | } | 844 | } |
582 | 845 | ||
846 | /* Callback parameter with return value */ | ||
847 | struct dwarf_callback_param { | ||
848 | void *data; | ||
849 | int retval; | ||
850 | }; | ||
851 | |||
583 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | 852 | static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) |
584 | { | 853 | { |
585 | struct probe_finder *pf = (struct probe_finder *)data; | 854 | struct dwarf_callback_param *param = data; |
586 | struct probe_point *pp = pf->pp; | 855 | struct probe_finder *pf = param->data; |
856 | struct perf_probe_point *pp = &pf->pev->point; | ||
857 | Dwarf_Addr addr; | ||
587 | 858 | ||
588 | if (pp->lazy_line) | 859 | if (pp->lazy_line) |
589 | find_probe_point_lazy(in_die, pf); | 860 | param->retval = find_probe_point_lazy(in_die, pf); |
590 | else { | 861 | else { |
591 | /* Get probe address */ | 862 | /* Get probe address */ |
592 | pf->addr = die_get_entrypc(in_die); | 863 | if (dwarf_entrypc(in_die, &addr) != 0) { |
864 | pr_warning("Failed to get entry pc of %s.\n", | ||
865 | dwarf_diename(in_die)); | ||
866 | param->retval = -ENOENT; | ||
867 | return DWARF_CB_ABORT; | ||
868 | } | ||
869 | pf->addr = addr; | ||
593 | pf->addr += pp->offset; | 870 | pf->addr += pp->offset; |
594 | pr_debug("found inline addr: 0x%jx\n", | 871 | pr_debug("found inline addr: 0x%jx\n", |
595 | (uintmax_t)pf->addr); | 872 | (uintmax_t)pf->addr); |
596 | 873 | ||
597 | show_probe_point(in_die, pf); | 874 | param->retval = convert_probe_point(in_die, pf); |
875 | if (param->retval < 0) | ||
876 | return DWARF_CB_ABORT; | ||
598 | } | 877 | } |
599 | 878 | ||
600 | return DWARF_CB_OK; | 879 | return DWARF_CB_OK; |
@@ -603,59 +882,88 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) | |||
603 | /* Search function from function name */ | 882 | /* Search function from function name */ |
604 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) | 883 | static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) |
605 | { | 884 | { |
606 | struct probe_finder *pf = (struct probe_finder *)data; | 885 | struct dwarf_callback_param *param = data; |
607 | struct probe_point *pp = pf->pp; | 886 | struct probe_finder *pf = param->data; |
887 | struct perf_probe_point *pp = &pf->pev->point; | ||
608 | 888 | ||
609 | /* Check tag and diename */ | 889 | /* Check tag and diename */ |
610 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || | 890 | if (dwarf_tag(sp_die) != DW_TAG_subprogram || |
611 | die_compare_name(sp_die, pp->function) != 0) | 891 | die_compare_name(sp_die, pp->function) != 0) |
612 | return 0; | 892 | return DWARF_CB_OK; |
613 | 893 | ||
614 | pf->fname = dwarf_decl_file(sp_die); | 894 | pf->fname = dwarf_decl_file(sp_die); |
615 | if (pp->line) { /* Function relative line */ | 895 | if (pp->line) { /* Function relative line */ |
616 | dwarf_decl_line(sp_die, &pf->lno); | 896 | dwarf_decl_line(sp_die, &pf->lno); |
617 | pf->lno += pp->line; | 897 | pf->lno += pp->line; |
618 | find_probe_point_by_line(pf); | 898 | param->retval = find_probe_point_by_line(pf); |
619 | } else if (!dwarf_func_inline(sp_die)) { | 899 | } else if (!dwarf_func_inline(sp_die)) { |
620 | /* Real function */ | 900 | /* Real function */ |
621 | if (pp->lazy_line) | 901 | if (pp->lazy_line) |
622 | find_probe_point_lazy(sp_die, pf); | 902 | param->retval = find_probe_point_lazy(sp_die, pf); |
623 | else { | 903 | else { |
624 | pf->addr = die_get_entrypc(sp_die); | 904 | if (dwarf_entrypc(sp_die, &pf->addr) != 0) { |
905 | pr_warning("Failed to get entry pc of %s.\n", | ||
906 | dwarf_diename(sp_die)); | ||
907 | param->retval = -ENOENT; | ||
908 | return DWARF_CB_ABORT; | ||
909 | } | ||
625 | pf->addr += pp->offset; | 910 | pf->addr += pp->offset; |
626 | /* TODO: Check the address in this function */ | 911 | /* TODO: Check the address in this function */ |
627 | show_probe_point(sp_die, pf); | 912 | param->retval = convert_probe_point(sp_die, pf); |
628 | } | 913 | } |
629 | } else | 914 | } else { |
915 | struct dwarf_callback_param _param = {.data = (void *)pf, | ||
916 | .retval = 0}; | ||
630 | /* Inlined function: search instances */ | 917 | /* Inlined function: search instances */ |
631 | dwarf_func_inline_instances(sp_die, probe_point_inline_cb, pf); | 918 | dwarf_func_inline_instances(sp_die, probe_point_inline_cb, |
919 | &_param); | ||
920 | param->retval = _param.retval; | ||
921 | } | ||
632 | 922 | ||
633 | return 1; /* Exit; no same symbol in this CU. */ | 923 | return DWARF_CB_ABORT; /* Exit; no same symbol in this CU. */ |
634 | } | 924 | } |
635 | 925 | ||
636 | static void find_probe_point_by_func(struct probe_finder *pf) | 926 | static int find_probe_point_by_func(struct probe_finder *pf) |
637 | { | 927 | { |
638 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, pf, 0); | 928 | struct dwarf_callback_param _param = {.data = (void *)pf, |
929 | .retval = 0}; | ||
930 | dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0); | ||
931 | return _param.retval; | ||
639 | } | 932 | } |
640 | 933 | ||
641 | /* Find a probe point */ | 934 | /* Find kprobe_trace_events specified by perf_probe_event from debuginfo */ |
642 | int find_probe_point(int fd, struct probe_point *pp) | 935 | int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, |
936 | struct kprobe_trace_event **tevs, int max_tevs) | ||
643 | { | 937 | { |
644 | struct probe_finder pf = {.pp = pp}; | 938 | struct probe_finder pf = {.pev = pev, .max_tevs = max_tevs}; |
939 | struct perf_probe_point *pp = &pev->point; | ||
645 | Dwarf_Off off, noff; | 940 | Dwarf_Off off, noff; |
646 | size_t cuhl; | 941 | size_t cuhl; |
647 | Dwarf_Die *diep; | 942 | Dwarf_Die *diep; |
648 | Dwarf *dbg; | 943 | Dwarf *dbg; |
944 | int ret = 0; | ||
945 | |||
946 | pf.tevs = zalloc(sizeof(struct kprobe_trace_event) * max_tevs); | ||
947 | if (pf.tevs == NULL) | ||
948 | return -ENOMEM; | ||
949 | *tevs = pf.tevs; | ||
950 | pf.ntevs = 0; | ||
649 | 951 | ||
650 | dbg = dwarf_begin(fd, DWARF_C_READ); | 952 | dbg = dwarf_begin(fd, DWARF_C_READ); |
651 | if (!dbg) | 953 | if (!dbg) { |
652 | return -ENOENT; | 954 | pr_warning("No dwarf info found in the vmlinux - " |
955 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
956 | return -EBADF; | ||
957 | } | ||
958 | |||
959 | /* Get the call frame information from this dwarf */ | ||
960 | pf.cfi = dwarf_getcfi(dbg); | ||
653 | 961 | ||
654 | pp->found = 0; | ||
655 | off = 0; | 962 | off = 0; |
656 | line_list__init(&pf.lcache); | 963 | line_list__init(&pf.lcache); |
657 | /* Loop on CUs (Compilation Unit) */ | 964 | /* Loop on CUs (Compilation Unit) */ |
658 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL)) { | 965 | while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) && |
966 | ret >= 0) { | ||
659 | /* Get the DIE(Debugging Information Entry) of this CU */ | 967 | /* Get the DIE(Debugging Information Entry) of this CU */ |
660 | diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die); | 968 | diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die); |
661 | if (!diep) | 969 | if (!diep) |
@@ -669,12 +977,12 @@ int find_probe_point(int fd, struct probe_point *pp) | |||
669 | 977 | ||
670 | if (!pp->file || pf.fname) { | 978 | if (!pp->file || pf.fname) { |
671 | if (pp->function) | 979 | if (pp->function) |
672 | find_probe_point_by_func(&pf); | 980 | ret = find_probe_point_by_func(&pf); |
673 | else if (pp->lazy_line) | 981 | else if (pp->lazy_line) |
674 | find_probe_point_lazy(NULL, &pf); | 982 | ret = find_probe_point_lazy(NULL, &pf); |
675 | else { | 983 | else { |
676 | pf.lno = pp->line; | 984 | pf.lno = pp->line; |
677 | find_probe_point_by_line(&pf); | 985 | ret = find_probe_point_by_line(&pf); |
678 | } | 986 | } |
679 | } | 987 | } |
680 | off = noff; | 988 | off = noff; |
@@ -682,41 +990,169 @@ int find_probe_point(int fd, struct probe_point *pp) | |||
682 | line_list__free(&pf.lcache); | 990 | line_list__free(&pf.lcache); |
683 | dwarf_end(dbg); | 991 | dwarf_end(dbg); |
684 | 992 | ||
685 | return pp->found; | 993 | return (ret < 0) ? ret : pf.ntevs; |
994 | } | ||
995 | |||
996 | /* Reverse search */ | ||
997 | int find_perf_probe_point(int fd, unsigned long addr, | ||
998 | struct perf_probe_point *ppt) | ||
999 | { | ||
1000 | Dwarf_Die cudie, spdie, indie; | ||
1001 | Dwarf *dbg; | ||
1002 | Dwarf_Line *line; | ||
1003 | Dwarf_Addr laddr, eaddr; | ||
1004 | const char *tmp; | ||
1005 | int lineno, ret = 0; | ||
1006 | bool found = false; | ||
1007 | |||
1008 | dbg = dwarf_begin(fd, DWARF_C_READ); | ||
1009 | if (!dbg) | ||
1010 | return -EBADF; | ||
1011 | |||
1012 | /* Find cu die */ | ||
1013 | if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) { | ||
1014 | ret = -EINVAL; | ||
1015 | goto end; | ||
1016 | } | ||
1017 | |||
1018 | /* Find a corresponding line */ | ||
1019 | line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr); | ||
1020 | if (line) { | ||
1021 | if (dwarf_lineaddr(line, &laddr) == 0 && | ||
1022 | (Dwarf_Addr)addr == laddr && | ||
1023 | dwarf_lineno(line, &lineno) == 0) { | ||
1024 | tmp = dwarf_linesrc(line, NULL, NULL); | ||
1025 | if (tmp) { | ||
1026 | ppt->line = lineno; | ||
1027 | ppt->file = strdup(tmp); | ||
1028 | if (ppt->file == NULL) { | ||
1029 | ret = -ENOMEM; | ||
1030 | goto end; | ||
1031 | } | ||
1032 | found = true; | ||
1033 | } | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | /* Find a corresponding function */ | ||
1038 | if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) { | ||
1039 | tmp = dwarf_diename(&spdie); | ||
1040 | if (!tmp || dwarf_entrypc(&spdie, &eaddr) != 0) | ||
1041 | goto end; | ||
1042 | |||
1043 | if (ppt->line) { | ||
1044 | if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr, | ||
1045 | &indie)) { | ||
1046 | /* addr in an inline function */ | ||
1047 | tmp = dwarf_diename(&indie); | ||
1048 | if (!tmp) | ||
1049 | goto end; | ||
1050 | ret = dwarf_decl_line(&indie, &lineno); | ||
1051 | } else { | ||
1052 | if (eaddr == addr) { /* Function entry */ | ||
1053 | lineno = ppt->line; | ||
1054 | ret = 0; | ||
1055 | } else | ||
1056 | ret = dwarf_decl_line(&spdie, &lineno); | ||
1057 | } | ||
1058 | if (ret == 0) { | ||
1059 | /* Make a relative line number */ | ||
1060 | ppt->line -= lineno; | ||
1061 | goto found; | ||
1062 | } | ||
1063 | } | ||
1064 | /* We don't have a line number, let's use offset */ | ||
1065 | ppt->offset = addr - (unsigned long)eaddr; | ||
1066 | found: | ||
1067 | ppt->function = strdup(tmp); | ||
1068 | if (ppt->function == NULL) { | ||
1069 | ret = -ENOMEM; | ||
1070 | goto end; | ||
1071 | } | ||
1072 | found = true; | ||
1073 | } | ||
1074 | |||
1075 | end: | ||
1076 | dwarf_end(dbg); | ||
1077 | if (ret >= 0) | ||
1078 | ret = found ? 1 : 0; | ||
1079 | return ret; | ||
1080 | } | ||
1081 | |||
1082 | /* Add a line and store the src path */ | ||
1083 | static int line_range_add_line(const char *src, unsigned int lineno, | ||
1084 | struct line_range *lr) | ||
1085 | { | ||
1086 | /* Copy real path */ | ||
1087 | if (!lr->path) { | ||
1088 | lr->path = strdup(src); | ||
1089 | if (lr->path == NULL) | ||
1090 | return -ENOMEM; | ||
1091 | } | ||
1092 | return line_list__add_line(&lr->line_list, lineno); | ||
1093 | } | ||
1094 | |||
1095 | /* Search function declaration lines */ | ||
1096 | static int line_range_funcdecl_cb(Dwarf_Die *sp_die, void *data) | ||
1097 | { | ||
1098 | struct dwarf_callback_param *param = data; | ||
1099 | struct line_finder *lf = param->data; | ||
1100 | const char *src; | ||
1101 | int lineno; | ||
1102 | |||
1103 | src = dwarf_decl_file(sp_die); | ||
1104 | if (src && strtailcmp(src, lf->fname) != 0) | ||
1105 | return DWARF_CB_OK; | ||
1106 | |||
1107 | if (dwarf_decl_line(sp_die, &lineno) != 0 || | ||
1108 | (lf->lno_s > lineno || lf->lno_e < lineno)) | ||
1109 | return DWARF_CB_OK; | ||
1110 | |||
1111 | param->retval = line_range_add_line(src, lineno, lf->lr); | ||
1112 | if (param->retval < 0) | ||
1113 | return DWARF_CB_ABORT; | ||
1114 | return DWARF_CB_OK; | ||
1115 | } | ||
1116 | |||
1117 | static int find_line_range_func_decl_lines(struct line_finder *lf) | ||
1118 | { | ||
1119 | struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0}; | ||
1120 | dwarf_getfuncs(&lf->cu_die, line_range_funcdecl_cb, ¶m, 0); | ||
1121 | return param.retval; | ||
686 | } | 1122 | } |
687 | 1123 | ||
688 | /* Find line range from its line number */ | 1124 | /* Find line range from its line number */ |
689 | static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | 1125 | static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) |
690 | { | 1126 | { |
691 | Dwarf_Lines *lines; | 1127 | Dwarf_Lines *lines; |
692 | Dwarf_Line *line; | 1128 | Dwarf_Line *line; |
693 | size_t nlines, i; | 1129 | size_t nlines, i; |
694 | Dwarf_Addr addr; | 1130 | Dwarf_Addr addr; |
695 | int lineno; | 1131 | int lineno, ret = 0; |
696 | int ret; | ||
697 | const char *src; | 1132 | const char *src; |
698 | Dwarf_Die die_mem; | 1133 | Dwarf_Die die_mem; |
699 | 1134 | ||
700 | line_list__init(&lf->lr->line_list); | 1135 | line_list__init(&lf->lr->line_list); |
701 | ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines); | 1136 | if (dwarf_getsrclines(&lf->cu_die, &lines, &nlines) != 0) { |
702 | DIE_IF(ret != 0); | 1137 | pr_warning("No source lines found in this CU.\n"); |
1138 | return -ENOENT; | ||
1139 | } | ||
703 | 1140 | ||
1141 | /* Search probable lines on lines list */ | ||
704 | for (i = 0; i < nlines; i++) { | 1142 | for (i = 0; i < nlines; i++) { |
705 | line = dwarf_onesrcline(lines, i); | 1143 | line = dwarf_onesrcline(lines, i); |
706 | ret = dwarf_lineno(line, &lineno); | 1144 | if (dwarf_lineno(line, &lineno) != 0 || |
707 | DIE_IF(ret != 0); | 1145 | (lf->lno_s > lineno || lf->lno_e < lineno)) |
708 | if (lf->lno_s > lineno || lf->lno_e < lineno) | ||
709 | continue; | 1146 | continue; |
710 | 1147 | ||
711 | if (sp_die) { | 1148 | if (sp_die) { |
712 | /* Address filtering 1: does sp_die include addr? */ | 1149 | /* Address filtering 1: does sp_die include addr? */ |
713 | ret = dwarf_lineaddr(line, &addr); | 1150 | if (dwarf_lineaddr(line, &addr) != 0 || |
714 | DIE_IF(ret != 0); | 1151 | !dwarf_haspc(sp_die, addr)) |
715 | if (!dwarf_haspc(sp_die, addr)) | ||
716 | continue; | 1152 | continue; |
717 | 1153 | ||
718 | /* Address filtering 2: No child include addr? */ | 1154 | /* Address filtering 2: No child include addr? */ |
719 | if (die_get_inlinefunc(sp_die, addr, &die_mem)) | 1155 | if (die_find_inlinefunc(sp_die, addr, &die_mem)) |
720 | continue; | 1156 | continue; |
721 | } | 1157 | } |
722 | 1158 | ||
@@ -725,30 +1161,49 @@ static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf) | |||
725 | if (strtailcmp(src, lf->fname) != 0) | 1161 | if (strtailcmp(src, lf->fname) != 0) |
726 | continue; | 1162 | continue; |
727 | 1163 | ||
728 | /* Copy real path */ | 1164 | ret = line_range_add_line(src, lineno, lf->lr); |
729 | if (!lf->lr->path) | 1165 | if (ret < 0) |
730 | lf->lr->path = strdup(src); | 1166 | return ret; |
731 | line_list__add_line(&lf->lr->line_list, (unsigned int)lineno); | ||
732 | } | 1167 | } |
1168 | |||
1169 | /* | ||
1170 | * Dwarf lines doesn't include function declarations. We have to | ||
1171 | * check functions list or given function. | ||
1172 | */ | ||
1173 | if (sp_die) { | ||
1174 | src = dwarf_decl_file(sp_die); | ||
1175 | if (src && dwarf_decl_line(sp_die, &lineno) == 0 && | ||
1176 | (lf->lno_s <= lineno && lf->lno_e >= lineno)) | ||
1177 | ret = line_range_add_line(src, lineno, lf->lr); | ||
1178 | } else | ||
1179 | ret = find_line_range_func_decl_lines(lf); | ||
1180 | |||
733 | /* Update status */ | 1181 | /* Update status */ |
734 | if (!list_empty(&lf->lr->line_list)) | 1182 | if (ret >= 0) |
735 | lf->found = 1; | 1183 | if (!list_empty(&lf->lr->line_list)) |
1184 | ret = lf->found = 1; | ||
1185 | else | ||
1186 | ret = 0; /* Lines are not found */ | ||
736 | else { | 1187 | else { |
737 | free(lf->lr->path); | 1188 | free(lf->lr->path); |
738 | lf->lr->path = NULL; | 1189 | lf->lr->path = NULL; |
739 | } | 1190 | } |
1191 | return ret; | ||
740 | } | 1192 | } |
741 | 1193 | ||
742 | static int line_range_inline_cb(Dwarf_Die *in_die, void *data) | 1194 | static int line_range_inline_cb(Dwarf_Die *in_die, void *data) |
743 | { | 1195 | { |
744 | find_line_range_by_line(in_die, (struct line_finder *)data); | 1196 | struct dwarf_callback_param *param = data; |
1197 | |||
1198 | param->retval = find_line_range_by_line(in_die, param->data); | ||
745 | return DWARF_CB_ABORT; /* No need to find other instances */ | 1199 | return DWARF_CB_ABORT; /* No need to find other instances */ |
746 | } | 1200 | } |
747 | 1201 | ||
748 | /* Search function from function name */ | 1202 | /* Search function from function name */ |
749 | static int line_range_search_cb(Dwarf_Die *sp_die, void *data) | 1203 | static int line_range_search_cb(Dwarf_Die *sp_die, void *data) |
750 | { | 1204 | { |
751 | struct line_finder *lf = (struct line_finder *)data; | 1205 | struct dwarf_callback_param *param = data; |
1206 | struct line_finder *lf = param->data; | ||
752 | struct line_range *lr = lf->lr; | 1207 | struct line_range *lr = lf->lr; |
753 | 1208 | ||
754 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && | 1209 | if (dwarf_tag(sp_die) == DW_TAG_subprogram && |
@@ -757,44 +1212,55 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data) | |||
757 | dwarf_decl_line(sp_die, &lr->offset); | 1212 | dwarf_decl_line(sp_die, &lr->offset); |
758 | pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); | 1213 | pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset); |
759 | lf->lno_s = lr->offset + lr->start; | 1214 | lf->lno_s = lr->offset + lr->start; |
760 | if (!lr->end) | 1215 | if (lf->lno_s < 0) /* Overflow */ |
1216 | lf->lno_s = INT_MAX; | ||
1217 | lf->lno_e = lr->offset + lr->end; | ||
1218 | if (lf->lno_e < 0) /* Overflow */ | ||
761 | lf->lno_e = INT_MAX; | 1219 | lf->lno_e = INT_MAX; |
762 | else | 1220 | pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e); |
763 | lf->lno_e = lr->offset + lr->end; | ||
764 | lr->start = lf->lno_s; | 1221 | lr->start = lf->lno_s; |
765 | lr->end = lf->lno_e; | 1222 | lr->end = lf->lno_e; |
766 | if (dwarf_func_inline(sp_die)) | 1223 | if (dwarf_func_inline(sp_die)) { |
1224 | struct dwarf_callback_param _param; | ||
1225 | _param.data = (void *)lf; | ||
1226 | _param.retval = 0; | ||
767 | dwarf_func_inline_instances(sp_die, | 1227 | dwarf_func_inline_instances(sp_die, |
768 | line_range_inline_cb, lf); | 1228 | line_range_inline_cb, |
769 | else | 1229 | &_param); |
770 | find_line_range_by_line(sp_die, lf); | 1230 | param->retval = _param.retval; |
771 | return 1; | 1231 | } else |
1232 | param->retval = find_line_range_by_line(sp_die, lf); | ||
1233 | return DWARF_CB_ABORT; | ||
772 | } | 1234 | } |
773 | return 0; | 1235 | return DWARF_CB_OK; |
774 | } | 1236 | } |
775 | 1237 | ||
776 | static void find_line_range_by_func(struct line_finder *lf) | 1238 | static int find_line_range_by_func(struct line_finder *lf) |
777 | { | 1239 | { |
778 | dwarf_getfuncs(&lf->cu_die, line_range_search_cb, lf, 0); | 1240 | struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0}; |
1241 | dwarf_getfuncs(&lf->cu_die, line_range_search_cb, ¶m, 0); | ||
1242 | return param.retval; | ||
779 | } | 1243 | } |
780 | 1244 | ||
781 | int find_line_range(int fd, struct line_range *lr) | 1245 | int find_line_range(int fd, struct line_range *lr) |
782 | { | 1246 | { |
783 | struct line_finder lf = {.lr = lr, .found = 0}; | 1247 | struct line_finder lf = {.lr = lr, .found = 0}; |
784 | int ret; | 1248 | int ret = 0; |
785 | Dwarf_Off off = 0, noff; | 1249 | Dwarf_Off off = 0, noff; |
786 | size_t cuhl; | 1250 | size_t cuhl; |
787 | Dwarf_Die *diep; | 1251 | Dwarf_Die *diep; |
788 | Dwarf *dbg; | 1252 | Dwarf *dbg; |
789 | 1253 | ||
790 | dbg = dwarf_begin(fd, DWARF_C_READ); | 1254 | dbg = dwarf_begin(fd, DWARF_C_READ); |
791 | if (!dbg) | 1255 | if (!dbg) { |
792 | return -ENOENT; | 1256 | pr_warning("No dwarf info found in the vmlinux - " |
1257 | "please rebuild with CONFIG_DEBUG_INFO=y.\n"); | ||
1258 | return -EBADF; | ||
1259 | } | ||
793 | 1260 | ||
794 | /* Loop on CUs (Compilation Unit) */ | 1261 | /* Loop on CUs (Compilation Unit) */ |
795 | while (!lf.found) { | 1262 | while (!lf.found && ret >= 0) { |
796 | ret = dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL); | 1263 | if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0) |
797 | if (ret != 0) | ||
798 | break; | 1264 | break; |
799 | 1265 | ||
800 | /* Get the DIE(Debugging Information Entry) of this CU */ | 1266 | /* Get the DIE(Debugging Information Entry) of this CU */ |
@@ -810,20 +1276,18 @@ int find_line_range(int fd, struct line_range *lr) | |||
810 | 1276 | ||
811 | if (!lr->file || lf.fname) { | 1277 | if (!lr->file || lf.fname) { |
812 | if (lr->function) | 1278 | if (lr->function) |
813 | find_line_range_by_func(&lf); | 1279 | ret = find_line_range_by_func(&lf); |
814 | else { | 1280 | else { |
815 | lf.lno_s = lr->start; | 1281 | lf.lno_s = lr->start; |
816 | if (!lr->end) | 1282 | lf.lno_e = lr->end; |
817 | lf.lno_e = INT_MAX; | 1283 | ret = find_line_range_by_line(NULL, &lf); |
818 | else | ||
819 | lf.lno_e = lr->end; | ||
820 | find_line_range_by_line(NULL, &lf); | ||
821 | } | 1284 | } |
822 | } | 1285 | } |
823 | off = noff; | 1286 | off = noff; |
824 | } | 1287 | } |
825 | pr_debug("path: %lx\n", (unsigned long)lr->path); | 1288 | pr_debug("path: %lx\n", (unsigned long)lr->path); |
826 | dwarf_end(dbg); | 1289 | dwarf_end(dbg); |
827 | return lf.found; | 1290 | |
1291 | return (ret < 0) ? ret : lf.found; | ||
828 | } | 1292 | } |
829 | 1293 | ||
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h index 21f7354397b4..66f1980e3855 100644 --- a/tools/perf/util/probe-finder.h +++ b/tools/perf/util/probe-finder.h | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include "util.h" | 5 | #include "util.h" |
6 | #include "probe-event.h" | ||
6 | 7 | ||
7 | #define MAX_PATH_LEN 256 | 8 | #define MAX_PATH_LEN 256 |
8 | #define MAX_PROBE_BUFFER 1024 | 9 | #define MAX_PROBE_BUFFER 1024 |
@@ -14,67 +15,39 @@ static inline int is_c_varname(const char *name) | |||
14 | return isalpha(name[0]) || name[0] == '_'; | 15 | return isalpha(name[0]) || name[0] == '_'; |
15 | } | 16 | } |
16 | 17 | ||
17 | struct probe_point { | 18 | #ifdef DWARF_SUPPORT |
18 | char *event; /* Event name */ | 19 | /* Find kprobe_trace_events specified by perf_probe_event from debuginfo */ |
19 | char *group; /* Event group */ | 20 | extern int find_kprobe_trace_events(int fd, struct perf_probe_event *pev, |
21 | struct kprobe_trace_event **tevs, | ||
22 | int max_tevs); | ||
20 | 23 | ||
21 | /* Inputs */ | 24 | /* Find a perf_probe_point from debuginfo */ |
22 | char *file; /* File name */ | 25 | extern int find_perf_probe_point(int fd, unsigned long addr, |
23 | int line; /* Line number */ | 26 | struct perf_probe_point *ppt); |
24 | char *lazy_line; /* Lazy line pattern */ | ||
25 | 27 | ||
26 | char *function; /* Function name */ | ||
27 | int offset; /* Offset bytes */ | ||
28 | |||
29 | int nr_args; /* Number of arguments */ | ||
30 | char **args; /* Arguments */ | ||
31 | |||
32 | int retprobe; /* Return probe */ | ||
33 | |||
34 | /* Output */ | ||
35 | int found; /* Number of found probe points */ | ||
36 | char *probes[MAX_PROBES]; /* Output buffers (will be allocated)*/ | ||
37 | }; | ||
38 | |||
39 | /* Line number container */ | ||
40 | struct line_node { | ||
41 | struct list_head list; | ||
42 | unsigned int line; | ||
43 | }; | ||
44 | |||
45 | /* Line range */ | ||
46 | struct line_range { | ||
47 | char *file; /* File name */ | ||
48 | char *function; /* Function name */ | ||
49 | unsigned int start; /* Start line number */ | ||
50 | unsigned int end; /* End line number */ | ||
51 | int offset; /* Start line offset */ | ||
52 | char *path; /* Real path name */ | ||
53 | struct list_head line_list; /* Visible lines */ | ||
54 | }; | ||
55 | |||
56 | #ifndef NO_DWARF_SUPPORT | ||
57 | extern int find_probe_point(int fd, struct probe_point *pp); | ||
58 | extern int find_line_range(int fd, struct line_range *lr); | 28 | extern int find_line_range(int fd, struct line_range *lr); |
59 | 29 | ||
60 | #include <dwarf.h> | 30 | #include <dwarf.h> |
61 | #include <libdw.h> | 31 | #include <libdw.h> |
62 | 32 | ||
63 | struct probe_finder { | 33 | struct probe_finder { |
64 | struct probe_point *pp; /* Target probe point */ | 34 | struct perf_probe_event *pev; /* Target probe event */ |
35 | struct kprobe_trace_event *tevs; /* Result trace events */ | ||
36 | int ntevs; /* Number of trace events */ | ||
37 | int max_tevs; /* Max number of trace events */ | ||
65 | 38 | ||
66 | /* For function searching */ | 39 | /* For function searching */ |
67 | Dwarf_Addr addr; /* Address */ | ||
68 | const char *fname; /* File name */ | ||
69 | int lno; /* Line number */ | 40 | int lno; /* Line number */ |
41 | Dwarf_Addr addr; /* Address */ | ||
42 | const char *fname; /* Real file name */ | ||
70 | Dwarf_Die cu_die; /* Current CU */ | 43 | Dwarf_Die cu_die; /* Current CU */ |
44 | struct list_head lcache; /* Line cache for lazy match */ | ||
71 | 45 | ||
72 | /* For variable searching */ | 46 | /* For variable searching */ |
47 | Dwarf_CFI *cfi; /* Call Frame Information */ | ||
73 | Dwarf_Op *fb_ops; /* Frame base attribute */ | 48 | Dwarf_Op *fb_ops; /* Frame base attribute */ |
74 | const char *var; /* Current variable name */ | 49 | struct perf_probe_arg *pvar; /* Current target variable */ |
75 | char *buf; /* Current output buffer */ | 50 | struct kprobe_trace_arg *tvar; /* Current result variable */ |
76 | int len; /* Length of output buffer */ | ||
77 | struct list_head lcache; /* Line cache for lazy match */ | ||
78 | }; | 51 | }; |
79 | 52 | ||
80 | struct line_finder { | 53 | struct line_finder { |
@@ -87,6 +60,6 @@ struct line_finder { | |||
87 | int found; | 60 | int found; |
88 | }; | 61 | }; |
89 | 62 | ||
90 | #endif /* NO_DWARF_SUPPORT */ | 63 | #endif /* DWARF_SUPPORT */ |
91 | 64 | ||
92 | #endif /*_PROBE_FINDER_H */ | 65 | #endif /*_PROBE_FINDER_H */ |
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c new file mode 100644 index 000000000000..13d36faf64eb --- /dev/null +++ b/tools/perf/util/pstack.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * Simple pointer stack | ||
3 | * | ||
4 | * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com> | ||
5 | */ | ||
6 | |||
7 | #include "util.h" | ||
8 | #include "pstack.h" | ||
9 | #include <linux/kernel.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | struct pstack { | ||
13 | unsigned short top; | ||
14 | unsigned short max_nr_entries; | ||
15 | void *entries[0]; | ||
16 | }; | ||
17 | |||
18 | struct pstack *pstack__new(unsigned short max_nr_entries) | ||
19 | { | ||
20 | struct pstack *self = zalloc((sizeof(*self) + | ||
21 | max_nr_entries * sizeof(void *))); | ||
22 | if (self != NULL) | ||
23 | self->max_nr_entries = max_nr_entries; | ||
24 | return self; | ||
25 | } | ||
26 | |||
27 | void pstack__delete(struct pstack *self) | ||
28 | { | ||
29 | free(self); | ||
30 | } | ||
31 | |||
32 | bool pstack__empty(const struct pstack *self) | ||
33 | { | ||
34 | return self->top == 0; | ||
35 | } | ||
36 | |||
37 | void pstack__remove(struct pstack *self, void *key) | ||
38 | { | ||
39 | unsigned short i = self->top, last_index = self->top - 1; | ||
40 | |||
41 | while (i-- != 0) { | ||
42 | if (self->entries[i] == key) { | ||
43 | if (i < last_index) | ||
44 | memmove(self->entries + i, | ||
45 | self->entries + i + 1, | ||
46 | (last_index - i) * sizeof(void *)); | ||
47 | --self->top; | ||
48 | return; | ||
49 | } | ||
50 | } | ||
51 | pr_err("%s: %p not on the pstack!\n", __func__, key); | ||
52 | } | ||
53 | |||
54 | void pstack__push(struct pstack *self, void *key) | ||
55 | { | ||
56 | if (self->top == self->max_nr_entries) { | ||
57 | pr_err("%s: top=%d, overflow!\n", __func__, self->top); | ||
58 | return; | ||
59 | } | ||
60 | self->entries[self->top++] = key; | ||
61 | } | ||
62 | |||
63 | void *pstack__pop(struct pstack *self) | ||
64 | { | ||
65 | void *ret; | ||
66 | |||
67 | if (self->top == 0) { | ||
68 | pr_err("%s: underflow!\n", __func__); | ||
69 | return NULL; | ||
70 | } | ||
71 | |||
72 | ret = self->entries[--self->top]; | ||
73 | self->entries[self->top] = NULL; | ||
74 | return ret; | ||
75 | } | ||
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h new file mode 100644 index 000000000000..5ad07023504b --- /dev/null +++ b/tools/perf/util/pstack.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #ifndef _PERF_PSTACK_ | ||
2 | #define _PERF_PSTACK_ | ||
3 | |||
4 | struct pstack; | ||
5 | struct pstack *pstack__new(unsigned short max_nr_entries); | ||
6 | void pstack__delete(struct pstack *self); | ||
7 | bool pstack__empty(const struct pstack *self); | ||
8 | void pstack__remove(struct pstack *self, void *key); | ||
9 | void pstack__push(struct pstack *self, void *key); | ||
10 | void *pstack__pop(struct pstack *self); | ||
11 | |||
12 | #endif /* _PERF_PSTACK_ */ | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c index 5376378e0cfc..b059dc50cc2d 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c | |||
@@ -371,7 +371,6 @@ static int perl_start_script(const char *script, int argc, const char **argv) | |||
371 | run_start_sub(); | 371 | run_start_sub(); |
372 | 372 | ||
373 | free(command_line); | 373 | free(command_line); |
374 | fprintf(stderr, "perf trace started with Perl script %s\n\n", script); | ||
375 | return 0; | 374 | return 0; |
376 | error: | 375 | error: |
377 | perl_free(my_perl); | 376 | perl_free(my_perl); |
@@ -394,8 +393,6 @@ static int perl_stop_script(void) | |||
394 | perl_destruct(my_perl); | 393 | perl_destruct(my_perl); |
395 | perl_free(my_perl); | 394 | perl_free(my_perl); |
396 | 395 | ||
397 | fprintf(stderr, "\nperf trace Perl script stopped\n"); | ||
398 | |||
399 | return 0; | 396 | return 0; |
400 | } | 397 | } |
401 | 398 | ||
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 6a72f14c5986..81f39cab3aaa 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -374,8 +374,6 @@ static int python_start_script(const char *script, int argc, const char **argv) | |||
374 | } | 374 | } |
375 | 375 | ||
376 | free(command_line); | 376 | free(command_line); |
377 | fprintf(stderr, "perf trace started with Python script %s\n\n", | ||
378 | script); | ||
379 | 377 | ||
380 | return err; | 378 | return err; |
381 | error: | 379 | error: |
@@ -407,8 +405,6 @@ out: | |||
407 | Py_XDECREF(main_module); | 405 | Py_XDECREF(main_module); |
408 | Py_Finalize(); | 406 | Py_Finalize(); |
409 | 407 | ||
410 | fprintf(stderr, "\nperf trace Python script stopped\n"); | ||
411 | |||
412 | return err; | 408 | return err; |
413 | } | 409 | } |
414 | 410 | ||
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index eed1cb889008..25bfca4f10f0 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -14,6 +14,16 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
14 | { | 14 | { |
15 | struct stat input_stat; | 15 | struct stat input_stat; |
16 | 16 | ||
17 | if (!strcmp(self->filename, "-")) { | ||
18 | self->fd_pipe = true; | ||
19 | self->fd = STDIN_FILENO; | ||
20 | |||
21 | if (perf_header__read(self, self->fd) < 0) | ||
22 | pr_err("incompatible file format"); | ||
23 | |||
24 | return 0; | ||
25 | } | ||
26 | |||
17 | self->fd = open(self->filename, O_RDONLY); | 27 | self->fd = open(self->filename, O_RDONLY); |
18 | if (self->fd < 0) { | 28 | if (self->fd < 0) { |
19 | pr_err("failed to open file: %s", self->filename); | 29 | pr_err("failed to open file: %s", self->filename); |
@@ -38,7 +48,7 @@ static int perf_session__open(struct perf_session *self, bool force) | |||
38 | goto out_close; | 48 | goto out_close; |
39 | } | 49 | } |
40 | 50 | ||
41 | if (perf_header__read(&self->header, self->fd) < 0) { | 51 | if (perf_header__read(self, self->fd) < 0) { |
42 | pr_err("incompatible file format"); | 52 | pr_err("incompatible file format"); |
43 | goto out_close; | 53 | goto out_close; |
44 | } | 54 | } |
@@ -52,12 +62,21 @@ out_close: | |||
52 | return -1; | 62 | return -1; |
53 | } | 63 | } |
54 | 64 | ||
55 | static inline int perf_session__create_kernel_maps(struct perf_session *self) | 65 | void perf_session__update_sample_type(struct perf_session *self) |
66 | { | ||
67 | self->sample_type = perf_header__sample_type(&self->header); | ||
68 | } | ||
69 | |||
70 | int perf_session__create_kernel_maps(struct perf_session *self) | ||
56 | { | 71 | { |
57 | return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps); | 72 | int ret = machine__create_kernel_maps(&self->host_machine); |
73 | |||
74 | if (ret >= 0) | ||
75 | ret = machines__create_guest_kernel_maps(&self->machines); | ||
76 | return ret; | ||
58 | } | 77 | } |
59 | 78 | ||
60 | struct perf_session *perf_session__new(const char *filename, int mode, bool force) | 79 | struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe) |
61 | { | 80 | { |
62 | size_t len = filename ? strlen(filename) + 1 : 0; | 81 | size_t len = filename ? strlen(filename) + 1 : 0; |
63 | struct perf_session *self = zalloc(sizeof(*self) + len); | 82 | struct perf_session *self = zalloc(sizeof(*self) + len); |
@@ -70,13 +89,15 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc | |||
70 | 89 | ||
71 | memcpy(self->filename, filename, len); | 90 | memcpy(self->filename, filename, len); |
72 | self->threads = RB_ROOT; | 91 | self->threads = RB_ROOT; |
73 | self->stats_by_id = RB_ROOT; | 92 | self->hists_tree = RB_ROOT; |
74 | self->last_match = NULL; | 93 | self->last_match = NULL; |
75 | self->mmap_window = 32; | 94 | self->mmap_window = 32; |
76 | self->cwd = NULL; | 95 | self->cwd = NULL; |
77 | self->cwdlen = 0; | 96 | self->cwdlen = 0; |
78 | self->unknown_events = 0; | 97 | self->machines = RB_ROOT; |
79 | map_groups__init(&self->kmaps); | 98 | self->repipe = repipe; |
99 | INIT_LIST_HEAD(&self->ordered_samples.samples_head); | ||
100 | machine__init(&self->host_machine, "", HOST_KERNEL_ID); | ||
80 | 101 | ||
81 | if (mode == O_RDONLY) { | 102 | if (mode == O_RDONLY) { |
82 | if (perf_session__open(self, force) < 0) | 103 | if (perf_session__open(self, force) < 0) |
@@ -90,7 +111,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc | |||
90 | goto out_delete; | 111 | goto out_delete; |
91 | } | 112 | } |
92 | 113 | ||
93 | self->sample_type = perf_header__sample_type(&self->header); | 114 | perf_session__update_sample_type(self); |
94 | out: | 115 | out: |
95 | return self; | 116 | return self; |
96 | out_free: | 117 | out_free: |
@@ -117,22 +138,17 @@ static bool symbol__match_parent_regex(struct symbol *sym) | |||
117 | return 0; | 138 | return 0; |
118 | } | 139 | } |
119 | 140 | ||
120 | struct symbol **perf_session__resolve_callchain(struct perf_session *self, | 141 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
121 | struct thread *thread, | 142 | struct thread *thread, |
122 | struct ip_callchain *chain, | 143 | struct ip_callchain *chain, |
123 | struct symbol **parent) | 144 | struct symbol **parent) |
124 | { | 145 | { |
125 | u8 cpumode = PERF_RECORD_MISC_USER; | 146 | u8 cpumode = PERF_RECORD_MISC_USER; |
126 | struct symbol **syms = NULL; | ||
127 | unsigned int i; | 147 | unsigned int i; |
148 | struct map_symbol *syms = calloc(chain->nr, sizeof(*syms)); | ||
128 | 149 | ||
129 | if (symbol_conf.use_callchain) { | 150 | if (!syms) |
130 | syms = calloc(chain->nr, sizeof(*syms)); | 151 | return NULL; |
131 | if (!syms) { | ||
132 | fprintf(stderr, "Can't allocate memory for symbols\n"); | ||
133 | exit(-1); | ||
134 | } | ||
135 | } | ||
136 | 152 | ||
137 | for (i = 0; i < chain->nr; i++) { | 153 | for (i = 0; i < chain->nr; i++) { |
138 | u64 ip = chain->ips[i]; | 154 | u64 ip = chain->ips[i]; |
@@ -152,15 +168,17 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self, | |||
152 | continue; | 168 | continue; |
153 | } | 169 | } |
154 | 170 | ||
171 | al.filtered = false; | ||
155 | thread__find_addr_location(thread, self, cpumode, | 172 | thread__find_addr_location(thread, self, cpumode, |
156 | MAP__FUNCTION, ip, &al, NULL); | 173 | MAP__FUNCTION, thread->pid, ip, &al, NULL); |
157 | if (al.sym != NULL) { | 174 | if (al.sym != NULL) { |
158 | if (sort__has_parent && !*parent && | 175 | if (sort__has_parent && !*parent && |
159 | symbol__match_parent_regex(al.sym)) | 176 | symbol__match_parent_regex(al.sym)) |
160 | *parent = al.sym; | 177 | *parent = al.sym; |
161 | if (!symbol_conf.use_callchain) | 178 | if (!symbol_conf.use_callchain) |
162 | break; | 179 | break; |
163 | syms[i] = al.sym; | 180 | syms[i].map = al.map; |
181 | syms[i].sym = al.sym; | ||
164 | } | 182 | } |
165 | } | 183 | } |
166 | 184 | ||
@@ -174,6 +192,18 @@ static int process_event_stub(event_t *event __used, | |||
174 | return 0; | 192 | return 0; |
175 | } | 193 | } |
176 | 194 | ||
195 | static int process_finished_round_stub(event_t *event __used, | ||
196 | struct perf_session *session __used, | ||
197 | struct perf_event_ops *ops __used) | ||
198 | { | ||
199 | dump_printf(": unhandled!\n"); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int process_finished_round(event_t *event, | ||
204 | struct perf_session *session, | ||
205 | struct perf_event_ops *ops); | ||
206 | |||
177 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | 207 | static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) |
178 | { | 208 | { |
179 | if (handler->sample == NULL) | 209 | if (handler->sample == NULL) |
@@ -194,29 +224,20 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler) | |||
194 | handler->throttle = process_event_stub; | 224 | handler->throttle = process_event_stub; |
195 | if (handler->unthrottle == NULL) | 225 | if (handler->unthrottle == NULL) |
196 | handler->unthrottle = process_event_stub; | 226 | handler->unthrottle = process_event_stub; |
197 | } | 227 | if (handler->attr == NULL) |
198 | 228 | handler->attr = process_event_stub; | |
199 | static const char *event__name[] = { | 229 | if (handler->event_type == NULL) |
200 | [0] = "TOTAL", | 230 | handler->event_type = process_event_stub; |
201 | [PERF_RECORD_MMAP] = "MMAP", | 231 | if (handler->tracing_data == NULL) |
202 | [PERF_RECORD_LOST] = "LOST", | 232 | handler->tracing_data = process_event_stub; |
203 | [PERF_RECORD_COMM] = "COMM", | 233 | if (handler->build_id == NULL) |
204 | [PERF_RECORD_EXIT] = "EXIT", | 234 | handler->build_id = process_event_stub; |
205 | [PERF_RECORD_THROTTLE] = "THROTTLE", | 235 | if (handler->finished_round == NULL) { |
206 | [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE", | 236 | if (handler->ordered_samples) |
207 | [PERF_RECORD_FORK] = "FORK", | 237 | handler->finished_round = process_finished_round; |
208 | [PERF_RECORD_READ] = "READ", | 238 | else |
209 | [PERF_RECORD_SAMPLE] = "SAMPLE", | 239 | handler->finished_round = process_finished_round_stub; |
210 | }; | 240 | } |
211 | |||
212 | unsigned long event__total[PERF_RECORD_MAX]; | ||
213 | |||
214 | void event__print_totals(void) | ||
215 | { | ||
216 | int i; | ||
217 | for (i = 0; i < PERF_RECORD_MAX; ++i) | ||
218 | pr_info("%10s events: %10ld\n", | ||
219 | event__name[i], event__total[i]); | ||
220 | } | 241 | } |
221 | 242 | ||
222 | void mem_bswap_64(void *src, int byte_size) | 243 | void mem_bswap_64(void *src, int byte_size) |
@@ -270,6 +291,37 @@ static void event__read_swap(event_t *self) | |||
270 | self->read.id = bswap_64(self->read.id); | 291 | self->read.id = bswap_64(self->read.id); |
271 | } | 292 | } |
272 | 293 | ||
294 | static void event__attr_swap(event_t *self) | ||
295 | { | ||
296 | size_t size; | ||
297 | |||
298 | self->attr.attr.type = bswap_32(self->attr.attr.type); | ||
299 | self->attr.attr.size = bswap_32(self->attr.attr.size); | ||
300 | self->attr.attr.config = bswap_64(self->attr.attr.config); | ||
301 | self->attr.attr.sample_period = bswap_64(self->attr.attr.sample_period); | ||
302 | self->attr.attr.sample_type = bswap_64(self->attr.attr.sample_type); | ||
303 | self->attr.attr.read_format = bswap_64(self->attr.attr.read_format); | ||
304 | self->attr.attr.wakeup_events = bswap_32(self->attr.attr.wakeup_events); | ||
305 | self->attr.attr.bp_type = bswap_32(self->attr.attr.bp_type); | ||
306 | self->attr.attr.bp_addr = bswap_64(self->attr.attr.bp_addr); | ||
307 | self->attr.attr.bp_len = bswap_64(self->attr.attr.bp_len); | ||
308 | |||
309 | size = self->header.size; | ||
310 | size -= (void *)&self->attr.id - (void *)self; | ||
311 | mem_bswap_64(self->attr.id, size); | ||
312 | } | ||
313 | |||
314 | static void event__event_type_swap(event_t *self) | ||
315 | { | ||
316 | self->event_type.event_type.event_id = | ||
317 | bswap_64(self->event_type.event_type.event_id); | ||
318 | } | ||
319 | |||
320 | static void event__tracing_data_swap(event_t *self) | ||
321 | { | ||
322 | self->tracing_data.size = bswap_32(self->tracing_data.size); | ||
323 | } | ||
324 | |||
273 | typedef void (*event__swap_op)(event_t *self); | 325 | typedef void (*event__swap_op)(event_t *self); |
274 | 326 | ||
275 | static event__swap_op event__swap_ops[] = { | 327 | static event__swap_op event__swap_ops[] = { |
@@ -280,9 +332,212 @@ static event__swap_op event__swap_ops[] = { | |||
280 | [PERF_RECORD_LOST] = event__all64_swap, | 332 | [PERF_RECORD_LOST] = event__all64_swap, |
281 | [PERF_RECORD_READ] = event__read_swap, | 333 | [PERF_RECORD_READ] = event__read_swap, |
282 | [PERF_RECORD_SAMPLE] = event__all64_swap, | 334 | [PERF_RECORD_SAMPLE] = event__all64_swap, |
283 | [PERF_RECORD_MAX] = NULL, | 335 | [PERF_RECORD_HEADER_ATTR] = event__attr_swap, |
336 | [PERF_RECORD_HEADER_EVENT_TYPE] = event__event_type_swap, | ||
337 | [PERF_RECORD_HEADER_TRACING_DATA] = event__tracing_data_swap, | ||
338 | [PERF_RECORD_HEADER_BUILD_ID] = NULL, | ||
339 | [PERF_RECORD_HEADER_MAX] = NULL, | ||
284 | }; | 340 | }; |
285 | 341 | ||
342 | struct sample_queue { | ||
343 | u64 timestamp; | ||
344 | struct sample_event *event; | ||
345 | struct list_head list; | ||
346 | }; | ||
347 | |||
348 | static void flush_sample_queue(struct perf_session *s, | ||
349 | struct perf_event_ops *ops) | ||
350 | { | ||
351 | struct list_head *head = &s->ordered_samples.samples_head; | ||
352 | u64 limit = s->ordered_samples.next_flush; | ||
353 | struct sample_queue *tmp, *iter; | ||
354 | |||
355 | if (!ops->ordered_samples || !limit) | ||
356 | return; | ||
357 | |||
358 | list_for_each_entry_safe(iter, tmp, head, list) { | ||
359 | if (iter->timestamp > limit) | ||
360 | return; | ||
361 | |||
362 | if (iter == s->ordered_samples.last_inserted) | ||
363 | s->ordered_samples.last_inserted = NULL; | ||
364 | |||
365 | ops->sample((event_t *)iter->event, s); | ||
366 | |||
367 | s->ordered_samples.last_flush = iter->timestamp; | ||
368 | list_del(&iter->list); | ||
369 | free(iter->event); | ||
370 | free(iter); | ||
371 | } | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | * When perf record finishes a pass on every buffers, it records this pseudo | ||
376 | * event. | ||
377 | * We record the max timestamp t found in the pass n. | ||
378 | * Assuming these timestamps are monotonic across cpus, we know that if | ||
379 | * a buffer still has events with timestamps below t, they will be all | ||
380 | * available and then read in the pass n + 1. | ||
381 | * Hence when we start to read the pass n + 2, we can safely flush every | ||
382 | * events with timestamps below t. | ||
383 | * | ||
384 | * ============ PASS n ================= | ||
385 | * CPU 0 | CPU 1 | ||
386 | * | | ||
387 | * cnt1 timestamps | cnt2 timestamps | ||
388 | * 1 | 2 | ||
389 | * 2 | 3 | ||
390 | * - | 4 <--- max recorded | ||
391 | * | ||
392 | * ============ PASS n + 1 ============== | ||
393 | * CPU 0 | CPU 1 | ||
394 | * | | ||
395 | * cnt1 timestamps | cnt2 timestamps | ||
396 | * 3 | 5 | ||
397 | * 4 | 6 | ||
398 | * 5 | 7 <---- max recorded | ||
399 | * | ||
400 | * Flush every events below timestamp 4 | ||
401 | * | ||
402 | * ============ PASS n + 2 ============== | ||
403 | * CPU 0 | CPU 1 | ||
404 | * | | ||
405 | * cnt1 timestamps | cnt2 timestamps | ||
406 | * 6 | 8 | ||
407 | * 7 | 9 | ||
408 | * - | 10 | ||
409 | * | ||
410 | * Flush every events below timestamp 7 | ||
411 | * etc... | ||
412 | */ | ||
413 | static int process_finished_round(event_t *event __used, | ||
414 | struct perf_session *session, | ||
415 | struct perf_event_ops *ops) | ||
416 | { | ||
417 | flush_sample_queue(session, ops); | ||
418 | session->ordered_samples.next_flush = session->ordered_samples.max_timestamp; | ||
419 | |||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | static void __queue_sample_end(struct sample_queue *new, struct list_head *head) | ||
424 | { | ||
425 | struct sample_queue *iter; | ||
426 | |||
427 | list_for_each_entry_reverse(iter, head, list) { | ||
428 | if (iter->timestamp < new->timestamp) { | ||
429 | list_add(&new->list, &iter->list); | ||
430 | return; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | list_add(&new->list, head); | ||
435 | } | ||
436 | |||
437 | static void __queue_sample_before(struct sample_queue *new, | ||
438 | struct sample_queue *iter, | ||
439 | struct list_head *head) | ||
440 | { | ||
441 | list_for_each_entry_continue_reverse(iter, head, list) { | ||
442 | if (iter->timestamp < new->timestamp) { | ||
443 | list_add(&new->list, &iter->list); | ||
444 | return; | ||
445 | } | ||
446 | } | ||
447 | |||
448 | list_add(&new->list, head); | ||
449 | } | ||
450 | |||
451 | static void __queue_sample_after(struct sample_queue *new, | ||
452 | struct sample_queue *iter, | ||
453 | struct list_head *head) | ||
454 | { | ||
455 | list_for_each_entry_continue(iter, head, list) { | ||
456 | if (iter->timestamp > new->timestamp) { | ||
457 | list_add_tail(&new->list, &iter->list); | ||
458 | return; | ||
459 | } | ||
460 | } | ||
461 | list_add_tail(&new->list, head); | ||
462 | } | ||
463 | |||
464 | /* The queue is ordered by time */ | ||
465 | static void __queue_sample_event(struct sample_queue *new, | ||
466 | struct perf_session *s) | ||
467 | { | ||
468 | struct sample_queue *last_inserted = s->ordered_samples.last_inserted; | ||
469 | struct list_head *head = &s->ordered_samples.samples_head; | ||
470 | |||
471 | |||
472 | if (!last_inserted) { | ||
473 | __queue_sample_end(new, head); | ||
474 | return; | ||
475 | } | ||
476 | |||
477 | /* | ||
478 | * Most of the time the current event has a timestamp | ||
479 | * very close to the last event inserted, unless we just switched | ||
480 | * to another event buffer. Having a sorting based on a list and | ||
481 | * on the last inserted event that is close to the current one is | ||
482 | * probably more efficient than an rbtree based sorting. | ||
483 | */ | ||
484 | if (last_inserted->timestamp >= new->timestamp) | ||
485 | __queue_sample_before(new, last_inserted, head); | ||
486 | else | ||
487 | __queue_sample_after(new, last_inserted, head); | ||
488 | } | ||
489 | |||
490 | static int queue_sample_event(event_t *event, struct sample_data *data, | ||
491 | struct perf_session *s) | ||
492 | { | ||
493 | u64 timestamp = data->time; | ||
494 | struct sample_queue *new; | ||
495 | |||
496 | |||
497 | if (timestamp < s->ordered_samples.last_flush) { | ||
498 | printf("Warning: Timestamp below last timeslice flush\n"); | ||
499 | return -EINVAL; | ||
500 | } | ||
501 | |||
502 | new = malloc(sizeof(*new)); | ||
503 | if (!new) | ||
504 | return -ENOMEM; | ||
505 | |||
506 | new->timestamp = timestamp; | ||
507 | |||
508 | new->event = malloc(event->header.size); | ||
509 | if (!new->event) { | ||
510 | free(new); | ||
511 | return -ENOMEM; | ||
512 | } | ||
513 | |||
514 | memcpy(new->event, event, event->header.size); | ||
515 | |||
516 | __queue_sample_event(new, s); | ||
517 | s->ordered_samples.last_inserted = new; | ||
518 | |||
519 | if (new->timestamp > s->ordered_samples.max_timestamp) | ||
520 | s->ordered_samples.max_timestamp = new->timestamp; | ||
521 | |||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | static int perf_session__process_sample(event_t *event, struct perf_session *s, | ||
526 | struct perf_event_ops *ops) | ||
527 | { | ||
528 | struct sample_data data; | ||
529 | |||
530 | if (!ops->ordered_samples) | ||
531 | return ops->sample(event, s); | ||
532 | |||
533 | bzero(&data, sizeof(struct sample_data)); | ||
534 | event__parse_sample(event, s->sample_type, &data); | ||
535 | |||
536 | queue_sample_event(event, &data, s); | ||
537 | |||
538 | return 0; | ||
539 | } | ||
540 | |||
286 | static int perf_session__process_event(struct perf_session *self, | 541 | static int perf_session__process_event(struct perf_session *self, |
287 | event_t *event, | 542 | event_t *event, |
288 | struct perf_event_ops *ops, | 543 | struct perf_event_ops *ops, |
@@ -290,12 +545,11 @@ static int perf_session__process_event(struct perf_session *self, | |||
290 | { | 545 | { |
291 | trace_event(event); | 546 | trace_event(event); |
292 | 547 | ||
293 | if (event->header.type < PERF_RECORD_MAX) { | 548 | if (event->header.type < PERF_RECORD_HEADER_MAX) { |
294 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", | 549 | dump_printf("%#Lx [%#x]: PERF_RECORD_%s", |
295 | offset + head, event->header.size, | 550 | offset + head, event->header.size, |
296 | event__name[event->header.type]); | 551 | event__name[event->header.type]); |
297 | ++event__total[0]; | 552 | hists__inc_nr_events(&self->hists, event->header.type); |
298 | ++event__total[event->header.type]; | ||
299 | } | 553 | } |
300 | 554 | ||
301 | if (self->header.needs_swap && event__swap_ops[event->header.type]) | 555 | if (self->header.needs_swap && event__swap_ops[event->header.type]) |
@@ -303,7 +557,7 @@ static int perf_session__process_event(struct perf_session *self, | |||
303 | 557 | ||
304 | switch (event->header.type) { | 558 | switch (event->header.type) { |
305 | case PERF_RECORD_SAMPLE: | 559 | case PERF_RECORD_SAMPLE: |
306 | return ops->sample(event, self); | 560 | return perf_session__process_sample(event, self, ops); |
307 | case PERF_RECORD_MMAP: | 561 | case PERF_RECORD_MMAP: |
308 | return ops->mmap(event, self); | 562 | return ops->mmap(event, self); |
309 | case PERF_RECORD_COMM: | 563 | case PERF_RECORD_COMM: |
@@ -320,8 +574,20 @@ static int perf_session__process_event(struct perf_session *self, | |||
320 | return ops->throttle(event, self); | 574 | return ops->throttle(event, self); |
321 | case PERF_RECORD_UNTHROTTLE: | 575 | case PERF_RECORD_UNTHROTTLE: |
322 | return ops->unthrottle(event, self); | 576 | return ops->unthrottle(event, self); |
577 | case PERF_RECORD_HEADER_ATTR: | ||
578 | return ops->attr(event, self); | ||
579 | case PERF_RECORD_HEADER_EVENT_TYPE: | ||
580 | return ops->event_type(event, self); | ||
581 | case PERF_RECORD_HEADER_TRACING_DATA: | ||
582 | /* setup for reading amidst mmap */ | ||
583 | lseek(self->fd, offset + head, SEEK_SET); | ||
584 | return ops->tracing_data(event, self); | ||
585 | case PERF_RECORD_HEADER_BUILD_ID: | ||
586 | return ops->build_id(event, self); | ||
587 | case PERF_RECORD_FINISHED_ROUND: | ||
588 | return ops->finished_round(event, self, ops); | ||
323 | default: | 589 | default: |
324 | self->unknown_events++; | 590 | ++self->hists.stats.nr_unknown_events; |
325 | return -1; | 591 | return -1; |
326 | } | 592 | } |
327 | } | 593 | } |
@@ -333,56 +599,114 @@ void perf_event_header__bswap(struct perf_event_header *self) | |||
333 | self->size = bswap_16(self->size); | 599 | self->size = bswap_16(self->size); |
334 | } | 600 | } |
335 | 601 | ||
336 | int perf_header__read_build_ids(struct perf_header *self, | 602 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) |
337 | int input, u64 offset, u64 size) | ||
338 | { | 603 | { |
339 | struct build_id_event bev; | 604 | struct thread *thread = perf_session__findnew(self, 0); |
340 | char filename[PATH_MAX]; | ||
341 | u64 limit = offset + size; | ||
342 | int err = -1; | ||
343 | |||
344 | while (offset < limit) { | ||
345 | struct dso *dso; | ||
346 | ssize_t len; | ||
347 | struct list_head *head = &dsos__user; | ||
348 | 605 | ||
349 | if (read(input, &bev, sizeof(bev)) != sizeof(bev)) | 606 | if (thread == NULL || thread__set_comm(thread, "swapper")) { |
350 | goto out; | 607 | pr_err("problem inserting idle task.\n"); |
608 | thread = NULL; | ||
609 | } | ||
351 | 610 | ||
352 | if (self->needs_swap) | 611 | return thread; |
353 | perf_event_header__bswap(&bev.header); | 612 | } |
354 | 613 | ||
355 | len = bev.header.size - sizeof(bev); | 614 | int do_read(int fd, void *buf, size_t size) |
356 | if (read(input, filename, len) != len) | 615 | { |
357 | goto out; | 616 | void *buf_start = buf; |
358 | 617 | ||
359 | if (bev.header.misc & PERF_RECORD_MISC_KERNEL) | 618 | while (size) { |
360 | head = &dsos__kernel; | 619 | int ret = read(fd, buf, size); |
361 | 620 | ||
362 | dso = __dsos__findnew(head, filename); | 621 | if (ret <= 0) |
363 | if (dso != NULL) { | 622 | return ret; |
364 | dso__set_build_id(dso, &bev.build_id); | ||
365 | if (head == &dsos__kernel && filename[0] == '[') | ||
366 | dso->kernel = 1; | ||
367 | } | ||
368 | 623 | ||
369 | offset += bev.header.size; | 624 | size -= ret; |
625 | buf += ret; | ||
370 | } | 626 | } |
371 | err = 0; | 627 | |
372 | out: | 628 | return buf - buf_start; |
373 | return err; | ||
374 | } | 629 | } |
375 | 630 | ||
376 | static struct thread *perf_session__register_idle_thread(struct perf_session *self) | 631 | #define session_done() (*(volatile int *)(&session_done)) |
632 | volatile int session_done; | ||
633 | |||
634 | static int __perf_session__process_pipe_events(struct perf_session *self, | ||
635 | struct perf_event_ops *ops) | ||
377 | { | 636 | { |
378 | struct thread *thread = perf_session__findnew(self, 0); | 637 | event_t event; |
638 | uint32_t size; | ||
639 | int skip = 0; | ||
640 | u64 head; | ||
641 | int err; | ||
642 | void *p; | ||
379 | 643 | ||
380 | if (thread == NULL || thread__set_comm(thread, "swapper")) { | 644 | perf_event_ops__fill_defaults(ops); |
381 | pr_err("problem inserting idle task.\n"); | 645 | |
382 | thread = NULL; | 646 | head = 0; |
647 | more: | ||
648 | err = do_read(self->fd, &event, sizeof(struct perf_event_header)); | ||
649 | if (err <= 0) { | ||
650 | if (err == 0) | ||
651 | goto done; | ||
652 | |||
653 | pr_err("failed to read event header\n"); | ||
654 | goto out_err; | ||
383 | } | 655 | } |
384 | 656 | ||
385 | return thread; | 657 | if (self->header.needs_swap) |
658 | perf_event_header__bswap(&event.header); | ||
659 | |||
660 | size = event.header.size; | ||
661 | if (size == 0) | ||
662 | size = 8; | ||
663 | |||
664 | p = &event; | ||
665 | p += sizeof(struct perf_event_header); | ||
666 | |||
667 | if (size - sizeof(struct perf_event_header)) { | ||
668 | err = do_read(self->fd, p, | ||
669 | size - sizeof(struct perf_event_header)); | ||
670 | if (err <= 0) { | ||
671 | if (err == 0) { | ||
672 | pr_err("unexpected end of event stream\n"); | ||
673 | goto done; | ||
674 | } | ||
675 | |||
676 | pr_err("failed to read event data\n"); | ||
677 | goto out_err; | ||
678 | } | ||
679 | } | ||
680 | |||
681 | if (size == 0 || | ||
682 | (skip = perf_session__process_event(self, &event, ops, | ||
683 | 0, head)) < 0) { | ||
684 | dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", | ||
685 | head, event.header.size, event.header.type); | ||
686 | /* | ||
687 | * assume we lost track of the stream, check alignment, and | ||
688 | * increment a single u64 in the hope to catch on again 'soon'. | ||
689 | */ | ||
690 | if (unlikely(head & 7)) | ||
691 | head &= ~7ULL; | ||
692 | |||
693 | size = 8; | ||
694 | } | ||
695 | |||
696 | head += size; | ||
697 | |||
698 | dump_printf("\n%#Lx [%#x]: event: %d\n", | ||
699 | head, event.header.size, event.header.type); | ||
700 | |||
701 | if (skip > 0) | ||
702 | head += skip; | ||
703 | |||
704 | if (!session_done()) | ||
705 | goto more; | ||
706 | done: | ||
707 | err = 0; | ||
708 | out_err: | ||
709 | return err; | ||
386 | } | 710 | } |
387 | 711 | ||
388 | int __perf_session__process_events(struct perf_session *self, | 712 | int __perf_session__process_events(struct perf_session *self, |
@@ -396,6 +720,10 @@ int __perf_session__process_events(struct perf_session *self, | |||
396 | event_t *event; | 720 | event_t *event; |
397 | uint32_t size; | 721 | uint32_t size; |
398 | char *buf; | 722 | char *buf; |
723 | struct ui_progress *progress = ui_progress__new("Processing events...", | ||
724 | self->size); | ||
725 | if (progress == NULL) | ||
726 | return -1; | ||
399 | 727 | ||
400 | perf_event_ops__fill_defaults(ops); | 728 | perf_event_ops__fill_defaults(ops); |
401 | 729 | ||
@@ -424,6 +752,7 @@ remap: | |||
424 | 752 | ||
425 | more: | 753 | more: |
426 | event = (event_t *)(buf + head); | 754 | event = (event_t *)(buf + head); |
755 | ui_progress__update(progress, offset); | ||
427 | 756 | ||
428 | if (self->header.needs_swap) | 757 | if (self->header.needs_swap) |
429 | perf_event_header__bswap(&event->header); | 758 | perf_event_header__bswap(&event->header); |
@@ -473,7 +802,11 @@ more: | |||
473 | goto more; | 802 | goto more; |
474 | done: | 803 | done: |
475 | err = 0; | 804 | err = 0; |
805 | /* do the final flush for ordered samples */ | ||
806 | self->ordered_samples.next_flush = ULLONG_MAX; | ||
807 | flush_sample_queue(self, ops); | ||
476 | out_err: | 808 | out_err: |
809 | ui_progress__delete(progress); | ||
477 | return err; | 810 | return err; |
478 | } | 811 | } |
479 | 812 | ||
@@ -502,9 +835,13 @@ out_getcwd_err: | |||
502 | self->cwdlen = strlen(self->cwd); | 835 | self->cwdlen = strlen(self->cwd); |
503 | } | 836 | } |
504 | 837 | ||
505 | err = __perf_session__process_events(self, self->header.data_offset, | 838 | if (!self->fd_pipe) |
506 | self->header.data_size, | 839 | err = __perf_session__process_events(self, |
507 | self->size, ops); | 840 | self->header.data_offset, |
841 | self->header.data_size, | ||
842 | self->size, ops); | ||
843 | else | ||
844 | err = __perf_session__process_pipe_events(self, ops); | ||
508 | out_err: | 845 | out_err: |
509 | return err; | 846 | return err; |
510 | } | 847 | } |
@@ -519,56 +856,41 @@ bool perf_session__has_traces(struct perf_session *self, const char *msg) | |||
519 | return true; | 856 | return true; |
520 | } | 857 | } |
521 | 858 | ||
522 | int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self, | 859 | int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, |
523 | const char *symbol_name, | 860 | const char *symbol_name, |
524 | u64 addr) | 861 | u64 addr) |
525 | { | 862 | { |
526 | char *bracket; | 863 | char *bracket; |
527 | enum map_type i; | 864 | enum map_type i; |
865 | struct ref_reloc_sym *ref; | ||
528 | 866 | ||
529 | self->ref_reloc_sym.name = strdup(symbol_name); | 867 | ref = zalloc(sizeof(struct ref_reloc_sym)); |
530 | if (self->ref_reloc_sym.name == NULL) | 868 | if (ref == NULL) |
531 | return -ENOMEM; | 869 | return -ENOMEM; |
532 | 870 | ||
533 | bracket = strchr(self->ref_reloc_sym.name, ']'); | 871 | ref->name = strdup(symbol_name); |
872 | if (ref->name == NULL) { | ||
873 | free(ref); | ||
874 | return -ENOMEM; | ||
875 | } | ||
876 | |||
877 | bracket = strchr(ref->name, ']'); | ||
534 | if (bracket) | 878 | if (bracket) |
535 | *bracket = '\0'; | 879 | *bracket = '\0'; |
536 | 880 | ||
537 | self->ref_reloc_sym.addr = addr; | 881 | ref->addr = addr; |
538 | 882 | ||
539 | for (i = 0; i < MAP__NR_TYPES; ++i) { | 883 | for (i = 0; i < MAP__NR_TYPES; ++i) { |
540 | struct kmap *kmap = map__kmap(self->vmlinux_maps[i]); | 884 | struct kmap *kmap = map__kmap(maps[i]); |
541 | kmap->ref_reloc_sym = &self->ref_reloc_sym; | 885 | kmap->ref_reloc_sym = ref; |
542 | } | 886 | } |
543 | 887 | ||
544 | return 0; | 888 | return 0; |
545 | } | 889 | } |
546 | 890 | ||
547 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | 891 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) |
548 | { | ||
549 | return ip + (s64)map->pgoff; | ||
550 | } | ||
551 | |||
552 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
553 | { | ||
554 | return ip - (s64)map->pgoff; | ||
555 | } | ||
556 | |||
557 | void map__reloc_vmlinux(struct map *self) | ||
558 | { | 892 | { |
559 | struct kmap *kmap = map__kmap(self); | 893 | return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + |
560 | s64 reloc; | 894 | __dsos__fprintf(&self->host_machine.user_dsos, fp) + |
561 | 895 | machines__fprintf_dsos(&self->machines, fp); | |
562 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
563 | return; | ||
564 | |||
565 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
566 | kmap->ref_reloc_sym->addr); | ||
567 | |||
568 | if (!reloc) | ||
569 | return; | ||
570 | |||
571 | self->map_ip = map__reloc_map_ip; | ||
572 | self->unmap_ip = map__reloc_unmap_ip; | ||
573 | self->pgoff = reloc; | ||
574 | } | 896 | } |
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 5c33417eebb3..e7fce486ebe2 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __PERF_SESSION_H | 1 | #ifndef __PERF_SESSION_H |
2 | #define __PERF_SESSION_H | 2 | #define __PERF_SESSION_H |
3 | 3 | ||
4 | #include "hist.h" | ||
4 | #include "event.h" | 5 | #include "event.h" |
5 | #include "header.h" | 6 | #include "header.h" |
6 | #include "symbol.h" | 7 | #include "symbol.h" |
@@ -8,45 +9,69 @@ | |||
8 | #include <linux/rbtree.h> | 9 | #include <linux/rbtree.h> |
9 | #include "../../../include/linux/perf_event.h" | 10 | #include "../../../include/linux/perf_event.h" |
10 | 11 | ||
12 | struct sample_queue; | ||
11 | struct ip_callchain; | 13 | struct ip_callchain; |
12 | struct thread; | 14 | struct thread; |
13 | 15 | ||
16 | struct ordered_samples { | ||
17 | u64 last_flush; | ||
18 | u64 next_flush; | ||
19 | u64 max_timestamp; | ||
20 | struct list_head samples_head; | ||
21 | struct sample_queue *last_inserted; | ||
22 | }; | ||
23 | |||
14 | struct perf_session { | 24 | struct perf_session { |
15 | struct perf_header header; | 25 | struct perf_header header; |
16 | unsigned long size; | 26 | unsigned long size; |
17 | unsigned long mmap_window; | 27 | unsigned long mmap_window; |
18 | struct map_groups kmaps; | ||
19 | struct rb_root threads; | 28 | struct rb_root threads; |
20 | struct thread *last_match; | 29 | struct thread *last_match; |
21 | struct map *vmlinux_maps[MAP__NR_TYPES]; | 30 | struct machine host_machine; |
22 | struct events_stats events_stats; | 31 | struct rb_root machines; |
23 | struct rb_root stats_by_id; | 32 | struct rb_root hists_tree; |
24 | unsigned long event_total[PERF_RECORD_MAX]; | 33 | /* |
25 | unsigned long unknown_events; | 34 | * FIXME: should point to the first entry in hists_tree and |
26 | struct rb_root hists; | 35 | * be a hists instance. Right now its only 'report' |
36 | * that is using ->hists_tree while all the rest use | ||
37 | * ->hists. | ||
38 | */ | ||
39 | struct hists hists; | ||
27 | u64 sample_type; | 40 | u64 sample_type; |
28 | struct ref_reloc_sym ref_reloc_sym; | ||
29 | int fd; | 41 | int fd; |
42 | bool fd_pipe; | ||
43 | bool repipe; | ||
30 | int cwdlen; | 44 | int cwdlen; |
31 | char *cwd; | 45 | char *cwd; |
46 | struct ordered_samples ordered_samples; | ||
32 | char filename[0]; | 47 | char filename[0]; |
33 | }; | 48 | }; |
34 | 49 | ||
50 | struct perf_event_ops; | ||
51 | |||
35 | typedef int (*event_op)(event_t *self, struct perf_session *session); | 52 | typedef int (*event_op)(event_t *self, struct perf_session *session); |
53 | typedef int (*event_op2)(event_t *self, struct perf_session *session, | ||
54 | struct perf_event_ops *ops); | ||
36 | 55 | ||
37 | struct perf_event_ops { | 56 | struct perf_event_ops { |
38 | event_op sample, | 57 | event_op sample, |
39 | mmap, | 58 | mmap, |
40 | comm, | 59 | comm, |
41 | fork, | 60 | fork, |
42 | exit, | 61 | exit, |
43 | lost, | 62 | lost, |
44 | read, | 63 | read, |
45 | throttle, | 64 | throttle, |
46 | unthrottle; | 65 | unthrottle, |
66 | attr, | ||
67 | event_type, | ||
68 | tracing_data, | ||
69 | build_id; | ||
70 | event_op2 finished_round; | ||
71 | bool ordered_samples; | ||
47 | }; | 72 | }; |
48 | 73 | ||
49 | struct perf_session *perf_session__new(const char *filename, int mode, bool force); | 74 | struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe); |
50 | void perf_session__delete(struct perf_session *self); | 75 | void perf_session__delete(struct perf_session *self); |
51 | 76 | ||
52 | void perf_event_header__bswap(struct perf_event_header *self); | 77 | void perf_event_header__bswap(struct perf_event_header *self); |
@@ -57,33 +82,66 @@ int __perf_session__process_events(struct perf_session *self, | |||
57 | int perf_session__process_events(struct perf_session *self, | 82 | int perf_session__process_events(struct perf_session *self, |
58 | struct perf_event_ops *event_ops); | 83 | struct perf_event_ops *event_ops); |
59 | 84 | ||
60 | struct symbol **perf_session__resolve_callchain(struct perf_session *self, | 85 | struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, |
61 | struct thread *thread, | 86 | struct thread *thread, |
62 | struct ip_callchain *chain, | 87 | struct ip_callchain *chain, |
63 | struct symbol **parent); | 88 | struct symbol **parent); |
64 | 89 | ||
65 | bool perf_session__has_traces(struct perf_session *self, const char *msg); | 90 | bool perf_session__has_traces(struct perf_session *self, const char *msg); |
66 | 91 | ||
67 | int perf_header__read_build_ids(struct perf_header *self, int input, | 92 | int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, |
68 | u64 offset, u64 file_size); | ||
69 | |||
70 | int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self, | ||
71 | const char *symbol_name, | 93 | const char *symbol_name, |
72 | u64 addr); | 94 | u64 addr); |
73 | 95 | ||
74 | void mem_bswap_64(void *src, int byte_size); | 96 | void mem_bswap_64(void *src, int byte_size); |
75 | 97 | ||
76 | static inline int __perf_session__create_kernel_maps(struct perf_session *self, | 98 | int perf_session__create_kernel_maps(struct perf_session *self); |
77 | struct dso *kernel) | 99 | |
100 | int do_read(int fd, void *buf, size_t size); | ||
101 | void perf_session__update_sample_type(struct perf_session *self); | ||
102 | |||
103 | static inline | ||
104 | struct machine *perf_session__find_host_machine(struct perf_session *self) | ||
105 | { | ||
106 | return &self->host_machine; | ||
107 | } | ||
108 | |||
109 | static inline | ||
110 | struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) | ||
111 | { | ||
112 | if (pid == HOST_KERNEL_ID) | ||
113 | return &self->host_machine; | ||
114 | return machines__find(&self->machines, pid); | ||
115 | } | ||
116 | |||
117 | static inline | ||
118 | struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) | ||
119 | { | ||
120 | if (pid == HOST_KERNEL_ID) | ||
121 | return &self->host_machine; | ||
122 | return machines__findnew(&self->machines, pid); | ||
123 | } | ||
124 | |||
125 | static inline | ||
126 | void perf_session__process_machines(struct perf_session *self, | ||
127 | machine__process_t process) | ||
128 | { | ||
129 | process(&self->host_machine, self); | ||
130 | return machines__process(&self->machines, process, self); | ||
131 | } | ||
132 | |||
133 | size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); | ||
134 | |||
135 | static inline | ||
136 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, | ||
137 | bool with_hits) | ||
78 | { | 138 | { |
79 | return __map_groups__create_kernel_maps(&self->kmaps, | 139 | return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits); |
80 | self->vmlinux_maps, kernel); | ||
81 | } | 140 | } |
82 | 141 | ||
83 | static inline struct map * | 142 | static inline |
84 | perf_session__new_module_map(struct perf_session *self, | 143 | size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) |
85 | u64 start, const char *filename) | ||
86 | { | 144 | { |
87 | return map_groups__new_module(&self->kmaps, start, filename); | 145 | return hists__fprintf_nr_events(&self->hists, fp); |
88 | } | 146 | } |
89 | #endif /* __PERF_SESSION_H */ | 147 | #endif /* __PERF_SESSION_H */ |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index cb0f327de9e8..2316cb5a4116 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -1,10 +1,10 @@ | |||
1 | #include "sort.h" | 1 | #include "sort.h" |
2 | 2 | ||
3 | regex_t parent_regex; | 3 | regex_t parent_regex; |
4 | char default_parent_pattern[] = "^sys_|^do_page_fault"; | 4 | const char default_parent_pattern[] = "^sys_|^do_page_fault"; |
5 | char *parent_pattern = default_parent_pattern; | 5 | const char *parent_pattern = default_parent_pattern; |
6 | char default_sort_order[] = "comm,dso,symbol"; | 6 | const char default_sort_order[] = "comm,dso,symbol"; |
7 | char *sort_order = default_sort_order; | 7 | const char *sort_order = default_sort_order; |
8 | int sort__need_collapse = 0; | 8 | int sort__need_collapse = 0; |
9 | int sort__has_parent = 0; | 9 | int sort__has_parent = 0; |
10 | 10 | ||
@@ -18,39 +18,50 @@ char * field_sep; | |||
18 | 18 | ||
19 | LIST_HEAD(hist_entry__sort_list); | 19 | LIST_HEAD(hist_entry__sort_list); |
20 | 20 | ||
21 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, | ||
22 | size_t size, unsigned int width); | ||
23 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, | ||
24 | size_t size, unsigned int width); | ||
25 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, | ||
26 | size_t size, unsigned int width); | ||
27 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | ||
28 | size_t size, unsigned int width); | ||
29 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, | ||
30 | size_t size, unsigned int width); | ||
31 | |||
21 | struct sort_entry sort_thread = { | 32 | struct sort_entry sort_thread = { |
22 | .header = "Command: Pid", | 33 | .se_header = "Command: Pid", |
23 | .cmp = sort__thread_cmp, | 34 | .se_cmp = sort__thread_cmp, |
24 | .print = sort__thread_print, | 35 | .se_snprintf = hist_entry__thread_snprintf, |
25 | .width = &threads__col_width, | 36 | .se_width = &threads__col_width, |
26 | }; | 37 | }; |
27 | 38 | ||
28 | struct sort_entry sort_comm = { | 39 | struct sort_entry sort_comm = { |
29 | .header = "Command", | 40 | .se_header = "Command", |
30 | .cmp = sort__comm_cmp, | 41 | .se_cmp = sort__comm_cmp, |
31 | .collapse = sort__comm_collapse, | 42 | .se_collapse = sort__comm_collapse, |
32 | .print = sort__comm_print, | 43 | .se_snprintf = hist_entry__comm_snprintf, |
33 | .width = &comms__col_width, | 44 | .se_width = &comms__col_width, |
34 | }; | 45 | }; |
35 | 46 | ||
36 | struct sort_entry sort_dso = { | 47 | struct sort_entry sort_dso = { |
37 | .header = "Shared Object", | 48 | .se_header = "Shared Object", |
38 | .cmp = sort__dso_cmp, | 49 | .se_cmp = sort__dso_cmp, |
39 | .print = sort__dso_print, | 50 | .se_snprintf = hist_entry__dso_snprintf, |
40 | .width = &dsos__col_width, | 51 | .se_width = &dsos__col_width, |
41 | }; | 52 | }; |
42 | 53 | ||
43 | struct sort_entry sort_sym = { | 54 | struct sort_entry sort_sym = { |
44 | .header = "Symbol", | 55 | .se_header = "Symbol", |
45 | .cmp = sort__sym_cmp, | 56 | .se_cmp = sort__sym_cmp, |
46 | .print = sort__sym_print, | 57 | .se_snprintf = hist_entry__sym_snprintf, |
47 | }; | 58 | }; |
48 | 59 | ||
49 | struct sort_entry sort_parent = { | 60 | struct sort_entry sort_parent = { |
50 | .header = "Parent symbol", | 61 | .se_header = "Parent symbol", |
51 | .cmp = sort__parent_cmp, | 62 | .se_cmp = sort__parent_cmp, |
52 | .print = sort__parent_print, | 63 | .se_snprintf = hist_entry__parent_snprintf, |
53 | .width = &parent_symbol__col_width, | 64 | .se_width = &parent_symbol__col_width, |
54 | }; | 65 | }; |
55 | 66 | ||
56 | struct sort_dimension { | 67 | struct sort_dimension { |
@@ -85,45 +96,38 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) | |||
85 | return right->thread->pid - left->thread->pid; | 96 | return right->thread->pid - left->thread->pid; |
86 | } | 97 | } |
87 | 98 | ||
88 | int repsep_fprintf(FILE *fp, const char *fmt, ...) | 99 | static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...) |
89 | { | 100 | { |
90 | int n; | 101 | int n; |
91 | va_list ap; | 102 | va_list ap; |
92 | 103 | ||
93 | va_start(ap, fmt); | 104 | va_start(ap, fmt); |
94 | if (!field_sep) | 105 | n = vsnprintf(bf, size, fmt, ap); |
95 | n = vfprintf(fp, fmt, ap); | 106 | if (field_sep && n > 0) { |
96 | else { | 107 | char *sep = bf; |
97 | char *bf = NULL; | 108 | |
98 | n = vasprintf(&bf, fmt, ap); | 109 | while (1) { |
99 | if (n > 0) { | 110 | sep = strchr(sep, *field_sep); |
100 | char *sep = bf; | 111 | if (sep == NULL) |
101 | 112 | break; | |
102 | while (1) { | 113 | *sep = '.'; |
103 | sep = strchr(sep, *field_sep); | ||
104 | if (sep == NULL) | ||
105 | break; | ||
106 | *sep = '.'; | ||
107 | } | ||
108 | } | 114 | } |
109 | fputs(bf, fp); | ||
110 | free(bf); | ||
111 | } | 115 | } |
112 | va_end(ap); | 116 | va_end(ap); |
113 | return n; | 117 | return n; |
114 | } | 118 | } |
115 | 119 | ||
116 | size_t | 120 | static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf, |
117 | sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width) | 121 | size_t size, unsigned int width) |
118 | { | 122 | { |
119 | return repsep_fprintf(fp, "%*s:%5d", width - 6, | 123 | return repsep_snprintf(bf, size, "%*s:%5d", width, |
120 | self->thread->comm ?: "", self->thread->pid); | 124 | self->thread->comm ?: "", self->thread->pid); |
121 | } | 125 | } |
122 | 126 | ||
123 | size_t | 127 | static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf, |
124 | sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) | 128 | size_t size, unsigned int width) |
125 | { | 129 | { |
126 | return repsep_fprintf(fp, "%*s", width, self->thread->comm); | 130 | return repsep_snprintf(bf, size, "%*s", width, self->thread->comm); |
127 | } | 131 | } |
128 | 132 | ||
129 | /* --sort dso */ | 133 | /* --sort dso */ |
@@ -131,8 +135,8 @@ sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width) | |||
131 | int64_t | 135 | int64_t |
132 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | 136 | sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) |
133 | { | 137 | { |
134 | struct dso *dso_l = left->map ? left->map->dso : NULL; | 138 | struct dso *dso_l = left->ms.map ? left->ms.map->dso : NULL; |
135 | struct dso *dso_r = right->map ? right->map->dso : NULL; | 139 | struct dso *dso_r = right->ms.map ? right->ms.map->dso : NULL; |
136 | const char *dso_name_l, *dso_name_r; | 140 | const char *dso_name_l, *dso_name_r; |
137 | 141 | ||
138 | if (!dso_l || !dso_r) | 142 | if (!dso_l || !dso_r) |
@@ -149,16 +153,16 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) | |||
149 | return strcmp(dso_name_l, dso_name_r); | 153 | return strcmp(dso_name_l, dso_name_r); |
150 | } | 154 | } |
151 | 155 | ||
152 | size_t | 156 | static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf, |
153 | sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width) | 157 | size_t size, unsigned int width) |
154 | { | 158 | { |
155 | if (self->map && self->map->dso) { | 159 | if (self->ms.map && self->ms.map->dso) { |
156 | const char *dso_name = !verbose ? self->map->dso->short_name : | 160 | const char *dso_name = !verbose ? self->ms.map->dso->short_name : |
157 | self->map->dso->long_name; | 161 | self->ms.map->dso->long_name; |
158 | return repsep_fprintf(fp, "%-*s", width, dso_name); | 162 | return repsep_snprintf(bf, size, "%-*s", width, dso_name); |
159 | } | 163 | } |
160 | 164 | ||
161 | return repsep_fprintf(fp, "%*llx", width, (u64)self->ip); | 165 | return repsep_snprintf(bf, size, "%*Lx", width, self->ip); |
162 | } | 166 | } |
163 | 167 | ||
164 | /* --sort symbol */ | 168 | /* --sort symbol */ |
@@ -168,31 +172,31 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right) | |||
168 | { | 172 | { |
169 | u64 ip_l, ip_r; | 173 | u64 ip_l, ip_r; |
170 | 174 | ||
171 | if (left->sym == right->sym) | 175 | if (left->ms.sym == right->ms.sym) |
172 | return 0; | 176 | return 0; |
173 | 177 | ||
174 | ip_l = left->sym ? left->sym->start : left->ip; | 178 | ip_l = left->ms.sym ? left->ms.sym->start : left->ip; |
175 | ip_r = right->sym ? right->sym->start : right->ip; | 179 | ip_r = right->ms.sym ? right->ms.sym->start : right->ip; |
176 | 180 | ||
177 | return (int64_t)(ip_r - ip_l); | 181 | return (int64_t)(ip_r - ip_l); |
178 | } | 182 | } |
179 | 183 | ||
180 | 184 | static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf, | |
181 | size_t | 185 | size_t size, unsigned int width __used) |
182 | sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used) | ||
183 | { | 186 | { |
184 | size_t ret = 0; | 187 | size_t ret = 0; |
185 | 188 | ||
186 | if (verbose) { | 189 | if (verbose) { |
187 | char o = self->map ? dso__symtab_origin(self->map->dso) : '!'; | 190 | char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!'; |
188 | ret += repsep_fprintf(fp, "%#018llx %c ", (u64)self->ip, o); | 191 | ret += repsep_snprintf(bf, size, "%#018llx %c ", self->ip, o); |
189 | } | 192 | } |
190 | 193 | ||
191 | ret += repsep_fprintf(fp, "[%c] ", self->level); | 194 | ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level); |
192 | if (self->sym) | 195 | if (self->ms.sym) |
193 | ret += repsep_fprintf(fp, "%s", self->sym->name); | 196 | ret += repsep_snprintf(bf + ret, size - ret, "%s", |
197 | self->ms.sym->name); | ||
194 | else | 198 | else |
195 | ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip); | 199 | ret += repsep_snprintf(bf + ret, size - ret, "%#016llx", self->ip); |
196 | 200 | ||
197 | return ret; | 201 | return ret; |
198 | } | 202 | } |
@@ -231,10 +235,10 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right) | |||
231 | return strcmp(sym_l->name, sym_r->name); | 235 | return strcmp(sym_l->name, sym_r->name); |
232 | } | 236 | } |
233 | 237 | ||
234 | size_t | 238 | static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf, |
235 | sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width) | 239 | size_t size, unsigned int width) |
236 | { | 240 | { |
237 | return repsep_fprintf(fp, "%-*s", width, | 241 | return repsep_snprintf(bf, size, "%-*s", width, |
238 | self->parent ? self->parent->name : "[other]"); | 242 | self->parent ? self->parent->name : "[other]"); |
239 | } | 243 | } |
240 | 244 | ||
@@ -251,7 +255,7 @@ int sort_dimension__add(const char *tok) | |||
251 | if (strncasecmp(tok, sd->name, strlen(tok))) | 255 | if (strncasecmp(tok, sd->name, strlen(tok))) |
252 | continue; | 256 | continue; |
253 | 257 | ||
254 | if (sd->entry->collapse) | 258 | if (sd->entry->se_collapse) |
255 | sort__need_collapse = 1; | 259 | sort__need_collapse = 1; |
256 | 260 | ||
257 | if (sd->entry == &sort_parent) { | 261 | if (sd->entry == &sort_parent) { |
@@ -260,9 +264,8 @@ int sort_dimension__add(const char *tok) | |||
260 | char err[BUFSIZ]; | 264 | char err[BUFSIZ]; |
261 | 265 | ||
262 | regerror(ret, &parent_regex, err, sizeof(err)); | 266 | regerror(ret, &parent_regex, err, sizeof(err)); |
263 | fprintf(stderr, "Invalid regex: %s\n%s", | 267 | pr_err("Invalid regex: %s\n%s", parent_pattern, err); |
264 | parent_pattern, err); | 268 | return -EINVAL; |
265 | exit(-1); | ||
266 | } | 269 | } |
267 | sort__has_parent = 1; | 270 | sort__has_parent = 1; |
268 | } | 271 | } |
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 753f9ea99fb0..0d61c4082f43 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h | |||
@@ -25,10 +25,10 @@ | |||
25 | #include "sort.h" | 25 | #include "sort.h" |
26 | 26 | ||
27 | extern regex_t parent_regex; | 27 | extern regex_t parent_regex; |
28 | extern char *sort_order; | 28 | extern const char *sort_order; |
29 | extern char default_parent_pattern[]; | 29 | extern const char default_parent_pattern[]; |
30 | extern char *parent_pattern; | 30 | extern const char *parent_pattern; |
31 | extern char default_sort_order[]; | 31 | extern const char default_sort_order[]; |
32 | extern int sort__need_collapse; | 32 | extern int sort__need_collapse; |
33 | extern int sort__has_parent; | 33 | extern int sort__has_parent; |
34 | extern char *field_sep; | 34 | extern char *field_sep; |
@@ -43,19 +43,24 @@ extern enum sort_type sort__first_dimension; | |||
43 | 43 | ||
44 | struct hist_entry { | 44 | struct hist_entry { |
45 | struct rb_node rb_node; | 45 | struct rb_node rb_node; |
46 | u64 count; | 46 | u64 period; |
47 | u64 period_sys; | ||
48 | u64 period_us; | ||
49 | u64 period_guest_sys; | ||
50 | u64 period_guest_us; | ||
51 | struct map_symbol ms; | ||
47 | struct thread *thread; | 52 | struct thread *thread; |
48 | struct map *map; | ||
49 | struct symbol *sym; | ||
50 | u64 ip; | 53 | u64 ip; |
54 | u32 nr_events; | ||
51 | char level; | 55 | char level; |
52 | struct symbol *parent; | 56 | u8 filtered; |
53 | struct callchain_node callchain; | 57 | struct symbol *parent; |
54 | union { | 58 | union { |
55 | unsigned long position; | 59 | unsigned long position; |
56 | struct hist_entry *pair; | 60 | struct hist_entry *pair; |
57 | struct rb_root sorted_chain; | 61 | struct rb_root sorted_chain; |
58 | }; | 62 | }; |
63 | struct callchain_node callchain[0]; | ||
59 | }; | 64 | }; |
60 | 65 | ||
61 | enum sort_type { | 66 | enum sort_type { |
@@ -73,12 +78,13 @@ enum sort_type { | |||
73 | struct sort_entry { | 78 | struct sort_entry { |
74 | struct list_head list; | 79 | struct list_head list; |
75 | 80 | ||
76 | const char *header; | 81 | const char *se_header; |
77 | 82 | ||
78 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); | 83 | int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); |
79 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); | 84 | int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); |
80 | size_t (*print)(FILE *fp, struct hist_entry *, unsigned int width); | 85 | int (*se_snprintf)(struct hist_entry *self, char *bf, size_t size, |
81 | unsigned int *width; | 86 | unsigned int width); |
87 | unsigned int *se_width; | ||
82 | bool elide; | 88 | bool elide; |
83 | }; | 89 | }; |
84 | 90 | ||
@@ -87,7 +93,6 @@ extern struct list_head hist_entry__sort_list; | |||
87 | 93 | ||
88 | void setup_sorting(const char * const usagestr[], const struct option *opts); | 94 | void setup_sorting(const char * const usagestr[], const struct option *opts); |
89 | 95 | ||
90 | extern int repsep_fprintf(FILE *fp, const char *fmt, ...); | ||
91 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); | 96 | extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int); |
92 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); | 97 | extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int); |
93 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); | 98 | extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int); |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index a175949ed216..0409fc7c0058 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -1,48 +1,5 @@ | |||
1 | #include "string.h" | ||
2 | #include "util.h" | 1 | #include "util.h" |
3 | 2 | #include "string.h" | |
4 | static int hex(char ch) | ||
5 | { | ||
6 | if ((ch >= '0') && (ch <= '9')) | ||
7 | return ch - '0'; | ||
8 | if ((ch >= 'a') && (ch <= 'f')) | ||
9 | return ch - 'a' + 10; | ||
10 | if ((ch >= 'A') && (ch <= 'F')) | ||
11 | return ch - 'A' + 10; | ||
12 | return -1; | ||
13 | } | ||
14 | |||
15 | /* | ||
16 | * While we find nice hex chars, build a long_val. | ||
17 | * Return number of chars processed. | ||
18 | */ | ||
19 | int hex2u64(const char *ptr, u64 *long_val) | ||
20 | { | ||
21 | const char *p = ptr; | ||
22 | *long_val = 0; | ||
23 | |||
24 | while (*p) { | ||
25 | const int hex_val = hex(*p); | ||
26 | |||
27 | if (hex_val < 0) | ||
28 | break; | ||
29 | |||
30 | *long_val = (*long_val << 4) | hex_val; | ||
31 | p++; | ||
32 | } | ||
33 | |||
34 | return p - ptr; | ||
35 | } | ||
36 | |||
37 | char *strxfrchar(char *s, char from, char to) | ||
38 | { | ||
39 | char *p = s; | ||
40 | |||
41 | while ((p = strchr(p, from)) != NULL) | ||
42 | *p++ = to; | ||
43 | |||
44 | return s; | ||
45 | } | ||
46 | 3 | ||
47 | #define K 1024LL | 4 | #define K 1024LL |
48 | /* | 5 | /* |
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h deleted file mode 100644 index 542e44de3719..000000000000 --- a/tools/perf/util/string.h +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | #ifndef __PERF_STRING_H_ | ||
2 | #define __PERF_STRING_H_ | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include "types.h" | ||
6 | |||
7 | int hex2u64(const char *ptr, u64 *val); | ||
8 | char *strxfrchar(char *s, char from, char to); | ||
9 | s64 perf_atoll(const char *str); | ||
10 | char **argv_split(const char *str, int *argcp); | ||
11 | void argv_free(char **argv); | ||
12 | bool strglobmatch(const char *str, const char *pat); | ||
13 | bool strlazymatch(const char *str, const char *pat); | ||
14 | |||
15 | #define _STR(x) #x | ||
16 | #define STR(x) _STR(x) | ||
17 | |||
18 | #endif /* __PERF_STRING_H */ | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index c458c4a371d1..a06131f6259a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -1,13 +1,19 @@ | |||
1 | #include "util.h" | 1 | #define _GNU_SOURCE |
2 | #include "../perf.h" | 2 | #include <ctype.h> |
3 | #include "sort.h" | 3 | #include <dirent.h> |
4 | #include "string.h" | 4 | #include <errno.h> |
5 | #include <libgen.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <stdio.h> | ||
8 | #include <string.h> | ||
9 | #include <sys/types.h> | ||
10 | #include <sys/stat.h> | ||
11 | #include <sys/param.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <unistd.h> | ||
5 | #include "symbol.h" | 14 | #include "symbol.h" |
6 | #include "thread.h" | 15 | #include "strlist.h" |
7 | 16 | ||
8 | #include "debug.h" | ||
9 | |||
10 | #include <asm/bug.h> | ||
11 | #include <libelf.h> | 17 | #include <libelf.h> |
12 | #include <gelf.h> | 18 | #include <gelf.h> |
13 | #include <elf.h> | 19 | #include <elf.h> |
@@ -18,22 +24,12 @@ | |||
18 | #define NT_GNU_BUILD_ID 3 | 24 | #define NT_GNU_BUILD_ID 3 |
19 | #endif | 25 | #endif |
20 | 26 | ||
21 | enum dso_origin { | ||
22 | DSO__ORIG_KERNEL = 0, | ||
23 | DSO__ORIG_JAVA_JIT, | ||
24 | DSO__ORIG_BUILD_ID_CACHE, | ||
25 | DSO__ORIG_FEDORA, | ||
26 | DSO__ORIG_UBUNTU, | ||
27 | DSO__ORIG_BUILDID, | ||
28 | DSO__ORIG_DSO, | ||
29 | DSO__ORIG_KMODULE, | ||
30 | DSO__ORIG_NOT_FOUND, | ||
31 | }; | ||
32 | |||
33 | static void dsos__add(struct list_head *head, struct dso *dso); | 27 | static void dsos__add(struct list_head *head, struct dso *dso); |
34 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type); | 28 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type); |
35 | static int dso__load_kernel_sym(struct dso *self, struct map *map, | 29 | static int dso__load_kernel_sym(struct dso *self, struct map *map, |
36 | symbol_filter_t filter); | 30 | symbol_filter_t filter); |
31 | static int dso__load_guest_kernel_sym(struct dso *self, struct map *map, | ||
32 | symbol_filter_t filter); | ||
37 | static int vmlinux_path__nr_entries; | 33 | static int vmlinux_path__nr_entries; |
38 | static char **vmlinux_path; | 34 | static char **vmlinux_path; |
39 | 35 | ||
@@ -126,16 +122,17 @@ static void map_groups__fixup_end(struct map_groups *self) | |||
126 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) | 122 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) |
127 | { | 123 | { |
128 | size_t namelen = strlen(name) + 1; | 124 | size_t namelen = strlen(name) + 1; |
129 | struct symbol *self = zalloc(symbol_conf.priv_size + | 125 | struct symbol *self = calloc(1, (symbol_conf.priv_size + |
130 | sizeof(*self) + namelen); | 126 | sizeof(*self) + namelen)); |
131 | if (self == NULL) | 127 | if (self == NULL) |
132 | return NULL; | 128 | return NULL; |
133 | 129 | ||
134 | if (symbol_conf.priv_size) | 130 | if (symbol_conf.priv_size) |
135 | self = ((void *)self) + symbol_conf.priv_size; | 131 | self = ((void *)self) + symbol_conf.priv_size; |
136 | 132 | ||
137 | self->start = start; | 133 | self->start = start; |
138 | self->end = len ? start + len - 1 : start; | 134 | self->end = len ? start + len - 1 : start; |
135 | self->namelen = namelen - 1; | ||
139 | 136 | ||
140 | pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); | 137 | pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); |
141 | 138 | ||
@@ -178,7 +175,7 @@ static void dso__set_basename(struct dso *self) | |||
178 | 175 | ||
179 | struct dso *dso__new(const char *name) | 176 | struct dso *dso__new(const char *name) |
180 | { | 177 | { |
181 | struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1); | 178 | struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1); |
182 | 179 | ||
183 | if (self != NULL) { | 180 | if (self != NULL) { |
184 | int i; | 181 | int i; |
@@ -192,6 +189,8 @@ struct dso *dso__new(const char *name) | |||
192 | self->loaded = 0; | 189 | self->loaded = 0; |
193 | self->sorted_by_name = 0; | 190 | self->sorted_by_name = 0; |
194 | self->has_build_id = 0; | 191 | self->has_build_id = 0; |
192 | self->kernel = DSO_TYPE_USER; | ||
193 | INIT_LIST_HEAD(&self->node); | ||
195 | } | 194 | } |
196 | 195 | ||
197 | return self; | 196 | return self; |
@@ -408,12 +407,9 @@ int kallsyms__parse(const char *filename, void *arg, | |||
408 | char *symbol_name; | 407 | char *symbol_name; |
409 | 408 | ||
410 | line_len = getline(&line, &n, file); | 409 | line_len = getline(&line, &n, file); |
411 | if (line_len < 0) | 410 | if (line_len < 0 || !line) |
412 | break; | 411 | break; |
413 | 412 | ||
414 | if (!line) | ||
415 | goto out_failure; | ||
416 | |||
417 | line[--line_len] = '\0'; /* \n */ | 413 | line[--line_len] = '\0'; /* \n */ |
418 | 414 | ||
419 | len = hex2u64(line, &start); | 415 | len = hex2u64(line, &start); |
@@ -465,6 +461,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name, | |||
465 | * map__split_kallsyms, when we have split the maps per module | 461 | * map__split_kallsyms, when we have split the maps per module |
466 | */ | 462 | */ |
467 | symbols__insert(root, sym); | 463 | symbols__insert(root, sym); |
464 | |||
468 | return 0; | 465 | return 0; |
469 | } | 466 | } |
470 | 467 | ||
@@ -489,6 +486,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
489 | symbol_filter_t filter) | 486 | symbol_filter_t filter) |
490 | { | 487 | { |
491 | struct map_groups *kmaps = map__kmap(map)->kmaps; | 488 | struct map_groups *kmaps = map__kmap(map)->kmaps; |
489 | struct machine *machine = kmaps->machine; | ||
492 | struct map *curr_map = map; | 490 | struct map *curr_map = map; |
493 | struct symbol *pos; | 491 | struct symbol *pos; |
494 | int count = 0; | 492 | int count = 0; |
@@ -510,15 +508,33 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
510 | *module++ = '\0'; | 508 | *module++ = '\0'; |
511 | 509 | ||
512 | if (strcmp(curr_map->dso->short_name, module)) { | 510 | if (strcmp(curr_map->dso->short_name, module)) { |
513 | curr_map = map_groups__find_by_name(kmaps, map->type, module); | 511 | if (curr_map != map && |
512 | self->kernel == DSO_TYPE_GUEST_KERNEL && | ||
513 | machine__is_default_guest(machine)) { | ||
514 | /* | ||
515 | * We assume all symbols of a module are | ||
516 | * continuous in * kallsyms, so curr_map | ||
517 | * points to a module and all its | ||
518 | * symbols are in its kmap. Mark it as | ||
519 | * loaded. | ||
520 | */ | ||
521 | dso__set_loaded(curr_map->dso, | ||
522 | curr_map->type); | ||
523 | } | ||
524 | |||
525 | curr_map = map_groups__find_by_name(kmaps, | ||
526 | map->type, module); | ||
514 | if (curr_map == NULL) { | 527 | if (curr_map == NULL) { |
515 | pr_debug("/proc/{kallsyms,modules} " | 528 | pr_debug("%s/proc/{kallsyms,modules} " |
516 | "inconsistency while looking " | 529 | "inconsistency while looking " |
517 | "for \"%s\" module!\n", module); | 530 | "for \"%s\" module!\n", |
518 | return -1; | 531 | machine->root_dir, module); |
532 | curr_map = map; | ||
533 | goto discard_symbol; | ||
519 | } | 534 | } |
520 | 535 | ||
521 | if (curr_map->dso->loaded) | 536 | if (curr_map->dso->loaded && |
537 | !machine__is_default_guest(machine)) | ||
522 | goto discard_symbol; | 538 | goto discard_symbol; |
523 | } | 539 | } |
524 | /* | 540 | /* |
@@ -531,13 +547,21 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, | |||
531 | char dso_name[PATH_MAX]; | 547 | char dso_name[PATH_MAX]; |
532 | struct dso *dso; | 548 | struct dso *dso; |
533 | 549 | ||
534 | snprintf(dso_name, sizeof(dso_name), "[kernel].%d", | 550 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
535 | kernel_range++); | 551 | snprintf(dso_name, sizeof(dso_name), |
552 | "[guest.kernel].%d", | ||
553 | kernel_range++); | ||
554 | else | ||
555 | snprintf(dso_name, sizeof(dso_name), | ||
556 | "[kernel].%d", | ||
557 | kernel_range++); | ||
536 | 558 | ||
537 | dso = dso__new(dso_name); | 559 | dso = dso__new(dso_name); |
538 | if (dso == NULL) | 560 | if (dso == NULL) |
539 | return -1; | 561 | return -1; |
540 | 562 | ||
563 | dso->kernel = self->kernel; | ||
564 | |||
541 | curr_map = map__new2(pos->start, dso, map->type); | 565 | curr_map = map__new2(pos->start, dso, map->type); |
542 | if (curr_map == NULL) { | 566 | if (curr_map == NULL) { |
543 | dso__delete(dso); | 567 | dso__delete(dso); |
@@ -561,6 +585,12 @@ discard_symbol: rb_erase(&pos->rb_node, root); | |||
561 | } | 585 | } |
562 | } | 586 | } |
563 | 587 | ||
588 | if (curr_map != map && | ||
589 | self->kernel == DSO_TYPE_GUEST_KERNEL && | ||
590 | machine__is_default_guest(kmaps->machine)) { | ||
591 | dso__set_loaded(curr_map->dso, curr_map->type); | ||
592 | } | ||
593 | |||
564 | return count; | 594 | return count; |
565 | } | 595 | } |
566 | 596 | ||
@@ -571,7 +601,10 @@ int dso__load_kallsyms(struct dso *self, const char *filename, | |||
571 | return -1; | 601 | return -1; |
572 | 602 | ||
573 | symbols__fixup_end(&self->symbols[map->type]); | 603 | symbols__fixup_end(&self->symbols[map->type]); |
574 | self->origin = DSO__ORIG_KERNEL; | 604 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
605 | self->origin = DSO__ORIG_GUEST_KERNEL; | ||
606 | else | ||
607 | self->origin = DSO__ORIG_KERNEL; | ||
575 | 608 | ||
576 | return dso__split_kallsyms(self, map, filter); | 609 | return dso__split_kallsyms(self, map, filter); |
577 | } | 610 | } |
@@ -870,8 +903,8 @@ out_close: | |||
870 | if (err == 0) | 903 | if (err == 0) |
871 | return nr; | 904 | return nr; |
872 | out: | 905 | out: |
873 | pr_warning("%s: problems reading %s PLT info.\n", | 906 | pr_debug("%s: problems reading %s PLT info.\n", |
874 | __func__, self->long_name); | 907 | __func__, self->long_name); |
875 | return 0; | 908 | return 0; |
876 | } | 909 | } |
877 | 910 | ||
@@ -958,7 +991,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, | |||
958 | nr_syms = shdr.sh_size / shdr.sh_entsize; | 991 | nr_syms = shdr.sh_size / shdr.sh_entsize; |
959 | 992 | ||
960 | memset(&sym, 0, sizeof(sym)); | 993 | memset(&sym, 0, sizeof(sym)); |
961 | if (!self->kernel) { | 994 | if (self->kernel == DSO_TYPE_USER) { |
962 | self->adjust_symbols = (ehdr.e_type == ET_EXEC || | 995 | self->adjust_symbols = (ehdr.e_type == ET_EXEC || |
963 | elf_section_by_name(elf, &ehdr, &shdr, | 996 | elf_section_by_name(elf, &ehdr, &shdr, |
964 | ".gnu.prelink_undo", | 997 | ".gnu.prelink_undo", |
@@ -990,7 +1023,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, | |||
990 | 1023 | ||
991 | section_name = elf_sec__name(&shdr, secstrs); | 1024 | section_name = elf_sec__name(&shdr, secstrs); |
992 | 1025 | ||
993 | if (self->kernel || kmodule) { | 1026 | if (self->kernel != DSO_TYPE_USER || kmodule) { |
994 | char dso_name[PATH_MAX]; | 1027 | char dso_name[PATH_MAX]; |
995 | 1028 | ||
996 | if (strcmp(section_name, | 1029 | if (strcmp(section_name, |
@@ -1017,6 +1050,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, | |||
1017 | curr_dso = dso__new(dso_name); | 1050 | curr_dso = dso__new(dso_name); |
1018 | if (curr_dso == NULL) | 1051 | if (curr_dso == NULL) |
1019 | goto out_elf_end; | 1052 | goto out_elf_end; |
1053 | curr_dso->kernel = self->kernel; | ||
1020 | curr_map = map__new2(start, curr_dso, | 1054 | curr_map = map__new2(start, curr_dso, |
1021 | map->type); | 1055 | map->type); |
1022 | if (curr_map == NULL) { | 1056 | if (curr_map == NULL) { |
@@ -1025,9 +1059,9 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, | |||
1025 | } | 1059 | } |
1026 | curr_map->map_ip = identity__map_ip; | 1060 | curr_map->map_ip = identity__map_ip; |
1027 | curr_map->unmap_ip = identity__map_ip; | 1061 | curr_map->unmap_ip = identity__map_ip; |
1028 | curr_dso->origin = DSO__ORIG_KERNEL; | 1062 | curr_dso->origin = self->origin; |
1029 | map_groups__insert(kmap->kmaps, curr_map); | 1063 | map_groups__insert(kmap->kmaps, curr_map); |
1030 | dsos__add(&dsos__kernel, curr_dso); | 1064 | dsos__add(&self->node, curr_dso); |
1031 | dso__set_loaded(curr_dso, map->type); | 1065 | dso__set_loaded(curr_dso, map->type); |
1032 | } else | 1066 | } else |
1033 | curr_dso = curr_map->dso; | 1067 | curr_dso = curr_map->dso; |
@@ -1089,7 +1123,7 @@ static bool dso__build_id_equal(const struct dso *self, u8 *build_id) | |||
1089 | return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0; | 1123 | return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0; |
1090 | } | 1124 | } |
1091 | 1125 | ||
1092 | static bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | 1126 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits) |
1093 | { | 1127 | { |
1094 | bool have_build_id = false; | 1128 | bool have_build_id = false; |
1095 | struct dso *pos; | 1129 | struct dso *pos; |
@@ -1107,13 +1141,6 @@ static bool __dsos__read_build_ids(struct list_head *head, bool with_hits) | |||
1107 | return have_build_id; | 1141 | return have_build_id; |
1108 | } | 1142 | } |
1109 | 1143 | ||
1110 | bool dsos__read_build_ids(bool with_hits) | ||
1111 | { | ||
1112 | bool kbuildids = __dsos__read_build_ids(&dsos__kernel, with_hits), | ||
1113 | ubuildids = __dsos__read_build_ids(&dsos__user, with_hits); | ||
1114 | return kbuildids || ubuildids; | ||
1115 | } | ||
1116 | |||
1117 | /* | 1144 | /* |
1118 | * Align offset to 4 bytes as needed for note name and descriptor data. | 1145 | * Align offset to 4 bytes as needed for note name and descriptor data. |
1119 | */ | 1146 | */ |
@@ -1248,6 +1275,8 @@ char dso__symtab_origin(const struct dso *self) | |||
1248 | [DSO__ORIG_BUILDID] = 'b', | 1275 | [DSO__ORIG_BUILDID] = 'b', |
1249 | [DSO__ORIG_DSO] = 'd', | 1276 | [DSO__ORIG_DSO] = 'd', |
1250 | [DSO__ORIG_KMODULE] = 'K', | 1277 | [DSO__ORIG_KMODULE] = 'K', |
1278 | [DSO__ORIG_GUEST_KERNEL] = 'g', | ||
1279 | [DSO__ORIG_GUEST_KMODULE] = 'G', | ||
1251 | }; | 1280 | }; |
1252 | 1281 | ||
1253 | if (self == NULL || self->origin == DSO__ORIG_NOT_FOUND) | 1282 | if (self == NULL || self->origin == DSO__ORIG_NOT_FOUND) |
@@ -1263,11 +1292,20 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) | |||
1263 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; | 1292 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; |
1264 | int ret = -1; | 1293 | int ret = -1; |
1265 | int fd; | 1294 | int fd; |
1295 | struct machine *machine; | ||
1296 | const char *root_dir; | ||
1266 | 1297 | ||
1267 | dso__set_loaded(self, map->type); | 1298 | dso__set_loaded(self, map->type); |
1268 | 1299 | ||
1269 | if (self->kernel) | 1300 | if (self->kernel == DSO_TYPE_KERNEL) |
1270 | return dso__load_kernel_sym(self, map, filter); | 1301 | return dso__load_kernel_sym(self, map, filter); |
1302 | else if (self->kernel == DSO_TYPE_GUEST_KERNEL) | ||
1303 | return dso__load_guest_kernel_sym(self, map, filter); | ||
1304 | |||
1305 | if (map->groups && map->groups->machine) | ||
1306 | machine = map->groups->machine; | ||
1307 | else | ||
1308 | machine = NULL; | ||
1271 | 1309 | ||
1272 | name = malloc(size); | 1310 | name = malloc(size); |
1273 | if (!name) | 1311 | if (!name) |
@@ -1321,6 +1359,13 @@ more: | |||
1321 | case DSO__ORIG_DSO: | 1359 | case DSO__ORIG_DSO: |
1322 | snprintf(name, size, "%s", self->long_name); | 1360 | snprintf(name, size, "%s", self->long_name); |
1323 | break; | 1361 | break; |
1362 | case DSO__ORIG_GUEST_KMODULE: | ||
1363 | if (map->groups && map->groups->machine) | ||
1364 | root_dir = map->groups->machine->root_dir; | ||
1365 | else | ||
1366 | root_dir = ""; | ||
1367 | snprintf(name, size, "%s%s", root_dir, self->long_name); | ||
1368 | break; | ||
1324 | 1369 | ||
1325 | default: | 1370 | default: |
1326 | goto out; | 1371 | goto out; |
@@ -1374,7 +1419,8 @@ struct map *map_groups__find_by_name(struct map_groups *self, | |||
1374 | return NULL; | 1419 | return NULL; |
1375 | } | 1420 | } |
1376 | 1421 | ||
1377 | static int dso__kernel_module_get_build_id(struct dso *self) | 1422 | static int dso__kernel_module_get_build_id(struct dso *self, |
1423 | const char *root_dir) | ||
1378 | { | 1424 | { |
1379 | char filename[PATH_MAX]; | 1425 | char filename[PATH_MAX]; |
1380 | /* | 1426 | /* |
@@ -1384,8 +1430,8 @@ static int dso__kernel_module_get_build_id(struct dso *self) | |||
1384 | const char *name = self->short_name + 1; | 1430 | const char *name = self->short_name + 1; |
1385 | 1431 | ||
1386 | snprintf(filename, sizeof(filename), | 1432 | snprintf(filename, sizeof(filename), |
1387 | "/sys/module/%.*s/notes/.note.gnu.build-id", | 1433 | "%s/sys/module/%.*s/notes/.note.gnu.build-id", |
1388 | (int)strlen(name - 1), name); | 1434 | root_dir, (int)strlen(name) - 1, name); |
1389 | 1435 | ||
1390 | if (sysfs__read_build_id(filename, self->build_id, | 1436 | if (sysfs__read_build_id(filename, self->build_id, |
1391 | sizeof(self->build_id)) == 0) | 1437 | sizeof(self->build_id)) == 0) |
@@ -1394,26 +1440,33 @@ static int dso__kernel_module_get_build_id(struct dso *self) | |||
1394 | return 0; | 1440 | return 0; |
1395 | } | 1441 | } |
1396 | 1442 | ||
1397 | static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname) | 1443 | static int map_groups__set_modules_path_dir(struct map_groups *self, |
1444 | const char *dir_name) | ||
1398 | { | 1445 | { |
1399 | struct dirent *dent; | 1446 | struct dirent *dent; |
1400 | DIR *dir = opendir(dirname); | 1447 | DIR *dir = opendir(dir_name); |
1401 | 1448 | ||
1402 | if (!dir) { | 1449 | if (!dir) { |
1403 | pr_debug("%s: cannot open %s dir\n", __func__, dirname); | 1450 | pr_debug("%s: cannot open %s dir\n", __func__, dir_name); |
1404 | return -1; | 1451 | return -1; |
1405 | } | 1452 | } |
1406 | 1453 | ||
1407 | while ((dent = readdir(dir)) != NULL) { | 1454 | while ((dent = readdir(dir)) != NULL) { |
1408 | char path[PATH_MAX]; | 1455 | char path[PATH_MAX]; |
1456 | struct stat st; | ||
1409 | 1457 | ||
1410 | if (dent->d_type == DT_DIR) { | 1458 | /*sshfs might return bad dent->d_type, so we have to stat*/ |
1459 | sprintf(path, "%s/%s", dir_name, dent->d_name); | ||
1460 | if (stat(path, &st)) | ||
1461 | continue; | ||
1462 | |||
1463 | if (S_ISDIR(st.st_mode)) { | ||
1411 | if (!strcmp(dent->d_name, ".") || | 1464 | if (!strcmp(dent->d_name, ".") || |
1412 | !strcmp(dent->d_name, "..")) | 1465 | !strcmp(dent->d_name, "..")) |
1413 | continue; | 1466 | continue; |
1414 | 1467 | ||
1415 | snprintf(path, sizeof(path), "%s/%s", | 1468 | snprintf(path, sizeof(path), "%s/%s", |
1416 | dirname, dent->d_name); | 1469 | dir_name, dent->d_name); |
1417 | if (map_groups__set_modules_path_dir(self, path) < 0) | 1470 | if (map_groups__set_modules_path_dir(self, path) < 0) |
1418 | goto failure; | 1471 | goto failure; |
1419 | } else { | 1472 | } else { |
@@ -1433,13 +1486,13 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna | |||
1433 | continue; | 1486 | continue; |
1434 | 1487 | ||
1435 | snprintf(path, sizeof(path), "%s/%s", | 1488 | snprintf(path, sizeof(path), "%s/%s", |
1436 | dirname, dent->d_name); | 1489 | dir_name, dent->d_name); |
1437 | 1490 | ||
1438 | long_name = strdup(path); | 1491 | long_name = strdup(path); |
1439 | if (long_name == NULL) | 1492 | if (long_name == NULL) |
1440 | goto failure; | 1493 | goto failure; |
1441 | dso__set_long_name(map->dso, long_name); | 1494 | dso__set_long_name(map->dso, long_name); |
1442 | dso__kernel_module_get_build_id(map->dso); | 1495 | dso__kernel_module_get_build_id(map->dso, ""); |
1443 | } | 1496 | } |
1444 | } | 1497 | } |
1445 | 1498 | ||
@@ -1449,18 +1502,47 @@ failure: | |||
1449 | return -1; | 1502 | return -1; |
1450 | } | 1503 | } |
1451 | 1504 | ||
1452 | static int map_groups__set_modules_path(struct map_groups *self) | 1505 | static char *get_kernel_version(const char *root_dir) |
1453 | { | 1506 | { |
1454 | struct utsname uts; | 1507 | char version[PATH_MAX]; |
1508 | FILE *file; | ||
1509 | char *name, *tmp; | ||
1510 | const char *prefix = "Linux version "; | ||
1511 | |||
1512 | sprintf(version, "%s/proc/version", root_dir); | ||
1513 | file = fopen(version, "r"); | ||
1514 | if (!file) | ||
1515 | return NULL; | ||
1516 | |||
1517 | version[0] = '\0'; | ||
1518 | tmp = fgets(version, sizeof(version), file); | ||
1519 | fclose(file); | ||
1520 | |||
1521 | name = strstr(version, prefix); | ||
1522 | if (!name) | ||
1523 | return NULL; | ||
1524 | name += strlen(prefix); | ||
1525 | tmp = strchr(name, ' '); | ||
1526 | if (tmp) | ||
1527 | *tmp = '\0'; | ||
1528 | |||
1529 | return strdup(name); | ||
1530 | } | ||
1531 | |||
1532 | static int machine__set_modules_path(struct machine *self) | ||
1533 | { | ||
1534 | char *version; | ||
1455 | char modules_path[PATH_MAX]; | 1535 | char modules_path[PATH_MAX]; |
1456 | 1536 | ||
1457 | if (uname(&uts) < 0) | 1537 | version = get_kernel_version(self->root_dir); |
1538 | if (!version) | ||
1458 | return -1; | 1539 | return -1; |
1459 | 1540 | ||
1460 | snprintf(modules_path, sizeof(modules_path), "/lib/modules/%s/kernel", | 1541 | snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel", |
1461 | uts.release); | 1542 | self->root_dir, version); |
1543 | free(version); | ||
1462 | 1544 | ||
1463 | return map_groups__set_modules_path_dir(self, modules_path); | 1545 | return map_groups__set_modules_path_dir(&self->kmaps, modules_path); |
1464 | } | 1546 | } |
1465 | 1547 | ||
1466 | /* | 1548 | /* |
@@ -1470,8 +1552,8 @@ static int map_groups__set_modules_path(struct map_groups *self) | |||
1470 | */ | 1552 | */ |
1471 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) | 1553 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) |
1472 | { | 1554 | { |
1473 | struct map *self = zalloc(sizeof(*self) + | 1555 | struct map *self = calloc(1, (sizeof(*self) + |
1474 | (dso->kernel ? sizeof(struct kmap) : 0)); | 1556 | (dso->kernel ? sizeof(struct kmap) : 0))); |
1475 | if (self != NULL) { | 1557 | if (self != NULL) { |
1476 | /* | 1558 | /* |
1477 | * ->end will be filled after we load all the symbols | 1559 | * ->end will be filled after we load all the symbols |
@@ -1482,11 +1564,11 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) | |||
1482 | return self; | 1564 | return self; |
1483 | } | 1565 | } |
1484 | 1566 | ||
1485 | struct map *map_groups__new_module(struct map_groups *self, u64 start, | 1567 | struct map *machine__new_module(struct machine *self, u64 start, |
1486 | const char *filename) | 1568 | const char *filename) |
1487 | { | 1569 | { |
1488 | struct map *map; | 1570 | struct map *map; |
1489 | struct dso *dso = __dsos__findnew(&dsos__kernel, filename); | 1571 | struct dso *dso = __dsos__findnew(&self->kernel_dsos, filename); |
1490 | 1572 | ||
1491 | if (dso == NULL) | 1573 | if (dso == NULL) |
1492 | return NULL; | 1574 | return NULL; |
@@ -1495,18 +1577,31 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start, | |||
1495 | if (map == NULL) | 1577 | if (map == NULL) |
1496 | return NULL; | 1578 | return NULL; |
1497 | 1579 | ||
1498 | dso->origin = DSO__ORIG_KMODULE; | 1580 | if (machine__is_host(self)) |
1499 | map_groups__insert(self, map); | 1581 | dso->origin = DSO__ORIG_KMODULE; |
1582 | else | ||
1583 | dso->origin = DSO__ORIG_GUEST_KMODULE; | ||
1584 | map_groups__insert(&self->kmaps, map); | ||
1500 | return map; | 1585 | return map; |
1501 | } | 1586 | } |
1502 | 1587 | ||
1503 | static int map_groups__create_modules(struct map_groups *self) | 1588 | static int machine__create_modules(struct machine *self) |
1504 | { | 1589 | { |
1505 | char *line = NULL; | 1590 | char *line = NULL; |
1506 | size_t n; | 1591 | size_t n; |
1507 | FILE *file = fopen("/proc/modules", "r"); | 1592 | FILE *file; |
1508 | struct map *map; | 1593 | struct map *map; |
1594 | const char *modules; | ||
1595 | char path[PATH_MAX]; | ||
1596 | |||
1597 | if (machine__is_default_guest(self)) | ||
1598 | modules = symbol_conf.default_guest_modules; | ||
1599 | else { | ||
1600 | sprintf(path, "%s/proc/modules", self->root_dir); | ||
1601 | modules = path; | ||
1602 | } | ||
1509 | 1603 | ||
1604 | file = fopen(modules, "r"); | ||
1510 | if (file == NULL) | 1605 | if (file == NULL) |
1511 | return -1; | 1606 | return -1; |
1512 | 1607 | ||
@@ -1538,16 +1633,16 @@ static int map_groups__create_modules(struct map_groups *self) | |||
1538 | *sep = '\0'; | 1633 | *sep = '\0'; |
1539 | 1634 | ||
1540 | snprintf(name, sizeof(name), "[%s]", line); | 1635 | snprintf(name, sizeof(name), "[%s]", line); |
1541 | map = map_groups__new_module(self, start, name); | 1636 | map = machine__new_module(self, start, name); |
1542 | if (map == NULL) | 1637 | if (map == NULL) |
1543 | goto out_delete_line; | 1638 | goto out_delete_line; |
1544 | dso__kernel_module_get_build_id(map->dso); | 1639 | dso__kernel_module_get_build_id(map->dso, self->root_dir); |
1545 | } | 1640 | } |
1546 | 1641 | ||
1547 | free(line); | 1642 | free(line); |
1548 | fclose(file); | 1643 | fclose(file); |
1549 | 1644 | ||
1550 | return map_groups__set_modules_path(self); | 1645 | return machine__set_modules_path(self); |
1551 | 1646 | ||
1552 | out_delete_line: | 1647 | out_delete_line: |
1553 | free(line); | 1648 | free(line); |
@@ -1714,8 +1809,56 @@ out_fixup: | |||
1714 | return err; | 1809 | return err; |
1715 | } | 1810 | } |
1716 | 1811 | ||
1717 | LIST_HEAD(dsos__user); | 1812 | static int dso__load_guest_kernel_sym(struct dso *self, struct map *map, |
1718 | LIST_HEAD(dsos__kernel); | 1813 | symbol_filter_t filter) |
1814 | { | ||
1815 | int err; | ||
1816 | const char *kallsyms_filename = NULL; | ||
1817 | struct machine *machine; | ||
1818 | char path[PATH_MAX]; | ||
1819 | |||
1820 | if (!map->groups) { | ||
1821 | pr_debug("Guest kernel map hasn't the point to groups\n"); | ||
1822 | return -1; | ||
1823 | } | ||
1824 | machine = map->groups->machine; | ||
1825 | |||
1826 | if (machine__is_default_guest(machine)) { | ||
1827 | /* | ||
1828 | * if the user specified a vmlinux filename, use it and only | ||
1829 | * it, reporting errors to the user if it cannot be used. | ||
1830 | * Or use file guest_kallsyms inputted by user on commandline | ||
1831 | */ | ||
1832 | if (symbol_conf.default_guest_vmlinux_name != NULL) { | ||
1833 | err = dso__load_vmlinux(self, map, | ||
1834 | symbol_conf.default_guest_vmlinux_name, filter); | ||
1835 | goto out_try_fixup; | ||
1836 | } | ||
1837 | |||
1838 | kallsyms_filename = symbol_conf.default_guest_kallsyms; | ||
1839 | if (!kallsyms_filename) | ||
1840 | return -1; | ||
1841 | } else { | ||
1842 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); | ||
1843 | kallsyms_filename = path; | ||
1844 | } | ||
1845 | |||
1846 | err = dso__load_kallsyms(self, kallsyms_filename, map, filter); | ||
1847 | if (err > 0) | ||
1848 | pr_debug("Using %s for symbols\n", kallsyms_filename); | ||
1849 | |||
1850 | out_try_fixup: | ||
1851 | if (err > 0) { | ||
1852 | if (kallsyms_filename != NULL) { | ||
1853 | machine__mmap_name(machine, path, sizeof(path)); | ||
1854 | dso__set_long_name(self, strdup(path)); | ||
1855 | } | ||
1856 | map__fixup_start(map); | ||
1857 | map__fixup_end(map); | ||
1858 | } | ||
1859 | |||
1860 | return err; | ||
1861 | } | ||
1719 | 1862 | ||
1720 | static void dsos__add(struct list_head *head, struct dso *dso) | 1863 | static void dsos__add(struct list_head *head, struct dso *dso) |
1721 | { | 1864 | { |
@@ -1747,21 +1890,32 @@ struct dso *__dsos__findnew(struct list_head *head, const char *name) | |||
1747 | return dso; | 1890 | return dso; |
1748 | } | 1891 | } |
1749 | 1892 | ||
1750 | static void __dsos__fprintf(struct list_head *head, FILE *fp) | 1893 | size_t __dsos__fprintf(struct list_head *head, FILE *fp) |
1751 | { | 1894 | { |
1752 | struct dso *pos; | 1895 | struct dso *pos; |
1896 | size_t ret = 0; | ||
1753 | 1897 | ||
1754 | list_for_each_entry(pos, head, node) { | 1898 | list_for_each_entry(pos, head, node) { |
1755 | int i; | 1899 | int i; |
1756 | for (i = 0; i < MAP__NR_TYPES; ++i) | 1900 | for (i = 0; i < MAP__NR_TYPES; ++i) |
1757 | dso__fprintf(pos, i, fp); | 1901 | ret += dso__fprintf(pos, i, fp); |
1758 | } | 1902 | } |
1903 | |||
1904 | return ret; | ||
1759 | } | 1905 | } |
1760 | 1906 | ||
1761 | void dsos__fprintf(FILE *fp) | 1907 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp) |
1762 | { | 1908 | { |
1763 | __dsos__fprintf(&dsos__kernel, fp); | 1909 | struct rb_node *nd; |
1764 | __dsos__fprintf(&dsos__user, fp); | 1910 | size_t ret = 0; |
1911 | |||
1912 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { | ||
1913 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | ||
1914 | ret += __dsos__fprintf(&pos->kernel_dsos, fp); | ||
1915 | ret += __dsos__fprintf(&pos->user_dsos, fp); | ||
1916 | } | ||
1917 | |||
1918 | return ret; | ||
1765 | } | 1919 | } |
1766 | 1920 | ||
1767 | static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | 1921 | static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, |
@@ -1779,10 +1933,17 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, | |||
1779 | return ret; | 1933 | return ret; |
1780 | } | 1934 | } |
1781 | 1935 | ||
1782 | size_t dsos__fprintf_buildid(FILE *fp, bool with_hits) | 1936 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) |
1783 | { | 1937 | { |
1784 | return (__dsos__fprintf_buildid(&dsos__kernel, fp, with_hits) + | 1938 | struct rb_node *nd; |
1785 | __dsos__fprintf_buildid(&dsos__user, fp, with_hits)); | 1939 | size_t ret = 0; |
1940 | |||
1941 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { | ||
1942 | struct machine *pos = rb_entry(nd, struct machine, rb_node); | ||
1943 | ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits); | ||
1944 | ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits); | ||
1945 | } | ||
1946 | return ret; | ||
1786 | } | 1947 | } |
1787 | 1948 | ||
1788 | struct dso *dso__new_kernel(const char *name) | 1949 | struct dso *dso__new_kernel(const char *name) |
@@ -1791,55 +1952,98 @@ struct dso *dso__new_kernel(const char *name) | |||
1791 | 1952 | ||
1792 | if (self != NULL) { | 1953 | if (self != NULL) { |
1793 | dso__set_short_name(self, "[kernel]"); | 1954 | dso__set_short_name(self, "[kernel]"); |
1794 | self->kernel = 1; | 1955 | self->kernel = DSO_TYPE_KERNEL; |
1795 | } | 1956 | } |
1796 | 1957 | ||
1797 | return self; | 1958 | return self; |
1798 | } | 1959 | } |
1799 | 1960 | ||
1800 | void dso__read_running_kernel_build_id(struct dso *self) | 1961 | static struct dso *dso__new_guest_kernel(struct machine *machine, |
1962 | const char *name) | ||
1801 | { | 1963 | { |
1802 | if (sysfs__read_build_id("/sys/kernel/notes", self->build_id, | 1964 | char bf[PATH_MAX]; |
1965 | struct dso *self = dso__new(name ?: machine__mmap_name(machine, bf, sizeof(bf))); | ||
1966 | |||
1967 | if (self != NULL) { | ||
1968 | dso__set_short_name(self, "[guest.kernel]"); | ||
1969 | self->kernel = DSO_TYPE_GUEST_KERNEL; | ||
1970 | } | ||
1971 | |||
1972 | return self; | ||
1973 | } | ||
1974 | |||
1975 | void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine) | ||
1976 | { | ||
1977 | char path[PATH_MAX]; | ||
1978 | |||
1979 | if (machine__is_default_guest(machine)) | ||
1980 | return; | ||
1981 | sprintf(path, "%s/sys/kernel/notes", machine->root_dir); | ||
1982 | if (sysfs__read_build_id(path, self->build_id, | ||
1803 | sizeof(self->build_id)) == 0) | 1983 | sizeof(self->build_id)) == 0) |
1804 | self->has_build_id = true; | 1984 | self->has_build_id = true; |
1805 | } | 1985 | } |
1806 | 1986 | ||
1807 | static struct dso *dsos__create_kernel(const char *vmlinux) | 1987 | static struct dso *machine__create_kernel(struct machine *self) |
1808 | { | 1988 | { |
1809 | struct dso *kernel = dso__new_kernel(vmlinux); | 1989 | const char *vmlinux_name = NULL; |
1990 | struct dso *kernel; | ||
1810 | 1991 | ||
1811 | if (kernel != NULL) { | 1992 | if (machine__is_host(self)) { |
1812 | dso__read_running_kernel_build_id(kernel); | 1993 | vmlinux_name = symbol_conf.vmlinux_name; |
1813 | dsos__add(&dsos__kernel, kernel); | 1994 | kernel = dso__new_kernel(vmlinux_name); |
1995 | } else { | ||
1996 | if (machine__is_default_guest(self)) | ||
1997 | vmlinux_name = symbol_conf.default_guest_vmlinux_name; | ||
1998 | kernel = dso__new_guest_kernel(self, vmlinux_name); | ||
1814 | } | 1999 | } |
1815 | 2000 | ||
2001 | if (kernel != NULL) { | ||
2002 | dso__read_running_kernel_build_id(kernel, self); | ||
2003 | dsos__add(&self->kernel_dsos, kernel); | ||
2004 | } | ||
1816 | return kernel; | 2005 | return kernel; |
1817 | } | 2006 | } |
1818 | 2007 | ||
1819 | int __map_groups__create_kernel_maps(struct map_groups *self, | 2008 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) |
1820 | struct map *vmlinux_maps[MAP__NR_TYPES], | ||
1821 | struct dso *kernel) | ||
1822 | { | 2009 | { |
1823 | enum map_type type; | 2010 | enum map_type type; |
1824 | 2011 | ||
1825 | for (type = 0; type < MAP__NR_TYPES; ++type) { | 2012 | for (type = 0; type < MAP__NR_TYPES; ++type) { |
1826 | struct kmap *kmap; | 2013 | struct kmap *kmap; |
1827 | 2014 | ||
1828 | vmlinux_maps[type] = map__new2(0, kernel, type); | 2015 | self->vmlinux_maps[type] = map__new2(0, kernel, type); |
1829 | if (vmlinux_maps[type] == NULL) | 2016 | if (self->vmlinux_maps[type] == NULL) |
1830 | return -1; | 2017 | return -1; |
1831 | 2018 | ||
1832 | vmlinux_maps[type]->map_ip = | 2019 | self->vmlinux_maps[type]->map_ip = |
1833 | vmlinux_maps[type]->unmap_ip = identity__map_ip; | 2020 | self->vmlinux_maps[type]->unmap_ip = identity__map_ip; |
1834 | 2021 | ||
1835 | kmap = map__kmap(vmlinux_maps[type]); | 2022 | kmap = map__kmap(self->vmlinux_maps[type]); |
1836 | kmap->kmaps = self; | 2023 | kmap->kmaps = &self->kmaps; |
1837 | map_groups__insert(self, vmlinux_maps[type]); | 2024 | map_groups__insert(&self->kmaps, self->vmlinux_maps[type]); |
1838 | } | 2025 | } |
1839 | 2026 | ||
1840 | return 0; | 2027 | return 0; |
1841 | } | 2028 | } |
1842 | 2029 | ||
2030 | int machine__create_kernel_maps(struct machine *self) | ||
2031 | { | ||
2032 | struct dso *kernel = machine__create_kernel(self); | ||
2033 | |||
2034 | if (kernel == NULL || | ||
2035 | __machine__create_kernel_maps(self, kernel) < 0) | ||
2036 | return -1; | ||
2037 | |||
2038 | if (symbol_conf.use_modules && machine__create_modules(self) < 0) | ||
2039 | pr_debug("Problems creating module maps, continuing anyway...\n"); | ||
2040 | /* | ||
2041 | * Now that we have all the maps created, just set the ->end of them: | ||
2042 | */ | ||
2043 | map_groups__fixup_end(&self->kmaps); | ||
2044 | return 0; | ||
2045 | } | ||
2046 | |||
1843 | static void vmlinux_path__exit(void) | 2047 | static void vmlinux_path__exit(void) |
1844 | { | 2048 | { |
1845 | while (--vmlinux_path__nr_entries >= 0) { | 2049 | while (--vmlinux_path__nr_entries >= 0) { |
@@ -1895,6 +2099,17 @@ out_fail: | |||
1895 | return -1; | 2099 | return -1; |
1896 | } | 2100 | } |
1897 | 2101 | ||
2102 | size_t vmlinux_path__fprintf(FILE *fp) | ||
2103 | { | ||
2104 | int i; | ||
2105 | size_t printed = 0; | ||
2106 | |||
2107 | for (i = 0; i < vmlinux_path__nr_entries; ++i) | ||
2108 | printed += fprintf(fp, "[%d] %s\n", i, vmlinux_path[i]); | ||
2109 | |||
2110 | return printed; | ||
2111 | } | ||
2112 | |||
1898 | static int setup_list(struct strlist **list, const char *list_str, | 2113 | static int setup_list(struct strlist **list, const char *list_str, |
1899 | const char *list_name) | 2114 | const char *list_name) |
1900 | { | 2115 | { |
@@ -1945,22 +2160,129 @@ out_free_comm_list: | |||
1945 | return -1; | 2160 | return -1; |
1946 | } | 2161 | } |
1947 | 2162 | ||
1948 | int map_groups__create_kernel_maps(struct map_groups *self, | 2163 | int machines__create_kernel_maps(struct rb_root *self, pid_t pid) |
1949 | struct map *vmlinux_maps[MAP__NR_TYPES]) | ||
1950 | { | 2164 | { |
1951 | struct dso *kernel = dsos__create_kernel(symbol_conf.vmlinux_name); | 2165 | struct machine *machine = machines__findnew(self, pid); |
1952 | 2166 | ||
1953 | if (kernel == NULL) | 2167 | if (machine == NULL) |
1954 | return -1; | 2168 | return -1; |
1955 | 2169 | ||
1956 | if (__map_groups__create_kernel_maps(self, vmlinux_maps, kernel) < 0) | 2170 | return machine__create_kernel_maps(machine); |
1957 | return -1; | 2171 | } |
1958 | 2172 | ||
1959 | if (symbol_conf.use_modules && map_groups__create_modules(self) < 0) | 2173 | static int hex(char ch) |
1960 | pr_debug("Problems creating module maps, continuing anyway...\n"); | 2174 | { |
1961 | /* | 2175 | if ((ch >= '0') && (ch <= '9')) |
1962 | * Now that we have all the maps created, just set the ->end of them: | 2176 | return ch - '0'; |
1963 | */ | 2177 | if ((ch >= 'a') && (ch <= 'f')) |
1964 | map_groups__fixup_end(self); | 2178 | return ch - 'a' + 10; |
1965 | return 0; | 2179 | if ((ch >= 'A') && (ch <= 'F')) |
2180 | return ch - 'A' + 10; | ||
2181 | return -1; | ||
2182 | } | ||
2183 | |||
2184 | /* | ||
2185 | * While we find nice hex chars, build a long_val. | ||
2186 | * Return number of chars processed. | ||
2187 | */ | ||
2188 | int hex2u64(const char *ptr, u64 *long_val) | ||
2189 | { | ||
2190 | const char *p = ptr; | ||
2191 | *long_val = 0; | ||
2192 | |||
2193 | while (*p) { | ||
2194 | const int hex_val = hex(*p); | ||
2195 | |||
2196 | if (hex_val < 0) | ||
2197 | break; | ||
2198 | |||
2199 | *long_val = (*long_val << 4) | hex_val; | ||
2200 | p++; | ||
2201 | } | ||
2202 | |||
2203 | return p - ptr; | ||
2204 | } | ||
2205 | |||
2206 | char *strxfrchar(char *s, char from, char to) | ||
2207 | { | ||
2208 | char *p = s; | ||
2209 | |||
2210 | while ((p = strchr(p, from)) != NULL) | ||
2211 | *p++ = to; | ||
2212 | |||
2213 | return s; | ||
2214 | } | ||
2215 | |||
2216 | int machines__create_guest_kernel_maps(struct rb_root *self) | ||
2217 | { | ||
2218 | int ret = 0; | ||
2219 | struct dirent **namelist = NULL; | ||
2220 | int i, items = 0; | ||
2221 | char path[PATH_MAX]; | ||
2222 | pid_t pid; | ||
2223 | |||
2224 | if (symbol_conf.default_guest_vmlinux_name || | ||
2225 | symbol_conf.default_guest_modules || | ||
2226 | symbol_conf.default_guest_kallsyms) { | ||
2227 | machines__create_kernel_maps(self, DEFAULT_GUEST_KERNEL_ID); | ||
2228 | } | ||
2229 | |||
2230 | if (symbol_conf.guestmount) { | ||
2231 | items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL); | ||
2232 | if (items <= 0) | ||
2233 | return -ENOENT; | ||
2234 | for (i = 0; i < items; i++) { | ||
2235 | if (!isdigit(namelist[i]->d_name[0])) { | ||
2236 | /* Filter out . and .. */ | ||
2237 | continue; | ||
2238 | } | ||
2239 | pid = atoi(namelist[i]->d_name); | ||
2240 | sprintf(path, "%s/%s/proc/kallsyms", | ||
2241 | symbol_conf.guestmount, | ||
2242 | namelist[i]->d_name); | ||
2243 | ret = access(path, R_OK); | ||
2244 | if (ret) { | ||
2245 | pr_debug("Can't access file %s\n", path); | ||
2246 | goto failure; | ||
2247 | } | ||
2248 | machines__create_kernel_maps(self, pid); | ||
2249 | } | ||
2250 | failure: | ||
2251 | free(namelist); | ||
2252 | } | ||
2253 | |||
2254 | return ret; | ||
2255 | } | ||
2256 | |||
2257 | int machine__load_kallsyms(struct machine *self, const char *filename, | ||
2258 | enum map_type type, symbol_filter_t filter) | ||
2259 | { | ||
2260 | struct map *map = self->vmlinux_maps[type]; | ||
2261 | int ret = dso__load_kallsyms(map->dso, filename, map, filter); | ||
2262 | |||
2263 | if (ret > 0) { | ||
2264 | dso__set_loaded(map->dso, type); | ||
2265 | /* | ||
2266 | * Since /proc/kallsyms will have multiple sessions for the | ||
2267 | * kernel, with modules between them, fixup the end of all | ||
2268 | * sections. | ||
2269 | */ | ||
2270 | __map_groups__fixup_end(&self->kmaps, type); | ||
2271 | } | ||
2272 | |||
2273 | return ret; | ||
2274 | } | ||
2275 | |||
2276 | int machine__load_vmlinux_path(struct machine *self, enum map_type type, | ||
2277 | symbol_filter_t filter) | ||
2278 | { | ||
2279 | struct map *map = self->vmlinux_maps[type]; | ||
2280 | int ret = dso__load_vmlinux_path(map->dso, map, filter); | ||
2281 | |||
2282 | if (ret > 0) { | ||
2283 | dso__set_loaded(map->dso, type); | ||
2284 | map__reloc_vmlinux(map); | ||
2285 | } | ||
2286 | |||
2287 | return ret; | ||
1966 | } | 2288 | } |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index f30a37428919..032469e41876 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -3,10 +3,11 @@ | |||
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include "types.h" | 6 | #include <stdint.h> |
7 | #include "map.h" | ||
7 | #include <linux/list.h> | 8 | #include <linux/list.h> |
8 | #include <linux/rbtree.h> | 9 | #include <linux/rbtree.h> |
9 | #include "event.h" | 10 | #include <stdio.h> |
10 | 11 | ||
11 | #define DEBUG_CACHE_DIR ".debug" | 12 | #define DEBUG_CACHE_DIR ".debug" |
12 | 13 | ||
@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, | |||
29 | #endif | 30 | #endif |
30 | #endif | 31 | #endif |
31 | 32 | ||
33 | int hex2u64(const char *ptr, u64 *val); | ||
34 | char *strxfrchar(char *s, char from, char to); | ||
35 | |||
32 | /* | 36 | /* |
33 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | 37 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; |
34 | * for newer versions we can use mmap to reduce memory usage: | 38 | * for newer versions we can use mmap to reduce memory usage: |
@@ -44,10 +48,13 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, | |||
44 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | 48 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ |
45 | #endif | 49 | #endif |
46 | 50 | ||
51 | #define BUILD_ID_SIZE 20 | ||
52 | |||
47 | struct symbol { | 53 | struct symbol { |
48 | struct rb_node rb_node; | 54 | struct rb_node rb_node; |
49 | u64 start; | 55 | u64 start; |
50 | u64 end; | 56 | u64 end; |
57 | u16 namelen; | ||
51 | char name[0]; | 58 | char name[0]; |
52 | }; | 59 | }; |
53 | 60 | ||
@@ -63,10 +70,15 @@ struct symbol_conf { | |||
63 | show_nr_samples, | 70 | show_nr_samples, |
64 | use_callchain, | 71 | use_callchain, |
65 | exclude_other, | 72 | exclude_other, |
66 | full_paths; | 73 | full_paths, |
74 | show_cpu_utilization; | ||
67 | const char *vmlinux_name, | 75 | const char *vmlinux_name, |
68 | *field_sep; | 76 | *field_sep; |
69 | char *dso_list_str, | 77 | const char *default_guest_vmlinux_name, |
78 | *default_guest_kallsyms, | ||
79 | *default_guest_modules; | ||
80 | const char *guestmount; | ||
81 | const char *dso_list_str, | ||
70 | *comm_list_str, | 82 | *comm_list_str, |
71 | *sym_list_str, | 83 | *sym_list_str, |
72 | *col_width_list_str; | 84 | *col_width_list_str; |
@@ -88,6 +100,11 @@ struct ref_reloc_sym { | |||
88 | u64 unrelocated_addr; | 100 | u64 unrelocated_addr; |
89 | }; | 101 | }; |
90 | 102 | ||
103 | struct map_symbol { | ||
104 | struct map *map; | ||
105 | struct symbol *sym; | ||
106 | }; | ||
107 | |||
91 | struct addr_location { | 108 | struct addr_location { |
92 | struct thread *thread; | 109 | struct thread *thread; |
93 | struct map *map; | 110 | struct map *map; |
@@ -95,6 +112,13 @@ struct addr_location { | |||
95 | u64 addr; | 112 | u64 addr; |
96 | char level; | 113 | char level; |
97 | bool filtered; | 114 | bool filtered; |
115 | unsigned int cpumode; | ||
116 | }; | ||
117 | |||
118 | enum dso_kernel_type { | ||
119 | DSO_TYPE_USER = 0, | ||
120 | DSO_TYPE_KERNEL, | ||
121 | DSO_TYPE_GUEST_KERNEL | ||
98 | }; | 122 | }; |
99 | 123 | ||
100 | struct dso { | 124 | struct dso { |
@@ -104,8 +128,9 @@ struct dso { | |||
104 | u8 adjust_symbols:1; | 128 | u8 adjust_symbols:1; |
105 | u8 slen_calculated:1; | 129 | u8 slen_calculated:1; |
106 | u8 has_build_id:1; | 130 | u8 has_build_id:1; |
107 | u8 kernel:1; | 131 | enum dso_kernel_type kernel; |
108 | u8 hit:1; | 132 | u8 hit:1; |
133 | u8 annotate_warned:1; | ||
109 | unsigned char origin; | 134 | unsigned char origin; |
110 | u8 sorted_by_name; | 135 | u8 sorted_by_name; |
111 | u8 loaded; | 136 | u8 loaded; |
@@ -131,42 +156,65 @@ static inline void dso__set_loaded(struct dso *self, enum map_type type) | |||
131 | 156 | ||
132 | void dso__sort_by_name(struct dso *self, enum map_type type); | 157 | void dso__sort_by_name(struct dso *self, enum map_type type); |
133 | 158 | ||
134 | extern struct list_head dsos__user, dsos__kernel; | ||
135 | |||
136 | struct dso *__dsos__findnew(struct list_head *head, const char *name); | 159 | struct dso *__dsos__findnew(struct list_head *head, const char *name); |
137 | 160 | ||
138 | static inline struct dso *dsos__findnew(const char *name) | ||
139 | { | ||
140 | return __dsos__findnew(&dsos__user, name); | ||
141 | } | ||
142 | |||
143 | int dso__load(struct dso *self, struct map *map, symbol_filter_t filter); | 161 | int dso__load(struct dso *self, struct map *map, symbol_filter_t filter); |
144 | int dso__load_vmlinux_path(struct dso *self, struct map *map, | 162 | int dso__load_vmlinux_path(struct dso *self, struct map *map, |
145 | symbol_filter_t filter); | 163 | symbol_filter_t filter); |
146 | int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map, | 164 | int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map, |
147 | symbol_filter_t filter); | 165 | symbol_filter_t filter); |
148 | void dsos__fprintf(FILE *fp); | 166 | int machine__load_kallsyms(struct machine *self, const char *filename, |
149 | size_t dsos__fprintf_buildid(FILE *fp, bool with_hits); | 167 | enum map_type type, symbol_filter_t filter); |
168 | int machine__load_vmlinux_path(struct machine *self, enum map_type type, | ||
169 | symbol_filter_t filter); | ||
170 | |||
171 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); | ||
172 | |||
173 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp); | ||
174 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits); | ||
150 | 175 | ||
151 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); | 176 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp); |
152 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); | 177 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp); |
178 | |||
179 | enum dso_origin { | ||
180 | DSO__ORIG_KERNEL = 0, | ||
181 | DSO__ORIG_GUEST_KERNEL, | ||
182 | DSO__ORIG_JAVA_JIT, | ||
183 | DSO__ORIG_BUILD_ID_CACHE, | ||
184 | DSO__ORIG_FEDORA, | ||
185 | DSO__ORIG_UBUNTU, | ||
186 | DSO__ORIG_BUILDID, | ||
187 | DSO__ORIG_DSO, | ||
188 | DSO__ORIG_GUEST_KMODULE, | ||
189 | DSO__ORIG_KMODULE, | ||
190 | DSO__ORIG_NOT_FOUND, | ||
191 | }; | ||
192 | |||
153 | char dso__symtab_origin(const struct dso *self); | 193 | char dso__symtab_origin(const struct dso *self); |
154 | void dso__set_long_name(struct dso *self, char *name); | 194 | void dso__set_long_name(struct dso *self, char *name); |
155 | void dso__set_build_id(struct dso *self, void *build_id); | 195 | void dso__set_build_id(struct dso *self, void *build_id); |
156 | void dso__read_running_kernel_build_id(struct dso *self); | 196 | void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine); |
157 | struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr); | 197 | struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr); |
158 | struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type, | 198 | struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type, |
159 | const char *name); | 199 | const char *name); |
160 | 200 | ||
161 | int filename__read_build_id(const char *filename, void *bf, size_t size); | 201 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
162 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); | 202 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
163 | bool dsos__read_build_ids(bool with_hits); | 203 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); |
164 | int build_id__sprintf(const u8 *self, int len, char *bf); | 204 | int build_id__sprintf(const u8 *self, int len, char *bf); |
165 | int kallsyms__parse(const char *filename, void *arg, | 205 | int kallsyms__parse(const char *filename, void *arg, |
166 | int (*process_symbol)(void *arg, const char *name, | 206 | int (*process_symbol)(void *arg, const char *name, |
167 | char type, u64 start)); | 207 | char type, u64 start)); |
168 | 208 | ||
209 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel); | ||
210 | int machine__create_kernel_maps(struct machine *self); | ||
211 | |||
212 | int machines__create_kernel_maps(struct rb_root *self, pid_t pid); | ||
213 | int machines__create_guest_kernel_maps(struct rb_root *self); | ||
214 | |||
169 | int symbol__init(void); | 215 | int symbol__init(void); |
170 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); | 216 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
171 | 217 | ||
218 | size_t vmlinux_path__fprintf(FILE *fp); | ||
219 | |||
172 | #endif /* __PERF_SYMBOL */ | 220 | #endif /* __PERF_SYMBOL */ |
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index fa968312ee7d..1f7ecd47f499 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
@@ -7,13 +7,35 @@ | |||
7 | #include "util.h" | 7 | #include "util.h" |
8 | #include "debug.h" | 8 | #include "debug.h" |
9 | 9 | ||
10 | void map_groups__init(struct map_groups *self) | 10 | int find_all_tid(int pid, pid_t ** all_tid) |
11 | { | 11 | { |
12 | char name[256]; | ||
13 | int items; | ||
14 | struct dirent **namelist = NULL; | ||
15 | int ret = 0; | ||
12 | int i; | 16 | int i; |
13 | for (i = 0; i < MAP__NR_TYPES; ++i) { | 17 | |
14 | self->maps[i] = RB_ROOT; | 18 | sprintf(name, "/proc/%d/task", pid); |
15 | INIT_LIST_HEAD(&self->removed_maps[i]); | 19 | items = scandir(name, &namelist, NULL, NULL); |
20 | if (items <= 0) | ||
21 | return -ENOENT; | ||
22 | *all_tid = malloc(sizeof(pid_t) * items); | ||
23 | if (!*all_tid) { | ||
24 | ret = -ENOMEM; | ||
25 | goto failure; | ||
16 | } | 26 | } |
27 | |||
28 | for (i = 0; i < items; i++) | ||
29 | (*all_tid)[i] = atoi(namelist[i]->d_name); | ||
30 | |||
31 | ret = items; | ||
32 | |||
33 | failure: | ||
34 | for (i=0; i<items; i++) | ||
35 | free(namelist[i]); | ||
36 | free(namelist); | ||
37 | |||
38 | return ret; | ||
17 | } | 39 | } |
18 | 40 | ||
19 | static struct thread *thread__new(pid_t pid) | 41 | static struct thread *thread__new(pid_t pid) |
@@ -31,28 +53,6 @@ static struct thread *thread__new(pid_t pid) | |||
31 | return self; | 53 | return self; |
32 | } | 54 | } |
33 | 55 | ||
34 | static void map_groups__flush(struct map_groups *self) | ||
35 | { | ||
36 | int type; | ||
37 | |||
38 | for (type = 0; type < MAP__NR_TYPES; type++) { | ||
39 | struct rb_root *root = &self->maps[type]; | ||
40 | struct rb_node *next = rb_first(root); | ||
41 | |||
42 | while (next) { | ||
43 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
44 | next = rb_next(&pos->rb_node); | ||
45 | rb_erase(&pos->rb_node, root); | ||
46 | /* | ||
47 | * We may have references to this map, for | ||
48 | * instance in some hist_entry instances, so | ||
49 | * just move them to a separate list. | ||
50 | */ | ||
51 | list_add_tail(&pos->node, &self->removed_maps[pos->type]); | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | |||
56 | int thread__set_comm(struct thread *self, const char *comm) | 56 | int thread__set_comm(struct thread *self, const char *comm) |
57 | { | 57 | { |
58 | int err; | 58 | int err; |
@@ -79,69 +79,10 @@ int thread__comm_len(struct thread *self) | |||
79 | return self->comm_len; | 79 | return self->comm_len; |
80 | } | 80 | } |
81 | 81 | ||
82 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
83 | enum map_type type, FILE *fp) | ||
84 | { | ||
85 | size_t printed = fprintf(fp, "%s:\n", map_type__name[type]); | ||
86 | struct rb_node *nd; | ||
87 | |||
88 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { | ||
89 | struct map *pos = rb_entry(nd, struct map, rb_node); | ||
90 | printed += fprintf(fp, "Map:"); | ||
91 | printed += map__fprintf(pos, fp); | ||
92 | if (verbose > 2) { | ||
93 | printed += dso__fprintf(pos->dso, type, fp); | ||
94 | printed += fprintf(fp, "--\n"); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return printed; | ||
99 | } | ||
100 | |||
101 | size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp) | ||
102 | { | ||
103 | size_t printed = 0, i; | ||
104 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
105 | printed += __map_groups__fprintf_maps(self, i, fp); | ||
106 | return printed; | ||
107 | } | ||
108 | |||
109 | static size_t __map_groups__fprintf_removed_maps(struct map_groups *self, | ||
110 | enum map_type type, FILE *fp) | ||
111 | { | ||
112 | struct map *pos; | ||
113 | size_t printed = 0; | ||
114 | |||
115 | list_for_each_entry(pos, &self->removed_maps[type], node) { | ||
116 | printed += fprintf(fp, "Map:"); | ||
117 | printed += map__fprintf(pos, fp); | ||
118 | if (verbose > 1) { | ||
119 | printed += dso__fprintf(pos->dso, type, fp); | ||
120 | printed += fprintf(fp, "--\n"); | ||
121 | } | ||
122 | } | ||
123 | return printed; | ||
124 | } | ||
125 | |||
126 | static size_t map_groups__fprintf_removed_maps(struct map_groups *self, FILE *fp) | ||
127 | { | ||
128 | size_t printed = 0, i; | ||
129 | for (i = 0; i < MAP__NR_TYPES; ++i) | ||
130 | printed += __map_groups__fprintf_removed_maps(self, i, fp); | ||
131 | return printed; | ||
132 | } | ||
133 | |||
134 | static size_t map_groups__fprintf(struct map_groups *self, FILE *fp) | ||
135 | { | ||
136 | size_t printed = map_groups__fprintf_maps(self, fp); | ||
137 | printed += fprintf(fp, "Removed maps:\n"); | ||
138 | return printed + map_groups__fprintf_removed_maps(self, fp); | ||
139 | } | ||
140 | |||
141 | static size_t thread__fprintf(struct thread *self, FILE *fp) | 82 | static size_t thread__fprintf(struct thread *self, FILE *fp) |
142 | { | 83 | { |
143 | return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + | 84 | return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) + |
144 | map_groups__fprintf(&self->mg, fp); | 85 | map_groups__fprintf(&self->mg, verbose, fp); |
145 | } | 86 | } |
146 | 87 | ||
147 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) | 88 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) |
@@ -183,127 +124,12 @@ struct thread *perf_session__findnew(struct perf_session *self, pid_t pid) | |||
183 | return th; | 124 | return th; |
184 | } | 125 | } |
185 | 126 | ||
186 | static int map_groups__fixup_overlappings(struct map_groups *self, | ||
187 | struct map *map) | ||
188 | { | ||
189 | struct rb_root *root = &self->maps[map->type]; | ||
190 | struct rb_node *next = rb_first(root); | ||
191 | |||
192 | while (next) { | ||
193 | struct map *pos = rb_entry(next, struct map, rb_node); | ||
194 | next = rb_next(&pos->rb_node); | ||
195 | |||
196 | if (!map__overlap(pos, map)) | ||
197 | continue; | ||
198 | |||
199 | if (verbose >= 2) { | ||
200 | fputs("overlapping maps:\n", stderr); | ||
201 | map__fprintf(map, stderr); | ||
202 | map__fprintf(pos, stderr); | ||
203 | } | ||
204 | |||
205 | rb_erase(&pos->rb_node, root); | ||
206 | /* | ||
207 | * We may have references to this map, for instance in some | ||
208 | * hist_entry instances, so just move them to a separate | ||
209 | * list. | ||
210 | */ | ||
211 | list_add_tail(&pos->node, &self->removed_maps[map->type]); | ||
212 | /* | ||
213 | * Now check if we need to create new maps for areas not | ||
214 | * overlapped by the new map: | ||
215 | */ | ||
216 | if (map->start > pos->start) { | ||
217 | struct map *before = map__clone(pos); | ||
218 | |||
219 | if (before == NULL) | ||
220 | return -ENOMEM; | ||
221 | |||
222 | before->end = map->start - 1; | ||
223 | map_groups__insert(self, before); | ||
224 | if (verbose >= 2) | ||
225 | map__fprintf(before, stderr); | ||
226 | } | ||
227 | |||
228 | if (map->end < pos->end) { | ||
229 | struct map *after = map__clone(pos); | ||
230 | |||
231 | if (after == NULL) | ||
232 | return -ENOMEM; | ||
233 | |||
234 | after->start = map->end + 1; | ||
235 | map_groups__insert(self, after); | ||
236 | if (verbose >= 2) | ||
237 | map__fprintf(after, stderr); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | void maps__insert(struct rb_root *maps, struct map *map) | ||
245 | { | ||
246 | struct rb_node **p = &maps->rb_node; | ||
247 | struct rb_node *parent = NULL; | ||
248 | const u64 ip = map->start; | ||
249 | struct map *m; | ||
250 | |||
251 | while (*p != NULL) { | ||
252 | parent = *p; | ||
253 | m = rb_entry(parent, struct map, rb_node); | ||
254 | if (ip < m->start) | ||
255 | p = &(*p)->rb_left; | ||
256 | else | ||
257 | p = &(*p)->rb_right; | ||
258 | } | ||
259 | |||
260 | rb_link_node(&map->rb_node, parent, p); | ||
261 | rb_insert_color(&map->rb_node, maps); | ||
262 | } | ||
263 | |||
264 | struct map *maps__find(struct rb_root *maps, u64 ip) | ||
265 | { | ||
266 | struct rb_node **p = &maps->rb_node; | ||
267 | struct rb_node *parent = NULL; | ||
268 | struct map *m; | ||
269 | |||
270 | while (*p != NULL) { | ||
271 | parent = *p; | ||
272 | m = rb_entry(parent, struct map, rb_node); | ||
273 | if (ip < m->start) | ||
274 | p = &(*p)->rb_left; | ||
275 | else if (ip > m->end) | ||
276 | p = &(*p)->rb_right; | ||
277 | else | ||
278 | return m; | ||
279 | } | ||
280 | |||
281 | return NULL; | ||
282 | } | ||
283 | |||
284 | void thread__insert_map(struct thread *self, struct map *map) | 127 | void thread__insert_map(struct thread *self, struct map *map) |
285 | { | 128 | { |
286 | map_groups__fixup_overlappings(&self->mg, map); | 129 | map_groups__fixup_overlappings(&self->mg, map, verbose, stderr); |
287 | map_groups__insert(&self->mg, map); | 130 | map_groups__insert(&self->mg, map); |
288 | } | 131 | } |
289 | 132 | ||
290 | /* | ||
291 | * XXX This should not really _copy_ te maps, but refcount them. | ||
292 | */ | ||
293 | static int map_groups__clone(struct map_groups *self, | ||
294 | struct map_groups *parent, enum map_type type) | ||
295 | { | ||
296 | struct rb_node *nd; | ||
297 | for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) { | ||
298 | struct map *map = rb_entry(nd, struct map, rb_node); | ||
299 | struct map *new = map__clone(map); | ||
300 | if (new == NULL) | ||
301 | return -ENOMEM; | ||
302 | map_groups__insert(self, new); | ||
303 | } | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | int thread__fork(struct thread *self, struct thread *parent) | 133 | int thread__fork(struct thread *self, struct thread *parent) |
308 | { | 134 | { |
309 | int i; | 135 | int i; |
@@ -336,15 +162,3 @@ size_t perf_session__fprintf(struct perf_session *self, FILE *fp) | |||
336 | 162 | ||
337 | return ret; | 163 | return ret; |
338 | } | 164 | } |
339 | |||
340 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
341 | enum map_type type, u64 addr, | ||
342 | symbol_filter_t filter) | ||
343 | { | ||
344 | struct map *map = map_groups__find(self, type, addr); | ||
345 | |||
346 | if (map != NULL) | ||
347 | return map__find_symbol(map, map->map_ip(map, addr), filter); | ||
348 | |||
349 | return NULL; | ||
350 | } | ||
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index dcf70303e58e..1dfd9ff8bdcd 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
@@ -5,14 +5,6 @@ | |||
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include "symbol.h" | 6 | #include "symbol.h" |
7 | 7 | ||
8 | struct map_groups { | ||
9 | struct rb_root maps[MAP__NR_TYPES]; | ||
10 | struct list_head removed_maps[MAP__NR_TYPES]; | ||
11 | }; | ||
12 | |||
13 | size_t __map_groups__fprintf_maps(struct map_groups *self, | ||
14 | enum map_type type, FILE *fp); | ||
15 | |||
16 | struct thread { | 8 | struct thread { |
17 | struct rb_node rb_node; | 9 | struct rb_node rb_node; |
18 | struct map_groups mg; | 10 | struct map_groups mg; |
@@ -23,29 +15,16 @@ struct thread { | |||
23 | int comm_len; | 15 | int comm_len; |
24 | }; | 16 | }; |
25 | 17 | ||
26 | void map_groups__init(struct map_groups *self); | 18 | struct perf_session; |
19 | |||
20 | int find_all_tid(int pid, pid_t ** all_tid); | ||
27 | int thread__set_comm(struct thread *self, const char *comm); | 21 | int thread__set_comm(struct thread *self, const char *comm); |
28 | int thread__comm_len(struct thread *self); | 22 | int thread__comm_len(struct thread *self); |
29 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); | 23 | struct thread *perf_session__findnew(struct perf_session *self, pid_t pid); |
30 | void thread__insert_map(struct thread *self, struct map *map); | 24 | void thread__insert_map(struct thread *self, struct map *map); |
31 | int thread__fork(struct thread *self, struct thread *parent); | 25 | int thread__fork(struct thread *self, struct thread *parent); |
32 | size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp); | ||
33 | size_t perf_session__fprintf(struct perf_session *self, FILE *fp); | 26 | size_t perf_session__fprintf(struct perf_session *self, FILE *fp); |
34 | 27 | ||
35 | void maps__insert(struct rb_root *maps, struct map *map); | ||
36 | struct map *maps__find(struct rb_root *maps, u64 addr); | ||
37 | |||
38 | static inline void map_groups__insert(struct map_groups *self, struct map *map) | ||
39 | { | ||
40 | maps__insert(&self->maps[map->type], map); | ||
41 | } | ||
42 | |||
43 | static inline struct map *map_groups__find(struct map_groups *self, | ||
44 | enum map_type type, u64 addr) | ||
45 | { | ||
46 | return maps__find(&self->maps[type], addr); | ||
47 | } | ||
48 | |||
49 | static inline struct map *thread__find_map(struct thread *self, | 28 | static inline struct map *thread__find_map(struct thread *self, |
50 | enum map_type type, u64 addr) | 29 | enum map_type type, u64 addr) |
51 | { | 30 | { |
@@ -54,34 +33,12 @@ static inline struct map *thread__find_map(struct thread *self, | |||
54 | 33 | ||
55 | void thread__find_addr_map(struct thread *self, | 34 | void thread__find_addr_map(struct thread *self, |
56 | struct perf_session *session, u8 cpumode, | 35 | struct perf_session *session, u8 cpumode, |
57 | enum map_type type, u64 addr, | 36 | enum map_type type, pid_t pid, u64 addr, |
58 | struct addr_location *al); | 37 | struct addr_location *al); |
59 | 38 | ||
60 | void thread__find_addr_location(struct thread *self, | 39 | void thread__find_addr_location(struct thread *self, |
61 | struct perf_session *session, u8 cpumode, | 40 | struct perf_session *session, u8 cpumode, |
62 | enum map_type type, u64 addr, | 41 | enum map_type type, pid_t pid, u64 addr, |
63 | struct addr_location *al, | 42 | struct addr_location *al, |
64 | symbol_filter_t filter); | 43 | symbol_filter_t filter); |
65 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
66 | enum map_type type, u64 addr, | ||
67 | symbol_filter_t filter); | ||
68 | |||
69 | static inline struct symbol *map_groups__find_function(struct map_groups *self, | ||
70 | u64 addr, | ||
71 | symbol_filter_t filter) | ||
72 | { | ||
73 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter); | ||
74 | } | ||
75 | |||
76 | struct map *map_groups__find_by_name(struct map_groups *self, | ||
77 | enum map_type type, const char *name); | ||
78 | |||
79 | int __map_groups__create_kernel_maps(struct map_groups *self, | ||
80 | struct map *vmlinux_maps[MAP__NR_TYPES], | ||
81 | struct dso *kernel); | ||
82 | int map_groups__create_kernel_maps(struct map_groups *self, | ||
83 | struct map *vmlinux_maps[MAP__NR_TYPES]); | ||
84 | |||
85 | struct map *map_groups__new_module(struct map_groups *self, u64 start, | ||
86 | const char *filename); | ||
87 | #endif /* __PERF_THREAD_H */ | 44 | #endif /* __PERF_THREAD_H */ |
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c index 5ea8973ad331..b1572601286c 100644 --- a/tools/perf/util/trace-event-info.c +++ b/tools/perf/util/trace-event-info.c | |||
@@ -154,10 +154,17 @@ static void put_tracing_file(char *file) | |||
154 | free(file); | 154 | free(file); |
155 | } | 155 | } |
156 | 156 | ||
157 | static ssize_t calc_data_size; | ||
158 | |||
157 | static ssize_t write_or_die(const void *buf, size_t len) | 159 | static ssize_t write_or_die(const void *buf, size_t len) |
158 | { | 160 | { |
159 | int ret; | 161 | int ret; |
160 | 162 | ||
163 | if (calc_data_size) { | ||
164 | calc_data_size += len; | ||
165 | return len; | ||
166 | } | ||
167 | |||
161 | ret = write(output_fd, buf, len); | 168 | ret = write(output_fd, buf, len); |
162 | if (ret < 0) | 169 | if (ret < 0) |
163 | die("writing to '%s'", output_file); | 170 | die("writing to '%s'", output_file); |
@@ -480,6 +487,17 @@ get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events) | |||
480 | return nr_tracepoints > 0 ? path.next : NULL; | 487 | return nr_tracepoints > 0 ? path.next : NULL; |
481 | } | 488 | } |
482 | 489 | ||
490 | bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events) | ||
491 | { | ||
492 | int i; | ||
493 | |||
494 | for (i = 0; i < nb_events; i++) | ||
495 | if (pattrs[i].type == PERF_TYPE_TRACEPOINT) | ||
496 | return true; | ||
497 | |||
498 | return false; | ||
499 | } | ||
500 | |||
483 | int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events) | 501 | int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events) |
484 | { | 502 | { |
485 | char buf[BUFSIZ]; | 503 | char buf[BUFSIZ]; |
@@ -526,3 +544,20 @@ int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events) | |||
526 | 544 | ||
527 | return 0; | 545 | return 0; |
528 | } | 546 | } |
547 | |||
548 | ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs, | ||
549 | int nb_events) | ||
550 | { | ||
551 | ssize_t size; | ||
552 | int err = 0; | ||
553 | |||
554 | calc_data_size = 1; | ||
555 | err = read_tracing_data(fd, pattrs, nb_events); | ||
556 | size = calc_data_size - 1; | ||
557 | calc_data_size = 0; | ||
558 | |||
559 | if (err < 0) | ||
560 | return err; | ||
561 | |||
562 | return size; | ||
563 | } | ||
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index 613c9cc90570..73a02223c629 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -37,10 +37,12 @@ int header_page_ts_offset; | |||
37 | int header_page_ts_size; | 37 | int header_page_ts_size; |
38 | int header_page_size_offset; | 38 | int header_page_size_offset; |
39 | int header_page_size_size; | 39 | int header_page_size_size; |
40 | int header_page_overwrite_offset; | ||
41 | int header_page_overwrite_size; | ||
40 | int header_page_data_offset; | 42 | int header_page_data_offset; |
41 | int header_page_data_size; | 43 | int header_page_data_size; |
42 | 44 | ||
43 | int latency_format; | 45 | bool latency_format; |
44 | 46 | ||
45 | static char *input_buf; | 47 | static char *input_buf; |
46 | static unsigned long long input_buf_ptr; | 48 | static unsigned long long input_buf_ptr; |
@@ -628,23 +630,32 @@ static int test_type(enum event_type type, enum event_type expect) | |||
628 | return 0; | 630 | return 0; |
629 | } | 631 | } |
630 | 632 | ||
631 | static int test_type_token(enum event_type type, char *token, | 633 | static int __test_type_token(enum event_type type, char *token, |
632 | enum event_type expect, const char *expect_tok) | 634 | enum event_type expect, const char *expect_tok, |
635 | bool warn) | ||
633 | { | 636 | { |
634 | if (type != expect) { | 637 | if (type != expect) { |
635 | warning("Error: expected type %d but read %d", | 638 | if (warn) |
636 | expect, type); | 639 | warning("Error: expected type %d but read %d", |
640 | expect, type); | ||
637 | return -1; | 641 | return -1; |
638 | } | 642 | } |
639 | 643 | ||
640 | if (strcmp(token, expect_tok) != 0) { | 644 | if (strcmp(token, expect_tok) != 0) { |
641 | warning("Error: expected '%s' but read '%s'", | 645 | if (warn) |
642 | expect_tok, token); | 646 | warning("Error: expected '%s' but read '%s'", |
647 | expect_tok, token); | ||
643 | return -1; | 648 | return -1; |
644 | } | 649 | } |
645 | return 0; | 650 | return 0; |
646 | } | 651 | } |
647 | 652 | ||
653 | static int test_type_token(enum event_type type, char *token, | ||
654 | enum event_type expect, const char *expect_tok) | ||
655 | { | ||
656 | return __test_type_token(type, token, expect, expect_tok, true); | ||
657 | } | ||
658 | |||
648 | static int __read_expect_type(enum event_type expect, char **tok, int newline_ok) | 659 | static int __read_expect_type(enum event_type expect, char **tok, int newline_ok) |
649 | { | 660 | { |
650 | enum event_type type; | 661 | enum event_type type; |
@@ -661,7 +672,8 @@ static int read_expect_type(enum event_type expect, char **tok) | |||
661 | return __read_expect_type(expect, tok, 1); | 672 | return __read_expect_type(expect, tok, 1); |
662 | } | 673 | } |
663 | 674 | ||
664 | static int __read_expected(enum event_type expect, const char *str, int newline_ok) | 675 | static int __read_expected(enum event_type expect, const char *str, |
676 | int newline_ok, bool warn) | ||
665 | { | 677 | { |
666 | enum event_type type; | 678 | enum event_type type; |
667 | char *token; | 679 | char *token; |
@@ -672,7 +684,7 @@ static int __read_expected(enum event_type expect, const char *str, int newline_ | |||
672 | else | 684 | else |
673 | type = read_token_item(&token); | 685 | type = read_token_item(&token); |
674 | 686 | ||
675 | ret = test_type_token(type, token, expect, str); | 687 | ret = __test_type_token(type, token, expect, str, warn); |
676 | 688 | ||
677 | free_token(token); | 689 | free_token(token); |
678 | 690 | ||
@@ -681,12 +693,12 @@ static int __read_expected(enum event_type expect, const char *str, int newline_ | |||
681 | 693 | ||
682 | static int read_expected(enum event_type expect, const char *str) | 694 | static int read_expected(enum event_type expect, const char *str) |
683 | { | 695 | { |
684 | return __read_expected(expect, str, 1); | 696 | return __read_expected(expect, str, 1, true); |
685 | } | 697 | } |
686 | 698 | ||
687 | static int read_expected_item(enum event_type expect, const char *str) | 699 | static int read_expected_item(enum event_type expect, const char *str) |
688 | { | 700 | { |
689 | return __read_expected(expect, str, 0); | 701 | return __read_expected(expect, str, 0, true); |
690 | } | 702 | } |
691 | 703 | ||
692 | static char *event_read_name(void) | 704 | static char *event_read_name(void) |
@@ -744,7 +756,7 @@ static int field_is_string(struct format_field *field) | |||
744 | 756 | ||
745 | static int field_is_dynamic(struct format_field *field) | 757 | static int field_is_dynamic(struct format_field *field) |
746 | { | 758 | { |
747 | if (!strcmp(field->type, "__data_loc")) | 759 | if (!strncmp(field->type, "__data_loc", 10)) |
748 | return 1; | 760 | return 1; |
749 | 761 | ||
750 | return 0; | 762 | return 0; |
@@ -3087,88 +3099,6 @@ static void print_args(struct print_arg *args) | |||
3087 | } | 3099 | } |
3088 | } | 3100 | } |
3089 | 3101 | ||
3090 | static void parse_header_field(const char *field, | ||
3091 | int *offset, int *size) | ||
3092 | { | ||
3093 | char *token; | ||
3094 | int type; | ||
3095 | |||
3096 | if (read_expected(EVENT_ITEM, "field") < 0) | ||
3097 | return; | ||
3098 | if (read_expected(EVENT_OP, ":") < 0) | ||
3099 | return; | ||
3100 | |||
3101 | /* type */ | ||
3102 | if (read_expect_type(EVENT_ITEM, &token) < 0) | ||
3103 | goto fail; | ||
3104 | free_token(token); | ||
3105 | |||
3106 | if (read_expected(EVENT_ITEM, field) < 0) | ||
3107 | return; | ||
3108 | if (read_expected(EVENT_OP, ";") < 0) | ||
3109 | return; | ||
3110 | if (read_expected(EVENT_ITEM, "offset") < 0) | ||
3111 | return; | ||
3112 | if (read_expected(EVENT_OP, ":") < 0) | ||
3113 | return; | ||
3114 | if (read_expect_type(EVENT_ITEM, &token) < 0) | ||
3115 | goto fail; | ||
3116 | *offset = atoi(token); | ||
3117 | free_token(token); | ||
3118 | if (read_expected(EVENT_OP, ";") < 0) | ||
3119 | return; | ||
3120 | if (read_expected(EVENT_ITEM, "size") < 0) | ||
3121 | return; | ||
3122 | if (read_expected(EVENT_OP, ":") < 0) | ||
3123 | return; | ||
3124 | if (read_expect_type(EVENT_ITEM, &token) < 0) | ||
3125 | goto fail; | ||
3126 | *size = atoi(token); | ||
3127 | free_token(token); | ||
3128 | if (read_expected(EVENT_OP, ";") < 0) | ||
3129 | return; | ||
3130 | type = read_token(&token); | ||
3131 | if (type != EVENT_NEWLINE) { | ||
3132 | /* newer versions of the kernel have a "signed" type */ | ||
3133 | if (type != EVENT_ITEM) | ||
3134 | goto fail; | ||
3135 | |||
3136 | if (strcmp(token, "signed") != 0) | ||
3137 | goto fail; | ||
3138 | |||
3139 | free_token(token); | ||
3140 | |||
3141 | if (read_expected(EVENT_OP, ":") < 0) | ||
3142 | return; | ||
3143 | |||
3144 | if (read_expect_type(EVENT_ITEM, &token)) | ||
3145 | goto fail; | ||
3146 | |||
3147 | free_token(token); | ||
3148 | if (read_expected(EVENT_OP, ";") < 0) | ||
3149 | return; | ||
3150 | |||
3151 | if (read_expect_type(EVENT_NEWLINE, &token)) | ||
3152 | goto fail; | ||
3153 | } | ||
3154 | fail: | ||
3155 | free_token(token); | ||
3156 | } | ||
3157 | |||
3158 | int parse_header_page(char *buf, unsigned long size) | ||
3159 | { | ||
3160 | init_input_buf(buf, size); | ||
3161 | |||
3162 | parse_header_field("timestamp", &header_page_ts_offset, | ||
3163 | &header_page_ts_size); | ||
3164 | parse_header_field("commit", &header_page_size_offset, | ||
3165 | &header_page_size_size); | ||
3166 | parse_header_field("data", &header_page_data_offset, | ||
3167 | &header_page_data_size); | ||
3168 | |||
3169 | return 0; | ||
3170 | } | ||
3171 | |||
3172 | int parse_ftrace_file(char *buf, unsigned long size) | 3102 | int parse_ftrace_file(char *buf, unsigned long size) |
3173 | { | 3103 | { |
3174 | struct format_field *field; | 3104 | struct format_field *field; |
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index 7cd1193918c7..cb54cd002f49 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c | |||
@@ -50,14 +50,51 @@ static int long_size; | |||
50 | 50 | ||
51 | static unsigned long page_size; | 51 | static unsigned long page_size; |
52 | 52 | ||
53 | static ssize_t calc_data_size; | ||
54 | static bool repipe; | ||
55 | |||
56 | /* If it fails, the next read will report it */ | ||
57 | static void skip(int size) | ||
58 | { | ||
59 | lseek(input_fd, size, SEEK_CUR); | ||
60 | } | ||
61 | |||
62 | static int do_read(int fd, void *buf, int size) | ||
63 | { | ||
64 | int rsize = size; | ||
65 | |||
66 | while (size) { | ||
67 | int ret = read(fd, buf, size); | ||
68 | |||
69 | if (ret <= 0) | ||
70 | return -1; | ||
71 | |||
72 | if (repipe) { | ||
73 | int retw = write(STDOUT_FILENO, buf, ret); | ||
74 | |||
75 | if (retw <= 0 || retw != ret) | ||
76 | die("repiping input file"); | ||
77 | } | ||
78 | |||
79 | size -= ret; | ||
80 | buf += ret; | ||
81 | } | ||
82 | |||
83 | return rsize; | ||
84 | } | ||
85 | |||
53 | static int read_or_die(void *data, int size) | 86 | static int read_or_die(void *data, int size) |
54 | { | 87 | { |
55 | int r; | 88 | int r; |
56 | 89 | ||
57 | r = read(input_fd, data, size); | 90 | r = do_read(input_fd, data, size); |
58 | if (r != size) | 91 | if (r <= 0) |
59 | die("reading input file (size expected=%d received=%d)", | 92 | die("reading input file (size expected=%d received=%d)", |
60 | size, r); | 93 | size, r); |
94 | |||
95 | if (calc_data_size) | ||
96 | calc_data_size += r; | ||
97 | |||
61 | return r; | 98 | return r; |
62 | } | 99 | } |
63 | 100 | ||
@@ -82,57 +119,36 @@ static char *read_string(void) | |||
82 | char buf[BUFSIZ]; | 119 | char buf[BUFSIZ]; |
83 | char *str = NULL; | 120 | char *str = NULL; |
84 | int size = 0; | 121 | int size = 0; |
85 | int i; | ||
86 | off_t r; | 122 | off_t r; |
123 | char c; | ||
87 | 124 | ||
88 | for (;;) { | 125 | for (;;) { |
89 | r = read(input_fd, buf, BUFSIZ); | 126 | r = read(input_fd, &c, 1); |
90 | if (r < 0) | 127 | if (r < 0) |
91 | die("reading input file"); | 128 | die("reading input file"); |
92 | 129 | ||
93 | if (!r) | 130 | if (!r) |
94 | die("no data"); | 131 | die("no data"); |
95 | 132 | ||
96 | for (i = 0; i < r; i++) { | 133 | if (repipe) { |
97 | if (!buf[i]) | 134 | int retw = write(STDOUT_FILENO, &c, 1); |
98 | break; | ||
99 | } | ||
100 | if (i < r) | ||
101 | break; | ||
102 | 135 | ||
103 | if (str) { | 136 | if (retw <= 0 || retw != r) |
104 | size += BUFSIZ; | 137 | die("repiping input file string"); |
105 | str = realloc(str, size); | ||
106 | if (!str) | ||
107 | die("malloc of size %d", size); | ||
108 | memcpy(str + (size - BUFSIZ), buf, BUFSIZ); | ||
109 | } else { | ||
110 | size = BUFSIZ; | ||
111 | str = malloc_or_die(size); | ||
112 | memcpy(str, buf, size); | ||
113 | } | 138 | } |
114 | } | ||
115 | 139 | ||
116 | /* trailing \0: */ | 140 | buf[size++] = c; |
117 | i++; | 141 | |
118 | 142 | if (!c) | |
119 | /* move the file descriptor to the end of the string */ | 143 | break; |
120 | r = lseek(input_fd, -(r - i), SEEK_CUR); | ||
121 | if (r == (off_t)-1) | ||
122 | die("lseek"); | ||
123 | |||
124 | if (str) { | ||
125 | size += i; | ||
126 | str = realloc(str, size); | ||
127 | if (!str) | ||
128 | die("malloc of size %d", size); | ||
129 | memcpy(str + (size - i), buf, i); | ||
130 | } else { | ||
131 | size = i; | ||
132 | str = malloc_or_die(i); | ||
133 | memcpy(str, buf, i); | ||
134 | } | 144 | } |
135 | 145 | ||
146 | if (calc_data_size) | ||
147 | calc_data_size += size; | ||
148 | |||
149 | str = malloc_or_die(size); | ||
150 | memcpy(str, buf, size); | ||
151 | |||
136 | return str; | 152 | return str; |
137 | } | 153 | } |
138 | 154 | ||
@@ -174,7 +190,6 @@ static void read_ftrace_printk(void) | |||
174 | static void read_header_files(void) | 190 | static void read_header_files(void) |
175 | { | 191 | { |
176 | unsigned long long size; | 192 | unsigned long long size; |
177 | char *header_page; | ||
178 | char *header_event; | 193 | char *header_event; |
179 | char buf[BUFSIZ]; | 194 | char buf[BUFSIZ]; |
180 | 195 | ||
@@ -184,10 +199,7 @@ static void read_header_files(void) | |||
184 | die("did not read header page"); | 199 | die("did not read header page"); |
185 | 200 | ||
186 | size = read8(); | 201 | size = read8(); |
187 | header_page = malloc_or_die(size); | 202 | skip(size); |
188 | read_or_die(header_page, size); | ||
189 | parse_header_page(header_page, size); | ||
190 | free(header_page); | ||
191 | 203 | ||
192 | /* | 204 | /* |
193 | * The size field in the page is of type long, | 205 | * The size field in the page is of type long, |
@@ -459,7 +471,7 @@ struct record *trace_read_data(int cpu) | |||
459 | return data; | 471 | return data; |
460 | } | 472 | } |
461 | 473 | ||
462 | void trace_report(int fd) | 474 | ssize_t trace_report(int fd, bool __repipe) |
463 | { | 475 | { |
464 | char buf[BUFSIZ]; | 476 | char buf[BUFSIZ]; |
465 | char test[] = { 23, 8, 68 }; | 477 | char test[] = { 23, 8, 68 }; |
@@ -467,6 +479,10 @@ void trace_report(int fd) | |||
467 | int show_version = 0; | 479 | int show_version = 0; |
468 | int show_funcs = 0; | 480 | int show_funcs = 0; |
469 | int show_printk = 0; | 481 | int show_printk = 0; |
482 | ssize_t size; | ||
483 | |||
484 | calc_data_size = 1; | ||
485 | repipe = __repipe; | ||
470 | 486 | ||
471 | input_fd = fd; | 487 | input_fd = fd; |
472 | 488 | ||
@@ -499,14 +515,18 @@ void trace_report(int fd) | |||
499 | read_proc_kallsyms(); | 515 | read_proc_kallsyms(); |
500 | read_ftrace_printk(); | 516 | read_ftrace_printk(); |
501 | 517 | ||
518 | size = calc_data_size - 1; | ||
519 | calc_data_size = 0; | ||
520 | repipe = false; | ||
521 | |||
502 | if (show_funcs) { | 522 | if (show_funcs) { |
503 | print_funcs(); | 523 | print_funcs(); |
504 | return; | 524 | return size; |
505 | } | 525 | } |
506 | if (show_printk) { | 526 | if (show_printk) { |
507 | print_printk(); | 527 | print_printk(); |
508 | return; | 528 | return size; |
509 | } | 529 | } |
510 | 530 | ||
511 | return; | 531 | return size; |
512 | } | 532 | } |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index c3269b937db4..406d452956db 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __PERF_TRACE_EVENTS_H | 1 | #ifndef __PERF_TRACE_EVENTS_H |
2 | #define __PERF_TRACE_EVENTS_H | 2 | #define __PERF_TRACE_EVENTS_H |
3 | 3 | ||
4 | #include <stdbool.h> | ||
4 | #include "parse-events.h" | 5 | #include "parse-events.h" |
5 | 6 | ||
6 | #define __unused __attribute__((unused)) | 7 | #define __unused __attribute__((unused)) |
@@ -162,7 +163,7 @@ struct record *trace_read_data(int cpu); | |||
162 | 163 | ||
163 | void parse_set_info(int nr_cpus, int long_sz); | 164 | void parse_set_info(int nr_cpus, int long_sz); |
164 | 165 | ||
165 | void trace_report(int fd); | 166 | ssize_t trace_report(int fd, bool repipe); |
166 | 167 | ||
167 | void *malloc_or_die(unsigned int size); | 168 | void *malloc_or_die(unsigned int size); |
168 | 169 | ||
@@ -241,9 +242,8 @@ extern int header_page_size_size; | |||
241 | extern int header_page_data_offset; | 242 | extern int header_page_data_offset; |
242 | extern int header_page_data_size; | 243 | extern int header_page_data_size; |
243 | 244 | ||
244 | extern int latency_format; | 245 | extern bool latency_format; |
245 | 246 | ||
246 | int parse_header_page(char *buf, unsigned long size); | ||
247 | int trace_parse_common_type(void *data); | 247 | int trace_parse_common_type(void *data); |
248 | int trace_parse_common_pid(void *data); | 248 | int trace_parse_common_pid(void *data); |
249 | int parse_common_pc(void *data); | 249 | int parse_common_pc(void *data); |
@@ -258,6 +258,8 @@ void *raw_field_ptr(struct event *event, const char *name, void *data); | |||
258 | unsigned long long eval_flag(const char *flag); | 258 | unsigned long long eval_flag(const char *flag); |
259 | 259 | ||
260 | int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events); | 260 | int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events); |
261 | ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs, | ||
262 | int nb_events); | ||
261 | 263 | ||
262 | /* taken from kernel/trace/trace.h */ | 264 | /* taken from kernel/trace/trace.h */ |
263 | enum trace_flag_type { | 265 | enum trace_flag_type { |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index f9b890fde681..214265674ddd 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -92,3 +92,25 @@ out_close_from: | |||
92 | out: | 92 | out: |
93 | return err; | 93 | return err; |
94 | } | 94 | } |
95 | |||
96 | unsigned long convert_unit(unsigned long value, char *unit) | ||
97 | { | ||
98 | *unit = ' '; | ||
99 | |||
100 | if (value > 1000) { | ||
101 | value /= 1000; | ||
102 | *unit = 'K'; | ||
103 | } | ||
104 | |||
105 | if (value > 1000) { | ||
106 | value /= 1000; | ||
107 | *unit = 'M'; | ||
108 | } | ||
109 | |||
110 | if (value > 1000) { | ||
111 | value /= 1000; | ||
112 | *unit = 'G'; | ||
113 | } | ||
114 | |||
115 | return value; | ||
116 | } | ||
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0f5b2a6f1080..0795bf304b19 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -42,12 +42,14 @@ | |||
42 | #define _ALL_SOURCE 1 | 42 | #define _ALL_SOURCE 1 |
43 | #define _GNU_SOURCE 1 | 43 | #define _GNU_SOURCE 1 |
44 | #define _BSD_SOURCE 1 | 44 | #define _BSD_SOURCE 1 |
45 | #define HAS_BOOL | ||
45 | 46 | ||
46 | #include <unistd.h> | 47 | #include <unistd.h> |
47 | #include <stdio.h> | 48 | #include <stdio.h> |
48 | #include <sys/stat.h> | 49 | #include <sys/stat.h> |
49 | #include <sys/statfs.h> | 50 | #include <sys/statfs.h> |
50 | #include <fcntl.h> | 51 | #include <fcntl.h> |
52 | #include <stdbool.h> | ||
51 | #include <stddef.h> | 53 | #include <stddef.h> |
52 | #include <stdlib.h> | 54 | #include <stdlib.h> |
53 | #include <stdarg.h> | 55 | #include <stdarg.h> |
@@ -78,6 +80,7 @@ | |||
78 | #include <pwd.h> | 80 | #include <pwd.h> |
79 | #include <inttypes.h> | 81 | #include <inttypes.h> |
80 | #include "../../../include/linux/magic.h" | 82 | #include "../../../include/linux/magic.h" |
83 | #include "types.h" | ||
81 | 84 | ||
82 | 85 | ||
83 | #ifndef NO_ICONV | 86 | #ifndef NO_ICONV |
@@ -295,6 +298,13 @@ extern void *xmemdupz(const void *data, size_t len); | |||
295 | extern char *xstrndup(const char *str, size_t len); | 298 | extern char *xstrndup(const char *str, size_t len); |
296 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); | 299 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); |
297 | 300 | ||
301 | static inline void *xzalloc(size_t size) | ||
302 | { | ||
303 | void *buf = xmalloc(size); | ||
304 | |||
305 | return memset(buf, 0, size); | ||
306 | } | ||
307 | |||
298 | static inline void *zalloc(size_t size) | 308 | static inline void *zalloc(size_t size) |
299 | { | 309 | { |
300 | return calloc(1, size); | 310 | return calloc(1, size); |
@@ -309,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
309 | { | 319 | { |
310 | size_t len = strlen(filename); | 320 | size_t len = strlen(filename); |
311 | size_t extlen = strlen(ext); | 321 | size_t extlen = strlen(ext); |
322 | |||
312 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); | 323 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); |
313 | } | 324 | } |
314 | 325 | ||
@@ -322,6 +333,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
322 | #undef isalnum | 333 | #undef isalnum |
323 | #undef tolower | 334 | #undef tolower |
324 | #undef toupper | 335 | #undef toupper |
336 | |||
325 | extern unsigned char sane_ctype[256]; | 337 | extern unsigned char sane_ctype[256]; |
326 | #define GIT_SPACE 0x01 | 338 | #define GIT_SPACE 0x01 |
327 | #define GIT_DIGIT 0x02 | 339 | #define GIT_DIGIT 0x02 |
@@ -406,4 +418,14 @@ void git_qsort(void *base, size_t nmemb, size_t size, | |||
406 | int mkdir_p(char *path, mode_t mode); | 418 | int mkdir_p(char *path, mode_t mode); |
407 | int copyfile(const char *from, const char *to); | 419 | int copyfile(const char *from, const char *to); |
408 | 420 | ||
421 | s64 perf_atoll(const char *str); | ||
422 | char **argv_split(const char *str, int *argcp); | ||
423 | void argv_free(char **argv); | ||
424 | bool strglobmatch(const char *str, const char *pat); | ||
425 | bool strlazymatch(const char *str, const char *pat); | ||
426 | unsigned long convert_unit(unsigned long value, char *unit); | ||
427 | |||
428 | #define _STR(x) #x | ||
429 | #define STR(x) _STR(x) | ||
430 | |||
409 | #endif | 431 | #endif |
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 03a5eb22da2b..7c79c1d76d0c 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c | |||
@@ -197,7 +197,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) | |||
197 | union kvm_ioapic_redirect_entry entry; | 197 | union kvm_ioapic_redirect_entry entry; |
198 | int ret = 1; | 198 | int ret = 1; |
199 | 199 | ||
200 | mutex_lock(&ioapic->lock); | 200 | spin_lock(&ioapic->lock); |
201 | if (irq >= 0 && irq < IOAPIC_NUM_PINS) { | 201 | if (irq >= 0 && irq < IOAPIC_NUM_PINS) { |
202 | entry = ioapic->redirtbl[irq]; | 202 | entry = ioapic->redirtbl[irq]; |
203 | level ^= entry.fields.polarity; | 203 | level ^= entry.fields.polarity; |
@@ -214,7 +214,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) | |||
214 | } | 214 | } |
215 | trace_kvm_ioapic_set_irq(entry.bits, irq, ret == 0); | 215 | trace_kvm_ioapic_set_irq(entry.bits, irq, ret == 0); |
216 | } | 216 | } |
217 | mutex_unlock(&ioapic->lock); | 217 | spin_unlock(&ioapic->lock); |
218 | 218 | ||
219 | return ret; | 219 | return ret; |
220 | } | 220 | } |
@@ -238,9 +238,9 @@ static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int vector, | |||
238 | * is dropped it will be put into irr and will be delivered | 238 | * is dropped it will be put into irr and will be delivered |
239 | * after ack notifier returns. | 239 | * after ack notifier returns. |
240 | */ | 240 | */ |
241 | mutex_unlock(&ioapic->lock); | 241 | spin_unlock(&ioapic->lock); |
242 | kvm_notify_acked_irq(ioapic->kvm, KVM_IRQCHIP_IOAPIC, i); | 242 | kvm_notify_acked_irq(ioapic->kvm, KVM_IRQCHIP_IOAPIC, i); |
243 | mutex_lock(&ioapic->lock); | 243 | spin_lock(&ioapic->lock); |
244 | 244 | ||
245 | if (trigger_mode != IOAPIC_LEVEL_TRIG) | 245 | if (trigger_mode != IOAPIC_LEVEL_TRIG) |
246 | continue; | 246 | continue; |
@@ -259,9 +259,9 @@ void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode) | |||
259 | smp_rmb(); | 259 | smp_rmb(); |
260 | if (!test_bit(vector, ioapic->handled_vectors)) | 260 | if (!test_bit(vector, ioapic->handled_vectors)) |
261 | return; | 261 | return; |
262 | mutex_lock(&ioapic->lock); | 262 | spin_lock(&ioapic->lock); |
263 | __kvm_ioapic_update_eoi(ioapic, vector, trigger_mode); | 263 | __kvm_ioapic_update_eoi(ioapic, vector, trigger_mode); |
264 | mutex_unlock(&ioapic->lock); | 264 | spin_unlock(&ioapic->lock); |
265 | } | 265 | } |
266 | 266 | ||
267 | static inline struct kvm_ioapic *to_ioapic(struct kvm_io_device *dev) | 267 | static inline struct kvm_ioapic *to_ioapic(struct kvm_io_device *dev) |
@@ -287,7 +287,7 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | |||
287 | ASSERT(!(addr & 0xf)); /* check alignment */ | 287 | ASSERT(!(addr & 0xf)); /* check alignment */ |
288 | 288 | ||
289 | addr &= 0xff; | 289 | addr &= 0xff; |
290 | mutex_lock(&ioapic->lock); | 290 | spin_lock(&ioapic->lock); |
291 | switch (addr) { | 291 | switch (addr) { |
292 | case IOAPIC_REG_SELECT: | 292 | case IOAPIC_REG_SELECT: |
293 | result = ioapic->ioregsel; | 293 | result = ioapic->ioregsel; |
@@ -301,7 +301,7 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | |||
301 | result = 0; | 301 | result = 0; |
302 | break; | 302 | break; |
303 | } | 303 | } |
304 | mutex_unlock(&ioapic->lock); | 304 | spin_unlock(&ioapic->lock); |
305 | 305 | ||
306 | switch (len) { | 306 | switch (len) { |
307 | case 8: | 307 | case 8: |
@@ -338,7 +338,7 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, | |||
338 | } | 338 | } |
339 | 339 | ||
340 | addr &= 0xff; | 340 | addr &= 0xff; |
341 | mutex_lock(&ioapic->lock); | 341 | spin_lock(&ioapic->lock); |
342 | switch (addr) { | 342 | switch (addr) { |
343 | case IOAPIC_REG_SELECT: | 343 | case IOAPIC_REG_SELECT: |
344 | ioapic->ioregsel = data; | 344 | ioapic->ioregsel = data; |
@@ -356,7 +356,7 @@ static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, | |||
356 | default: | 356 | default: |
357 | break; | 357 | break; |
358 | } | 358 | } |
359 | mutex_unlock(&ioapic->lock); | 359 | spin_unlock(&ioapic->lock); |
360 | return 0; | 360 | return 0; |
361 | } | 361 | } |
362 | 362 | ||
@@ -386,7 +386,7 @@ int kvm_ioapic_init(struct kvm *kvm) | |||
386 | ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL); | 386 | ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL); |
387 | if (!ioapic) | 387 | if (!ioapic) |
388 | return -ENOMEM; | 388 | return -ENOMEM; |
389 | mutex_init(&ioapic->lock); | 389 | spin_lock_init(&ioapic->lock); |
390 | kvm->arch.vioapic = ioapic; | 390 | kvm->arch.vioapic = ioapic; |
391 | kvm_ioapic_reset(ioapic); | 391 | kvm_ioapic_reset(ioapic); |
392 | kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); | 392 | kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); |
@@ -419,9 +419,9 @@ int kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) | |||
419 | if (!ioapic) | 419 | if (!ioapic) |
420 | return -EINVAL; | 420 | return -EINVAL; |
421 | 421 | ||
422 | mutex_lock(&ioapic->lock); | 422 | spin_lock(&ioapic->lock); |
423 | memcpy(state, ioapic, sizeof(struct kvm_ioapic_state)); | 423 | memcpy(state, ioapic, sizeof(struct kvm_ioapic_state)); |
424 | mutex_unlock(&ioapic->lock); | 424 | spin_unlock(&ioapic->lock); |
425 | return 0; | 425 | return 0; |
426 | } | 426 | } |
427 | 427 | ||
@@ -431,9 +431,9 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) | |||
431 | if (!ioapic) | 431 | if (!ioapic) |
432 | return -EINVAL; | 432 | return -EINVAL; |
433 | 433 | ||
434 | mutex_lock(&ioapic->lock); | 434 | spin_lock(&ioapic->lock); |
435 | memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); | 435 | memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); |
436 | update_handled_vectors(ioapic); | 436 | update_handled_vectors(ioapic); |
437 | mutex_unlock(&ioapic->lock); | 437 | spin_unlock(&ioapic->lock); |
438 | return 0; | 438 | return 0; |
439 | } | 439 | } |
diff --git a/virt/kvm/ioapic.h b/virt/kvm/ioapic.h index 8a751b78a430..0b190c34ccc3 100644 --- a/virt/kvm/ioapic.h +++ b/virt/kvm/ioapic.h | |||
@@ -45,7 +45,7 @@ struct kvm_ioapic { | |||
45 | struct kvm_io_device dev; | 45 | struct kvm_io_device dev; |
46 | struct kvm *kvm; | 46 | struct kvm *kvm; |
47 | void (*ack_notifier)(void *opaque, int irq); | 47 | void (*ack_notifier)(void *opaque, int irq); |
48 | struct mutex lock; | 48 | spinlock_t lock; |
49 | DECLARE_BITMAP(handled_vectors, 256); | 49 | DECLARE_BITMAP(handled_vectors, 256); |
50 | }; | 50 | }; |
51 | 51 | ||
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index 80fd3ad3b2de..11692b9e8830 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
@@ -32,12 +32,30 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm); | |||
32 | static void kvm_iommu_put_pages(struct kvm *kvm, | 32 | static void kvm_iommu_put_pages(struct kvm *kvm, |
33 | gfn_t base_gfn, unsigned long npages); | 33 | gfn_t base_gfn, unsigned long npages); |
34 | 34 | ||
35 | static pfn_t kvm_pin_pages(struct kvm *kvm, struct kvm_memory_slot *slot, | ||
36 | gfn_t gfn, unsigned long size) | ||
37 | { | ||
38 | gfn_t end_gfn; | ||
39 | pfn_t pfn; | ||
40 | |||
41 | pfn = gfn_to_pfn_memslot(kvm, slot, gfn); | ||
42 | end_gfn = gfn + (size >> PAGE_SHIFT); | ||
43 | gfn += 1; | ||
44 | |||
45 | if (is_error_pfn(pfn)) | ||
46 | return pfn; | ||
47 | |||
48 | while (gfn < end_gfn) | ||
49 | gfn_to_pfn_memslot(kvm, slot, gfn++); | ||
50 | |||
51 | return pfn; | ||
52 | } | ||
53 | |||
35 | int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) | 54 | int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) |
36 | { | 55 | { |
37 | gfn_t gfn = slot->base_gfn; | 56 | gfn_t gfn, end_gfn; |
38 | unsigned long npages = slot->npages; | ||
39 | pfn_t pfn; | 57 | pfn_t pfn; |
40 | int i, r = 0; | 58 | int r = 0; |
41 | struct iommu_domain *domain = kvm->arch.iommu_domain; | 59 | struct iommu_domain *domain = kvm->arch.iommu_domain; |
42 | int flags; | 60 | int flags; |
43 | 61 | ||
@@ -45,31 +63,62 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot) | |||
45 | if (!domain) | 63 | if (!domain) |
46 | return 0; | 64 | return 0; |
47 | 65 | ||
66 | gfn = slot->base_gfn; | ||
67 | end_gfn = gfn + slot->npages; | ||
68 | |||
48 | flags = IOMMU_READ | IOMMU_WRITE; | 69 | flags = IOMMU_READ | IOMMU_WRITE; |
49 | if (kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY) | 70 | if (kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY) |
50 | flags |= IOMMU_CACHE; | 71 | flags |= IOMMU_CACHE; |
51 | 72 | ||
52 | for (i = 0; i < npages; i++) { | 73 | |
53 | /* check if already mapped */ | 74 | while (gfn < end_gfn) { |
54 | if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) | 75 | unsigned long page_size; |
76 | |||
77 | /* Check if already mapped */ | ||
78 | if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) { | ||
79 | gfn += 1; | ||
80 | continue; | ||
81 | } | ||
82 | |||
83 | /* Get the page size we could use to map */ | ||
84 | page_size = kvm_host_page_size(kvm, gfn); | ||
85 | |||
86 | /* Make sure the page_size does not exceed the memslot */ | ||
87 | while ((gfn + (page_size >> PAGE_SHIFT)) > end_gfn) | ||
88 | page_size >>= 1; | ||
89 | |||
90 | /* Make sure gfn is aligned to the page size we want to map */ | ||
91 | while ((gfn << PAGE_SHIFT) & (page_size - 1)) | ||
92 | page_size >>= 1; | ||
93 | |||
94 | /* | ||
95 | * Pin all pages we are about to map in memory. This is | ||
96 | * important because we unmap and unpin in 4kb steps later. | ||
97 | */ | ||
98 | pfn = kvm_pin_pages(kvm, slot, gfn, page_size); | ||
99 | if (is_error_pfn(pfn)) { | ||
100 | gfn += 1; | ||
55 | continue; | 101 | continue; |
102 | } | ||
56 | 103 | ||
57 | pfn = gfn_to_pfn_memslot(kvm, slot, gfn); | 104 | /* Map into IO address space */ |
58 | r = iommu_map_range(domain, | 105 | r = iommu_map(domain, gfn_to_gpa(gfn), pfn_to_hpa(pfn), |
59 | gfn_to_gpa(gfn), | 106 | get_order(page_size), flags); |
60 | pfn_to_hpa(pfn), | ||
61 | PAGE_SIZE, flags); | ||
62 | if (r) { | 107 | if (r) { |
63 | printk(KERN_ERR "kvm_iommu_map_address:" | 108 | printk(KERN_ERR "kvm_iommu_map_address:" |
64 | "iommu failed to map pfn=%lx\n", pfn); | 109 | "iommu failed to map pfn=%lx\n", pfn); |
65 | goto unmap_pages; | 110 | goto unmap_pages; |
66 | } | 111 | } |
67 | gfn++; | 112 | |
113 | gfn += page_size >> PAGE_SHIFT; | ||
114 | |||
115 | |||
68 | } | 116 | } |
117 | |||
69 | return 0; | 118 | return 0; |
70 | 119 | ||
71 | unmap_pages: | 120 | unmap_pages: |
72 | kvm_iommu_put_pages(kvm, slot->base_gfn, i); | 121 | kvm_iommu_put_pages(kvm, slot->base_gfn, gfn); |
73 | return r; | 122 | return r; |
74 | } | 123 | } |
75 | 124 | ||
@@ -189,27 +238,47 @@ out_unmap: | |||
189 | return r; | 238 | return r; |
190 | } | 239 | } |
191 | 240 | ||
241 | static void kvm_unpin_pages(struct kvm *kvm, pfn_t pfn, unsigned long npages) | ||
242 | { | ||
243 | unsigned long i; | ||
244 | |||
245 | for (i = 0; i < npages; ++i) | ||
246 | kvm_release_pfn_clean(pfn + i); | ||
247 | } | ||
248 | |||
192 | static void kvm_iommu_put_pages(struct kvm *kvm, | 249 | static void kvm_iommu_put_pages(struct kvm *kvm, |
193 | gfn_t base_gfn, unsigned long npages) | 250 | gfn_t base_gfn, unsigned long npages) |
194 | { | 251 | { |
195 | gfn_t gfn = base_gfn; | 252 | struct iommu_domain *domain; |
253 | gfn_t end_gfn, gfn; | ||
196 | pfn_t pfn; | 254 | pfn_t pfn; |
197 | struct iommu_domain *domain = kvm->arch.iommu_domain; | ||
198 | unsigned long i; | ||
199 | u64 phys; | 255 | u64 phys; |
200 | 256 | ||
257 | domain = kvm->arch.iommu_domain; | ||
258 | end_gfn = base_gfn + npages; | ||
259 | gfn = base_gfn; | ||
260 | |||
201 | /* check if iommu exists and in use */ | 261 | /* check if iommu exists and in use */ |
202 | if (!domain) | 262 | if (!domain) |
203 | return; | 263 | return; |
204 | 264 | ||
205 | for (i = 0; i < npages; i++) { | 265 | while (gfn < end_gfn) { |
266 | unsigned long unmap_pages; | ||
267 | int order; | ||
268 | |||
269 | /* Get physical address */ | ||
206 | phys = iommu_iova_to_phys(domain, gfn_to_gpa(gfn)); | 270 | phys = iommu_iova_to_phys(domain, gfn_to_gpa(gfn)); |
207 | pfn = phys >> PAGE_SHIFT; | 271 | pfn = phys >> PAGE_SHIFT; |
208 | kvm_release_pfn_clean(pfn); | 272 | |
209 | gfn++; | 273 | /* Unmap address from IO address space */ |
210 | } | 274 | order = iommu_unmap(domain, gfn_to_gpa(gfn), PAGE_SIZE); |
275 | unmap_pages = 1ULL << order; | ||
211 | 276 | ||
212 | iommu_unmap_range(domain, gfn_to_gpa(base_gfn), PAGE_SIZE * npages); | 277 | /* Unpin all pages we just unmapped to not leak any memory */ |
278 | kvm_unpin_pages(kvm, pfn, unmap_pages); | ||
279 | |||
280 | gfn += unmap_pages; | ||
281 | } | ||
213 | } | 282 | } |
214 | 283 | ||
215 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) | 284 | static int kvm_iommu_unmap_memslots(struct kvm *kvm) |