forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/arch/powerpc/platforms/pseries/dtl.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Virtual Processor Dispatch Trace Log
34 *
45 * (C) Copyright IBM Corporation 2009
56 *
67 * 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.
218 */
229
2310 #include <linux/slab.h>
....@@ -25,6 +12,7 @@
2512 #include <asm/smp.h>
2613 #include <linux/uaccess.h>
2714 #include <asm/firmware.h>
15
+#include <asm/dtl.h>
2816 #include <asm/lppaca.h>
2917 #include <asm/debugfs.h>
3018 #include <asm/plpar_wrappers.h>
....@@ -32,7 +20,6 @@
3220
3321 struct dtl {
3422 struct dtl_entry *buf;
35
- struct dentry *file;
3623 int cpu;
3724 int buf_entries;
3825 u64 last_idx;
....@@ -40,13 +27,7 @@
4027 };
4128 static DEFINE_PER_CPU(struct dtl, cpu_dtl);
4229
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;
5031
5132
5233 /*
....@@ -61,7 +42,6 @@
6142 struct dtl_entry *write_ptr;
6243 struct dtl_entry *buf;
6344 struct dtl_entry *buf_end;
64
- u8 saved_dtl_mask;
6545 };
6646
6747 static DEFINE_PER_CPU(struct dtl_ring, dtl_rings);
....@@ -111,7 +91,6 @@
11191 dtlr->write_ptr = dtl->buf;
11292
11393 /* enable event logging */
114
- dtlr->saved_dtl_mask = lppaca_of(dtl->cpu).dtl_enable_mask;
11594 lppaca_of(dtl->cpu).dtl_enable_mask |= dtl_event_mask;
11695
11796 dtl_consumer = consume_dtle;
....@@ -129,7 +108,7 @@
129108 dtlr->buf = NULL;
130109
131110 /* 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;
133112
134113 if (atomic_dec_and_test(&dtl_count))
135114 dtl_consumer = NULL;
....@@ -201,11 +180,16 @@
201180 if (dtl->buf)
202181 return -EBUSY;
203182
183
+ /* ensure there are no other conflicting dtl users */
184
+ if (!read_trylock(&dtl_access_lock))
185
+ return -EBUSY;
186
+
204187 n_entries = dtl_buf_entries;
205188 buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu));
206189 if (!buf) {
207190 printk(KERN_WARNING "%s: buffer alloc failed for cpu %d\n",
208191 __func__, dtl->cpu);
192
+ read_unlock(&dtl_access_lock);
209193 return -ENOMEM;
210194 }
211195
....@@ -222,8 +206,11 @@
222206 }
223207 spin_unlock(&dtl->lock);
224208
225
- if (rc)
209
+ if (rc) {
210
+ read_unlock(&dtl_access_lock);
226211 kmem_cache_free(dtl_cache, buf);
212
+ }
213
+
227214 return rc;
228215 }
229216
....@@ -235,6 +222,7 @@
235222 dtl->buf = NULL;
236223 dtl->buf_entries = 0;
237224 spin_unlock(&dtl->lock);
225
+ read_unlock(&dtl_access_lock);
238226 }
239227
240228 /* file interface */
....@@ -332,46 +320,28 @@
332320
333321 static struct dentry *dtl_dir;
334322
335
-static int dtl_setup_file(struct dtl *dtl)
323
+static void dtl_setup_file(struct dtl *dtl)
336324 {
337325 char name[10];
338326
339327 sprintf(name, "cpu-%d", dtl->cpu);
340328
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);
346330 }
347331
348332 static int dtl_init(void)
349333 {
350
- struct dentry *event_mask_file, *buf_entries_file;
351
- int rc, i;
334
+ int i;
352335
353336 if (!firmware_has_feature(FW_FEATURE_SPLPAR))
354337 return -ENODEV;
355338
356339 /* set up common debugfs structure */
357340
358
- rc = -ENOMEM;
359341 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
- }
365342
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);
375345
376346 /* set up the per-cpu log structures */
377347 for_each_possible_cpu(i) {
....@@ -379,16 +349,9 @@
379349 spin_lock_init(&dtl->lock);
380350 dtl->cpu = i;
381351
382
- rc = dtl_setup_file(dtl);
383
- if (rc)
384
- goto err_remove_dir;
352
+ dtl_setup_file(dtl);
385353 }
386354
387355 return 0;
388
-
389
-err_remove_dir:
390
- debugfs_remove_recursive(dtl_dir);
391
-err:
392
- return rc;
393356 }
394357 machine_arch_initcall(pseries, dtl_init);