Page MenuHomeFreeBSD

D61681.1795024441.diff
No OneTemporary

Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None

D61681.1795024441.diff

diff --git a/sys/amd64/pt/pt.c b/sys/amd64/pt/pt.c
--- a/sys/amd64/pt/pt.c
+++ b/sys/amd64/pt/pt.c
@@ -413,28 +413,16 @@
memset(pt_ctx, 0, sizeof(*pt_ctx));
}
-/*
- * HWT backend configuration method.
- *
- * Checks and translates the user-defined configuration to a
- * set of PT tracing features. Uses the feature set to initialize
- * the tracing context for the target CPU or thread.
- */
static int
-pt_backend_configure(struct hwt_context *ctx, int cpu_id, int thread_id)
+pt_configure_ctx(struct pt_ctx *pt_ctx, struct hwt_context *ctx,
+ struct pt_cpu_config *cfg)
{
- struct hwt_cpu *hwt_cpu;
- struct hwt_thread *thr;
- struct pt_ctx *pt_ctx;
- struct pt_cpu_config *cfg;
struct pt_ext_area *pt_ext;
struct xstate_hdr *hdr;
int error;
- dprintf("%s\n", __func__);
-
- cfg = (struct pt_cpu_config *)ctx->config;
- pt_ctx = NULL;
+ KASSERT(pt_ctx->hwt_ctx == NULL,
+ ("%s: tracing context was already configured", __func__));
/* Clear any flags we don't support yet. */
cfg->rtit_ctl &= PT_SUPPORTED_FLAGS;
@@ -462,6 +450,48 @@
}
/* TODO: support for more config bits. */
+ dprintf("%s: preparing MSRs\n", __func__);
+ pt_ext = pt_ctx_get_ext_area(pt_ctx);
+ hdr = pt_ctx_get_xstate_hdr(pt_ctx);
+
+ pt_ext->rtit_ctl |= cfg->rtit_ctl;
+ if (cfg->nranges != 0) {
+ dprintf("%s: preparing IPF ranges\n", __func__);
+ if ((error = pt_configure_ranges(pt_ctx, cfg)) != 0)
+ return (error);
+ }
+ pt_ctx->hwt_ctx = ctx;
+ pt_ext->rtit_ctl |= RTIT_CTL_TOPA;
+ pt_ext->rtit_output_base = (uint64_t)vtophys(pt_ctx->buf.topa_hw);
+ pt_ext->rtit_output_mask_ptrs = PT_TOPA_MASK_PTRS;
+ hdr->xstate_bv = XFEATURE_ENABLED_PT;
+ hdr->xstate_xcomp_bv = XFEATURE_ENABLED_PT |
+ XSTATE_XCOMP_BV_COMPACT;
+ pt_ext->rtit_ctl |= RTIT_CTL_TRACEEN;
+
+ return (0);
+}
+
+/*
+ * HWT backend configuration method.
+ *
+ * Checks and translates the user-defined configuration to a
+ * set of PT tracing features. Uses the feature set to initialize
+ * the tracing context for the target CPU or thread.
+ */
+static int
+pt_backend_configure(struct hwt_context *ctx, int cpu_id, int thread_id)
+{
+ struct hwt_cpu *hwt_cpu;
+ struct hwt_thread *thr;
+ struct pt_ctx *pt_ctx;
+ struct pt_cpu_config *cfg;
+ int error;
+
+ dprintf("%s\n", __func__);
+
+ cfg = (struct pt_cpu_config *)ctx->config;
+ pt_ctx = NULL;
if (ctx->mode == HWT_MODE_CPU) {
TAILQ_FOREACH(hwt_cpu, &ctx->cpus, next) {
if (hwt_cpu->cpu_id != cpu_id)
@@ -484,24 +514,11 @@
if (pt_ctx == NULL)
return (ENOENT);
- dprintf("%s: preparing MSRs\n", __func__);
- pt_ext = pt_ctx_get_ext_area(pt_ctx);
- hdr = pt_ctx_get_xstate_hdr(pt_ctx);
-
- pt_ext->rtit_ctl |= cfg->rtit_ctl;
- if (cfg->nranges != 0) {
- dprintf("%s: preparing IPF ranges\n", __func__);
- if ((error = pt_configure_ranges(pt_ctx, cfg)) != 0)
+ if (pt_ctx->hwt_ctx == NULL) {
+ error = pt_configure_ctx(pt_ctx, ctx, cfg);
+ if (error)
return (error);
}
- pt_ctx->hwt_ctx = ctx;
- pt_ext->rtit_ctl |= RTIT_CTL_TOPA;
- pt_ext->rtit_output_base = (uint64_t)vtophys(pt_ctx->buf.topa_hw);
- pt_ext->rtit_output_mask_ptrs = PT_TOPA_MASK_PTRS;
- hdr->xstate_bv = XFEATURE_ENABLED_PT;
- hdr->xstate_xcomp_bv = XFEATURE_ENABLED_PT |
- XSTATE_XCOMP_BV_COMPACT;
- pt_ext->rtit_ctl |= RTIT_CTL_TRACEEN;
pt_pcpu[cpu_id].ctx = pt_ctx;
return (0);
diff --git a/sys/arm64/spe/arm_spe_backend.c b/sys/arm64/spe/arm_spe_backend.c
--- a/sys/arm64/spe/arm_spe_backend.c
+++ b/sys/arm64/spe/arm_spe_backend.c
@@ -294,27 +294,15 @@
}
static int
-spe_backend_configure(struct hwt_context *ctx, int cpu_id, int thread_id)
+spe_configure_ctx(struct arm_spe_info *info, struct hwt_context *ctx,
+ struct hwt_thread *thr, int cpu_id, int thread_id)
{
- struct arm_spe_info *info = NULL;
struct arm_spe_config *cfg;
- struct hwt_thread *thr = NULL;
- int err = 0;
- if (ctx->mode == HWT_MODE_CPU)
- info = &spe_info_cpu[cpu_id];
- else {
- TAILQ_FOREACH(thr, &ctx->threads, next) {
- if (thr->thread_id != thread_id)
- continue;
- info = (struct arm_spe_info *)thr->private;
- break;
- }
- if (info == NULL)
- return (ENOENT);
- }
+ mtx_assert(&info->lock, MA_OWNED);
+ KASSERT(!info->configured,
+ ("%s: tracing context was already configured", __func__));
- mtx_lock_spin(&info->lock);
if (ctx->mode == HWT_MODE_CPU)
info->ident = cpu_id;
else
@@ -342,13 +330,45 @@
if (cfg->ctx_field)
info->ctx_field = cfg->ctx_field;
} else
- err = (EINVAL);
+ return (EINVAL);
if (ctx->mode == HWT_MODE_THREAD) {
info->kvaddr = thr->vm->kvaddr;
info->buf_size = ctx->bufsize;
}
+ info->configured = true;
+ return (0);
+}
+
+static int
+spe_backend_configure(struct hwt_context *ctx, int cpu_id, int thread_id)
+{
+ struct arm_spe_info *info = NULL;
+ struct hwt_thread *thr = NULL;
+ int err = 0;
+
+ if (ctx->mode == HWT_MODE_CPU)
+ info = &spe_info_cpu[cpu_id];
+ else {
+ TAILQ_FOREACH(thr, &ctx->threads, next) {
+ if (thr->thread_id != thread_id)
+ continue;
+ info = (struct arm_spe_info *)thr->private;
+ break;
+ }
+ if (info == NULL)
+ return (ENOENT);
+ }
+
+ mtx_lock_spin(&info->lock);
+ if (!info->configured) {
+ err = spe_configure_ctx(info, ctx, thr, cpu_id, thread_id);
+ if (err) {
+ mtx_unlock_spin(&info->lock);
+ return (err);
+ }
+ }
spe_info[cpu_id] = info;
mtx_unlock_spin(&info->lock);
diff --git a/sys/arm64/spe/arm_spe_dev.h b/sys/arm64/spe/arm_spe_dev.h
--- a/sys/arm64/spe/arm_spe_dev.h
+++ b/sys/arm64/spe/arm_spe_dev.h
@@ -108,6 +108,7 @@
struct task flush_task;
bool enabled : 1;
bool stopped : 1;
+ bool configured : 1;
/* buffer is split in half as a ping-pong buffer */
vm_object_t bufobj;
diff --git a/sys/dev/hwt/hwt_hook.c b/sys/dev/hwt/hwt_hook.c
--- a/sys/dev/hwt/hwt_hook.c
+++ b/sys/dev/hwt/hwt_hook.c
@@ -63,6 +63,7 @@
struct hwt_thread *thr;
struct proc *p;
int cpu_id;
+ int err;
p = td->td_proc;
@@ -86,7 +87,14 @@
dprintf("%s: thr %p index %d tid %d on cpu_id %d\n", __func__, thr,
thr->thread_id, td->td_tid, cpu_id);
- hwt_backend_configure(ctx, cpu_id, thr->thread_id);
+ err = hwt_backend_configure(ctx, cpu_id, thr->thread_id);
+ if (err != 0) {
+ printf("%s: failed to configure tracing for thread %d: %d\n",
+ __func__, thr->thread_id, err);
+ hwt_ctx_put(ctx);
+ return;
+ }
+
hwt_backend_enable(ctx, cpu_id);
hwt_ctx_put(ctx);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 18, 5:54 PM (21 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41829575
Default Alt Text
D61681.1795024441.diff (6 KB)

Event Timeline