prevent auto cycle adjusting to lower the cycles too much on heavy background load
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3080
This commit is contained in:
parent
4cb280c42a
commit
ae447b6477
4 changed files with 74 additions and 20 deletions
|
@ -16,6 +16,8 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: cpu.h,v 1.52 2008-01-16 20:16:31 c2woody Exp $ */
|
||||
|
||||
#ifndef DOSBOX_CPU_H
|
||||
#define DOSBOX_CPU_H
|
||||
|
||||
|
@ -36,6 +38,8 @@
|
|||
#define CPU_AUTODETERMINE_SHIFT 0x02
|
||||
#define CPU_AUTODETERMINE_MASK 0x03
|
||||
|
||||
#define CPU_CYCLES_LOWER_LIMIT 100
|
||||
|
||||
/* CPU Cycle Timing */
|
||||
extern Bit32s CPU_Cycles;
|
||||
extern Bit32s CPU_CycleLeft;
|
||||
|
@ -45,6 +49,7 @@ extern Bit32s CPU_CyclePercUsed;
|
|||
extern Bit32s CPU_CycleLimit;
|
||||
extern Bit64s CPU_IODelayRemoved;
|
||||
extern bool CPU_CycleAutoAdjust;
|
||||
extern bool CPU_SkipCycleAutoAdjust;
|
||||
extern Bitu CPU_AutoDetermineMode;
|
||||
|
||||
/* Some common Defines */
|
||||
|
@ -61,6 +66,11 @@ Bits CPU_Core_Dyn_X86_Trap_Run(void);
|
|||
Bits CPU_Core_Dynrec_Run(void);
|
||||
Bits CPU_Core_Dynrec_Trap_Run(void);
|
||||
|
||||
void CPU_Enable_SkipAutoAdjust(void);
|
||||
void CPU_Disable_SkipAutoAdjust(void);
|
||||
void CPU_Reset_AutoAdjust(void);
|
||||
|
||||
|
||||
//CPU Stuff
|
||||
|
||||
extern Bit16u parity_lookup[256];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2007 The DOSBox Team
|
||||
* Copyright (C) 2002-2008 The DOSBox Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: cpu.cpp,v 1.106 2007-12-07 20:49:19 c2woody Exp $ */
|
||||
/* $Id: cpu.cpp,v 1.107 2008-01-16 20:17:15 c2woody Exp $ */
|
||||
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
|
@ -57,8 +57,9 @@ Bit32s CPU_CycleUp = 0;
|
|||
Bit32s CPU_CycleDown = 0;
|
||||
Bit64s CPU_IODelayRemoved = 0;
|
||||
CPU_Decoder * cpudecoder;
|
||||
bool CPU_CycleAutoAdjust;
|
||||
Bitu CPU_AutoDetermineMode;
|
||||
bool CPU_CycleAutoAdjust = false;
|
||||
bool CPU_SkipCycleAutoAdjust = false;
|
||||
Bitu CPU_AutoDetermineMode = 0;
|
||||
|
||||
void CPU_Core_Full_Init(void);
|
||||
void CPU_Core_Normal_Init(void);
|
||||
|
@ -2074,6 +2075,29 @@ static void CPU_CycleDecrease(bool pressed) {
|
|||
}
|
||||
}
|
||||
|
||||
void CPU_Enable_SkipAutoAdjust(void) {
|
||||
if (CPU_CycleAutoAdjust) {
|
||||
CPU_CycleMax /= 2;
|
||||
if (CPU_CycleMax < CPU_CYCLES_LOWER_LIMIT)
|
||||
CPU_CycleMax = CPU_CYCLES_LOWER_LIMIT;
|
||||
}
|
||||
CPU_SkipCycleAutoAdjust=true;
|
||||
}
|
||||
|
||||
void CPU_Disable_SkipAutoAdjust(void) {
|
||||
CPU_SkipCycleAutoAdjust=false;
|
||||
}
|
||||
|
||||
|
||||
extern Bit32s ticksDone;
|
||||
extern Bit32u ticksScheduled;
|
||||
|
||||
void CPU_Reset_AutoAdjust(void) {
|
||||
CPU_IODelayRemoved = 0;
|
||||
ticksDone = 0;
|
||||
ticksScheduled = 0;
|
||||
}
|
||||
|
||||
class CPU: public Module_base {
|
||||
private:
|
||||
static bool inited;
|
||||
|
@ -2138,6 +2162,7 @@ public:
|
|||
CPU_AutoDetermineMode=CPU_AUTODETERMINE_NONE;
|
||||
CPU_CycleLeft=0;//needed ?
|
||||
CPU_Cycles=0;
|
||||
CPU_SkipCycleAutoAdjust=false;
|
||||
|
||||
std::string str;
|
||||
CommandLine cmd(0,section->Get_string("cycles"));
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: dosbox.cpp,v 1.125 2008-01-09 20:34:21 c2woody Exp $ */
|
||||
/* $Id: dosbox.cpp,v 1.126 2008-01-16 20:16:31 c2woody Exp $ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -117,8 +117,8 @@ bool SDLNetInited;
|
|||
static Bit32u ticksRemain;
|
||||
static Bit32u ticksLast;
|
||||
static Bit32u ticksAdded;
|
||||
static Bit32s ticksDone;
|
||||
static Bit32u ticksScheduled;
|
||||
Bit32s ticksDone;
|
||||
Bit32u ticksScheduled;
|
||||
bool ticksLocked;
|
||||
|
||||
static Bitu Normal_Loop(void) {
|
||||
|
@ -162,15 +162,17 @@ increaseticks:
|
|||
ticksRemain = 20;
|
||||
}
|
||||
ticksAdded = ticksRemain;
|
||||
if (CPU_CycleAutoAdjust) {
|
||||
if(ticksScheduled >= 250 || ticksDone >= 250 || (ticksAdded > 15 && ticksScheduled >= 5) ) {
|
||||
if (CPU_CycleAutoAdjust && !CPU_SkipCycleAutoAdjust) {
|
||||
if (ticksScheduled >= 250 || ticksDone >= 250 || (ticksAdded > 15 && ticksScheduled >= 5) ) {
|
||||
/* ratio we are aiming for is around 90% usage*/
|
||||
Bits ratio = (ticksScheduled * (CPU_CyclePercUsed*90*1024/100/100)) / ticksDone;
|
||||
Bit32s new_cmax = CPU_CycleMax;
|
||||
Bit64s cproc = (Bit64s)CPU_CycleMax * (Bit64s)ticksScheduled;
|
||||
if(cproc > 0) {
|
||||
if (cproc > 0) {
|
||||
/* ignore the cycles added due to the io delay code in order
|
||||
to have smoother auto cycle adjustments */
|
||||
double ratioremoved = (double) CPU_IODelayRemoved / (double) cproc;
|
||||
if(ratioremoved < 1.0) {
|
||||
if (ratioremoved < 1.0) {
|
||||
ratio = (Bits)((double)ratio * (1 - ratioremoved));
|
||||
if (ratio <= 1024)
|
||||
new_cmax = (CPU_CycleMax * ratio) / 1024;
|
||||
|
@ -179,19 +181,32 @@ increaseticks:
|
|||
}
|
||||
}
|
||||
|
||||
// maybe care about not going negative
|
||||
if (new_cmax > 0)
|
||||
CPU_CycleMax = new_cmax;
|
||||
if (CPU_CycleLimit > 0) {
|
||||
if (CPU_CycleMax>CPU_CycleLimit) CPU_CycleMax = CPU_CycleLimit;
|
||||
if (new_cmax<CPU_CYCLES_LOWER_LIMIT)
|
||||
new_cmax=CPU_CYCLES_LOWER_LIMIT;
|
||||
|
||||
/* ratios below 1% are considered to be dropouts due to
|
||||
temporary load imbalance, the cycles adjusting is skipped */
|
||||
if (ratio>10) {
|
||||
/* ratios below 12% along with a large time since the last update
|
||||
has taken place are most likely caused by heavy load through a
|
||||
different application, the cycles adjusting is skipped as well */
|
||||
if ((ratio>120) || (ticksDone<700)) {
|
||||
CPU_CycleMax = new_cmax;
|
||||
if (CPU_CycleLimit > 0) {
|
||||
if (CPU_CycleMax>CPU_CycleLimit) CPU_CycleMax = CPU_CycleLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
CPU_IODelayRemoved = 0;
|
||||
ticksDone = 0;
|
||||
ticksScheduled = 0;
|
||||
} else if (ticksAdded > 15) {
|
||||
/* ticksAdded > 15 but ticksScheduled < 5, lower the cycles
|
||||
but do not reset the scheduled/done ticks to take them into
|
||||
account during the next auto cycle adjustment */
|
||||
CPU_CycleMax /= 3;
|
||||
if (CPU_CycleMax < 100)
|
||||
CPU_CycleMax = 100;
|
||||
if (CPU_CycleMax < CPU_CYCLES_LOWER_LIMIT)
|
||||
CPU_CycleMax = CPU_CYCLES_LOWER_LIMIT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2007 The DOSBox Team
|
||||
* Copyright (C) 2002-2008 The DOSBox Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: sdlmain.cpp,v 1.137 2007-12-12 13:37:38 qbix79 Exp $ */
|
||||
/* $Id: sdlmain.cpp,v 1.138 2008-01-16 20:17:15 c2woody Exp $ */
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
|
@ -45,6 +45,7 @@
|
|||
#include "mapper.h"
|
||||
#include "vga.h"
|
||||
#include "keyboard.h"
|
||||
#include "cpu.h"
|
||||
|
||||
//#define DISABLE_JOYSTICK
|
||||
|
||||
|
@ -309,6 +310,7 @@ void GFX_ResetScreen(void) {
|
|||
if (sdl.draw.callback)
|
||||
(sdl.draw.callback)( GFX_CallBackReset );
|
||||
GFX_Start();
|
||||
CPU_Reset_AutoAdjust();
|
||||
}
|
||||
|
||||
static int int_log2 (int val) {
|
||||
|
@ -1198,6 +1200,7 @@ void GFX_Events() {
|
|||
if (sdl.desktop.fullscreen && !sdl.mouse.locked)
|
||||
GFX_CaptureMouse();
|
||||
SetPriority(sdl.priority.focus);
|
||||
CPU_Disable_SkipAutoAdjust();
|
||||
} else {
|
||||
if (sdl.mouse.locked) {
|
||||
#ifdef WIN32
|
||||
|
@ -1211,6 +1214,7 @@ void GFX_Events() {
|
|||
}
|
||||
SetPriority(sdl.priority.nofocus);
|
||||
MAPPER_LosingFocus();
|
||||
CPU_Enable_SkipAutoAdjust();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue