Skip to content

Commit 627cf58

Browse files
Athira Rajeevmaddy-kerneldev
authored andcommitted
powerpc/pseries/htmdump: Add htm status support to htmdump module
Support dumping status of Hardware Trace Macro (HTM) function via debugfs interface. Under debugfs folder "/sys/kernel/debug/powerpc/htmdump", add file "htmstatus". The interface allows only read of this file which will present the content of HTM status buffer from the hcall. The 16th offset of HTM status buffer has value for the number of HTM entries in the status buffer. Each nest htm status entry is 0x6 bytes, where as core HTM status entry is 0x8 bytes. Calculate the number of bytes to read based on this detail. Signed-off-by: Athira Rajeev <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent e03e4b1 commit 627cf58

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

arch/powerpc/platforms/pseries/htmdump.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <asm/plpar_wrappers.h>
1313

1414
static void *htm_buf;
15+
static void *htm_status_buf;
1516
static u32 nodeindex;
1617
static u32 nodalchipindex;
1718
static u32 coreindexonchip;
@@ -205,6 +206,53 @@ static int htmstart_get(void *data, u64 *val)
205206
return 0;
206207
}
207208

209+
static ssize_t htmstatus_read(struct file *filp, char __user *ubuf,
210+
size_t count, loff_t *ppos)
211+
{
212+
void *htm_status_buf = filp->private_data;
213+
long rc, ret;
214+
u64 *num_entries;
215+
u64 to_copy;
216+
int htmstatus_flag;
217+
218+
/*
219+
* Invoke H_HTM call with:
220+
* - operation as htm status (H_HTM_OP_STATUS)
221+
* - last three values as addr, size and offset
222+
*/
223+
rc = htm_hcall_wrapper(nodeindex, nodalchipindex, coreindexonchip,
224+
htmtype, H_HTM_OP_STATUS, virt_to_phys(htm_status_buf),
225+
PAGE_SIZE, 0);
226+
227+
ret = htm_return_check(rc);
228+
if (ret <= 0) {
229+
pr_debug("H_HTM hcall failed for op: H_HTM_OP_STATUS, returning %ld\n", ret);
230+
return ret;
231+
}
232+
233+
/*
234+
* HTM status buffer, start of buffer + 0x10 gives the
235+
* number of HTM entries in the buffer. Each nest htm status
236+
* entry is 0x6 bytes where each core htm status entry is
237+
* 0x8 bytes.
238+
* So total count to copy is:
239+
* 32 bytes (for first 7 fields) + (number of HTM entries * entry size)
240+
*/
241+
num_entries = htm_status_buf + 0x10;
242+
if (htmtype == 0x2)
243+
htmstatus_flag = 0x8;
244+
else
245+
htmstatus_flag = 0x6;
246+
to_copy = 32 + (be64_to_cpu(*num_entries) * htmstatus_flag);
247+
return simple_read_from_buffer(ubuf, count, ppos, htm_status_buf, to_copy);
248+
}
249+
250+
static const struct file_operations htmstatus_fops = {
251+
.llseek = NULL,
252+
.read = htmstatus_read,
253+
.open = simple_open,
254+
};
255+
208256
DEFINE_SIMPLE_ATTRIBUTE(htmconfigure_fops, htmconfigure_get, htmconfigure_set, "%llu\n");
209257
DEFINE_SIMPLE_ATTRIBUTE(htmstart_fops, htmstart_get, htmstart_set, "%llu\n");
210258

@@ -235,6 +283,15 @@ static int htmdump_init_debugfs(void)
235283
debugfs_create_file("htmconfigure", 0600, htmdump_debugfs_dir, NULL, &htmconfigure_fops);
236284
debugfs_create_file("htmstart", 0600, htmdump_debugfs_dir, NULL, &htmstart_fops);
237285

286+
/* Debugfs interface file to present status of HTM */
287+
htm_status_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
288+
if (!htm_status_buf) {
289+
pr_err("Failed to allocate htmstatus buf\n");
290+
return -ENOMEM;
291+
}
292+
293+
debugfs_create_file("htmstatus", 0400, htmdump_debugfs_dir, htm_status_buf, &htmstatus_fops);
294+
238295
return 0;
239296
}
240297

0 commit comments

Comments
 (0)