Received: by 10.223.164.202 with SMTP id h10csp172809wrb; Fri, 10 Nov 2017 04:32:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMYFHdHy4/nNYgPEgVONpshLlM6gSWmJ2NV38EAqEYtzTvn6HGOFXqxhTvnP2xNCDcT99CM/ X-Received: by 10.159.229.136 with SMTP id az8mr183713plb.423.1510317168572; Fri, 10 Nov 2017 04:32:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510317168; cv=none; d=google.com; s=arc-20160816; b=KMArqe9ih0RpzmoNJtprjT0pFdqbKsgoqMqu1bPxkKZgqCstnxJ4WNyE29KTWmRQm7 Ex/pVEo/n7qzScokArWtyF1h5p+SfqPk4uEUqz6hjpZipq9xyz5KfOdwJvP5Uw5q5qTW VcaLaUPJZXvhiFUlqE/iIj+q2tS9ALLdofB92wnPrlFfvO7Keu33zMflkvXPi2rUj2aJ 1luxhdittwn8drhLsOG8p2IWARdlz4BsimFnKJcxMmqjCWvice6pGmmRFz4mksJ3n/CC Q9rWpKngq8VXFSRxJB4nNCLdY6DXgXsQtmDb20gmhTN9HSVtgdLVICctyIxlrpwrDkgm /YSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=dp4OvWdzQEe2Zj7zUTR8irm9UTGk4rIjR+ZtPVo7+bc=; b=gDkvWqkRqbMbO/kCmAxlDCEj6tMHM8Dj2VGFfox/zo0bqq6mb/PqUGRi6mrw6/xG1V /914QCq2H7VlvDNGVlBwKrMebz8OE/o4sOEaDSQapzJcCcrwFniAqr7ffqGy0Almp0ao /+amPyBVDJc9XZDRM9h93ejgnFqJOYVaZFrkotU+gK7mo3TNYYSiajOBjpgSGSCk+tEW YYjkMZ6AFjCQLPchVdmPhDTYm3DYCpqQLrjvlUIp+pVOuDsO+J15YUkiFO8O4wNUCv4V sowwj6/HkF66RAptQ5HUMeAXlDv0/sorYESvPaC+7rewqQKSsvgR6FVTBBEVE+Xrehau zQoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nKwVWMEs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si9899867plr.221.2017.11.10.04.32.36; Fri, 10 Nov 2017 04:32:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nKwVWMEs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753193AbdKJMbd (ORCPT + 82 others); Fri, 10 Nov 2017 07:31:33 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:50047 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752257AbdKJMbE (ORCPT ); Fri, 10 Nov 2017 07:31:04 -0500 Received: by mail-wr0-f194.google.com with SMTP id o88so8454157wrb.6 for ; Fri, 10 Nov 2017 04:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dp4OvWdzQEe2Zj7zUTR8irm9UTGk4rIjR+ZtPVo7+bc=; b=nKwVWMEsUVm5NQiO72N1s9lQz5i91VW0o8H8w5n+UmkDIjBmg08N8mHV5VoPGaBMLI 0JUB8FehwYl8Q/CAfcA4NrV0gDpe66FhJ1iz1xXOhWj+SGvd0VqwNhnVY4cH1YpALxWt mWBkTs7IDvtOrTZVfgVANKbvJogdmR36Zq7kIdNDmwcycFbHcYjpBlW8Wz7sohpU/fwk 939ZBGysGSmJco7XZx4bn8b/wUu6ABVuqFjoESIOjsYsHRzYlxLAbzqjuYCZ7tKBqqbl 0xQoeFg5Oz1H4RcomqNV2GRmDo4gx/J3z/iZjN0fmEbEAdvx2EMjYrgxM8AapGHlHxSZ 28bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dp4OvWdzQEe2Zj7zUTR8irm9UTGk4rIjR+ZtPVo7+bc=; b=M5z4R5EvA+4wAxpz1T2HT8AUw+fRHCuxfEMbZveX3w2cdnv5/bG90tKoCRIFa9k3Gm DDokyQlhhH3OZCQYxFarqqM3dT94QQQyZ+yxG1GredXqf3OgT6sxZ733vLkun398TXZw uelNsJmqP+QEZHwo9dSxrqZ9g12dH6AWc+CUJ7nLmpIDZgFjYyb1Oxnd9M2skNYQWLLP J0jAZsGz6HudXiI8AyPXB7KvVvoj6QAhPddzGhEnFZX1/AoMpzVyAvlOi8xm2cKd5r76 Aw3A0xotjivjYBNpcqBR10h/KjL0dXFYIvJC4SwmEtXh0qcXtFEuevhn7D8i4e7PsxJ3 pJ1Q== X-Gm-Message-State: AJaThX5O7GZjUKUkU03SFLD3rUlqGof5SXlX0zJOV0H9GXUKwDAm4jNX L8Extqhz3B5sR/R/LTiTU2M= X-Received: by 10.223.133.134 with SMTP id 6mr188258wrt.256.1510317063553; Fri, 10 Nov 2017 04:31:03 -0800 (PST) Received: from sc9-mailhost2.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id p4sm6196517wrf.36.2017.11.10.04.31.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 04:31:03 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: jan.kiszka@siemens.com, linux-kernel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 4/4] kernelshark: Adding a GUI plugin for xenomai events Date: Fri, 10 Nov 2017 14:29:15 +0200 Message-Id: <20171110122915.24929-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.15.0.rc0 In-Reply-To: <20171110122915.24929-1-y.karadz@gmail.com> References: <20171110122915.24929-1-y.karadz@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A plugin for processing xenomai events "cobalt_switch_context" and "cobalt_thread_resume" is added. Signed-off-by: Yordan Karadzhov (VMware) --- Makefile | 1 + kshark-plugin.h | 10 ++ plugin_xenomai_gui.c | 300 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 311 insertions(+) create mode 100644 plugin_xenomai_gui.c diff --git a/Makefile b/Makefile index 992e6b0..e4d280b 100644 --- a/Makefile +++ b/Makefile @@ -384,6 +384,7 @@ PLUGIN_OBJS += plugin_tlb.o PLUGINS := $(PLUGIN_OBJS:.o=.so) GUI_PLUGIN_OBJS = +GUI_PLUGIN_OBJS += plugin_xenomai_gui.o GUI_PLUGINS := $(GUI_PLUGIN_OBJS:.o=.so) diff --git a/kshark-plugin.h b/kshark-plugin.h index 42fb40c..1166781 100644 --- a/kshark-plugin.h +++ b/kshark-plugin.h @@ -53,6 +53,16 @@ enum gui_plugin_actions { KSHARK_PLUGIN_GET_COMMAND, }; +enum gui_plugin_ctx_updates { + KSHARK_PLUGIN_UPDATE_SWITCH_EVENT = (1 << 0), + KSHARK_PLUGIN_UPDATE_WAKEUP_EVENT = (1 << 1), + KSHARK_PLUGIN_UPDATE_WAKEUP_PID = (1 << 2), + KSHARK_PLUGIN_UPDATE_SWITCH_PID = (1 << 3), + KSHARK_PLUGIN_UPDATE_PREV_STATE = (1 << 4), + KSHARK_PLUGIN_UPDATE_NEXT_NAME = (1 << 5), + KSHARK_PLUGIN_UPDATE_ALL = INT_MAX +}; + enum gui_event_types { KSHARK_PLUGIN_SWITCH_EVENT, KSHARK_PLUGIN_WAKEUP_EVENT, diff --git a/plugin_xenomai_gui.c b/plugin_xenomai_gui.c new file mode 100644 index 0000000..c786cc8 --- /dev/null +++ b/plugin_xenomai_gui.c @@ -0,0 +1,300 @@ +/* + * Copyright (C) 2017 VMware Inc, Yordan Karadzhov + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License (not later!) + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +#include +#include + +#include "event-parse.h" +#include "kernel-shark.h" +#include "kshark-plugin.h" + +struct xenomai_context { + struct pevent *pevent; + + struct event_format *cobalt_switch_event; + struct format_field *cobalt_switch_next_pid_field; + struct format_field *cobalt_switch_prev_state_field; + struct format_field *cobalt_switch_next_name_field; + + struct event_format *cobalt_wakeup_event; + struct format_field *cobalt_wakeup_pid_field; +}; + +struct xenomai_context *xenomai_context_handler = NULL; +struct gui_event_handler *switch_handler = NULL; +struct gui_event_handler *wakeup_handler = NULL; + +#define COBALT_PREV_STATE_BIT (1 << 3) +#define COBALT_COMM_OFFSET_MASK 0xFFFF + +static gboolean xenomai_update_context(struct pevent *pevent, int task_id) +{ + struct event_format *event; + struct xenomai_context *ctx = xenomai_context_handler; + + if (!ctx) + return FALSE; + + if (task_id & KSHARK_PLUGIN_UPDATE_SWITCH_EVENT) { + event = pevent_find_event_by_name(pevent, + "cobalt_core", + "cobalt_switch_context"); + if (!event) + return FALSE; + + ctx->cobalt_switch_event = event; + } + + if (task_id & KSHARK_PLUGIN_UPDATE_WAKEUP_EVENT) { + event = pevent_find_event_by_name(pevent, + "cobalt_core", + "cobalt_thread_resume"); + if (!event) + return FALSE; + + ctx->cobalt_wakeup_event = event; + } + + if (task_id & KSHARK_PLUGIN_UPDATE_SWITCH_PID) { + ctx->cobalt_switch_next_pid_field = + pevent_find_field(ctx->cobalt_switch_event, "next_pid"); + } + + if (task_id & KSHARK_PLUGIN_UPDATE_PREV_STATE) { + ctx->cobalt_switch_prev_state_field = + pevent_find_field(ctx->cobalt_switch_event, "prev_state"); + } + + if (task_id & KSHARK_PLUGIN_UPDATE_NEXT_NAME) { + ctx->cobalt_switch_next_name_field = + pevent_find_field(ctx->cobalt_switch_event, "next_name"); + } + + if (task_id & KSHARK_PLUGIN_UPDATE_WAKEUP_PID) { + ctx->cobalt_wakeup_pid_field = + pevent_find_field(ctx->cobalt_wakeup_event, "pid"); + } + + return TRUE; +} + +static void xenomai_context_new(struct shark_info *info, struct trace_view_store *store) +{ + if (!xenomai_context_handler) { + xenomai_context_handler = + (struct xenomai_context*) malloc(sizeof(struct xenomai_context)); + } + + xenomai_context_handler->pevent = tracecmd_get_pevent(info->handle); + + int status = xenomai_update_context(xenomai_context_handler->pevent, + KSHARK_PLUGIN_UPDATE_ALL); + if (status == FALSE) { + free(xenomai_context_handler); + xenomai_context_handler = NULL; + } +} + +static int cobalt_get_next_pid(struct xenomai_context *ctx, + struct pevent_record *record, + int *pid) +{ + long long unsigned int val; + int status = pevent_read_number_field(ctx->cobalt_switch_next_pid_field, + record->data, &val); + if (pid) + *pid = val; + + return status; +} + +static int cobalt_get_prev_state(struct xenomai_context *ctx, + struct pevent_record *record, + int *state) +{ + long long unsigned int val; + pevent_read_number_field(ctx->cobalt_switch_prev_state_field, + record->data, &val); + + if (state) + *state = val; + + return (val & COBALT_PREV_STATE_BIT) ? 1 : 0; +} + +static void cobalt_get_command(struct xenomai_context *ctx, + struct pevent_record *record, + const char **comm) +{ + int offset = + data2host4(ctx->pevent, record->data + ctx->cobalt_switch_next_name_field->offset); + + offset &= COBALT_COMM_OFFSET_MASK; + *comm = record->data + offset; +} + +static gboolean xenomai_switch_handler(struct pevent_record *record, + int task_id, + void *output) +{ + struct xenomai_context *ctx = xenomai_context_handler; + + if (!ctx) + return FALSE; + + switch (task_id) { + case KSHARK_PLUGIN_GET_PID: + cobalt_get_next_pid(ctx, record, output); + return TRUE; + + case KSHARK_PLUGIN_GET_PREV_STATE: + return cobalt_get_prev_state(ctx, record, output); + + case KSHARK_PLUGIN_GET_COMMAND: + cobalt_get_command(ctx, record, (const char**) output); + return TRUE; + + default: + return FALSE; + } +} + +static int cobalt_get_wakeup_pid(struct xenomai_context *ctx, + struct pevent_record *record, + int *pid) +{ + long long unsigned int val; + int status = pevent_read_number_field(ctx->cobalt_wakeup_pid_field, + record->data, &val); + + if (pid) + *pid = val; + + return status; +} + +static gboolean xenomai_wakeup_handler(struct pevent_record *record, + int task_id, + void *output) +{ + struct xenomai_context *ctx = xenomai_context_handler; + + if (!ctx) + return FALSE; + + switch (task_id) { + case KSHARK_PLUGIN_GET_PID: + cobalt_get_wakeup_pid(ctx, record, output); + return TRUE; + + default: + return FALSE; + } +} + +void KSHARK_PLUGIN_LOADER(void *info, void *store) +{ + struct shark_info *ks_info = info; + struct trace_view_store *ks_store = store; + + xenomai_context_new(ks_info, ks_store); + + if (!xenomai_context_handler) + return; + + struct xenomai_context *ctx = xenomai_context_handler; + + switch_handler = make_gui_event_handler(ctx->cobalt_switch_event->id, + KSHARK_PLUGIN_SWITCH_EVENT, + xenomai_switch_handler, + xenomai_update_context); + + wakeup_handler = make_gui_event_handler(ctx->cobalt_wakeup_event->id, + KSHARK_PLUGIN_WAKEUP_EVENT, + xenomai_wakeup_handler, + xenomai_update_context); + + if (switch_handler && wakeup_handler) { + trace_view_store_register_gui_handler(ks_store, switch_handler); + trace_view_store_register_gui_handler(ks_store, wakeup_handler); + + trace_graph_register_gui_handler(ks_info->ginfo, switch_handler); + trace_graph_register_gui_handler(ks_info->ginfo, wakeup_handler); + } +} + +void KSHARK_PLUGIN_RELOADER(void *info, void *store) +{ + struct shark_info *ks_info = info; + struct trace_view_store *ks_store = store; + + if (!xenomai_context_handler) { + xenomai_context_new(ks_info, ks_store); + + if (!xenomai_context_handler) + return; + } else { + int status = xenomai_update_context(tracecmd_get_pevent(ks_info->handle), + KSHARK_PLUGIN_UPDATE_ALL); + + if (status == FALSE) + return; + } + + if (switch_handler && wakeup_handler) { + trace_view_store_register_gui_handler(ks_store, switch_handler); + trace_view_store_register_gui_handler(ks_store, wakeup_handler); + } +} + +void KSHARK_PLUGIN_UNLOADER(void *info, void *store) +{ + struct shark_info *ks_info = info; + struct trace_view_store *ks_store = store; + struct xenomai_context *ctx = xenomai_context_handler; + + if (!ctx) + return; + + if (switch_handler) { + unregister_gui_event_handler(&ks_store->event_handlers, + ctx->cobalt_switch_event->id); + + unregister_gui_event_handler(&ks_info->ginfo->event_handlers, + ctx->cobalt_switch_event->id); + + free(switch_handler); + switch_handler = NULL; + } + + if (wakeup_handler) { + unregister_gui_event_handler(&ks_store->event_handlers, + ctx->cobalt_wakeup_event->id); + + unregister_gui_event_handler(&ks_info->ginfo->event_handlers, + ctx->cobalt_wakeup_event->id); + + free(wakeup_handler); + wakeup_handler = NULL; + } + + free(ctx); + xenomai_context_handler = NULL; +} -- 2.15.0.rc0 From 1583640772375822033@xxx Fri Nov 10 01:32:11 +0000 2017 X-GM-THRID: 1583428326729047812 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread