diff mbox series

bios: interrupt: add a test to check ACPI SCI per second

Message ID 20210310191915.454317-1-alex.hung@canonical.com
State Accepted
Headers show
Series bios: interrupt: add a test to check ACPI SCI per second | expand

Commit Message

Alex Hung March 10, 2021, 7:19 p.m. UTC
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/Makefile.am                |   1 +
 src/bios/interrupt/interrupt.c | 100 +++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 src/bios/interrupt/interrupt.c

Comments

Colin Ian King March 11, 2021, 4:06 p.m. UTC | #1
On 10/03/2021 19:19, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/Makefile.am                |   1 +
>  src/bios/interrupt/interrupt.c | 100 +++++++++++++++++++++++++++++++++
>  2 files changed, 101 insertions(+)
>  create mode 100644 src/bios/interrupt/interrupt.c
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index b447e357..6af560de 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -154,6 +154,7 @@ fwts_SOURCES = main.c 				\
>  	bios/ebda_region/ebda_region.c 		\
>  	bios/ebdadump/ebdadump.c 		\
>  	bios/hdaaudio/hdaaudio.c 		\
> +	bios/interrupt/interrupt.c		\
>  	bios/memmapdump/memmapdump.c 		\
>  	bios/mtrr/mtrr.c 			\
>  	bios/multiproc/mpcheck.c 		\
> diff --git a/src/bios/interrupt/interrupt.c b/src/bios/interrupt/interrupt.c
> new file mode 100644
> index 00000000..3ff10ba8
> --- /dev/null
> +++ b/src/bios/interrupt/interrupt.c
> @@ -0,0 +1,100 @@
> +/*
> + * Copyright (C) 2021 Canonical
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> + *
> + */
> +#include "fwts.h"
> +
> +#if defined(FWTS_HAS_ACPI)
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <fcntl.h>
> +
> +#define ACPI_SCI_PATH	"/sys/firmware/acpi/interrupts/sci"
> +#define ACPI_SCI_THRESHOLD	30
> +#define ACPI_SCI_PERIOD		3
> +
> +static int interrupt_init(fwts_framework *fw)
> +{
> +	FWTS_UNUSED(fw);
> +	return FWTS_OK;
> +}
> +
> +static int interrupt_deinit(fwts_framework *fw)
> +{
> +	FWTS_UNUSED(fw);
> +	return FWTS_OK;
> +}
> +
> +static uint32_t get_acpi_sci(void)
> +{
> +	char *str;
> +	uint32_t val;
> +
> +	str = fwts_get(ACPI_SCI_PATH);
> +	if (!str)
> +		return 0;
> +
> +	val = atoi(str);
> +	free(str);
> +
> +	return val;
> +}
> +
> +static int interrupt_test0(fwts_framework *fw)
> +{
> +	uint32_t sci_init, average;
> +	bool passed = true;
> +
> +	if (access(ACPI_SCI_PATH, R_OK)) {
> +		fwts_log_warning(fw, "Could not open ACPI SCI data\n");
> +		return FWTS_ERROR;
> +	}
> +
> +	sci_init = get_acpi_sci();
> +	sleep(ACPI_SCI_PERIOD);
> +	average = (get_acpi_sci() - sci_init) / ACPI_SCI_PERIOD;
> +
> +	fwts_log_info(fw, "ACPI SCIs per second are %" PRId32 ".", average);
> +
> +	if (average > ACPI_SCI_THRESHOLD) {
> +		passed = false;
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "InterruptSCITooMany",
> +			"ACPI SCIs per second are above threshold %" PRId32 ".", ACPI_SCI_THRESHOLD);
> +	}
> +
> +	if (passed)
> +		fwts_passed(fw, "No issues found in ACPI SCI generation.");
> +
> +	return FWTS_OK;
> +}
> +
> +static fwts_framework_minor_test interrupt_tests[] = {
> +	{ interrupt_test0, "Check whether ACPI SCI is triggered excessively." },
> +	{ NULL, NULL }
> +};
> +
> +static fwts_framework_ops interrupt_ops = {
> +	.description = "Interrupt tests.",
> +	.init        = interrupt_init,
> +	.deinit      = interrupt_deinit,
> +	.minor_tests = interrupt_tests
> +};
> +
> +FWTS_REGISTER("interrupt", &interrupt_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ROOT_PRIV)
> +
> +#endif
> 

Acked-by: Colin Ian King <colin.king@canonical.com>
Ivan Hu March 15, 2021, 6:36 a.m. UTC | #2
On 3/11/21 3:19 AM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/Makefile.am                |   1 +
>  src/bios/interrupt/interrupt.c | 100 +++++++++++++++++++++++++++++++++
>  2 files changed, 101 insertions(+)
>  create mode 100644 src/bios/interrupt/interrupt.c
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index b447e357..6af560de 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -154,6 +154,7 @@ fwts_SOURCES = main.c 				\
>  	bios/ebda_region/ebda_region.c 		\
>  	bios/ebdadump/ebdadump.c 		\
>  	bios/hdaaudio/hdaaudio.c 		\
> +	bios/interrupt/interrupt.c		\
>  	bios/memmapdump/memmapdump.c 		\
>  	bios/mtrr/mtrr.c 			\
>  	bios/multiproc/mpcheck.c 		\
> diff --git a/src/bios/interrupt/interrupt.c b/src/bios/interrupt/interrupt.c
> new file mode 100644
> index 00000000..3ff10ba8
> --- /dev/null
> +++ b/src/bios/interrupt/interrupt.c
> @@ -0,0 +1,100 @@
> +/*
> + * Copyright (C) 2021 Canonical
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
> + *
> + */
> +#include "fwts.h"
> +
> +#if defined(FWTS_HAS_ACPI)
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <fcntl.h>
> +
> +#define ACPI_SCI_PATH	"/sys/firmware/acpi/interrupts/sci"
> +#define ACPI_SCI_THRESHOLD	30
> +#define ACPI_SCI_PERIOD		3
> +
> +static int interrupt_init(fwts_framework *fw)
> +{
> +	FWTS_UNUSED(fw);
> +	return FWTS_OK;
> +}
> +
> +static int interrupt_deinit(fwts_framework *fw)
> +{
> +	FWTS_UNUSED(fw);
> +	return FWTS_OK;
> +}
> +
> +static uint32_t get_acpi_sci(void)
> +{
> +	char *str;
> +	uint32_t val;
> +
> +	str = fwts_get(ACPI_SCI_PATH);
> +	if (!str)
> +		return 0;
> +
> +	val = atoi(str);
> +	free(str);
> +
> +	return val;
> +}
> +
> +static int interrupt_test0(fwts_framework *fw)
> +{
> +	uint32_t sci_init, average;
> +	bool passed = true;
> +
> +	if (access(ACPI_SCI_PATH, R_OK)) {
> +		fwts_log_warning(fw, "Could not open ACPI SCI data\n");
> +		return FWTS_ERROR;
> +	}
> +
> +	sci_init = get_acpi_sci();
> +	sleep(ACPI_SCI_PERIOD);
> +	average = (get_acpi_sci() - sci_init) / ACPI_SCI_PERIOD;
> +
> +	fwts_log_info(fw, "ACPI SCIs per second are %" PRId32 ".", average);
> +
> +	if (average > ACPI_SCI_THRESHOLD) {
> +		passed = false;
> +		fwts_failed(fw, LOG_LEVEL_HIGH, "InterruptSCITooMany",
> +			"ACPI SCIs per second are above threshold %" PRId32 ".", ACPI_SCI_THRESHOLD);
> +	}
> +
> +	if (passed)
> +		fwts_passed(fw, "No issues found in ACPI SCI generation.");
> +
> +	return FWTS_OK;
> +}
> +
> +static fwts_framework_minor_test interrupt_tests[] = {
> +	{ interrupt_test0, "Check whether ACPI SCI is triggered excessively." },
> +	{ NULL, NULL }
> +};
> +
> +static fwts_framework_ops interrupt_ops = {
> +	.description = "Interrupt tests.",
> +	.init        = interrupt_init,
> +	.deinit      = interrupt_deinit,
> +	.minor_tests = interrupt_tests
> +};
> +
> +FWTS_REGISTER("interrupt", &interrupt_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ROOT_PRIV)
> +
> +#endif
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index b447e357..6af560de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -154,6 +154,7 @@  fwts_SOURCES = main.c 				\
 	bios/ebda_region/ebda_region.c 		\
 	bios/ebdadump/ebdadump.c 		\
 	bios/hdaaudio/hdaaudio.c 		\
+	bios/interrupt/interrupt.c		\
 	bios/memmapdump/memmapdump.c 		\
 	bios/mtrr/mtrr.c 			\
 	bios/multiproc/mpcheck.c 		\
diff --git a/src/bios/interrupt/interrupt.c b/src/bios/interrupt/interrupt.c
new file mode 100644
index 00000000..3ff10ba8
--- /dev/null
+++ b/src/bios/interrupt/interrupt.c
@@ -0,0 +1,100 @@ 
+/*
+ * Copyright (C) 2021 Canonical
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include "fwts.h"
+
+#if defined(FWTS_HAS_ACPI)
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#define ACPI_SCI_PATH	"/sys/firmware/acpi/interrupts/sci"
+#define ACPI_SCI_THRESHOLD	30
+#define ACPI_SCI_PERIOD		3
+
+static int interrupt_init(fwts_framework *fw)
+{
+	FWTS_UNUSED(fw);
+	return FWTS_OK;
+}
+
+static int interrupt_deinit(fwts_framework *fw)
+{
+	FWTS_UNUSED(fw);
+	return FWTS_OK;
+}
+
+static uint32_t get_acpi_sci(void)
+{
+	char *str;
+	uint32_t val;
+
+	str = fwts_get(ACPI_SCI_PATH);
+	if (!str)
+		return 0;
+
+	val = atoi(str);
+	free(str);
+
+	return val;
+}
+
+static int interrupt_test0(fwts_framework *fw)
+{
+	uint32_t sci_init, average;
+	bool passed = true;
+
+	if (access(ACPI_SCI_PATH, R_OK)) {
+		fwts_log_warning(fw, "Could not open ACPI SCI data\n");
+		return FWTS_ERROR;
+	}
+
+	sci_init = get_acpi_sci();
+	sleep(ACPI_SCI_PERIOD);
+	average = (get_acpi_sci() - sci_init) / ACPI_SCI_PERIOD;
+
+	fwts_log_info(fw, "ACPI SCIs per second are %" PRId32 ".", average);
+
+	if (average > ACPI_SCI_THRESHOLD) {
+		passed = false;
+		fwts_failed(fw, LOG_LEVEL_HIGH, "InterruptSCITooMany",
+			"ACPI SCIs per second are above threshold %" PRId32 ".", ACPI_SCI_THRESHOLD);
+	}
+
+	if (passed)
+		fwts_passed(fw, "No issues found in ACPI SCI generation.");
+
+	return FWTS_OK;
+}
+
+static fwts_framework_minor_test interrupt_tests[] = {
+	{ interrupt_test0, "Check whether ACPI SCI is triggered excessively." },
+	{ NULL, NULL }
+};
+
+static fwts_framework_ops interrupt_ops = {
+	.description = "Interrupt tests.",
+	.init        = interrupt_init,
+	.deinit      = interrupt_deinit,
+	.minor_tests = interrupt_tests
+};
+
+FWTS_REGISTER("interrupt", &interrupt_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH | FWTS_FLAG_ROOT_PRIV)
+
+#endif