Skip to content

Commit 855ab61

Browse files
mathieupoiriergregkh
authored andcommitted
coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf()
Refactoring function tmc_etr_setup_perf_buf() so that it only deals with the high level etr_perf_buffer, leaving the allocation of the backend buffer (i.e etr_buf) to another function. That way the backend buffer allocation function can decide if it wants to reuse an existing buffer (CPU-wide trace scenarios) or simply create a new one. Signed-off-by: Mathieu Poirier <[email protected]> Tested-by: Leo Yan <[email protected]> Tested-by: Robert Walker <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a0f08a6 commit 855ab61

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

drivers/hwtracing/coresight/coresight-tmc-etr.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,29 +1160,24 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
11601160
}
11611161

11621162
/*
1163-
* tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf.
1163+
* alloc_etr_buf: Allocate ETR buffer for use by perf.
11641164
* The size of the hardware buffer is dependent on the size configured
11651165
* via sysfs and the perf ring buffer size. We prefer to allocate the
11661166
* largest possible size, scaling down the size by half until it
11671167
* reaches a minimum limit (1M), beyond which we give up.
11681168
*/
1169-
static struct etr_perf_buffer *
1170-
tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
1171-
int nr_pages, void **pages, bool snapshot)
1169+
static struct etr_buf *
1170+
alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
1171+
int nr_pages, void **pages, bool snapshot)
11721172
{
11731173
int node, cpu = event->cpu;
11741174
struct etr_buf *etr_buf;
1175-
struct etr_perf_buffer *etr_perf;
11761175
unsigned long size;
11771176

11781177
if (cpu == -1)
11791178
cpu = smp_processor_id();
11801179
node = cpu_to_node(cpu);
11811180

1182-
etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node);
1183-
if (!etr_perf)
1184-
return ERR_PTR(-ENOMEM);
1185-
11861181
/*
11871182
* Try to match the perf ring buffer size if it is larger
11881183
* than the size requested via sysfs.
@@ -1206,6 +1201,32 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
12061201
size /= 2;
12071202
} while (size >= TMC_ETR_PERF_MIN_BUF_SIZE);
12081203

1204+
return ERR_PTR(-ENOMEM);
1205+
1206+
done:
1207+
return etr_buf;
1208+
}
1209+
1210+
static struct etr_perf_buffer *
1211+
tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
1212+
int nr_pages, void **pages, bool snapshot)
1213+
{
1214+
int node, cpu = event->cpu;
1215+
struct etr_buf *etr_buf;
1216+
struct etr_perf_buffer *etr_perf;
1217+
1218+
if (cpu == -1)
1219+
cpu = smp_processor_id();
1220+
node = cpu_to_node(cpu);
1221+
1222+
etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node);
1223+
if (!etr_perf)
1224+
return ERR_PTR(-ENOMEM);
1225+
1226+
etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot);
1227+
if (!IS_ERR(etr_buf))
1228+
goto done;
1229+
12091230
kfree(etr_perf);
12101231
return ERR_PTR(-ENOMEM);
12111232

0 commit comments

Comments
 (0)