tools/testing/selftests/sparc64/drivers/adi-test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/sparc64/drivers/adi-test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/sparc64/drivers/adi-test.c
Extension
.c
Size
16592 bytes
Lines
718
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct stats {
	char		name[16];
	unsigned long	total;
	unsigned long	count;
	unsigned long	bytes;
};

static struct stats read_stats = {
	.name = "read", .total = 0, .count = 0, .bytes = 0};
static struct stats pread_stats = {
	.name = "pread", .total = 0, .count = 0, .bytes = 0};
static struct stats write_stats = {
	.name = "write", .total = 0, .count = 0, .bytes = 0};
static struct stats pwrite_stats = {
	.name = "pwrite", .total = 0, .count = 0, .bytes = 0};
static struct stats seek_stats = {
	.name = "seek", .total = 0, .count = 0, .bytes = 0};

static void update_stats(struct stats * const ustats,
			 unsigned long measurement, unsigned long bytes)
{
	ustats->total += measurement;
	ustats->bytes += bytes;
	ustats->count++;
}

static void print_ustats(const struct stats * const ustats)
{
	DEBUG_PRINT_L1("%s\t%7d\t%7.0f\t%7.0f\n",
		       ustats->name, ustats->count,
		       (float)ustats->total / (float)ustats->count,
		       (float)ustats->bytes / (float)ustats->count);
}

static void print_stats(void)
{
	DEBUG_PRINT_L1("\nSyscall\tCall\tAvgTime\tAvgSize\n"
		       "\tCount\t(ticks)\t(bytes)\n"
		       "-------------------------------\n");

	print_ustats(&read_stats);
	print_ustats(&pread_stats);
	print_ustats(&write_stats);
	print_ustats(&pwrite_stats);
	print_ustats(&seek_stats);
}

static int build_memory_map(void)
{
	char line[256];
	FILE *fp;
	int i;

	range_count = 0;

	fp = fopen("/proc/iomem", "r");
	if (!fp) {
		fprintf(stderr, "/proc/iomem: error %d: %s\n",
			errno, strerror(errno));
		return -errno;
	}

	while (fgets(line, sizeof(line), fp) != 0) {
		if (strstr(line, system_ram_str)) {
			char *dash, *end_ptr;

			/* Given a line like this:
			 * d0400000-10ffaffff : System RAM
			 * replace the "-" with a space
			 */
			dash = strstr(line, "-");
			dash[0] = 0x20;

			start_addr[range_count] = strtoull(line, &end_ptr, 16);
			end_addr[range_count] = strtoull(end_ptr, NULL, 16);
			range_count++;
		}
	}

	fclose(fp);

	DEBUG_PRINT_L1("RAM Ranges\n");
	for (i = 0; i < range_count; i++)
		DEBUG_PRINT_L1("\trange %d: 0x%llx\t- 0x%llx\n",
			       i, start_addr[i], end_addr[i]);

	if (range_count == 0) {
		fprintf(stderr, "No valid address ranges found.  Error.\n");
		return -1;
	}

Annotation

Implementation Notes