Rewrote timer code.

The new code is based on timestamps, rather than delays. This eliminates the
need to update every timer in timer_process(), which cost a non-trivial amount
of CPU time on low-end machines.

This involved changes to every user of the timer code, so this change almost
certainly introduces bugs.
This commit is contained in:
SarahW 2018-08-02 22:06:10 +01:00
commit a7d006b637
79 changed files with 1050 additions and 1033 deletions

View file

@ -47,7 +47,7 @@ typedef struct scsi_hd_data
int hd_id;
int callback;
pc_timer_t callback_timer;
scsi_bus_t *bus;
} scsi_hd_data;
@ -56,8 +56,6 @@ static void scsi_hd_callback(void *p)
{
scsi_hd_data *data = p;
data->callback = 0;
if (data->cmd_pos == CMD_POS_WAIT)
{
data->cmd_pos = data->new_cmd_pos;
@ -80,7 +78,7 @@ static void *scsi_hd_init(scsi_bus_t *bus, int id)
data->hd_id = id;
data->bus = bus;
timer_add(scsi_hd_callback, &data->callback, &data->callback, data);
timer_add(&data->callback_timer, scsi_hd_callback, data, 0);
return data;
}
@ -464,7 +462,7 @@ static int scsi_hd_command(uint8_t *cdb, void *p)
// pclog("SCSI_READ_6: addr=%08x len=%04x\n", data->addr, data->len);
data->cmd_pos = CMD_POS_WAIT;
data->callback = RW_DELAY;
timer_set_delay_u64(&data->callback_timer, RW_DELAY);
data->new_cmd_pos = CMD_POS_START_SECTOR;
data->sector_pos = 0;
@ -524,7 +522,7 @@ static int scsi_hd_command(uint8_t *cdb, void *p)
// pclog("SCSI_READ_10: addr=%08x len=%04x\n", data->addr, data->len);
data->cmd_pos = CMD_POS_WAIT;
data->callback = RW_DELAY;
timer_set_delay_u64(&data->callback_timer, RW_DELAY);
data->new_cmd_pos = CMD_POS_START_SECTOR;
data->sector_pos = 0;
@ -585,7 +583,7 @@ static int scsi_hd_command(uint8_t *cdb, void *p)
data->bytes_required = data->len * 512;
data->cmd_pos = CMD_POS_WAIT;
data->callback = RW_DELAY;
timer_set_delay_u64(&data->callback_timer, RW_DELAY);
data->new_cmd_pos = CMD_POS_TRANSFER;
data->sector_pos = 0;
@ -644,7 +642,7 @@ static int scsi_hd_command(uint8_t *cdb, void *p)
data->bytes_required = data->len * 512;
data->cmd_pos = CMD_POS_WAIT;
data->callback = RW_DELAY;
timer_set_delay_u64(&data->callback_timer, RW_DELAY);
data->new_cmd_pos = CMD_POS_TRANSFER;
data->sector_pos = 0;