Skip to contentSkip to conversation

drm/nouveau: Use more standard logging styles

PATCH In review Joe Perches 2 participants 4 messages Aug 30, 2018 – Aug 31, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/nouveau: Use more standard logging styles

Reduces object size ~4kb

Joe Perches (2):
drm/nouveau: Add new logging function nv_cli_printk drm/nouveau: Convert NV_PRINTK macros and uses to new nv_cli_<level> macros

 drivers/gpu/drm/nouveau/nouveau_abi16.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_chan.c  | 12 +++----
 drivers/gpu/drm/nouveau/nouveau_drm.c   | 21 +++++++++++
 drivers/gpu/drm/nouveau/nouveau_drv.h   | 44 ++++++++++++++---------
 drivers/gpu/drm/nouveau/nouveau_gem.c   | 62 ++++++++++++++++-----------------
 5 files changed, 87 insertions(+), 54 deletions(-)
Signature · 1 line
2.15.0
#1 lore raw

PATCH 1/2 drm/nouveau: Add new logging function nv_cli_printk

NV_PRINTK is a macro that adds the "%s: ", nouveau_cli.name to logging output.

Save a few KB by creating a specific function to add that name and change the users of theh NV_PRINTK macros to use the new logging function.

(size -t drivers/gpu/drm/nouveau/built-in.a x86/64 defconfig with nouveau)
text data bss dec hex filename
1737254 108484 1048 1846786 1c2e02 (TOTALS) (new)
1740706 108484 1048 1850238 1c3b7e (TOTALS) (old)

---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/nouveau/nouveau_drv.h | 34 ++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 12 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +21 -0
index c7ec86d6c3c9..aeca2ea3c4d1 100644
@@ -1153,6 +1153,27 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
 	return ERR_PTR(err);
 }
 
+void nouveau_cli_printk(struct nouveau_cli *cli, const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+	char level[2] = {KERN_SOH_ASCII, 0};
+
+	level[1] = printk_get_level(fmt);
+	if (level[1] == 0)
+		level[1] = 'd';
+
+	va_start(args, fmt);
+
+	vaf.fmt = printk_skip_headers(fmt);
+	vaf.va = &args;
+
+	dev_printk(level, cli->drm->dev->dev, "%s: %pV",
+		   cli->name, &vaf);
+
+	va_end(args);
+}
+
 static int __init
 nouveau_drm_init(void)
 {
drivers/gpu/drm/nouveau/nouveau_drv.h +22 -12
index 6e1acaec3400..6110730d5df0 100644
@@ -244,18 +244,28 @@ void nouveau_drm_device_remove(struct drm_device *dev);
 	struct nouveau_cli *_cli = (c);                                        \
 	dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a);                \
 } while(0)
-#define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a)
-#define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a)
-#define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a)
-#define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a)
-#define NV_DEBUG(drm,f,a...) do {                                              \
-	if (unlikely(drm_debug & DRM_UT_DRIVER))                               \
-		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
-} while(0)
-#define NV_ATOMIC(drm,f,a...) do {                                             \
-	if (unlikely(drm_debug & DRM_UT_ATOMIC))                               \
-		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
-} while(0)
+
+__printf(2, 3)
+void nouveau_cli_printk(struct nouveau_cli *cli, const char *fmt, ...);
+
+#define NV_FATAL(drm, fmt, ...)						\
+	nouveau_cli_printk(&(drm)->client, KERN_CRIT fmt, ##__VA_ARGS__)
+#define NV_ERROR(drm, fmt, ...)						\
+	nouveau_cli_printk(&(drm)->client, KERN_ERR fmt, ##__VA_ARGS__)
+#define NV_WARN(drm, fmt, ...)						\
+	nouveau_cli_printk(&(drm)->client, KERN_WARNING fmt, ##__VA_ARGS__)
+#define NV_INFO(drm, fmt, ...)						\
+	nouveau_cli_printk(&(drm)->client, KERN_INFO fmt, ##__VA_ARGS__)
+#define NV_DEBUG(drm, fmt, ...)						\
+do {									\
+	if (unlikely(drm_debug & DRM_UT_DRIVER))			\
+		NV_INFO(drm, fmt, ##__VA_ARGS__);			\
+} while (0)
+#define NV_ATOMIC(drm, fmt, ...)					\
+do {									\
+	if (unlikely(drm_debug & DRM_UT_ATOMIC))			\
+		NV_INFO(drm, fmt, ##__VA_ARGS__);			\
+} while (0)
 
 extern int nouveau_modeset;
 
Signature · 1 line
2.15.0
#2 lore raw

PATCH 2/2 drm/nouveau: Convert NV_PRINTK macros and uses to new nv_cli_<level> macros

In reply to Joe Perches

Use a more common logging style and reduce object size by calling the nouveau_cli_printk function.

(size -t drivers/gpu/drm/nouveau/built-in.a x86/64 defconfig with nouveau)
text data bss dec hex filename
1736437 108484 1048 1845969 1c2ad1 (TOTALS) (new)
1737254 108484 1048 1846786 1c2e02 (TOTALS) (old)

Miscellanea:

o Add nv_cli_<level> macros that use nouveau_cli_printk
o Convert the NV_PRINTK uses to the new nv_cli_<level> macros
o Realign arguments of the conversions

---
 drivers/gpu/drm/nouveau/nouveau_abi16.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_chan.c  | 12 +++----
 drivers/gpu/drm/nouveau/nouveau_drv.h   | 12 ++++---
 drivers/gpu/drm/nouveau/nouveau_gem.c   | 62 ++++++++++++++++-----------------
 4 files changed, 45 insertions(+), 43 deletions(-)
drivers/gpu/drm/nouveau/nouveau_abi16.c +1 -1
index e67a471331b5..8196c5417dde 100644
@@ -236,7 +236,7 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
 		getparam->value = nvkm_gr_units(gr);
 		break;
 	default:
-		NV_PRINTK(dbg, cli, "unknown parameter %lld\n", getparam->param);
+		nv_cli_dbg(cli, "unknown parameter %lld\n", getparam->param);
 		return -EINVAL;
 	}
 
drivers/gpu/drm/nouveau/nouveau_chan.c +6 -6
index 92d3115f96b5..0c9c6172ea29 100644
@@ -51,7 +51,7 @@ nouveau_channel_killed(struct nvif_notify *ntfy)
 {
 	struct nouveau_channel *chan = container_of(ntfy, typeof(*chan), kill);
 	struct nouveau_cli *cli = (void *)chan->user.client;
-	NV_PRINTK(warn, cli, "channel %d killed!\n", chan->chid);
+	nv_cli_warn(cli, "channel %d killed!\n", chan->chid);
 	atomic_set(&chan->killed, 1);
 	return NVIF_NOTIFY_DROP;
 }
@@ -71,8 +71,8 @@ nouveau_channel_idle(struct nouveau_channel *chan)
 		}
 
 		if (ret) {
-			NV_PRINTK(err, cli, "failed to idle channel %d [%s]\n",
-				  chan->chid, nvxx_client(&cli->base)->name);
+			nv_cli_err(cli, "failed to idle channel %d [%s]\n",
+				   chan->chid, nvxx_client(&cli->base)->name);
 			return ret;
 		}
 	}
@@ -460,17 +460,17 @@ nouveau_channel_new(struct nouveau_drm *drm, struct nvif_device *device,
 
 	ret = nouveau_channel_ind(drm, device, arg0, pchan);
 	if (ret) {
-		NV_PRINTK(dbg, cli, "ib channel create, %d\n", ret);
+		nv_cli_dbg(cli, "ib channel create, %d\n", ret);
 		ret = nouveau_channel_dma(drm, device, pchan);
 		if (ret) {
-			NV_PRINTK(dbg, cli, "dma channel create, %d\n", ret);
+			nv_cli_dbg(cli, "dma channel create, %d\n", ret);
 			goto done;
 		}
 	}
 
 	ret = nouveau_channel_init(*pchan, arg0, arg1);
 	if (ret) {
-		NV_PRINTK(err, cli, "channel failed to initialise, %d\n", ret);
+		nv_cli_err(cli, "channel failed to initialise, %d\n", ret);
 		nouveau_channel_del(pchan);
 	}
 
drivers/gpu/drm/nouveau/nouveau_drv.h +7 -5
index 6110730d5df0..a45bd44ac782 100644
@@ -240,14 +240,16 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
 			       struct platform_device *, struct nvkm_device **);
 void nouveau_drm_device_remove(struct drm_device *dev);
 
-#define NV_PRINTK(l,c,f,a...) do {                                             \
-	struct nouveau_cli *_cli = (c);                                        \
-	dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a);                \
-} while(0)
-
 __printf(2, 3)
 void nouveau_cli_printk(struct nouveau_cli *cli, const char *fmt, ...);
 
+#define nv_cli_err(cli, fmt, ...)					\
+	nouveau_cli_printk(cli, KERN_ERR fmt, ##__VA_ARGS__)
+#define nv_cli_warn(cli, fmt, ...)					\
+	nouveau_cli_printk(cli, KERN_WARNING fmt, ##__VA_ARGS__)
+#define nv_cli_dbg(cli, fmt, ...)					\
+	dev_dbg((cli)->drm->dev->dev, "%s: " fmt, (cli)->name, ##__VA_ARGS__)
+
 #define NV_FATAL(drm, fmt, ...)						\
 	nouveau_cli_printk(&(drm)->client, KERN_CRIT fmt, ##__VA_ARGS__)
 #define NV_ERROR(drm, fmt, ...)						\
drivers/gpu/drm/nouveau/nouveau_gem.c +31 -31

214 lines not on this page · raw message

Signature · 1 line
2.15.0
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to Joe Perches

For the whole series:

Nice catch!

Quoted 15 lines · Joe Perches

Reduces object size ~4kb

Joe Perches (2):
drm/nouveau: Add new logging function nv_cli_printk drm/nouveau: Convert NV_PRINTK macros and uses to new nv_cli_<level>
macros

 drivers/gpu/drm/nouveau/nouveau_abi16.c |  2 +-
 drivers/gpu/drm/nouveau/nouveau_chan.c  | 12 +++----
 drivers/gpu/drm/nouveau/nouveau_drm.c   | 21 +++++++++++
 drivers/gpu/drm/nouveau/nouveau_drv.h   | 44 ++++++++++++++---------
 drivers/gpu/drm/nouveau/nouveau_gem.c   | 62 ++++++++++++++++------------
-----
 5 files changed, 87 insertions(+), 54 deletions(-)
Signature · 2 lines
Cheers,
	Lyude Paul