trace.c (da537f0aef1372c5204356a7df06be8769467b7b) trace.c (91edde2e6ae1dd5e33812f076f3fe4cb7ccbfdd0)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ring buffer based function tracer
4 *
5 * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com>
6 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 *
8 * Originally taken from the RT patch by:

--- 31 unchanged lines hidden (view full) ---

40#include <linux/ctype.h>
41#include <linux/init.h>
42#include <linux/poll.h>
43#include <linux/nmi.h>
44#include <linux/fs.h>
45#include <linux/trace.h>
46#include <linux/sched/clock.h>
47#include <linux/sched/rt.h>
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * ring buffer based function tracer
4 *
5 * Copyright (C) 2007-2012 Steven Rostedt <srostedt@redhat.com>
6 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 *
8 * Originally taken from the RT patch by:

--- 31 unchanged lines hidden (view full) ---

40#include <linux/ctype.h>
41#include <linux/init.h>
42#include <linux/poll.h>
43#include <linux/nmi.h>
44#include <linux/fs.h>
45#include <linux/trace.h>
46#include <linux/sched/clock.h>
47#include <linux/sched/rt.h>
48#include <linux/fsnotify.h>
49#include <linux/irq_work.h>
50#include <linux/workqueue.h>
48
49#include "trace.h"
50#include "trace_output.h"
51
52/*
53 * On boot up, the ring buffer is set to the minimum size, so that
54 * we do not waste memory on systems that are not using tracing.
55 */

--- 1436 unchanged lines hidden (view full) ---

1492 cnt = len;
1493 memcpy(buf, s->buffer + s->seq.readpos, cnt);
1494
1495 s->seq.readpos += cnt;
1496 return cnt;
1497}
1498
1499unsigned long __read_mostly tracing_thresh;
51
52#include "trace.h"
53#include "trace_output.h"
54
55/*
56 * On boot up, the ring buffer is set to the minimum size, so that
57 * we do not waste memory on systems that are not using tracing.
58 */

--- 1436 unchanged lines hidden (view full) ---

1495 cnt = len;
1496 memcpy(buf, s->buffer + s->seq.readpos, cnt);
1497
1498 s->seq.readpos += cnt;
1499 return cnt;
1500}
1501
1502unsigned long __read_mostly tracing_thresh;
1503static const struct file_operations tracing_max_lat_fops;
1500
1504
1505#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
1506 defined(CONFIG_FSNOTIFY)
1507
1508static struct workqueue_struct *fsnotify_wq;
1509
1510static void latency_fsnotify_workfn(struct work_struct *work)
1511{
1512 struct trace_array *tr = container_of(work, struct trace_array,
1513 fsnotify_work);
1514 fsnotify(tr->d_max_latency->d_inode, FS_MODIFY,
1515 tr->d_max_latency->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
1516}
1517
1518static void latency_fsnotify_workfn_irq(struct irq_work *iwork)
1519{
1520 struct trace_array *tr = container_of(iwork, struct trace_array,
1521 fsnotify_irqwork);
1522 queue_work(fsnotify_wq, &tr->fsnotify_work);
1523}
1524
1525static void trace_create_maxlat_file(struct trace_array *tr,
1526 struct dentry *d_tracer)
1527{
1528 INIT_WORK(&tr->fsnotify_work, latency_fsnotify_workfn);
1529 init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
1530 tr->d_max_latency = trace_create_file("tracing_max_latency", 0644,
1531 d_tracer, &tr->max_latency,
1532 &tracing_max_lat_fops);
1533}
1534
1535__init static int latency_fsnotify_init(void)
1536{
1537 fsnotify_wq = alloc_workqueue("tr_max_lat_wq",
1538 WQ_UNBOUND | WQ_HIGHPRI, 0);
1539 if (!fsnotify_wq) {
1540 pr_err("Unable to allocate tr_max_lat_wq\n");
1541 return -ENOMEM;
1542 }
1543 return 0;
1544}
1545
1546late_initcall_sync(latency_fsnotify_init);
1547
1548void latency_fsnotify(struct trace_array *tr)
1549{
1550 if (!fsnotify_wq)
1551 return;
1552 /*
1553 * We cannot call queue_work(&tr->fsnotify_work) from here because it's
1554 * possible that we are called from __schedule() or do_idle(), which
1555 * could cause a deadlock.
1556 */
1557 irq_work_queue(&tr->fsnotify_irqwork);
1558}
1559
1560/*
1561 * (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
1562 * defined(CONFIG_FSNOTIFY)
1563 */
1564#else
1565
1566#define trace_create_maxlat_file(tr, d_tracer) \
1567 trace_create_file("tracing_max_latency", 0644, d_tracer, \
1568 &tr->max_latency, &tracing_max_lat_fops)
1569
1570#endif
1571
1501#ifdef CONFIG_TRACER_MAX_TRACE
1502/*
1503 * Copy the new maximum trace into the separate maximum-trace
1504 * structure. (this way the maximum trace is permanently saved,
1505 * for later retrieval via /sys/kernel/tracing/tracing_max_latency)
1506 */
1507static void
1508__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)

--- 22 unchanged lines hidden (view full) ---

1531 max_data->uid = task_uid(tsk);
1532
1533 max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
1534 max_data->policy = tsk->policy;
1535 max_data->rt_priority = tsk->rt_priority;
1536
1537 /* record this tasks comm */
1538 tracing_record_cmdline(tsk);
1572#ifdef CONFIG_TRACER_MAX_TRACE
1573/*
1574 * Copy the new maximum trace into the separate maximum-trace
1575 * structure. (this way the maximum trace is permanently saved,
1576 * for later retrieval via /sys/kernel/tracing/tracing_max_latency)
1577 */
1578static void
1579__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)

--- 22 unchanged lines hidden (view full) ---

1602 max_data->uid = task_uid(tsk);
1603
1604 max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
1605 max_data->policy = tsk->policy;
1606 max_data->rt_priority = tsk->rt_priority;
1607
1608 /* record this tasks comm */
1609 tracing_record_cmdline(tsk);
1610 latency_fsnotify(tr);
1539}
1540
1541/**
1542 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
1543 * @tr: tracer
1544 * @tsk: the task with the latency
1545 * @cpu: The cpu that initiated the trace.
1546 * @cond_data: User data associated with a conditional snapshot

--- 7042 unchanged lines hidden (view full) ---

8589 tr->buffer_percent = 50;
8590
8591 trace_create_file("buffer_percent", 0444, d_tracer,
8592 tr, &buffer_percent_fops);
8593
8594 create_trace_options_dir(tr);
8595
8596#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
1611}
1612
1613/**
1614 * update_max_tr - snapshot all trace buffers from global_trace to max_tr
1615 * @tr: tracer
1616 * @tsk: the task with the latency
1617 * @cpu: The cpu that initiated the trace.
1618 * @cond_data: User data associated with a conditional snapshot

--- 7042 unchanged lines hidden (view full) ---

8661 tr->buffer_percent = 50;
8662
8663 trace_create_file("buffer_percent", 0444, d_tracer,
8664 tr, &buffer_percent_fops);
8665
8666 create_trace_options_dir(tr);
8667
8668#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
8597 trace_create_file("tracing_max_latency", 0644, d_tracer,
8598 &tr->max_latency, &tracing_max_lat_fops);
8669 trace_create_maxlat_file(tr, d_tracer);
8599#endif
8600
8601 if (ftrace_create_function_files(tr, d_tracer))
8602 WARN(1, "Could not allocate function filter files");
8603
8604#ifdef CONFIG_TRACER_SNAPSHOT
8605 trace_create_file("snapshot", 0644, d_tracer,
8606 tr, &snapshot_fops);

--- 662 unchanged lines hidden ---
8670#endif
8671
8672 if (ftrace_create_function_files(tr, d_tracer))
8673 WARN(1, "Could not allocate function filter files");
8674
8675#ifdef CONFIG_TRACER_SNAPSHOT
8676 trace_create_file("snapshot", 0644, d_tracer,
8677 tr, &snapshot_fops);

--- 662 unchanged lines hidden ---