/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <libintl.h>
#include "libcpc.h"
/*
* Takes a string and converts it to a cpc_set_t.
*
* While processing the string using getsubopt(), we will use an array of
* requests to hold the data, and a proprietary representation of attributes
* which allow us to avoid a realloc()/bcopy() dance every time we come across
* a new attribute.
*
* Not until after the string has been processed in its entirety do we
* allocate and specify a request set properly.
*/
/*
* Leave enough room in token strings for picn, nousern, or sysn where n is
* picnum.
*/
typedef struct __tmp_attr {
char *name;
} tmp_attr_t;
typedef struct __tok_info {
char *name;
int picnum;
} tok_info_t;
typedef struct __request_t {
} request_t;
static void strtoset_cleanup(void);
static void smt_special(int picnum);
/*
* Clients of cpc_strtoset may set this to specify an error handler during
* string parsing.
*/
static int nreqs;
static int ncounters;
static int ntoks;
static char **toks;
static int (*(*tok_funcs))(int, char *);
static int nattrs;
static int found;
static void
{
if (strtoset_errfn == NULL)
return;
}
/*ARGSUSED*/
static void
{
found = 1;
}
static int
{
char *end_event;
int err;
found = 0;
if (found)
return (1);
if (found)
return (1);
/*
* Before assuming this is an invalid event, see if we have been given
* a raw event code.
* Check the second argument of strtol() to ensure invalid events
* beginning with number do not go through.
*/
errno = 0;
/*
* Success - this is a valid raw code in hex, decimal, or octal.
*/
return (1);
}
return (0);
}
/*
* An unknown token was encountered; check here if it is an implicit event
* name. We allow users to omit the "picn=" portion of the event spec, and
* assign such events to available pics in order they are returned from
* getsubopt(3C). We start our search for an available pic _after_ the highest
* picnum to be assigned. This ensures that the event spec can never be out of
* order; i.e. if the event string is "eventa,eventb" we must ensure that the
* picnum counting eventa is less than the picnum counting eventb.
*/
static int
{
int i;
/*
* Event names cannot have '=' in them. If present here, it means we
* have encountered an unknown token (foo=bar, for example).
*/
return (0);
/*
* Find the first unavailable pic, after which we must start our search.
*/
for (i = ncounters - 1; i >= 0; i--) {
break;
}
/*
* If the last counter has been assigned, we cannot place this event.
*/
if (i == ncounters - 1)
return (0);
/*
* If none of the counters have been assigned yet, i is -1 and we will
* begin our search at 0. Else we begin our search at the counter after
* the last one currently assigned.
*/
i++;
for (; i < ncounters; i++) {
if (event_valid(i, event) == 0)
continue;
nreqs++;
return (1);
}
return (0);
}
static int
{
/*
* Make sure the each pic only appears in the spec once.
*/
return (-1);
}
return (-1);
}
return (-1);
}
nreqs++;
return (0);
}
/*
* We explicitly ignore any value provided for these tokens, as their
* mere presence signals us to turn on or off the relevant flags.
*/
/*ARGSUSED*/
static int
{
int i;
/*
* If picnum is -1, this flag should be applied to all reqs.
*/
else
return (-1);
if (picnum != -1)
break;
}
return (0);
}
static int
{
int i;
char *endptr;
/*
* If picnum is -1, this attribute should be applied to all reqs.
*/
return (-1);
}
} else
/*
* No value was provided for this attribute,
* so specify a default value of 1.
*/
if (picnum != -1)
break;
}
return (0);
}
/*ARGSUSED*/
static void
{
/*
* We don't allow picnum to be specified by the user.
*/
return;
(*(int *)arg)++;
}
static int
{
int nattrs = 0;
return (nattrs);
}
static void
{
int *i = arg;
return;
exit(0);
}
}
{
int i;
int j;
int x;
char *opts;
char *val;
nattrs = 0;
for (i = 0; i < ncounters; i++) {
/*
* Each pic will have at least one attribute: the physical pic
* assignment via the "picnum" attribute. Set that up here for
* each request.
*/
}
/*
* Build up a list of acceptable tokens.
*
* Permitted tokens are
* picn=event
* nousern
* sysn
* attrn=val
* nouser
* sys
* attr=val
*
* Where n is a counter number, and attr is any attribute supported by
* the current processor.
*
* If a token appears without a counter number, it applies to all
* counters in the request set.
*
* The number of tokens is:
*
* picn: ncounters
* generic flags: 2 * ncounters (nouser, sys)
* attrs: nattrs * ncounters
* attrs with no picnum: nattrs
* generic flags with no picnum: 2 (nouser, sys)
* NULL token to signify end of list to getsubopt(3C).
*
* Matching each token's index in the token table is a function which
* process that token; these are in tok_funcs.
*/
/*
* Count the number of valid attributes.
* Set up the attrlist array to point to the attributes in attrlistp.
*/
i = 0;
sizeof (int (*)(char *)));
for (i = 0; i < ntoks; i++) {
}
x = 0;
for (i = 0; i < ncounters; i++) {
x++;
}
for (i = 0; i < ncounters; i++) {
x++;
}
for (i = 0; i < ncounters; i++) {
x++;
}
for (j = 0; j < nattrs; j++) {
for (i = 0; i < ncounters; i++) {
i);
x++;
}
/*
* Now create a token for this attribute with no picnum; if used
* it will be applied to all reqs.
*/
x++;
}
toks[x] = "nouser";
x++;
toks[x] = "sys";
x++;
while (*opts != '\0') {
if (idx == -1) {
if (find_event(val) == 0) {
goto inval;
} else
continue;
}
goto inval;
}
/*
* The string has been processed. Now count how many PICs were used,
* create a request set, and specify each request properly.
*/
exit(0);
}
for (i = 0; i < ncounters; i++) {
continue;
/*
* If the caller wishes to measure events on the physical CPU,
* we need to add SMT attributes to each request.
*/
if (smt)
smt_special(i);
sizeof (cpc_attr_t));
j = 0;
j++;
}
gettext("cpc_set_add_request() failed: %s\n"),
goto inval;
}
}
return (set);
return (NULL);
}
static void
strtoset_cleanup(void)
{
int i;
for (i = 0; i < nattrs; i++)
for (i = 0; i < ncounters; i++) {
}
}
for (i = 0; i < ntoks - 3; i++)
/*
* We free all but the last three tokens: "nouser", "sys", NULL
*/
}
/*
* The following is called to modify requests so that they count events on
* behalf of a physical processor, instead of a logical processor. It duplicates
* the request flags for the sibling processor (i.e. if the request counts user
* events, add an attribute to count user events on the sibling processor also).
*/
static void
{
}
}
}
/*
* If we ever fail to get memory, we print an error message and exit.
*/
static void *
{
void *p = malloc(n);
if (p == NULL) {
exit(0);
}
return (p);
}