From 9e6cc03cdf736fbd817ed53fa9a7f506bc91a244 Mon Sep 17 00:00:00 2001 From: Benjamin Hadad IV Date: Wed, 16 Aug 2023 22:00:20 -0400 Subject: A variety of changes have been made as part of the code review. - Functions have been consolidated. - Code was clarified and tidied up overall. - Unnecessary elements were removed. --- device_info_procfs.c | 57 +++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) (limited to 'device_info_procfs.c') diff --git a/device_info_procfs.c b/device_info_procfs.c index 5ddf240..efef41a 100644 --- a/device_info_procfs.c +++ b/device_info_procfs.c @@ -35,31 +35,24 @@ typedef struct { //// ==v== PTOP_DEVICE_INFO ==v== //// -static void* device_info_seq_start_backend(struct seq_file *s, loff_t *pos, int initial_entry_value, int total_entries) { +// Called to start or resume a sequence. Prior to 4.19, *pos is unreliable. +// Initializes iterator `idx` state and returns it. Ends sequence on NULL. +static void* device_info_file_seq_start(struct seq_file *s, loff_t *pos) { static device_info_iter idx; + struct nvdebug_state *g = &g_nvdebug_state[seq2gpuidx(s)]; + int is_ampere = g->chip_id == NV_CHIP_ID_AMPERE; // If start of sequence, reset `idx` if (*pos == 0) { idx.index = 0; - idx.type_of_next_entry = initial_entry_value; + idx.type_of_next_entry = is_ampere ? 0 : -1; } - idx.total_entries = total_entries; + idx.total_entries = is_ampere ? NV_PTOP_DEVICE_INFO__SIZE_1_PREVIOUS : NV_PTOP_DEVICE_INFO__SIZE_1_AMPERE(g); // Number of possible info entries is fixed, and list is sparse if (idx.index >= idx.total_entries) return NULL; return &idx; } -// Called to start or resume a sequence. Prior to 4.19, *pos is unreliable. -// Initializes iterator `idx` state and returns it. Ends sequence on NULL. -static void* device_info_file_seq_start_previous(struct seq_file *s, loff_t *pos) { - return device_info_seq_start_backend(s, pos, -1, NV_PTOP_DEVICE_INFO__SIZE_1_PREVIOUS); -} - -static void* device_info_file_seq_start_ampere(struct seq_file *s, loff_t *pos) { - struct nvdebug_state *g = &g_nvdebug_state[seq2gpuidx(s)]; - return device_info_seq_start_backend(s, pos, 0, NV_PTOP_DEVICE_INFO__SIZE_1_AMPERE(g)); -} - // Steps to next record. Returns new value of `idx`. // Calls show() on non-NULL return static void* device_info_file_seq_next(struct seq_file *s, void *idx, @@ -166,43 +159,25 @@ static int device_info_file_seq_show_ampere(struct seq_file *s, void *idx) { return 0; } - static void device_info_file_seq_stop(struct seq_file *s, void *idx) { // No cleanup needed } -static const struct seq_operations device_info_file_seq_ops_previous = { - .start = device_info_file_seq_start_previous, +static struct seq_operations device_info_file_seq_ops = { + .start = device_info_file_seq_start, .next = device_info_file_seq_next, - .stop = device_info_file_seq_stop, - .show = device_info_file_seq_show_previous, -}; - -static const struct seq_operations device_info_file_seq_ops_ampere = { - .start = device_info_file_seq_start_ampere, - .next = device_info_file_seq_next, - .stop = device_info_file_seq_stop, - .show = device_info_file_seq_show_ampere, + .stop = device_info_file_seq_stop }; -static int device_info_file_open_previous(struct inode *inode, struct file *f) { - return seq_open(f, &device_info_file_seq_ops_previous); +static int device_info_file_open(struct inode *inode, struct file *f) { + struct seq_operations file_seq_ops = device_info_file_seq_ops; + file_seq_ops.show = (g_nvdebug_state[file2parentgpuidx(f)].chip_id == NV_CHIP_ID_AMPERE) ? device_info_file_seq_show_ampere : device_info_file_seq_show_previous; + return seq_open(f, &file_seq_ops); } -static int device_info_file_open_ampere(struct inode *inode, struct file *f) { - return seq_open(f, &device_info_file_seq_ops_ampere); -} - -struct file_operations device_info_file_ops_previous = { - .open = device_info_file_open_previous, +struct file_operations device_info_file_ops = { + .open = device_info_file_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release, }; - -struct file_operations device_info_file_ops_ampere = { - .open = device_info_file_open_ampere, - .read = seq_read, - .llseek = seq_lseek, - .release = seq_release, -}; -- cgit v1.2.2