From: ljsebald <ljs...@us...> - 2023-12-29 01:17:08
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via b8a7ada874b94303dca9288ecb0457ef1083051b (commit) via b70501e99cc7e2d1a62b343c93926a3ec26ea71a (commit) via c6ce6113bdbaf274c5ea1fcd000fd626a90fc6ec (commit) from d59f16e00557ccd548aa58b634d6c3604fd4cc11 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b8a7ada874b94303dca9288ecb0457ef1083051b Author: Falco Girgis <gyr...@gm...> Date: Thu Dec 28 19:16:30 2023 -0600 Separate Performance Counter Driver (#425) * Created separate performance counter driver - Moved the performance counter API out of the timer API and into its own files: arch/perfctr.h + kernel/perfctr.c - Implemented timer_ns_gettime64() function which previously had a name conflict with the performance counter version - Revamped the performance counter API by making it all strongly-typed, adding a few functions, and fleshing out the doxygen further - Performance counter timer falls back to timer_ns_gettime64() gracefull now when it has been disabled * Renamed API function + fixed Doxygen warnings * Addressing review feedback (typo). * Added arch/perfctr.h to main kos.h include * Added disclaimer to perf_ctr_timer_enable() docs - Explicitly mentioning it's only counting active CPU cycles, not during SLEEP. * Added a disclaimer to perf_cntr_timer_ns() as well * Doxygen update - Apparently \note and \warning do not work when used within the descriptions for enumeration values. commit b70501e99cc7e2d1a62b343c93926a3ec26ea71a Merge: d59f16e c6ce611 Author: Lawrence Sebald <ljs...@us...> Date: Thu Dec 28 17:15:22 2023 -0500 Merge pull request #442 from KallistiOS/over_600 Remove non-functional 800x608 mode commit c6ce6113bdbaf274c5ea1fcd000fd626a90fc6ec Author: QuzarDC <qu...@co...> Date: Thu Dec 28 15:04:55 2023 -0500 Remove non-functional 800x600 mode ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG | 1 + examples/dreamcast/libdream/800x608/800x608.c | 54 ----- examples/dreamcast/libdream/800x608/Makefile | 4 - examples/dreamcast/libdream/Makefile | 2 +- examples/dreamcast/libdream/README | 2 - include/kos.h | 1 + kernel/arch/dreamcast/hardware/video.c | 34 ---- kernel/arch/dreamcast/include/arch/timer.h | 197 ++---------------- kernel/arch/dreamcast/include/dc/perfctr.h | 278 ++++++++++++++++++++++++++ kernel/arch/dreamcast/include/dc/video.h | 3 - kernel/arch/dreamcast/kernel/Makefile | 2 +- kernel/arch/dreamcast/kernel/init.c | 3 +- kernel/arch/dreamcast/kernel/perfctr.c | 101 ++++++++++ kernel/arch/dreamcast/kernel/timer.c | 86 +------- 14 files changed, 412 insertions(+), 356 deletions(-) delete mode 100644 examples/dreamcast/libdream/800x608/800x608.c delete mode 100644 examples/dreamcast/libdream/800x608/Makefile create mode 100644 kernel/arch/dreamcast/include/dc/perfctr.h create mode 100644 kernel/arch/dreamcast/kernel/perfctr.c diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 87b849a..4597f56 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -213,6 +213,7 @@ KallistiOS version 2.1.0 ----------------------------------------------- - DC Improved performance of IRQ context save / restore [PC] - DC Increased resolution of TMU timers + date/time functions [FG && PC] - *** Increased resolution of clock() and CLOCKS_PER_SEC to microseconds [FG] +- DC Created separate performance counter driver and enhanced API [FG] KallistiOS version 2.0.0 ----------------------------------------------- - DC Broadband Adapter driver fixes [Megan Potter == MP] diff --git a/examples/dreamcast/libdream/800x608/800x608.c b/examples/dreamcast/libdream/800x608/800x608.c deleted file mode 100644 index 15da9b1..0000000 --- a/examples/dreamcast/libdream/800x608/800x608.c +++ /dev/null @@ -1,54 +0,0 @@ -/* This sample program shows off 800x608, the mythical "unsupported" video - mode that Sega will probably complain doesn't work (like they did for - our 320x240 modes earlier on ;-). This will probably only work on a VGA - monitor and I highly recommend that you don't try it on a non-multisync. - Still needs some tweaking. - - In here I also demonstrate how to use the bfont BIOS font routines, and - how to initialize only selected parts of KOS (resulting in a much - smaller and less polluted binary). - - */ - -#include <kos.h> - -#define W 800 -#define H 608 - -int main(int argc, char **argv) { - int x, y; - - /* Press all buttons to exit */ - cont_btn_callback(0, CONT_START | CONT_A | CONT_B | CONT_X | CONT_Y, - (cont_btn_callback_t)arch_exit); - - printf("\n\n*** NOTE: This example is still a work in progress\n"); - printf(" as this resolution is not fully supported! ***\n\n"); - - /* Set video mode */ - vid_set_mode(DM_800x608, PM_RGB565); - - for(y = 0; y < H; y++) - for(x = 0; x < W; x++) { - int c = (x ^ y) & 255; - vram_s[y * W + x] = ((c >> 3) << 0); - } - - for(y = 0; y < H; y += 24) { - char tmp[16]; - sprintf(tmp, "%d", y); - bfont_draw_str(vram_s + y * W + 10, W, 0, tmp); - } - - for(x = 0; x < W; x += 100) { - char tmp[16]; - sprintf(tmp, "%d", x / 10); - bfont_draw_str(vram_s + 10 * W + x, W, 0, tmp); - } - - printf("\n\nPress all buttons simultaneously to exit.\n"); - fflush(stdout); - while(1); - - return 0; -} diff --git a/examples/dreamcast/libdream/800x608/Makefile b/examples/dreamcast/libdream/800x608/Makefile deleted file mode 100644 index 1030dd0..0000000 --- a/examples/dreamcast/libdream/800x608/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -BIN = 800x608 -OBJS = 800x608.o - -include ../Makefile.prefab diff --git a/examples/dreamcast/libdream/Makefile b/examples/dreamcast/libdream/Makefile index b2224ad..b32976d 100644 --- a/examples/dreamcast/libdream/Makefile +++ b/examples/dreamcast/libdream/Makefile @@ -1,7 +1,7 @@ # This will make all the examples, leaving only the elf files. # If you want to clean everything, use 'clean'. -SUBDIRS = 320x240 640x480 800x608 rgb888 ta +SUBDIRS = 320x240 640x480 rgb888 ta SUBDIRS += cdfs SUBDIRS += spu SUBDIRS += keyboard mouse lcd vmu diff --git a/examples/dreamcast/libdream/README b/examples/dreamcast/libdream/README index b5727b3..ad8f3cc 100644 --- a/examples/dreamcast/libdream/README +++ b/examples/dreamcast/libdream/README @@ -8,8 +8,6 @@ hello -- Serial output, partial initialization cdfs -- Reading from a CD-Rom, quiet console output 320x240 -- 320x240x565 mode, full init plus de-init of TA 640x480 -- 640x480x565 mode, quiet console output -800x608 -- 800x608x565 experimental mode; partial init; - please see notes in C file rgb888 -- 640x480x888 mode ta -- Tile accelerator; full init, sans threads and romdisk keyboard -- Keyboard support, BIOS font; lowlevel only init diff --git a/include/kos.h b/include/kos.h index 563207f..d5d838f 100644 --- a/include/kos.h +++ b/include/kos.h @@ -100,6 +100,7 @@ __BEGIN_DECLS # include <dc/modem/modem.h> # include <dc/net/broadband_adapter.h> # include <dc/net/lan_adapter.h> +# include <dc/perfctr.h> # include <dc/pvr.h> # include <dc/scif.h> # include <dc/sd.h> diff --git a/kernel/arch/dreamcast/hardware/video.c b/kernel/arch/dreamcast/hardware/video.c index a655f1b..af1e608 100644 --- a/kernel/arch/dreamcast/hardware/video.c +++ b/kernel/arch/dreamcast/hardware/video.c @@ -89,23 +89,6 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { { 0, 0, 0, 0 } }, - /* 800x608 NTSC 60Hz (VGA) [BROKEN!] */ - /* DM_800x608_VGA */ - { - DM_800x608, - 320, 240, - VID_INTERLACE, - 1/*CT_ANY*/, /* This will block the mode from being set. */ - 0, - 262, 857, - 164, 24, - 21, 82, - 141, 843, - 24, 264, - 0, 1, - { 0, 0, 0, 0 } - }, - /* 640x480 PAL 50Hz IL */ /* DM_640x480_PAL_IL */ { @@ -281,23 +264,6 @@ vid_mode_t vid_builtin[DM_MODE_COUNT] = { { FBPOS(0), FBPOS(1), FBPOS(2), FBPOS(3) } }, - /* 800x608 NTSC 60Hz (VGA) [BROKEN!] */ - /* DM_800x608_VGA_MB */ - { - DM_800x608 | DM_MULTIBUFFER, - 320, 240, - VID_INTERLACE, - 1/*CT_ANY*/, /* This will block the mode from being set. */ - 0, - 262, 857, - 164, 24, - 21, 82, - 141, 843, - 24, 264, - 0, VID_MAX_FB, - { FBPOS(0), FBPOS(1), FBPOS(2), FBPOS(3) } - }, - /* 640x480 PAL 50Hz IL */ /* DM_640x480_PAL_IL_MB */ { diff --git a/kernel/arch/dreamcast/include/arch/timer.h b/kernel/arch/dreamcast/include/arch/timer.h index bc59e14..3072448 100644 --- a/kernel/arch/dreamcast/include/arch/timer.h +++ b/kernel/arch/dreamcast/include/arch/timer.h @@ -280,22 +280,21 @@ uint64_t timer_ms_gettime64(void); This function retrieves the number of seconds and microseconds since KOS was started. + \note To get the total number of microseconds since boot, + calculate (*secs * 1000000) + *usecs, or use the + timer_us_gettime64() function. + \param secs A pointer to store the number of seconds since boot into. \param usecs A pointer to store the number of microseconds past a second since boot. - \note To get the total number of microseconds since boot, - calculate (*secs * 1000000) + *usecs, or use the - timer_us_gettime64() function. */ void timer_us_gettime(uint32_t *secs, uint32_t *usecs); /** \brief Get the current uptime of the system (in microseconds). \ingroup tmu_uptime - This function retrieves the number of microseconds since KOS was started. It - should be more precise, in theory, than timer_ms_gettime64(), but the exact - amount of preciseness is undetermined. + This function retrieves the number of microseconds since KOS was started. \return The number of microseconds since KOS started. */ @@ -307,16 +306,26 @@ uint64_t timer_us_gettime64(void); This function retrieves the number of seconds and nanoseconds since KOS was started. + \note To get the total number of nanoseconds since boot, + calculate (*secs * 1000000000) + *nsecs, or use the + timer_ns_gettime64() function. + \param secs A pointer to store the number of seconds since boot into. \param nsecs A pointer to store the number of nanoseconds past a second since boot. - \note To get the total number of nanoseconds since boot, - calculate (*secs * 1000000000) + *nsecs, or use the - timer_ns_gettime64() function. */ void timer_ns_gettime(uint32_t *secs, uint32_t *nsecs); +/** \brief Get the current uptime of the system (in nanoseconds). + \ingroup tmu_uptime + + This function retrieves the number of nanoseconds since KOS was started. + + \return The number of nanoseconds since KOS started. +*/ +uint64_t timer_ns_gettime64(void); + /** \defgroup tmu_sleep Sleeping \brief Low-level thread sleeping \ingroup timers @@ -396,176 +405,6 @@ int timer_init(void); void timer_shutdown(void); /** \endcond */ -/** \defgroup perf_counters Performance Counters - \brief SH4 CPU Performance Counter Driver - \ingroup debugging - - The performance counter API exposes the SH4's hardware profiling registers, - which consist of two different sets of independently operable 64-bit - counters. -*/ - -/** \brief SH4 Performance Counter. - \ingroup perf_counters - - This counter is used by the ns_gettime function in this header. -*/ -#define PRFC0 0 - -/** \brief SH4 Performance Counter. - \ingroup perf_counters - - A counter that is not used by KOS. -*/ -#define PRFC1 1 - -/** \brief CPU Cycles Count Type. - \ingroup perf_counters - - Count cycles. At 5 ns increments, a 48-bit cycle counter can - run continuously for 16.33 days. -*/ -#define PMCR_COUNT_CPU_CYCLES 0 - -/** \brief Ratio Cycles Count Type. - \ingroup perf_counters - - CPU/bus ratio mode where cycles (where T = C x B / 24 and T is time, - C is count, and B is time of one bus cycle). -*/ -#define PMCR_COUNT_RATIO_CYCLES 1 - -/** \defgroup perf_counters_modes Modes - \brief Performance Counter Modes - \ingroup perf_counters - - This is the list of modes that are allowed to be passed into the perf_cntr_start() - function, representing different things you want to count. - - @{ -*/ -/* MODE DEFINITION VALUE MEASUREMENT TYPE & NOTES */ -#define PMCR_INIT_NO_MODE 0x00 /**< \brief None; Just here to be complete */ -#define PMCR_OPERAND_READ_ACCESS_MODE 0x01 /**< \brief Quantity; With cache */ -#define PMCR_OPERAND_WRITE_ACCESS_MODE 0x02 /**< \brief Quantity; With cache */ -#define PMCR_UTLB_MISS_MODE 0x03 /**< \brief Quantity */ -#define PMCR_OPERAND_CACHE_READ_MISS_MODE 0x04 /**< \brief Quantity */ -#define PMCR_OPERAND_CACHE_WRITE_MISS_MODE 0x05 /**< \brief Quantity */ -#define PMCR_INSTRUCTION_FETCH_MODE 0x06 /**< \brief Quantity; With cache */ -#define PMCR_INSTRUCTION_TLB_MISS_MODE 0x07 /**< \brief Quantity */ -#define PMCR_INSTRUCTION_CACHE_MISS_MODE 0x08 /**< \brief Quantity */ -#define PMCR_ALL_OPERAND_ACCESS_MODE 0x09 /**< \brief Quantity */ -#define PMCR_ALL_INSTRUCTION_FETCH_MODE 0x0a /**< \brief Quantity */ -#define PMCR_ON_CHIP_RAM_OPERAND_ACCESS_MODE 0x0b /**< \brief Quantity */ -/* No 0x0c */ -#define PMCR_ON_CHIP_IO_ACCESS_MODE 0x0d /**< \brief Quantity */ -#define PMCR_OPERAND_ACCESS_MODE 0x0e /**< \brief Quantity; With cache, counts both reads and writes */ -#define PMCR_OPERAND_CACHE_MISS_MODE 0x0f /**< \brief Quantity */ -#define PMCR_BRANCH_ISSUED_MODE 0x10 /**< \brief Quantity; Not the same as branch taken! */ -#define PMCR_BRANCH_TAKEN_MODE 0x11 /**< \brief Quantity */ -#define PMCR_SUBROUTINE_ISSUED_MODE 0x12 /**< \brief Quantity; Issued a BSR, BSRF, JSR, JSR/N */ -#define PMCR_INSTRUCTION_ISSUED_MODE 0x13 /**< \brief Quantity */ -#define PMCR_PARALLEL_INSTRUCTION_ISSUED_MODE 0x14 /**< \brief Quantity */ -#define PMCR_FPU_INSTRUCTION_ISSUED_MODE 0x15 /**< \brief Quantity */ -#define PMCR_INTERRUPT_COUNTER_MODE 0x16 /**< \brief Quantity */ -#define PMCR_NMI_COUNTER_MODE 0x17 /**< \brief Quantity */ -#define PMCR_TRAPA_INSTRUCTION_COUNTER_MODE 0x18 /**< \brief Quantity */ -#define PMCR_UBC_A_MATCH_MODE 0x19 /**< \brief Quantity */ -#define PMCR_UBC_B_MATCH_MODE 0x1a /**< \brief Quantity */ -/* No 0x1b-0x20 */ -#define PMCR_INSTRUCTION_CACHE_FILL_MODE 0x21 /**< \brief Cycles */ -#define PMCR_OPERAND_CACHE_FILL_MODE 0x22 /**< \brief Cycles */ -#define PMCR_ELAPSED_TIME_MODE 0x23 /**< \brief Cycles; For 200MHz CPU: 5ns per count in 1 cycle = 1 count mode, or around 417.715ps per count (increments by 12) in CPU/bus ratio mode */ -#define PMCR_PIPELINE_FREEZE_BY_ICACHE_MISS_MODE 0x24 /**< \brief Cycles */ -#define PMCR_PIPELINE_FREEZE_BY_DCACHE_MISS_MODE 0x25 /**< \brief Cycles */ -/* No 0x26 */ -#define PMCR_PIPELINE_FREEZE_BY_BRANCH_MODE 0x27 /**< \brief Cycles */ -#define PMCR_PIPELINE_FREEZE_BY_CPU_REGISTER_MODE 0x28 /**< \brief Cycles */ -#define PMCR_PIPELINE_FREEZE_BY_FPU_MODE 0x29 /**< \brief Cycles */ -/** @} */ - - -/** \brief Get a performance counter's settings. - \ingroup perf_counters - - This function returns a performance counter's settings. - - \param which The performance counter (i.e, \ref PRFC0 or PRFC1). - \retval 0 On success. -*/ -uint16 perf_cntr_get_config(int which); - -/** \brief Start a performance counter. - \ingroup perf_counters - - This function starts a performance counter - - \param which The counter to start (i.e, \ref PRFC0 or PRFC1). - \param mode Use one of the 33 modes listed above. - \param count_type PMCR_COUNT_CPU_CYCLES or PMCR_COUNT_RATIO_CYCLES. - \retval 0 On success. -*/ -int perf_cntr_start(int which, int mode, int count_type); - -/** \brief Stop a performance counter. - \ingroup perf_counters - - This function stops a performance counter that was started with perf_cntr_start(). - Stopping a counter retains its count. To clear the count use perf_cntr_clear(). - - \param which The counter to stop (i.e, \ref PRFC0 or PRFC1). - \retval 0 On success. -*/ -int perf_cntr_stop(int which); - -/** \brief Clear a performance counter. - \ingroup perf_counters - - This function clears a performance counter. It resets its count to zero. - This function stops the counter before clearing it because you can't clear - a running counter. - - \param which The counter to clear (i.e, \ref PRFC0 or PRFC1). - \retval 0 On success. -*/ -int perf_cntr_clear(int which); - -/** \brief Obtain the count of a performance counter. - \ingroup perf_counters - - This function simply returns the count of the counter. - - \param which The counter to read (i.e, \ref PRFC0 or PRFC1). - \return The counter's count. -*/ -uint64 perf_cntr_count(int which); - -/** \brief Enable the nanosecond timer. - \ingroup perf_counters - - This function enables the performance counter used for the timer_ns_gettime64() - function. This is on by default. The function uses \ref PRFC0 to do the work. -*/ -void timer_ns_enable(void); - -/** \brief Disable the nanosecond timer. - \ingroup perf_counters - - This function disables the performance counter used for the timer_ns_gettime64() - function. Generally, you will not want to do this, unless you have some need to use - the counter \ref PRFC0 for something else. -*/ -void timer_ns_disable(void); - -/** \brief Get the current uptime of the system (in nanoseconds). - \ingroup perf_counters - - This function retrieves the number of nanoseconds since KOS was started. - - \return The number of nanoseconds since KOS started. -*/ -uint64 timer_ns_gettime64(void); - __END_DECLS #endif /* __ARCH_TIMER_H */ diff --git a/kernel/arch/dreamcast/include/dc/perfctr.h b/kernel/arch/dreamcast/include/dc/perfctr.h new file mode 100644 index 0000000..a253b7b --- /dev/null +++ b/kernel/arch/dreamcast/include/dc/perfctr.h @@ -0,0 +1,278 @@ +/* KallistiOS ##version## + + arch/dreamcast/include/dc/perfctr.h + Copyright (C) 2023 Andy Barajas + Copyright (C) 2023 Falco Girgis + +*/ + +/** \file dc/perfctr.h + \brief Low-level performance counter API + \ingroup perf_counters + + This file contains the low-level driver for interacting with and + utilizing the SH4's two Performance Counters, which are primarily + used for profiling and performance tuning. + + \author MoopTheHedgehog + \author Andy Barajas + \author Falco Girgis +*/ + +#ifndef __DC_PERFCTR_H +#define __DC_PERFCTR_H + +#include <stdint.h> +#include <stdbool.h> + +#include <sys/cdefs.h> +__BEGIN_DECLS + +/** \defgroup perf_counters Performance Counters + \brief SH4 CPU Performance Counter Driver + \ingroup debugging + + The performance counter API exposes the SH4's hardware profiling registers, + which consist of two different sets of independently operable 48-bit + counters. + + @{ +*/ + +/** \brief Identifiers for the two SH4 performance counters */ +typedef enum perf_cntr { + /** \brief SH4 Performance Counter 0 + + The first performance counter ID. + + This counter is used by KOS by default to implement the \ref + perf_counters_timer API. Reference it for details on how to + reconfigure it if necessary. + */ + PRFC0, + + /** \brief SH4 Performance Counter 1 + + The second performance counter ID. + + This counter is not used anywhere internally by KOS. + */ + PRFC1 +} perf_cntr_t; + +/** \brief Count clock types for the SH4 performance counters */ +typedef enum perf_cntr_clock { + /** \brief CPU Cycles + + Count CPU cycles. At 5 ns increments (for 200Mhz CPU clock), a 48-bit + cycle counter can run continuously for 16.33 days. + */ + PMCR_COUNT_CPU_CYCLES, + + /** \brief Ratio Cycles + + Count CPU/bus ratio mode cycles (where `T = C x B / 24` and `T` is + time, `C` is count, and `B` is time of one bus cycle). ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |