Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: add debugfs interface to see applied channel masks

Use debugfs to be able to view channel mask applied to every timestamp
event queue.

Every time the device is opened, a new entry is created in
`$DEBUGFS_MOUNTPOINT/ptpN/$INSTANCE_ADDRESS/mask`.

The mask value can be viewed grouped in 32bit decimal values using cat,
or converted to hexadecimal with the included `ptpchmaskfmt.sh` script.
32 bit values are listed from least significant to most significant.

Signed-off-by: Xabier Marquiegui <reibax@gmail.com>
Suggested-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Xabier Marquiegui and committed by
David S. Miller
403376dd c5a445b1

+39
+14
drivers/ptp/ptp_chardev.c
··· 10 10 #include <linux/sched.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/timekeeping.h> 13 + #include <linux/debugfs.h> 13 14 14 15 #include <linux/nospec.h> 15 16 ··· 107 106 struct ptp_clock *ptp = 108 107 container_of(pccontext->clk, struct ptp_clock, clock); 109 108 struct timestamp_event_queue *queue; 109 + char debugfsname[32]; 110 110 111 111 queue = kzalloc(sizeof(*queue), GFP_KERNEL); 112 112 if (!queue) ··· 121 119 spin_lock_init(&queue->lock); 122 120 list_add_tail(&queue->qlist, &ptp->tsevqs); 123 121 pccontext->private_clkdata = queue; 122 + 123 + /* Debugfs contents */ 124 + sprintf(debugfsname, "0x%p", queue); 125 + queue->debugfs_instance = 126 + debugfs_create_dir(debugfsname, ptp->debugfs_root); 127 + queue->dfs_bitmap.array = (u32 *)queue->mask; 128 + queue->dfs_bitmap.n_elements = 129 + DIV_ROUND_UP(PTP_MAX_CHANNELS, BITS_PER_BYTE * sizeof(u32)); 130 + debugfs_create_u32_array("mask", 0444, queue->debugfs_instance, 131 + &queue->dfs_bitmap); 132 + 124 133 return 0; 125 134 } 126 135 ··· 141 128 unsigned long flags; 142 129 143 130 if (queue) { 131 + debugfs_remove(queue->debugfs_instance); 144 132 pccontext->private_clkdata = NULL; 145 133 spin_lock_irqsave(&queue->lock, flags); 146 134 list_del(&queue->qlist);
+7
drivers/ptp/ptp_clock.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/syscalls.h> 17 17 #include <linux/uaccess.h> 18 + #include <linux/debugfs.h> 18 19 #include <uapi/linux/sched/types.h> 19 20 20 21 #include "ptp_private.h" ··· 186 185 spin_unlock_irqrestore(&tsevq->lock, flags); 187 186 bitmap_free(tsevq->mask); 188 187 kfree(tsevq); 188 + debugfs_remove(ptp->debugfs_root); 189 189 ida_free(&ptp_clocks_map, ptp->index); 190 190 kfree(ptp); 191 191 } ··· 220 218 struct ptp_clock *ptp; 221 219 struct timestamp_event_queue *queue = NULL; 222 220 int err = 0, index, major = MAJOR(ptp_devt); 221 + char debugfsname[8]; 223 222 size_t size; 224 223 225 224 if (info->n_alarm > PTP_MAX_ALARMS) ··· 341 338 pr_err("failed to create posix clock\n"); 342 339 return ERR_PTR(err); 343 340 } 341 + 342 + /* Debugfs initialization */ 343 + sprintf(debugfsname, "ptp%d", ptp->index); 344 + ptp->debugfs_root = debugfs_create_dir(debugfsname, NULL); 344 345 345 346 return ptp; 346 347
+4
drivers/ptp/ptp_private.h
··· 17 17 #include <linux/time.h> 18 18 #include <linux/list.h> 19 19 #include <linux/bitmap.h> 20 + #include <linux/debugfs.h> 20 21 21 22 #define PTP_MAX_TIMESTAMPS 128 22 23 #define PTP_BUF_TIMESTAMPS 30 ··· 31 30 spinlock_t lock; 32 31 struct list_head qlist; 33 32 unsigned long *mask; 33 + struct dentry *debugfs_instance; 34 + struct debugfs_u32_array dfs_bitmap; 34 35 }; 35 36 36 37 struct ptp_clock { ··· 60 57 struct mutex n_vclocks_mux; /* protect concurrent n_vclocks access */ 61 58 bool is_virtual_clock; 62 59 bool has_cycles; 60 + struct dentry *debugfs_root; 63 61 }; 64 62 65 63 #define info_to_vclock(d) container_of((d), struct ptp_vclock, info)
+14
tools/testing/selftests/ptp/ptpchmaskfmt.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # Simple helper script to transform ptp debugfs timestamp event queue filtering 5 + # masks from decimal values to hexadecimal values 6 + 7 + # Only takes the debugfs mask file path as an argument 8 + DEBUGFS_MASKFILE="${1}" 9 + 10 + #shellcheck disable=SC2013,SC2086 11 + for int in $(cat "$DEBUGFS_MASKFILE") ; do 12 + printf '0x%08X ' "$int" 13 + done 14 + echo