Example #1
0
File: output.c Project: 3a9LL/panda
// Write a character to debug port(s).
static void
putc_debug(struct putcinfo *action, char c)
{
    if (! CONFIG_DEBUG_LEVEL)
        return;
    if (! CONFIG_COREBOOT)
        // Send character to debug port.
        outb(c, PORT_BIOS_DEBUG);
    if (c == '\n')
        debug_serial('\r');
    debug_serial(c);
}
Example #2
0
//Switch process by running the scheduler alogrithm
void CALLING_CONVENTION CX86Scheduler::schedule()
{
	if (!m_bInitialised)
		return;
	m_lock.acquireSpinlock();
	size_t curcpu = getHal()->getMultiprocessorIrq()->getCurrentCpuNum();
	iterator_t orig, itr = m_runningList.findValue(m_execProcess[curcpu]);
	PTHREAD	curthread = m_execProcess[curcpu];
	bool isCurrentlyRunning = true;
	PTHREAD thread = 0;

	while (isCurrentlyRunning)
	{
		itr = m_runningList.getNext(itr);
		if (!m_runningList.isEntry(itr))
			itr = m_runningList.getHead();
		thread = m_runningList.getValue(itr);
		isCurrentlyRunning = false;
		for (unsigned int n = 0; n < m_numcpus; n++)
		{
			if (m_execProcess[n] == thread)
				isCurrentlyRunning = true;
		}
		if (thread == curthread)
		{
			thread = NULL;
			break;
		}
	}
	//OK, we have our thread
	if (!thread)
	{
		m_lock.releaseSpinlock();
		return;
	}
	//Check for page context switch
	PPROCESS process = (PPROCESS)thread->parent;
	if (thread->parent != curthread->parent)
	{
		getMemoryManager()->getVMemMngr()->loadAddressSpace(process->addrspace);
	}
	if (setjmp(curthread->context) == 0)
	{
		debug_serial("CONTEXT SWITCH\n");
		
		//We get here if we want to change process. this will switch to a different process
		CAPIC* apic = (CAPIC*)getHal()->getMultiprocessorIrq();
		apic->setNewQuantum(20 + process->priority * 4);
		m_execProcess[curcpu] = thread;
		m_lock.releaseSpinlock();
		longjmp(thread->context, 1);
	}
	else
	{
		m_lock.releaseSpinlock();
	}
	getHal()->getIrqChip()->eoi(0);
}
Example #3
0
/**
 * Log a reference count change to the log file (if enabled).
 * This is called via the pipe_reference() and debug_reference() functions,
 * basically whenever a reference count is initialized or changed.
 *
 * \param p  the refcount being changed (the value is not changed here)
 * \param get_desc  a function which will be called to print an object's
 *                  name/pointer into a string buffer during logging
 * \param change  the reference count change which must be +/-1 or 0 when
 *                creating the object and initializing the refcount.
 */
void
debug_reference_slowpath(const struct pipe_reference *p,
                         debug_reference_descriptor get_desc, int change)
{
   assert(change >= -1);
   assert(change <= 1);

   if (debug_refcnt_state < 0)
      return;

   if (!debug_refcnt_state) {
      const char *filename = debug_get_option("GALLIUM_REFCNT_LOG", NULL);
      if (filename && filename[0])
         stream = fopen(filename, "wt");

      if (stream)
         debug_refcnt_state = 1;
      else
         debug_refcnt_state = -1;
   }

   if (debug_refcnt_state > 0) {
      struct debug_stack_frame frames[STACK_LEN];
      const char *symbols[STACK_LEN];
      char buf[1024];
      unsigned i;
      unsigned refcnt = p->count;
      unsigned serial;
      boolean existing = debug_serial((void *) p, &serial);

      debug_backtrace_capture(frames, 1, STACK_LEN);
      for (i = 0; i < STACK_LEN; ++i) {
         if (frames[i].function)
            symbols[i] = debug_symbol_name_cached(frames[i].function);
         else
            symbols[i] = 0;
      }

      get_desc(buf, p);

      if (!existing) {
         fprintf(stream, "<%s> %p %u Create\n", buf, (void *) p, serial);
         dump_stack(symbols);

         /* this is here to provide a gradual change even if we don't see
          * the initialization
          */
         for (i = 1; i <= refcnt - change; ++i) {
            fprintf(stream, "<%s> %p %u AddRef %u\n", buf, (void *) p,
                    serial, i);
            dump_stack(symbols);
         }
      }

      if (change) {
         fprintf(stream, "<%s> %p %u %s %u\n", buf, (void *) p, serial,
                 change > 0 ? "AddRef" : "Release", refcnt);
         dump_stack(symbols);
      }

      if (!refcnt) {
         debug_serial_delete((void *) p);
         fprintf(stream, "<%s> %p %u Destroy\n", buf, (void *) p, serial);
         dump_stack(symbols);
      }

      fflush(stream);
   }
}