<commit_before>
IPF Machine Check (MC) error inject tool
========================================

IPF Machine Check (MC) error inject tool is used to inject MC
errors from Linux. The tool is a test bed for IPF MC work flow including
hardware correctable error handling, OS recoverable error handling, MC
event logging, etc.

The tool includes two parts: a kernel driver and a user application
sample. The driver provides interface to PAL to inject error
and query error injection capabilities. The driver code is in
arch/ia64/kernel/err_inject.c. The application sample (shown below)
provides a combination of various errors and calls the driver's interface
(sysfs interface) to inject errors or query error injection capabilities.

The tool can be used to test Intel IPF machine MC handling capabilities.
It's especially useful for people who can not access hardware MC injection
tool to inject error. It's also very useful to integrate with other
software test suits to do stressful testing on IPF.

Below is a sample application as part of the whole tool. The sample
can be used as a working test tool. Or it can be expanded to include
more features. It also can be a integrated into a libary or other user
application to have more thorough test.

The sample application takes err.conf as error configuation input. Gcc
compiles the code. After you install err_inject driver, you can run
this sample application to inject errors.

Errata: Itanium 2 Processors Specification Update lists some errata against
the pal_mc_error_inject PAL procedure. The following err.conf has been tested
on latest Montecito PAL.

err.conf:

#This is configuration file for err_inject_tool.
#The format of the each line is:
#cpu, loop, interval, err_type_info, err_struct_info, err_data_buffer
#where
#	cpu: logical cpu number the error will be inject in.
#	loop: times the error will be injected.
#	interval: In second. every so often one error is injected.
#	err_type_info, err_struct_info: PAL parameters.
#
#Note: All values are hex w/o or w/ 0x prefix.


#On cpu2, inject only total 0x10 errors, interval 5 seconds
#corrected, data cache, hier-2, physical addr(assigned by tool code).
#working on Montecito latest PAL.
2, 10, 5, 4101, 95

#On cpu4, inject and consume total 0x10 errors, interval 5 seconds
#corrected, data cache, hier-2, physical addr(assigned by tool code).
#working on Montecito latest PAL.
4, 10, 5, 4109, 95

#On cpu15, inject and consume total 0x10 errors, interval 5 seconds
#recoverable, DTR0, hier-2.
#working on Montecito latest PAL.
0xf, 0x10, 5, 4249, 15

The sample application source code:

err_injection_tool.c:

/*
 * 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, GOOD TITLE or
 * NON INFRINGEMENT.  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Copyright (C) 2006 Intel Co
 *	<NAME> <<EMAIL>>
 *
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/shm.h>

#define MAX_FN_SIZE 		256
#define MAX_BUF_SIZE 		256
#define DATA_BUF_SIZE 		256
#define NR_CPUS 		512
#define MAX_TASK_NUM		2048
#define MIN_INTERVAL		5	// seconds
#define	ERR_DATA_BUFFER_SIZE 	3	// Three 8-byte.
#define PARA_FIELD_NUM		5
#define MASK_SIZE		(NR_CPUS/64)
#define PATH_FORMAT "/sys/devices/system/node/node0/cpu%d/err_inject/"

int sched_setaffinity(pid_t pid, unsigned int len, unsigned long *mask);

int verbose;
#define vbprintf if (verbose) printf

int log_info(int cpu, const char *fmt, ...)
{
	FILE *log;
	char fn[MAX_FN_SIZE];
	char buf[MAX_BUF_SIZE];
	va_list args;

	sprintf(fn, "%d.log", cpu);
	log=fopen(fn, "a+");
	if (log==NULL) {
		perror("Error open:");
		return -1;
	}

	va_start(args, fmt);
	vprintf(fmt, args);
	memset(buf, 0, MAX_BUF_SIZE);<commit_msg>[IA64] Fix example error injection program<commit_after>
IPF Machine Check (MC) error inject tool
========================================

IPF Machine Check (MC) error inject tool is used to inject MC
errors from Linux. The tool is a test bed for IPF MC work flow including
hardware correctable error handling, OS recoverable error handling, MC
event logging, etc.

The tool includes two parts: a kernel driver and a user application
sample. The driver provides interface to PAL to inject error
and query error injection capabilities. The driver code is in
arch/ia64/kernel/err_inject.c. The application sample (shown below)
provides a combination of various errors and calls the driver's interface
(sysfs interface) to inject errors or query error injection capabilities.

The tool can be used to test Intel IPF machine MC handling capabilities.
It's especially useful for people who can not access hardware MC injection
tool to inject error. It's also very useful to integrate with other
software test suits to do stressful testing on IPF.

Below is a sample application as part of the whole tool. The sample
can be used as a working test tool. Or it can be expanded to include
more features. It also can be a integrated into a libary or other user
application to have more thorough test.

The sample application takes err.conf as error configuation input. Gcc
compiles the code. After you install err_inject driver, you can run
this sample application to inject errors.

Errata: Itanium 2 Processors Specification Update lists some errata against
the pal_mc_error_inject PAL procedure. The following err.conf has been tested
on latest Montecito PAL.

err.conf:

#This is configuration file for err_inject_tool.
#The format of the each line is:
#cpu, loop, interval, err_type_info, err_struct_info, err_data_buffer
#where
#	cpu: logical cpu number the error will be inject in.
#	loop: times the error will be injected.
#	interval: In second. every so often one error is injected.
#	err_type_info, err_struct_info: PAL parameters.
#
#Note: All values are hex w/o or w/ 0x prefix.


#On cpu2, inject only total 0x10 errors, interval 5 seconds
#corrected, data cache, hier-2, physical addr(assigned by tool code).
#working on Montecito latest PAL.
2, 10, 5, 4101, 95

#On cpu4, inject and consume total 0x10 errors, interval 5 seconds
#corrected, data cache, hier-2, physical addr(assigned by tool code).
#working on Montecito latest PAL.
4, 10, 5, 4109, 95

#On cpu15, inject and consume total 0x10 errors, interval 5 seconds
#recoverable, DTR0, hier-2.
#working on Montecito latest PAL.
0xf, 0x10, 5, 4249, 15

The sample application source code:

err_injection_tool.c:

/*
 * 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, GOOD TITLE or
 * NON INFRINGEMENT.  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Copyright (C) 2006 Intel Co
 *	<NAME> <<EMAIL>>
 *
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sched.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/shm.h>

#define MAX_FN_SIZE 		256
#define MAX_BUF_SIZE 		256
#define DATA_BUF_SIZE 		256
#define NR_CPUS 		512
#define MAX_TASK_NUM		2048
#define MIN_INTERVAL		5	// seconds
#define	ERR_DATA_BUFFER_SIZE 	3	// Three 8-byte.
#define PARA_FIELD_NUM		5
#define MASK_SIZE		(NR_CPUS/64)
#define PATH_FORMAT "/sys/devices/system/cpu/cpu%d/err_inject/"

int sched_setaffinity(pid_t pid, unsigned int len, unsigned long *mask);

int verbose;
#define vbprintf if (verbose) printf

int log_info(int cpu, const char *fmt, ...)
{
	FILE *log;
	char fn[MAX_FN_SIZE];
	char buf[MAX_BUF_SIZE];
	va_list args;

	sprintf(fn, "%d.log", cpu);
	log=fopen(fn, "a+");
	if (log==NULL) {
		perror("Error open:");
		return -1;
	}

	va_start(args, fmt);
	vprintf(fmt, args);
	memset(buf, 0, MAX_BUF_SIZE);
{'fraction_non_alphanumeric': 0.08620689655172414, 'fraction_numerical': 0.02053591038875467, 'mean_word_length': 4.450029922202274, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4802216', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2760, 'n_words': 1280}