Minor schedule.c optimization

This commit is contained in:
Nathan Woods 2013-03-28 12:45:22 +00:00
parent ecf2facc0a
commit c00f72eb4f
4 changed files with 51 additions and 19 deletions

View File

@ -278,6 +278,21 @@ void device_execute_interface::set_irq_acknowledge_callback(device_irq_acknowled
m_driver_irq_legacy = NULL;
}
//-------------------------------------------------
// suspend_resume_changed
//-------------------------------------------------
void device_execute_interface::suspend_resume_changed()
{
// inform the scheduler
device().machine().scheduler().suspend_resume_changed();
// if we're active, synchronize
abort_timeslice();
}
//-------------------------------------------------
// suspend - set a suspend reason for this device
//-------------------------------------------------
@ -288,9 +303,7 @@ if (TEMPLOG) printf("suspend %s (%X)\n", device().tag(), reason);
// set the suspend reason and eat cycles flag
m_nextsuspend |= reason;
m_nexteatcycles = eatcycles;
// if we're active, synchronize
abort_timeslice();
suspend_resume_changed();
}
@ -304,9 +317,7 @@ void device_execute_interface::resume(UINT32 reason)
if (TEMPLOG) printf("resume %s (%X)\n", device().tag(), reason);
// clear the suspend reason and eat cycles flag
m_nextsuspend &= ~reason;
// if we're active, synchronize
abort_timeslice();
suspend_resume_changed();
}

View File

@ -329,6 +329,7 @@ private:
static void static_trigger_periodic_interrupt(running_machine &machine, void *ptr, int param);
void trigger_periodic_interrupt();
void suspend_resume_changed();
attoseconds_t minimum_quantum() const;
};

View File

@ -348,6 +348,7 @@ device_scheduler::device_scheduler(running_machine &machine) :
m_callback_timer(NULL),
m_callback_timer_modified(false),
m_callback_timer_expire_time(attotime::zero),
m_suspend_changes_pending(true),
m_quantum_list(machine.respool()),
m_quantum_allocator(machine.respool()),
m_quantum_minimum(ATTOSECONDS_IN_NSEC(1) / 1000)
@ -412,6 +413,30 @@ bool device_scheduler::can_save() const
}
//-------------------------------------------------
// apply_suspend_changes - applies suspend/resume
// changes to all device_execute_interfaces
//-------------------------------------------------
inline void device_scheduler::apply_suspend_changes()
{
UINT32 suspendchanged = 0;
for (device_execute_interface *exec = m_execute_list; exec != NULL; exec = exec->m_nextexec)
{
suspendchanged |= exec->m_suspend ^ exec->m_nextsuspend;
exec->m_suspend = exec->m_nextsuspend;
exec->m_nextsuspend &= ~SUSPEND_REASON_TIMESLICE;
exec->m_eatcycles = exec->m_nexteatcycles;
}
// recompute the execute list if any CPUs changed their suspension state
if (suspendchanged != 0)
rebuild_execute_list();
else
m_suspend_changes_pending = false;
}
//-------------------------------------------------
// timeslice - execute all devices for a single
// timeslice
@ -441,19 +466,9 @@ void device_scheduler::timeslice()
LOG(("------------------\n"));
LOG(("cpu_timeslice: target = %s\n", target.as_string()));
// apply pending suspension changes
UINT32 suspendchanged = 0;
for (device_execute_interface *exec = m_execute_list; exec != NULL; exec = exec->m_nextexec)
{
suspendchanged |= exec->m_suspend ^ exec->m_nextsuspend;
exec->m_suspend = exec->m_nextsuspend;
exec->m_nextsuspend &= ~SUSPEND_REASON_TIMESLICE;
exec->m_eatcycles = exec->m_nexteatcycles;
}
// recompute the execute list if any CPUs changed their suspension state
if (suspendchanged != 0)
rebuild_execute_list();
// do we have pending suspension changes?
if (m_suspend_changes_pending)
apply_suspend_changes();
// loop over non-suspended CPUs
for (device_execute_interface *exec = m_execute_list; exec != NULL; exec = exec->m_nextexec)
@ -694,6 +709,8 @@ void device_scheduler::postload()
while ((timer = private_list.detach_head()) != NULL)
timer_list_insert(*timer);
m_suspend_changes_pending = true;
// report the timer state after a log
logerror("After resetting/reordering timers:\n");
dump_timers();

View File

@ -164,6 +164,7 @@ public:
void abort_timeslice();
void trigger(int trigid, attotime after = attotime::zero);
void boost_interleave(attotime timeslice_time, attotime boost_duration);
void suspend_resume_changed() { m_suspend_changes_pending = true; }
// timers, specified by callback/name
emu_timer *timer_alloc(timer_expired_delegate callback, void *ptr = NULL);
@ -196,6 +197,7 @@ private:
// scheduling helpers
void compute_perfect_interleave();
void rebuild_execute_list();
void apply_suspend_changes();
void add_scheduling_quantum(attotime quantum, attotime duration);
// timer helpers
@ -217,6 +219,7 @@ private:
emu_timer * m_callback_timer; // pointer to the current callback timer
bool m_callback_timer_modified; // true if the current callback timer was modified
attotime m_callback_timer_expire_time; // the original expiration time
bool m_suspend_changes_pending; // suspend/resume changes are pending
// scheduling quanta
class quantum_slot