From patchwork Mon May 11 08:41:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahesh J Salgaonkar X-Patchwork-Id: 1288186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Lmzx6Ls8z9sSg for ; Tue, 12 May 2020 15:47:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49Lmzx4CcRzDqgq for ; Tue, 12 May 2020 15:47:57 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=mahesh@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49LDtr5W52zDqZp for ; Mon, 11 May 2020 18:41:40 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04B8bW3x164803; Mon, 11 May 2020 04:41:38 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 30ws5dmscc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 04:41:38 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04B8cP1c167562; Mon, 11 May 2020 04:41:37 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 30ws5dmsb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 04:41:37 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04B8YtNb032043; Mon, 11 May 2020 08:41:35 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 30wm55kyx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2020 08:41:35 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04B8eMEU66060672 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 May 2020 08:40:22 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 884A3A4051; Mon, 11 May 2020 08:41:33 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA906A4053; Mon, 11 May 2020 08:41:32 +0000 (GMT) Received: from [192.168.0.24] (unknown [9.199.58.67]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 11 May 2020 08:41:32 +0000 (GMT) From: Mahesh Salgaonkar To: pdbg Date: Mon, 11 May 2020 14:11:31 +0530 Message-ID: <158918649143.16822.6515319767989338898.stgit@jupiter> In-Reply-To: <158918648405.16822.8656222589108716359.stgit@jupiter> References: <158918648405.16822.8656222589108716359.stgit@jupiter> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-11_03:2020-05-11, 2020-05-11 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005110071 X-Mailman-Approved-At: Tue, 12 May 2020 15:47:51 +1000 Subject: [Pdbg] [PATCH RFC 2/4] pdbg: Introduce a error registration framework. X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Add an interface to register error injections that can be used through pdbg inject command. Error injection can be split component wise. This interface will allow one to introduce multiple error injections per component. e.g. A timer facility components could be "tb" and "tod". And each component will define multiple error injections under it. e.g. "tb" component will have below error injections and so on... tfmr_parity hdec_parity dec_parity ... Signed-off-by: Mahesh Salgaonkar --- Makefile.am | 3 + src/err_inject.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/err_inject.h | 20 ++++++++ 3 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 src/err_inject.h diff --git a/Makefile.am b/Makefile.am index 1e444ba..05522cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,7 +121,8 @@ pdbg_SOURCES = \ src/thread.c \ src/util.c \ src/util.h \ - src/err_inject.c + src/err_inject.c \ + src/err_inject.h pdbg_CFLAGS = -I$(top_srcdir)/libpdbg -Wall -Werror -DGIT_SHA1=\"${GIT_SHA1}\" \ $(ARCH_FLAGS) diff --git a/src/err_inject.c b/src/err_inject.c index 23463e7..ef6bc97 100644 --- a/src/err_inject.c +++ b/src/err_inject.c @@ -21,26 +21,146 @@ #include #include +#include #include "main.h" #include "optcmd.h" #include "path.h" +#include "err_inject.h" + +struct list_head error_comp_list = LIST_HEAD_INIT(error_comp_list); + +struct error_type { + char *name; + char *desc; + inject_error_t inject_error; + void *data; + struct list_node error_link; +}; + +struct error_comp { + char *name; + struct list_head err_type_list; + struct list_node comp_link; +}; + +static struct error_comp *get_error_component(char *component) +{ + struct error_comp *err_comp = NULL; + + list_for_each(&error_comp_list, err_comp, comp_link) + if (!strcmp(err_comp->name, component)) + return err_comp; + return NULL; +} + +static struct error_comp *create_error_component(char *component) +{ + struct error_comp *err_comp = NULL; + + err_comp = malloc(sizeof(*err_comp)); + if (!err_comp) + return NULL; + + err_comp->name = strdup(component); + list_head_init(&err_comp->err_type_list); + list_add_tail(&error_comp_list, &err_comp->comp_link); + + return err_comp; +} + +static struct error_type *get_error_type(struct error_comp *err_comp, + char *error) +{ + struct error_type *err_type = NULL; + + list_for_each(&err_comp->err_type_list, err_type, error_link) + if (!strcmp(err_type->name, error)) + return err_type; + return NULL; +} + +int register_error_inject(char *component, char *error, char *error_desc, + inject_error_t func, void *data) +{ + struct error_comp *err_comp = NULL; + struct error_type *err_type = NULL; + + err_comp = get_error_component(component); + if (!err_comp) { + err_comp = create_error_component(component); + if (!err_comp) + return -ENOMEM; + } + + err_type = malloc(sizeof(*err_type)); + if (!err_type) + return -ENOMEM; + + err_type->name = strdup(error); + err_type->inject_error = func; + err_type->data = data; + if (error_desc) + err_type->desc = strdup(error_desc); + list_add_tail(&err_comp->err_type_list, &err_type->error_link); + + return 0; +} static void list_error_components(void) { - /* TODO: List error components */ + struct error_comp *err_comp = NULL; + + printf("Usage: pdbg inject \n"); + printf(" :\n"); + printf(" %-15s %s\n", "?", "Show component list"); + list_for_each(&error_comp_list, err_comp, comp_link) + printf(" %-15s\n", err_comp->name); } static void list_err_type(char *component) { - /* TODO: List error type for a give component */ + struct error_comp *err_comp = NULL; + struct error_type *err_type = NULL; + + err_comp = get_error_component(component); + if (!err_comp) { + printf("Invalid error component: %s\n", component); + return; + } + + printf("Usage: pdbg inject %s :\n", err_comp->name); + printf(" :\n"); + printf(" %-15s %s\n", "?", "Show error list"); + list_for_each(&err_comp->err_type_list, err_type, error_link) + printf(" %-15s %s\n", err_type->name, err_type->desc); } static void inject_errors(char *component, char *error) { - /* TODO: Inject errors */ -} + struct error_comp *err_comp = NULL; + struct error_type *err_type = NULL; + struct pdbg_target *target; + err_comp = get_error_component(component); + if (!err_comp) { + printf("Invalid error component: %s\n", component); + return; + } + + err_type = get_error_type(err_comp, error); + if (!err_type) { + printf("Invalid error type %s for %s\n", error, component); + return; + } + + for_each_path_target(target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + err_type->inject_error(target, err_type->data); + } +} static void error_inject_init(void) { diff --git a/src/err_inject.h b/src/err_inject.h new file mode 100644 index 0000000..76acee7 --- /dev/null +++ b/src/err_inject.h @@ -0,0 +1,20 @@ +#ifndef __ERR_INJECT_H +#define __ERR_INJECT_H + +#include +#include + +typedef int (*inject_error_t)(struct pdbg_target *target, void *data); + +/** + * @brief Register error injections that can be used through pdbg inject + * command + * @param[in] component Name of error component. + * @param[in] error Name of error type under given component. + * @param[in] error_desc Description of error to be injected. + * @param[in] func Error injection routine + * @param[in] data Opaque data pointer passed to func. + */ +extern int register_error_inject(char *component, char *error, + char *error_desc, inject_error_t func, void *data); +#endif