.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Virtual Processor Dispatch Trace Log |
---|
3 | 4 | * |
---|
4 | 5 | * (C) Copyright IBM Corporation 2009 |
---|
5 | 6 | * |
---|
6 | 7 | * Author: Jeremy Kerr <jk@ozlabs.org> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2, or (at your option) |
---|
11 | | - * any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | | - * |
---|
18 | | - * You should have received a copy of the GNU General Public License |
---|
19 | | - * along with this program; if not, write to the Free Software |
---|
20 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
23 | 10 | #include <linux/slab.h> |
---|
.. | .. |
---|
25 | 12 | #include <asm/smp.h> |
---|
26 | 13 | #include <linux/uaccess.h> |
---|
27 | 14 | #include <asm/firmware.h> |
---|
| 15 | +#include <asm/dtl.h> |
---|
28 | 16 | #include <asm/lppaca.h> |
---|
29 | 17 | #include <asm/debugfs.h> |
---|
30 | 18 | #include <asm/plpar_wrappers.h> |
---|
.. | .. |
---|
32 | 20 | |
---|
33 | 21 | struct dtl { |
---|
34 | 22 | struct dtl_entry *buf; |
---|
35 | | - struct dentry *file; |
---|
36 | 23 | int cpu; |
---|
37 | 24 | int buf_entries; |
---|
38 | 25 | u64 last_idx; |
---|
.. | .. |
---|
40 | 27 | }; |
---|
41 | 28 | static DEFINE_PER_CPU(struct dtl, cpu_dtl); |
---|
42 | 29 | |
---|
43 | | -/* |
---|
44 | | - * Dispatch trace log event mask: |
---|
45 | | - * 0x7: 0x1: voluntary virtual processor waits |
---|
46 | | - * 0x2: time-slice preempts |
---|
47 | | - * 0x4: virtual partition memory page faults |
---|
48 | | - */ |
---|
49 | | -static u8 dtl_event_mask = 0x7; |
---|
| 30 | +static u8 dtl_event_mask = DTL_LOG_ALL; |
---|
50 | 31 | |
---|
51 | 32 | |
---|
52 | 33 | /* |
---|
.. | .. |
---|
61 | 42 | struct dtl_entry *write_ptr; |
---|
62 | 43 | struct dtl_entry *buf; |
---|
63 | 44 | struct dtl_entry *buf_end; |
---|
64 | | - u8 saved_dtl_mask; |
---|
65 | 45 | }; |
---|
66 | 46 | |
---|
67 | 47 | static DEFINE_PER_CPU(struct dtl_ring, dtl_rings); |
---|
.. | .. |
---|
111 | 91 | dtlr->write_ptr = dtl->buf; |
---|
112 | 92 | |
---|
113 | 93 | /* enable event logging */ |
---|
114 | | - dtlr->saved_dtl_mask = lppaca_of(dtl->cpu).dtl_enable_mask; |
---|
115 | 94 | lppaca_of(dtl->cpu).dtl_enable_mask |= dtl_event_mask; |
---|
116 | 95 | |
---|
117 | 96 | dtl_consumer = consume_dtle; |
---|
.. | .. |
---|
129 | 108 | dtlr->buf = NULL; |
---|
130 | 109 | |
---|
131 | 110 | /* restore dtl_enable_mask */ |
---|
132 | | - lppaca_of(dtl->cpu).dtl_enable_mask = dtlr->saved_dtl_mask; |
---|
| 111 | + lppaca_of(dtl->cpu).dtl_enable_mask = DTL_LOG_PREEMPT; |
---|
133 | 112 | |
---|
134 | 113 | if (atomic_dec_and_test(&dtl_count)) |
---|
135 | 114 | dtl_consumer = NULL; |
---|
.. | .. |
---|
201 | 180 | if (dtl->buf) |
---|
202 | 181 | return -EBUSY; |
---|
203 | 182 | |
---|
| 183 | + /* ensure there are no other conflicting dtl users */ |
---|
| 184 | + if (!read_trylock(&dtl_access_lock)) |
---|
| 185 | + return -EBUSY; |
---|
| 186 | + |
---|
204 | 187 | n_entries = dtl_buf_entries; |
---|
205 | 188 | buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu)); |
---|
206 | 189 | if (!buf) { |
---|
207 | 190 | printk(KERN_WARNING "%s: buffer alloc failed for cpu %d\n", |
---|
208 | 191 | __func__, dtl->cpu); |
---|
| 192 | + read_unlock(&dtl_access_lock); |
---|
209 | 193 | return -ENOMEM; |
---|
210 | 194 | } |
---|
211 | 195 | |
---|
.. | .. |
---|
222 | 206 | } |
---|
223 | 207 | spin_unlock(&dtl->lock); |
---|
224 | 208 | |
---|
225 | | - if (rc) |
---|
| 209 | + if (rc) { |
---|
| 210 | + read_unlock(&dtl_access_lock); |
---|
226 | 211 | kmem_cache_free(dtl_cache, buf); |
---|
| 212 | + } |
---|
| 213 | + |
---|
227 | 214 | return rc; |
---|
228 | 215 | } |
---|
229 | 216 | |
---|
.. | .. |
---|
235 | 222 | dtl->buf = NULL; |
---|
236 | 223 | dtl->buf_entries = 0; |
---|
237 | 224 | spin_unlock(&dtl->lock); |
---|
| 225 | + read_unlock(&dtl_access_lock); |
---|
238 | 226 | } |
---|
239 | 227 | |
---|
240 | 228 | /* file interface */ |
---|
.. | .. |
---|
332 | 320 | |
---|
333 | 321 | static struct dentry *dtl_dir; |
---|
334 | 322 | |
---|
335 | | -static int dtl_setup_file(struct dtl *dtl) |
---|
| 323 | +static void dtl_setup_file(struct dtl *dtl) |
---|
336 | 324 | { |
---|
337 | 325 | char name[10]; |
---|
338 | 326 | |
---|
339 | 327 | sprintf(name, "cpu-%d", dtl->cpu); |
---|
340 | 328 | |
---|
341 | | - dtl->file = debugfs_create_file(name, 0400, dtl_dir, dtl, &dtl_fops); |
---|
342 | | - if (!dtl->file) |
---|
343 | | - return -ENOMEM; |
---|
344 | | - |
---|
345 | | - return 0; |
---|
| 329 | + debugfs_create_file(name, 0400, dtl_dir, dtl, &dtl_fops); |
---|
346 | 330 | } |
---|
347 | 331 | |
---|
348 | 332 | static int dtl_init(void) |
---|
349 | 333 | { |
---|
350 | | - struct dentry *event_mask_file, *buf_entries_file; |
---|
351 | | - int rc, i; |
---|
| 334 | + int i; |
---|
352 | 335 | |
---|
353 | 336 | if (!firmware_has_feature(FW_FEATURE_SPLPAR)) |
---|
354 | 337 | return -ENODEV; |
---|
355 | 338 | |
---|
356 | 339 | /* set up common debugfs structure */ |
---|
357 | 340 | |
---|
358 | | - rc = -ENOMEM; |
---|
359 | 341 | dtl_dir = debugfs_create_dir("dtl", powerpc_debugfs_root); |
---|
360 | | - if (!dtl_dir) { |
---|
361 | | - printk(KERN_WARNING "%s: can't create dtl root dir\n", |
---|
362 | | - __func__); |
---|
363 | | - goto err; |
---|
364 | | - } |
---|
365 | 342 | |
---|
366 | | - event_mask_file = debugfs_create_x8("dtl_event_mask", 0600, |
---|
367 | | - dtl_dir, &dtl_event_mask); |
---|
368 | | - buf_entries_file = debugfs_create_u32("dtl_buf_entries", 0400, |
---|
369 | | - dtl_dir, &dtl_buf_entries); |
---|
370 | | - |
---|
371 | | - if (!event_mask_file || !buf_entries_file) { |
---|
372 | | - printk(KERN_WARNING "%s: can't create dtl files\n", __func__); |
---|
373 | | - goto err_remove_dir; |
---|
374 | | - } |
---|
| 343 | + debugfs_create_x8("dtl_event_mask", 0600, dtl_dir, &dtl_event_mask); |
---|
| 344 | + debugfs_create_u32("dtl_buf_entries", 0400, dtl_dir, &dtl_buf_entries); |
---|
375 | 345 | |
---|
376 | 346 | /* set up the per-cpu log structures */ |
---|
377 | 347 | for_each_possible_cpu(i) { |
---|
.. | .. |
---|
379 | 349 | spin_lock_init(&dtl->lock); |
---|
380 | 350 | dtl->cpu = i; |
---|
381 | 351 | |
---|
382 | | - rc = dtl_setup_file(dtl); |
---|
383 | | - if (rc) |
---|
384 | | - goto err_remove_dir; |
---|
| 352 | + dtl_setup_file(dtl); |
---|
385 | 353 | } |
---|
386 | 354 | |
---|
387 | 355 | return 0; |
---|
388 | | - |
---|
389 | | -err_remove_dir: |
---|
390 | | - debugfs_remove_recursive(dtl_dir); |
---|
391 | | -err: |
---|
392 | | - return rc; |
---|
393 | 356 | } |
---|
394 | 357 | machine_arch_initcall(pseries, dtl_init); |
---|