/*
 * Copyright 2013-2015, Michael Ellerman, IBM Corp.
 * Licensed under GPLv2.
 */

#define _GNU_SOURCE	/* For CPU_ZERO etc. */

#include <elf.h>
#include <errno.h>
#include <fcntl.h>
#include <link.h>
#include <sched.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "utils.h"

static char auxv[4096];

void *get_auxv_entry(int type)
{
	ElfW(auxv_t) *p;
	void *result;
	ssize_t num;
	int fd;

	fd = open("/proc/self/auxv", O_RDONLY);
	if (fd == -1) {
		perror("open");
		return NULL;
	}

	result = NULL;

	num = read(fd, auxv, sizeof(auxv));
	if (num < 0) {
		perror("read");
		goto out;
	}

	if (num > sizeof(auxv)) {
		printf("Overflowed auxv buffer\n");
		goto out;
	}

	p = (ElfW(auxv_t) *)auxv;

	while (p->a_type != AT_NULL) {
		if (p->a_type == type) {
			result = (void *)p->a_un.a_val;
			break;
		}

		p++;
	}
out:
	close(fd);
	return result;
}

int pick_online_cpu(void)
{
	cpu_set_t mask;
	int cpu;

	CPU_ZERO(&mask);

	if (sched_getaffinity(0, sizeof(mask), &mask)) {
		perror("sched_getaffinity");
		return -1;
	}

	/* We prefer a primary thread, but skip 0 */
	for (cpu = 8; cpu < CPU_SETSIZE; cpu += 8)
		if (CPU_ISSET(cpu, &mask))
			return cpu;

	/* Search for anything, but in reverse */
	for (cpu = CPU_SETSIZE - 1; cpu >= 0; cpu--)
		if (CPU_ISSET(cpu, &mask))
			return cpu;

	printf("No cpus in affinity mask?!\n");
	return -1;
}
rm></td></tr>
<tr><td class='sub'>net-next plumbings</td><td class='sub right'>Tobias Klauser</td></tr></table>
<table class='tabs'><tr><td>
<a href='/cgit.cgi/linux/net-next.git/'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?id=983779235a4d08f94e8cda073200423e0ff01d2e'>refs</a><a href='/cgit.cgi/linux/net-next.git/log/include/dt-bindings/sound'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>tree</a><a class='active' href='/cgit.cgi/linux/net-next.git/commit/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/include/dt-bindings/sound'>
<input type='hidden' name='id' value='983779235a4d08f94e8cda073200423e0ff01d2e'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/commit/?id=983779235a4d08f94e8cda073200423e0ff01d2e'>root</a>/<a href='/cgit.cgi/linux/net-next.git/commit/include?id=983779235a4d08f94e8cda073200423e0ff01d2e'>include</a>/<a href='/cgit.cgi/linux/net-next.git/commit/include/dt-bindings?id=983779235a4d08f94e8cda073200423e0ff01d2e'>dt-bindings</a>/<a href='/cgit.cgi/linux/net-next.git/commit/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>sound</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='983779235a4d08f94e8cda073200423e0ff01d2e'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Venkat Reddy Talla &lt;vreddytalla@nvidia.com&gt;</td><td class='right'>2016-11-17 23:24:36 +0530</td></tr>
<tr><th>committer</th><td>Mark Brown &lt;broonie@kernel.org&gt;</td><td class='right'>2016-11-23 16:27:42 +0000</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>983779235a4d08f94e8cda073200423e0ff01d2e</a> (<a href='/cgit.cgi/linux/net-next.git/patch/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=983779235a4d08f94e8cda073200423e0ff01d2e'>254b624bd499c14b09d55abaf209ea95f3c860f7</a> /<a href='/cgit.cgi/linux/net-next.git/tree/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e'>include/dt-bindings/sound</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/include/dt-bindings/sound?id=383d0fca7035a12f1201277d33e8fc87c9d60c9a'>383d0fca7035a12f1201277d33e8fc87c9d60c9a</a> (<a href='/cgit.cgi/linux/net-next.git/diff/include/dt-bindings/sound?id=983779235a4d08f94e8cda073200423e0ff01d2e&amp;id2=383d0fca7035a12f1201277d33e8fc87c9d60c9a'>diff</a>)</td></tr></table>
<div class='commit-subject'>regulator: max77620: add documentation for MPOK property</div><div class='commit-msg'>Adding documentation for maxim,power-ok-control dts property

Signed-off-by: Venkat Reddy Talla &lt;vreddytalla@nvidia.com&gt;
Acked-by: Rob Herring &lt;robh@kernel.org&gt;
Acked-by: Lee Jones &lt;lee.jones@linaro.org&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=983779235a4d08f94e8cda073200423e0ff01d2e'>Diffstat</a> (limited to 'include/dt-bindings/sound')</div><table summary='diffstat' class='diffstat'>