提交 f089a081 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Merge branch 'scale-amd64' of git+ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

...@@ -65,26 +65,36 @@ namespace std { ...@@ -65,26 +65,36 @@ namespace std {
return static_cast<typename remove_reference<T>::type&&>(a); return static_cast<typename remove_reference<T>::type&&>(a);
} }
class ios_base {}; struct ostream { int next_width; };
class ostream : public ios_base {};
extern ostream cout; extern ostream cout;
static inline static inline
ostream& operator<<(ostream &s, const char *str) { ostream& operator<<(ostream &s, const char *str) {
if (!str)
str = "(null)";
int len = strlen(str);
cprintf("%s", str); cprintf("%s", str);
while (len < s.next_width) {
cprintf(" ");
len++;
}
s.next_width = 0;
return s; return s;
} }
static inline static inline
ostream& operator<<(ostream &s, u32 v) { ostream& operator<<(ostream &s, u32 v) {
cprintf("%d", v); char buf[32];
return s; snprintf(buf, sizeof(buf), "%d", v);
return s << buf;
} }
static inline static inline
ostream& operator<<(ostream &s, u64 v) { ostream& operator<<(ostream &s, u64 v) {
cprintf("%ld", v); char buf[32];
return s; snprintf(buf, sizeof(buf), "%ld", v);
return s << buf;
} }
static inline static inline
...@@ -94,7 +104,15 @@ namespace std { ...@@ -94,7 +104,15 @@ namespace std {
static inline ostream& endl(ostream &s) { s << "\n"; return s; } static inline ostream& endl(ostream &s) { s << "\n"; return s; }
static inline ostream& left(ostream &s) { return s; } static inline ostream& left(ostream &s) { return s; }
static inline const char *setw(int n) { return ""; }
struct ssetw { int _n; };
static inline ssetw setw(int n) { return { n }; }
static inline
ostream& operator<<(ostream &s, const ssetw &sw) {
s.next_width = sw._n;
return s;
}
} }
/* C++ runtime */ /* C++ runtime */
......
...@@ -307,6 +307,7 @@ void initnet(void); ...@@ -307,6 +307,7 @@ void initnet(void);
void initsched(void); void initsched(void);
void initlockstat(void); void initlockstat(void);
void initwq(void); void initwq(void);
void initsperf(void);
// other exported/imported functions // other exported/imported functions
void cmain(u64 mbmagic, u64 mbaddr); void cmain(u64 mbmagic, u64 mbaddr);
......
差异被折叠。
#pragma once
#include "scopedperf.hh"
extern scopedperf::ctrgroup_chain<scopedperf::tsc_ctr> *perfgroup;
...@@ -34,6 +34,7 @@ OBJS = \ ...@@ -34,6 +34,7 @@ OBJS = \
rnd.o \ rnd.o \
sampler.o \ sampler.o \
sched.o \ sched.o \
sperf.o \
spinlock.o \ spinlock.o \
swtch.o \ swtch.o \
string.o \ string.o \
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "fmt.hh" #include "fmt.hh"
#include <stddef.h> #include <stddef.h>
#include "sperf.hh"
#define BACKSPACE 0x100 #define BACKSPACE 0x100
...@@ -285,6 +286,9 @@ consoleintr(int (*getc)(void)) ...@@ -285,6 +286,9 @@ consoleintr(int (*getc)(void))
case C('F'): // kmem stats case C('F'): // kmem stats
kmemprint(); kmemprint();
break; break;
case C('Y'): // scopedperf stats
scopedperf::perfsum_base::printall();
break;
default: default:
if(c != 0 && input.e-input.r < INPUT_BUF){ if(c != 0 && input.e-input.r < INPUT_BUF){
c = (c == '\r') ? '\n' : c; c = (c == '\r') ? '\n' : c;
......
...@@ -63,6 +63,7 @@ __cxa_atexit(void (*f)(void*), void *p, void *d) ...@@ -63,6 +63,7 @@ __cxa_atexit(void (*f)(void*), void *p, void *d)
} }
void *__dso_handle; void *__dso_handle;
std::ostream std::cout;
namespace std { namespace std {
......
...@@ -95,6 +95,7 @@ cmain(u64 mbmagic, u64 mbaddr) ...@@ -95,6 +95,7 @@ cmain(u64 mbmagic, u64 mbaddr)
initpci(); initpci();
initnet(); initnet();
initidle(); initidle();
initsperf();
if (VERBOSE) if (VERBOSE)
cprintf("ncpu %d %lu MHz\n", ncpu, cpuhz / 1000000); cprintf("ncpu %d %lu MHz\n", ncpu, cpuhz / 1000000);
......
#include "types.h"
#include "kernel.hh"
#include "cpu.hh"
#include "cpputil.hh"
#include "spinlock.h"
#include "sperf.hh"
using namespace scopedperf;
ctrgroup_chain<tsc_ctr> *perfgroup;
void
initsperf()
{
static tsc_ctr tsc;
perfgroup = new ctrgroup_chain<tsc_ctr>(&tsc);
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
#include "vm.hh" #include "vm.hh"
#include "sperf.hh"
long long
sys_fork(int flags) sys_fork(int flags)
...@@ -85,6 +86,8 @@ sys_uptime(void) ...@@ -85,6 +86,8 @@ sys_uptime(void)
long long
sys_map(uptr addr, u64 len) sys_map(uptr addr, u64 len)
{ {
ANON_REGION(__func__, perfgroup);
vmnode *vmn = new vmnode(PGROUNDUP(len) / PGSIZE); vmnode *vmn = new vmnode(PGROUNDUP(len) / PGSIZE);
if (vmn == 0) if (vmn == 0)
return -1; return -1;
...@@ -100,6 +103,8 @@ sys_map(uptr addr, u64 len) ...@@ -100,6 +103,8 @@ sys_map(uptr addr, u64 len)
long long
sys_unmap(uptr addr, u64 len) sys_unmap(uptr addr, u64 len)
{ {
ANON_REGION(__func__, perfgroup);
uptr align_addr = PGROUNDDOWN(addr); uptr align_addr = PGROUNDDOWN(addr);
uptr align_len = PGROUNDUP(addr + len) - align_addr; uptr align_len = PGROUNDUP(addr + len) - align_addr;
if (myproc()->vmap->remove(align_addr, align_len) < 0) if (myproc()->vmap->remove(align_addr, align_len) < 0)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论