Machine/port issues

This commit is contained in:
James Cherry 2021-02-14 08:44:35 -08:00
parent 9003fb279d
commit 181a9f2ccf
17 changed files with 341 additions and 195 deletions

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include "Machine.hh"
#include "StringUtil.hh"
#include "Vector.hh"
#include "Sta.hh"

View File

@ -17,7 +17,6 @@
#pragma once
#include <stdarg.h>
#include "Machine.hh"
#include "DisallowCopyAssign.hh"
#include "Map.hh"
#include "StringUtil.hh"

View File

@ -46,8 +46,6 @@
#endif // _MSC_VER
#if defined(_WINDOWS) || defined(_WIN32)
// Export class definitions to DLLs.
#define DllExport __declspec(dllexport)
#include <stdarg.h>
#define va_copy(d,s) ((d)=(s))
#define strcasecmp _stricmp
@ -60,8 +58,6 @@
int vsnprint(char *str, size_t size, const char *fmt, va_list args);
}
#else
#define DllExport
#include <stdint.h> // intptr_t
#define vsnprint vsnprintf
#endif // _WINDOWS

View File

@ -20,7 +20,6 @@
#include <stdarg.h>
#include <string>
#include <mutex>
#include "Machine.hh"
#include "DisallowCopyAssign.hh"
struct Tcl_Interp;

View File

@ -18,7 +18,6 @@
#include <string>
#include "Machine.hh"
#include "DisallowCopyAssign.hh"
#include "StringSeq.hh"
#include "LibertyClass.hh"

View File

@ -19,7 +19,6 @@
#include <stdarg.h>
#include <string.h>
#include <string>
#include "Machine.hh"
#include "Vector.hh"
namespace sta {

View File

@ -16,7 +16,6 @@
#pragma once
#include "Machine.hh"
#include "DisallowCopyAssign.hh"
#include "Vector.hh"
#include "Transition.hh"

View File

@ -18,7 +18,6 @@
#include <functional>
#include "Machine.hh"
#include "DisallowCopyAssign.hh"
#include "Vector.hh"
#include "Map.hh"

View File

@ -16,7 +16,6 @@
#pragma once
#include "Machine.hh"
#include "Zlib.hh"
#include "Map.hh"
#include "StringSeq.hh"

View File

@ -16,6 +16,7 @@
#include "Sta.hh"
#include "Machine.hh"
#include "DispatchQueue.hh"
#include "ReportTcl.hh"
#include "Debug.hh"

View File

@ -35,6 +35,7 @@
#include <limits>
#include "Machine.hh"
#include "StaConfig.hh" // STA_VERSION
#include "Stats.hh"
#include "Report.hh"

View File

@ -14,189 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#ifdef WIN32
#include <stdio.h>
#include <windows.h> // GetSystemInfo
#include "StaConfig.hh"
namespace sta {
// Windows returns -1 if the string does not fit rather than the
// required string length as the standard specifies.
int
vsnprint(char *str, size_t size, const char *fmt, va_list args)
{
// Copy args before using them because consumption is destructive.
va_list args_copy1;
va_copy(args_copy1, args);
int length = vsnprintf(str, size, fmt, args);
while (length < 0) {
size *= 2;
char *buffer = new char[size];
va_list args_copy2;
va_copy(args_copy2, args_copy1);
length = vsnprintf(buffer, size, fmt, args_copy2);
delete [] buffer;
}
return length;
}
int
processorCount()
{
#if HAVE_PTHREAD_H
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
#if defined(WIN32)
#include "MachineWin32.cc"
#elif defined(__APPLE__)
#include "MachineApple.cc"
#elif defined(__linux__)
#include "MachineLinux.cc"
#else
return 1;
#include "MachineUnknown.cc"
#endif
}
void
initElapsedTime()
{
}
double
elapsedRunTime()
{
return 0.0;
}
double
userRunTime()
{
return 0.0;
}
double
systemRunTime()
{
return 0.0;
}
size_t
memoryUsage()
{
return 0;
}
}
#endif // WIN32
// Common to macos and linux
#if defined(__APPLE__) || defined(__linux__)
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "StaConfig.hh"
#include "StringUtil.hh"
namespace sta {
static struct timeval elapsed_begin_time_;
int
processorCount()
{
#if HAVE_PTHREAD_H
return sysconf(_SC_NPROCESSORS_CONF);
#else
return 1;
#endif
}
void
initElapsedTime()
{
struct timezone tz;
gettimeofday(&elapsed_begin_time_, &tz);
}
double
elapsedRunTime()
{
static struct timeval time;
struct timezone tz;
gettimeofday(&time, &tz);
return time.tv_sec - elapsed_begin_time_.tv_sec
+ (time.tv_usec - elapsed_begin_time_.tv_usec) * 1E-6;
}
double
userRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
}
double
systemRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
}
}
#endif // __APPLE__ || __linux__
#ifdef __linux__
namespace sta {
// rusage->ru_maxrss is not set in linux so read it from /proc.
size_t
memoryUsage()
{
string proc_filename;
stringPrint(proc_filename, "/proc/%d/status", getpid());
size_t memory = 0;
FILE *status = fopen(proc_filename.c_str(), "r");
if (status) {
const size_t line_length = 128;
char line[line_length];
while (fgets(line, line_length, status) != nullptr) {
char *field = strtok(line, " \t");
if (stringEq(field, "VmRSS:")) {
char *size = strtok(nullptr, " \t");
if (size) {
char *ignore;
// VmRSS is in kilobytes.
memory = strtol(size, &ignore, 10) * 1000;
break;
}
}
}
fclose(status);
}
return memory;
}
}
#endif // __linux__
#ifdef __APPLE__
namespace sta {
size_t
memoryUsage()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_maxrss;
}
}
#endif // __apple__

83
util/MachineApple.cc Normal file
View File

@ -0,0 +1,83 @@
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "StaConfig.hh"
#include "StringUtil.hh"
namespace sta {
static struct timeval elapsed_begin_time_;
int
processorCount()
{
#if HAVE_PTHREAD_H
return sysconf(_SC_NPROCESSORS_CONF);
#else
return 1;
#endif
}
void
initElapsedTime()
{
struct timezone tz;
gettimeofday(&elapsed_begin_time_, &tz);
}
double
elapsedRunTime()
{
static struct timeval time;
struct timezone tz;
gettimeofday(&time, &tz);
return time.tv_sec - elapsed_begin_time_.tv_sec
+ (time.tv_usec - elapsed_begin_time_.tv_usec) * 1E-6;
}
double
userRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
}
double
systemRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
}
size_t
memoryUsage()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_maxrss;
}
} // namespace

103
util/MachineLinux.cc Normal file
View File

@ -0,0 +1,103 @@
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "StaConfig.hh"
#include "StringUtil.hh"
namespace sta {
static struct timeval elapsed_begin_time_;
int
processorCount()
{
#if HAVE_PTHREAD_H
return sysconf(_SC_NPROCESSORS_CONF);
#else
return 1;
#endif
}
void
initElapsedTime()
{
struct timezone tz;
gettimeofday(&elapsed_begin_time_, &tz);
}
double
elapsedRunTime()
{
static struct timeval time;
struct timezone tz;
gettimeofday(&time, &tz);
return time.tv_sec - elapsed_begin_time_.tv_sec
+ (time.tv_usec - elapsed_begin_time_.tv_usec) * 1E-6;
}
double
userRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
}
double
systemRunTime()
{
struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage);
return rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
}
// rusage->ru_maxrss is not set in linux so read it from /proc.
size_t
memoryUsage()
{
string proc_filename;
stringPrint(proc_filename, "/proc/%d/status", getpid());
size_t memory = 0;
FILE *status = fopen(proc_filename.c_str(), "r");
if (status) {
const size_t line_length = 128;
char line[line_length];
while (fgets(line, line_length, status) != nullptr) {
char *field = strtok(line, " \t");
if (stringEq(field, "VmRSS:")) {
char *size = strtok(nullptr, " \t");
if (size) {
char *ignore;
// VmRSS is in kilobytes.
memory = strtol(size, &ignore, 10) * 1000;
break;
}
}
}
fclose(status);
}
return memory;
}
} // namespace

56
util/MachineUnknown.cc Normal file
View File

@ -0,0 +1,56 @@
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
namespace sta {
int
processorCount()
{
return 1;
}
void
initElapsedTime()
{
}
double
elapsedRunTime()
{
return 0.0;
}
double
userRunTime()
{
return 0.0;
}
double
systemRunTime()
{
return 0.0;
}
size_t
memoryUsage()
{
return 0;
}
} // namespace

88
util/MachineWin32.cc Normal file
View File

@ -0,0 +1,88 @@
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#include <stdio.h>
#include <windows.h> // GetSystemInfo
#include "StaConfig.hh" // HAVE_PTHREAD_H
namespace sta {
// Windows returns -1 if the string does not fit rather than the
// required string length as the standard specifies.
int
vsnprint(char *str, size_t size, const char *fmt, va_list args)
{
// Copy args before using them because consumption is destructive.
va_list args_copy1;
va_copy(args_copy1, args);
int length = vsnprintf(str, size, fmt, args);
while (length < 0) {
size *= 2;
char *buffer = new char[size];
va_list args_copy2;
va_copy(args_copy2, args_copy1);
length = vsnprintf(buffer, size, fmt, args_copy2);
delete [] buffer;
}
return length;
}
int
processorCount()
{
#if HAVE_PTHREAD_H
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
#else
return 1;
#endif
}
void
initElapsedTime()
{
}
double
elapsedRunTime()
{
return 0.0;
}
double
userRunTime()
{
return 0.0;
}
double
systemRunTime()
{
return 0.0;
}
size_t
memoryUsage()
{
return 0;
}
} // namespace

View File

@ -20,6 +20,7 @@
#include <cstdlib> // exit
#include <cstring> // strlen
#include "Machine.hh"
#include "Error.hh"
namespace sta {