misc.c revision f2fc321be9b4df7748e8c31a5edd154b0177b139
/*
* 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
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>
#include <time.h>
#include <libgen.h>
#include <unistd.h>
#include <strings.h>
#include "filebench.h"
#include "ipc.h"
#include "eventgen.h"
#include "utils.h"
/*
* Routines to access high resolution system time, initialize and
* shutdown filebench, obtain system generated random numbers from
* "urandom", log filebench run progress and errors, and access system
* information strings.
*/
/*
* Lets us use the rdtsc instruction to get highres time.
* Thanks to libmicro
*/
/*
* Uses the rdtsc instruction to get high resolution (cpu
* clock ticks) time. Only used for non Sun compiles.
*/
__inline__ long long
rdtsc(void)
{
unsigned long long x;
return (x);
}
/*
* Get high resolution time in nanoseconds. This is the version
* used when not compiled for Sun systems. It uses rdtsc call to
* get clock ticks and converts to nanoseconds
*/
gethrtime(void)
{
/* convert to nanosecs and return */
return (hrt);
}
/*
* Gets CPU clock frequency in MHz from cpuinfo file.
* Converts to cpu_hz and stores in cpu_hz global uint64_t.
* Only used for non Sun compiles.
*/
static uint64_t
parse_cpu_hz(void)
{
/*
* cpu MHz : 2191.563
*/
double hertz = -1;
}
char buffer[80];
}
break;
}
}
return (hz);
}
/*
* Get high resolution time in nanoseconds. This is the version
* used if compiled for Sun systems. It calls gettimeofday
* to get current time and converts it to nanoseconds.
*/
gethrtime(void)
{
return (hrt);
}
#endif
static int urandomfd;
/*
* Main filebench initialization. Opens the random number
* "device" file or shuts down the run if one is not found.
* Sets the cpu clock frequency variable or shuts down the
* run if one is not found.
*/
void
filebench_init(void)
{
/* open the "urandom" random number device file */
}
#if defined(USE_RDTSC) && (LINUX_PORT)
cpu_hz = parse_cpu_hz();
if (cpu_hz <= 0) {
}
#endif /* USE_RDTSC */
}
/*
* Reads a 64 bit random number from the urandom "file".
* Shuts down the run if the read fails. Otherwise returns
* the random number after rounding it off by "round".
* Returns 0 on success, -1 on failure.
*/
int
{
/* check for round value too large */
*randp = 0;
/* if it just fits, its ok, otherwise error */
return (0);
else
return (-1);
}
}
/* clip with max and optionally round */
if (round) {
}
return (0);
}
/*
* Reads a 32 bit random number from the urandom "file".
* Shuts down the run if the read fails. Otherwise returns
* the random number after rounding it off by "round".
* Returns 0 on success, -1 on failure.
*/
int
{
/* check for round value too large */
*randp = 0;
/* if it just fits, its ok, otherwise error */
return (0);
else
return (-1);
}
}
/* clip with max and optionally round */
if (round) {
}
return (0);
}
extern int lex_lineno;
/*
* Writes a message consisting of information formated by
* "fmt" to the log file, dump file or stdout. The supplied
* "level" argument determines which file to write to and
* what other actions to take. The level LOG_LOG writes to
* the "log" file, and will open the file on the first
* invocation. The level LOG_DUMP writes to the "dump" file,
* and will open it on the first invocation. Other levels
* print to the stdout device, with the amount of information
* dependent on the error level and the current error level
* setting in filebench_shm->debug_level.
*/
void filebench_log
{
char line[131072];
char buf[131072];
goto fatal;
/* open logfile if not already open and writing to it */
(filebench_shm->log_fd < 0)) {
char path[MAXPATHLEN];
char *s;
*s = 0;
else
}
/*
* if logfile still not open, switch to LOG_ERROR level so
* it gets reported to stdout
*/
(filebench_shm->log_fd < 0)) {
}
/* open dumpfile if not already open and writing to it */
(*filebench_shm->dump_filename == 0))
return;
(filebench_shm->dump_fd < 0)) {
}
(filebench_shm->dump_fd < 0)) {
}
/* Only log greater than debug setting */
return;
#ifdef __STDC__
#else
char *fmt;
#endif
return;
}
/* Serialize messages to log */
if (filebench_shm->log_fd > 0) {
}
}
line);
} else {
line);
}
}
}
}
/*
* Stops the run and exits filebench. If filebench is
* currently running a workload, calls procflow_shutdown()
* to stop the run. Also closes and deletes shared memory.
*/
void
filebench_shutdown(int error) {
(void) unlink("/tmp/filebench_shm");
if (filebench_shm->allrunning)
}
/*
* Put the hostname in ${hostname}. The system supplied
* host name string is copied into an allocated string and
* the pointer to the string is placed in the supplied
* variable "var". If var->var_string already points to
* a string, the string is freed. The routine always
* returns zero (0).
*/
var_t *
{
char hoststr[128];
if (var->var_string)
return (0);
}
/*
* Put the date string in ${date}. The system supplied date is
* copied into an allocated string and the pointer to the string
* is placed in the supplied var_t's var_string. If
* var->var_string already points to a string, the string
* is freed. The routine always returns a pointer to the
* supplied var_t.
*/
var_t *
{
char datestr[128];
#ifdef HAVE_CFTIME
#else
struct tm t;
#endif
#ifdef HAVE_CFTIME
#else
#endif
if (var->var_string)
return (var);
}
extern char *fscriptname;
/*
* Put the script name in ${script}. The path name of the script
* used with this filebench run trimmed of the trailing ".f" and
* all leading subdirectories. The remaining script name is
* copied into the var_string field of the supplied variable
* "var". The routine always returns a pointer to the supplied
* var_t.
*/
var_t *
{
char *scriptstr;
char *f = fb_stralloc(fscriptname);
/* Trim the .f suffix */
if (*scriptstr == '.') {
*scriptstr = 0;
break;
}
}
free(f);
return (var);
}