forked from mirrors/linux
		
	devres: Enable trace events
In some cases the printf() mechanism is too heavy and can't be used. For example, when debugging a race condition involving devres API. When CONFIG_DEBUG_DEVRES is enabled I can't reproduce an issue, and otherwise it's quite visible with a useful information being collected. Enable trace events for devres part of the driver core. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20210517122946.53161-4-andriy.shevchenko@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									a7f1d03b60
								
							
						
					
					
						commit
						09705dcb63
					
				
					 5 changed files with 100 additions and 47 deletions
				
			
		| 
						 | 
					@ -30,3 +30,6 @@ obj-y			+= test/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 | 
					ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# define_trace.h needs to know how to find our header
 | 
				
			||||||
 | 
					CFLAGS_trace.o		:= -I$(src)
 | 
				
			||||||
 | 
					obj-$(CONFIG_TRACING)	+= trace.o
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,14 +14,13 @@
 | 
				
			||||||
#include <asm/sections.h>
 | 
					#include <asm/sections.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "base.h"
 | 
					#include "base.h"
 | 
				
			||||||
 | 
					#include "trace.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct devres_node {
 | 
					struct devres_node {
 | 
				
			||||||
	struct list_head		entry;
 | 
						struct list_head		entry;
 | 
				
			||||||
	dr_release_t			release;
 | 
						dr_release_t			release;
 | 
				
			||||||
#ifdef CONFIG_DEBUG_DEVRES
 | 
					 | 
				
			||||||
	const char			*name;
 | 
						const char			*name;
 | 
				
			||||||
	size_t				size;
 | 
						size_t				size;
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct devres {
 | 
					struct devres {
 | 
				
			||||||
| 
						 | 
					@ -43,10 +42,6 @@ struct devres_group {
 | 
				
			||||||
	/* -- 8 pointers */
 | 
						/* -- 8 pointers */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef CONFIG_DEBUG_DEVRES
 | 
					 | 
				
			||||||
static int log_devres = 0;
 | 
					 | 
				
			||||||
module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void set_node_dbginfo(struct devres_node *node, const char *name,
 | 
					static void set_node_dbginfo(struct devres_node *node, const char *name,
 | 
				
			||||||
			     size_t size)
 | 
								     size_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -54,7 +49,11 @@ static void set_node_dbginfo(struct devres_node *node, const char *name,
 | 
				
			||||||
	node->size = size;
 | 
						node->size = size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void devres_log(struct device *dev, struct devres_node *node,
 | 
					#ifdef CONFIG_DEBUG_DEVRES
 | 
				
			||||||
 | 
					static int log_devres = 0;
 | 
				
			||||||
 | 
					module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void devres_dbg(struct device *dev, struct devres_node *node,
 | 
				
			||||||
		       const char *op)
 | 
							       const char *op)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (unlikely(log_devres))
 | 
						if (unlikely(log_devres))
 | 
				
			||||||
| 
						 | 
					@ -62,10 +61,16 @@ static void devres_log(struct device *dev, struct devres_node *node,
 | 
				
			||||||
			op, node, node->name, node->size);
 | 
								op, node, node->name, node->size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#else /* CONFIG_DEBUG_DEVRES */
 | 
					#else /* CONFIG_DEBUG_DEVRES */
 | 
				
			||||||
#define set_node_dbginfo(node, n, s)	do {} while (0)
 | 
					#define devres_dbg(dev, node, op)	do {} while (0)
 | 
				
			||||||
#define devres_log(dev, node, op)	do {} while (0)
 | 
					 | 
				
			||||||
#endif /* CONFIG_DEBUG_DEVRES */
 | 
					#endif /* CONFIG_DEBUG_DEVRES */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void devres_log(struct device *dev, struct devres_node *node,
 | 
				
			||||||
 | 
							       const char *op)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						trace_devres_log(dev, op, node, node->name, node->size);
 | 
				
			||||||
 | 
						devres_dbg(dev, node, op);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Release functions for devres group.  These callbacks are used only
 | 
					 * Release functions for devres group.  These callbacks are used only
 | 
				
			||||||
 * for identification.
 | 
					 * for identification.
 | 
				
			||||||
| 
						 | 
					@ -134,8 +139,22 @@ static void replace_dr(struct device *dev,
 | 
				
			||||||
	list_replace(&old->entry, &new->entry);
 | 
						list_replace(&old->entry, &new->entry);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef CONFIG_DEBUG_DEVRES
 | 
					/**
 | 
				
			||||||
void * __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid,
 | 
					 * __devres_alloc_node - Allocate device resource data
 | 
				
			||||||
 | 
					 * @release: Release function devres will be associated with
 | 
				
			||||||
 | 
					 * @size: Allocation size
 | 
				
			||||||
 | 
					 * @gfp: Allocation flags
 | 
				
			||||||
 | 
					 * @nid: NUMA node
 | 
				
			||||||
 | 
					 * @name: Name of the resource
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Allocate devres of @size bytes.  The allocated area is zeroed, then
 | 
				
			||||||
 | 
					 * associated with @release.  The returned pointer can be passed to
 | 
				
			||||||
 | 
					 * other devres_*() functions.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * RETURNS:
 | 
				
			||||||
 | 
					 * Pointer to allocated devres on success, NULL on failure.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid,
 | 
				
			||||||
			  const char *name)
 | 
								  const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct devres *dr;
 | 
						struct devres *dr;
 | 
				
			||||||
| 
						 | 
					@ -147,32 +166,6 @@ void * __devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid
 | 
				
			||||||
	return dr->data;
 | 
						return dr->data;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(__devres_alloc_node);
 | 
					EXPORT_SYMBOL_GPL(__devres_alloc_node);
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * devres_alloc_node - Allocate device resource data
 | 
					 | 
				
			||||||
 * @release: Release function devres will be associated with
 | 
					 | 
				
			||||||
 * @size: Allocation size
 | 
					 | 
				
			||||||
 * @gfp: Allocation flags
 | 
					 | 
				
			||||||
 * @nid: NUMA node
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Allocate devres of @size bytes.  The allocated area is zeroed, then
 | 
					 | 
				
			||||||
 * associated with @release.  The returned pointer can be passed to
 | 
					 | 
				
			||||||
 * other devres_*() functions.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * RETURNS:
 | 
					 | 
				
			||||||
 * Pointer to allocated devres on success, NULL on failure.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void * devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct devres *dr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	dr = alloc_dr(release, size, gfp | __GFP_ZERO, nid);
 | 
					 | 
				
			||||||
	if (unlikely(!dr))
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
	return dr->data;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
EXPORT_SYMBOL_GPL(devres_alloc_node);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * devres_for_each_res - Resource iterator
 | 
					 * devres_for_each_res - Resource iterator
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								drivers/base/trace.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								drivers/base/trace.c
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					/* SPDX-License-Identifier: GPL-2.0 */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Device core Trace Support
 | 
				
			||||||
 | 
					 * Copyright (C) 2021, Intel Corporation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define CREATE_TRACE_POINTS
 | 
				
			||||||
 | 
					#include "trace.h"
 | 
				
			||||||
							
								
								
									
										56
									
								
								drivers/base/trace.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								drivers/base/trace.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,56 @@
 | 
				
			||||||
 | 
					/* SPDX-License-Identifier: GPL-2.0 */
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Device core Trace Support
 | 
				
			||||||
 | 
					 * Copyright (C) 2021, Intel Corporation
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#undef TRACE_SYSTEM
 | 
				
			||||||
 | 
					#define TRACE_SYSTEM dev
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(__DEV_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
 | 
				
			||||||
 | 
					#define __DEV_TRACE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <linux/device.h>
 | 
				
			||||||
 | 
					#include <linux/tracepoint.h>
 | 
				
			||||||
 | 
					#include <linux/types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DECLARE_EVENT_CLASS(devres,
 | 
				
			||||||
 | 
						TP_PROTO(struct device *dev, const char *op, void *node, const char *name, size_t size),
 | 
				
			||||||
 | 
						TP_ARGS(dev, op, node, name, size),
 | 
				
			||||||
 | 
						TP_STRUCT__entry(
 | 
				
			||||||
 | 
							__string(devname, dev_name(dev))
 | 
				
			||||||
 | 
							__field(struct device *, dev)
 | 
				
			||||||
 | 
							__field(const char *, op)
 | 
				
			||||||
 | 
							__field(void *, node)
 | 
				
			||||||
 | 
							__field(const char *, name)
 | 
				
			||||||
 | 
							__field(size_t, size)
 | 
				
			||||||
 | 
						),
 | 
				
			||||||
 | 
						TP_fast_assign(
 | 
				
			||||||
 | 
							__assign_str(devname, dev_name(dev));
 | 
				
			||||||
 | 
							__entry->op = op;
 | 
				
			||||||
 | 
							__entry->node = node;
 | 
				
			||||||
 | 
							__entry->name = name;
 | 
				
			||||||
 | 
							__entry->size = size;
 | 
				
			||||||
 | 
						),
 | 
				
			||||||
 | 
						TP_printk("%s %3s %p %s (%zu bytes)", __get_str(devname),
 | 
				
			||||||
 | 
							  __entry->op, __entry->node, __entry->name, __entry->size)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DEFINE_EVENT(devres, devres_log,
 | 
				
			||||||
 | 
						TP_PROTO(struct device *dev, const char *op, void *node, const char *name, size_t size),
 | 
				
			||||||
 | 
						TP_ARGS(dev, op, node, name, size)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* __DEV_TRACE_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* this part has to be here */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#undef TRACE_INCLUDE_PATH
 | 
				
			||||||
 | 
					#define TRACE_INCLUDE_PATH .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#undef TRACE_INCLUDE_FILE
 | 
				
			||||||
 | 
					#define TRACE_INCLUDE_FILE trace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <trace/define_trace.h>
 | 
				
			||||||
| 
						 | 
					@ -165,21 +165,12 @@ void device_remove_bin_file(struct device *dev,
 | 
				
			||||||
typedef void (*dr_release_t)(struct device *dev, void *res);
 | 
					typedef void (*dr_release_t)(struct device *dev, void *res);
 | 
				
			||||||
typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
 | 
					typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef CONFIG_DEBUG_DEVRES
 | 
					 | 
				
			||||||
void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
 | 
					void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp,
 | 
				
			||||||
			  int nid, const char *name) __malloc;
 | 
								  int nid, const char *name) __malloc;
 | 
				
			||||||
#define devres_alloc(release, size, gfp) \
 | 
					#define devres_alloc(release, size, gfp) \
 | 
				
			||||||
	__devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
 | 
						__devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)
 | 
				
			||||||
#define devres_alloc_node(release, size, gfp, nid) \
 | 
					#define devres_alloc_node(release, size, gfp, nid) \
 | 
				
			||||||
	__devres_alloc_node(release, size, gfp, nid, #release)
 | 
						__devres_alloc_node(release, size, gfp, nid, #release)
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
void *devres_alloc_node(dr_release_t release, size_t size,
 | 
					 | 
				
			||||||
			gfp_t gfp, int nid) __malloc;
 | 
					 | 
				
			||||||
static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	return devres_alloc_node(release, size, gfp, NUMA_NO_NODE);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void devres_for_each_res(struct device *dev, dr_release_t release,
 | 
					void devres_for_each_res(struct device *dev, dr_release_t release,
 | 
				
			||||||
			 dr_match_t match, void *match_data,
 | 
								 dr_match_t match, void *match_data,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue