Beispiel #1
0
void RawDecoder::stats(char* wrk)
{
	/* pull stats out of reassembler */
	setstat(STAT_BADOFF, reasm_.badoff());
	setstat(STAT_HUGEFRM, reasm_.hugefrm());
	Decoder::stats(wrk);
}
Beispiel #2
0
static void
icacheinsert(u8int score[VtScoreSize], IAddr *ia, int state)
{
	IEntry *ie;

	if((ie = poplast(&icache.free)) == nil && (ie = evictlru()) == nil){
		addstat(StatIcacheStall, 1);
		while((ie = poplast(&icache.free)) == nil && (ie = evictlru()) == nil){
			// Could safely return here if state == IEClean.
			// But if state == IEDirty, have to wait to make
			// sure we don't lose an index write.  
			// Let's wait all the time.
			flushdcache();
			kickicache();
			rsleep(&icache.full);
		}
		addstat(StatIcacheStall, -1);
	}

	memmove(ie->score, score, VtScoreSize);
	ie->state = state;
	ie->ia = *ia;
	if(state == IEClean){
		addstat(StatIcachePrefetch, 1);
		pushfirst(&icache.clean, ie);
	}else{
		addstat(StatIcacheWrite, 1);
		assert(state == IEDirty);
		icache.ndirty++;
		setstat(StatIcacheDirty, icache.ndirty);
		delaykickicache();
		pushfirst(&icache.dirty, ie);
	}
	ihashinsert(icache.hash, ie);
}
Beispiel #3
0
bool
BCU1SerialLowLevelDriver::startsync ()
{
  int to = 0;
  int s = getstat ();
  setstat (s | TIOCM_RTS);
  while (!(getstat () & TIOCM_CTS))
    {
      to++;
      if (to > 0x10000)
	return false;
    }
  TRACEPRINTF (t, 0, this, "Startsync");
  return true;
}
Beispiel #4
0
void
initicache(u32int mem0)
{
	u32int mem;
	int i, entries, scache;
	
	icache.full.l = &icache.lock;

	mem = mem0;
	entries = mem / (sizeof(IEntry)+sizeof(IEntry*));
	scache = (entries/8) / ArenaCIGSize;
	entries -= entries/8;
	if(scache < 4)
		scache = 4;
	if(scache > 16)
		scache = 16;
	if(entries < 1000)
		entries = 1000;
fprint(2, "icache %,d bytes = %,d entries; %d scache\n", mem0, entries, scache);

	icache.clean.prev = icache.clean.next = &icache.clean;
	icache.dirty.prev = icache.dirty.next = &icache.dirty;
	icache.free.prev = icache.free.next = &icache.free;
	
	icache.hash = mkihash(entries);
	icache.nentries = entries;
	setstat(StatIcacheSize, entries);
	icache.entries = vtmallocz(entries*sizeof icache.entries[0]);
	icache.maxdirty = entries / 2;
	for(i=0; i<entries; i++)
		pushfirst(&icache.free, &icache.entries[i]);

	icache.nsum = scache;
	icache.sum = vtmallocz(scache*sizeof icache.sum[0]);
	icache.sum[0] = vtmallocz(scache*sizeof icache.sum[0][0]);
	icache.nsentries = scache * ArenaCIGSize;
	icache.sentries = vtmallocz(scache*ArenaCIGSize*sizeof icache.sentries[0]);
	icache.shash = mkihash(scache*ArenaCIGSize);
	for(i=0; i<scache; i++){
		icache.sum[i] = icache.sum[0] + i;
		icache.sum[i]->entries = icache.sentries + i*ArenaCIGSize;
	}
}
Beispiel #5
0
/*
 * The singly-linked non-circular list of index entries ie
 * has been written to disk.  Move them to the clean list.
 */
void
icacheclean(IEntry *ie)
{
	IEntry *next;
	
	trace(TraceProc, "icacheclean enter");
	qlock(&icache.lock);
	for(; ie; ie=next){
		assert(ie->state == IEDirty);
		next = ie->nextdirty;
		ie->nextdirty = nil;
		popout(ie); /* from icache.dirty */
		icache.ndirty--;
		ie->state = IEClean;
		pushfirst(&icache.clean, ie);
	}
	setstat(StatIcacheDirty, icache.ndirty);
	rwakeupall(&icache.full);
	qunlock(&icache.lock);
	trace(TraceProc, "icacheclean exit");
}
Beispiel #6
0
BCU1SerialLowLevelDriver::BCU1SerialLowLevelDriver (const char *dev,
						    Trace * tr)
{
  struct termios ti;

  t = tr;
  pth_sem_init (&in_signal);
  pth_sem_init (&out_signal);
  pth_sem_init (&send_empty);
  pth_sem_set_value (&send_empty, 1);
  getwait = pth_event (PTH_EVENT_SEM, &out_signal);

  TRACEPRINTF (t, 1, this, "Open");
  fd = open (dev, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC);
  if (fd == -1)
    return;
  set_low_latency (fd, &sold);

  close (fd);
  fd = open (dev, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC);
  if (fd == -1)
    return;

  if (tcgetattr (fd, &told))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }

  if (tcgetattr (fd, &ti))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }
  ti.c_cflag = CS8 | CLOCAL | CREAD;
  ti.c_iflag = IGNBRK | INPCK | ISIG;
  ti.c_oflag = 0;
  ti.c_lflag = 0;
  ti.c_cc[VTIME] = 1;
  ti.c_cc[VMIN] = 0;
  cfsetospeed (&ti, B9600);
  cfsetispeed (&ti, 0);

  if (tcsetattr (fd, TCSAFLUSH, &ti))
    {
      restore_low_latency (fd, &sold);
      close (fd);
      fd = -1;
      return;
    }

  setstat (getstat () & ~(TIOCM_RTS | TIOCM_CTS));
  while ((getstat () & TIOCM_CTS));

  Start ();
  TRACEPRINTF (t, 1, this, "Opened");
}
Beispiel #7
0
void
BCU1SerialLowLevelDriver::Run (pth_sem_t * stop1)
{
  pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
  pth_event_t input = pth_event (PTH_EVENT_SEM, &in_signal);
  pth_event_t timeout = pth_event (PTH_EVENT_RTIME, pth_time (0, 10));
  while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
    {
      int error;
      timeout =
	pth_event (PTH_EVENT_RTIME | PTH_MODE_REUSE, timeout,
		   pth_time (0, 150));
      pth_event_concat (stop, input, timeout, NULL);
      pth_wait (stop);
      pth_event_isolate (stop);
      pth_event_isolate (input);
      timeout =
	pth_event (PTH_EVENT_RTIME | PTH_MODE_REUSE, timeout,
		   pth_time (0, 200));
      pth_event_concat (stop, timeout, NULL);

      struct timeval v1, v2;
      gettimeofday (&v1, 0);

      CArray e;
      CArray r;
      uchar s;
      if (!inqueue.isempty ())
	{
	  const CArray & c = inqueue.top ();
	  e.resize (c () + 1);
	  s = c () & 0x1f;
	  s |= 0x20;
	  s |= 0x80 * bitcount (s);
	  e[0] = s;
	  e.setpart (c, 1);
	}
      else
	{
	  e.resize (1);
	  e[0] = 0xff;
	}
      if (!startsync ())
	{
	  error = 1;
	  goto err;
	}
      if (!exchange (e[0], s, stop))
	{
	  error = 3;
	  goto err;
	}
      if (!endsync ())
	{
	  error = 2;
	  goto err;
	}
      if (s == 0xff && e[0] != 0xff)
	{
	  for (unsigned i = 1; i < e (); i++)
	    {
	      if (!startsync ())
		{
		  error = 1;
		  goto err;
		}
	      if (!exchange (e[i], s, stop))
		{
		  error = 3;
		  goto err;
		}
	      if (endsync ())
		{
		  error = 2;
		  goto err;
		}
	    }
	  if (s != 0x00)
	    {
	      error = 10;
	      goto err;
	    }
	  inqueue.get ();
	  TRACEPRINTF (t, 0, this, "Sent");
	  pth_sem_dec (&in_signal);
	  if (inqueue.isempty ())
	    pth_sem_set_value (&send_empty, 1);
	}
      else if (s != 0xff)
	{
	  r.resize ((s & 0x1f));
	  for (unsigned i = 0; i < (s & 0x1f); i++)
	    {
	      if (!startsync ())
		{
		  error = 1;
		  goto err;
		}
	      if (!exchange (0, r[i], stop))
		{
		  error = 3;
		  goto err;
		}
	      if (!endsync ())
		{
		  error = 2;
		  goto err;
		}
	    }
	  TRACEPRINTF (t, 0, this, "Recv");
	  outqueue.put (new CArray (r));
	  pth_sem_inc (&out_signal, 1);
	}
      gettimeofday (&v2, 0);
      TRACEPRINTF (t, 1, this, "Recvtime: %d",
		   v2.tv_sec * 1000000L + v2.tv_usec -
		   (v1.tv_sec * 1000000L + v1.tv_usec));

      if (0)
	{
	err:
	  gettimeofday (&v2, 0);
	  TRACEPRINTF (t, 1, this, "ERecvtime: %d",
		       v2.tv_sec * 1000000L + v2.tv_usec -
		       (v1.tv_sec * 1000000L + v1.tv_usec));
	  setstat (getstat () & ~(TIOCM_RTS | TIOCM_CTS));
	  pth_usleep (2000);
	  while ((getstat () & TIOCM_CTS));
	  TRACEPRINTF (t, 0, this, "Restart %d", error);
	}

      pth_event_isolate (timeout);
    }
  pth_event_free (timeout, PTH_FREE_THIS);
  pth_event_free (stop, PTH_FREE_THIS);
  pth_event_free (input, PTH_FREE_THIS);
}
Beispiel #8
0
/*
 * The out of control system call
 * This is audit kitchen sink aka auditadm, aka auditon
 */
int
auditctl(
	int	cmd,
	caddr_t data,
	int	length)
{
	int result;

	switch (cmd) {
	case A_GETAMASK:
	case A_GETCOND:
	case A_GETCAR:
	case A_GETCLASS:
	case A_GETCWD:
	case A_GETKAUDIT:
	case A_GETKMASK:
	case A_GETPINFO:
	case A_GETPINFO_ADDR:
	case A_GETPOLICY:
	case A_GETQCTRL:
	case A_GETSTAT:
		if (secpolicy_audit_getattr(CRED(), B_FALSE) != 0)
			return (EPERM);
		break;
	default:
		if (secpolicy_audit_config(CRED()) != 0)
			return (EPERM);
		break;
	}

	switch (cmd) {
	case A_GETPOLICY:
		result = getpolicy(data);
		break;
	case A_SETPOLICY:
		result = setpolicy(data);
		break;
	case A_GETAMASK:
		result = getamask(data);
		break;
	case A_SETAMASK:
		result = setamask(data);
		break;
	case A_GETKMASK:
		result = getkmask(data);
		break;
	case A_SETKMASK:
		result = setkmask(data);
		break;
	case A_GETKAUDIT:
		result = getkaudit(data, length);
		break;
	case A_SETKAUDIT:
		result = setkaudit(data, length);
		break;
	case A_GETQCTRL:
		result = getqctrl(data);
		break;
	case A_SETQCTRL:
		result = setqctrl(data);
		break;
	case A_GETCWD:
		result = getcwd(data, length);
		break;
	case A_GETCAR:
		result = getcar(data, length);
		break;
	case A_GETSTAT:
		result = getstat(data);
		break;
	case A_SETSTAT:
		result = setstat(data);
		break;
	case A_SETUMASK:
		result = setumask(data);
		break;
	case A_SETSMASK:
		result = setsmask(data);
		break;
	case A_GETCOND:
		result = getcond(data);
		break;
	case A_SETCOND:
		result = setcond(data);
		break;
	case A_GETCLASS:
		result = getclass(data);
		break;
	case A_SETCLASS:
		result = setclass(data);
		break;
	case A_GETPINFO:
		result = getpinfo(data);
		break;
	case A_GETPINFO_ADDR:
		result = getpinfo_addr(data, length);
		break;
	case A_SETPMASK:
		result = setpmask(data);
		break;
	default:
		result = EINVAL;
		break;
	}
	return (result);
}