tools/perf/util/util.c

Source file repositories/reference/linux-study-clean/tools/perf/util/util.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/util.c
Extension
.c
Size
10881 bytes
Lines
556
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

if (!match_pat(d->d_name, pat)) {
			ret =  -2;
			break;
		}

		scnprintf(namebuf, sizeof(namebuf), "%s/%s",
			  path, d->d_name);

		/* We have to check symbolic link itself */
		ret = lstat(namebuf, &statbuf);
		if (ret < 0) {
			pr_debug("stat failed: %s\n", namebuf);
			break;
		}

		if (S_ISDIR(statbuf.st_mode))
			ret = depth ? rm_rf_depth_pat(namebuf, depth - 1, pat) : 0;
		else
			ret = unlink(namebuf);
	}
	closedir(dir);

	if (ret < 0)
		return ret;

	return rmdir(path);
}

static int rm_rf_a_kcore_dir(const char *path, const char *name)
{
	char kcore_dir_path[PATH_MAX];
	const char *pat[] = {
		"kcore",
		"kallsyms",
		"modules",
		NULL,
	};

	snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/%s", path, name);

	return rm_rf_depth_pat(kcore_dir_path, 0, pat);
}

static bool kcore_dir_filter(const char *name __maybe_unused, struct dirent *d)
{
	const char *pat[] = {
		"kcore_dir",
		"kcore_dir__[1-9]*",
		NULL,
	};

	return match_pat(d->d_name, pat);
}

static int rm_rf_kcore_dir(const char *path)
{
	struct strlist *kcore_dirs;
	struct str_node *nd;
	int ret;

	kcore_dirs = lsdir(path, kcore_dir_filter);

	if (!kcore_dirs)
		return 0;

	strlist__for_each_entry(nd, kcore_dirs) {
		ret = rm_rf_a_kcore_dir(path, nd->s);
		if (ret)
			return ret;
	}

	strlist__delete(kcore_dirs);

	return 0;
}

void cpumask_to_cpulist(char *cpumask, char *cpulist)
{
	int i, j, bm_size, nbits;
	int len = strlen(cpumask);
	unsigned long *bm;
	char cpus[MAX_NR_CPUS];

	for (i = 0; i < len; i++) {
		if (cpumask[i] == ',') {
			for (j = i; j < len; j++)
				cpumask[j] = cpumask[j + 1];
		}
	}

Annotation

Implementation Notes