2003-02-07 09:41:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Alan Korr
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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 the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2003-02-07 09:41:57 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __SYSTEM_H__
|
|
|
|
#define __SYSTEM_H__
|
|
|
|
|
2014-01-05 00:22:19 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2004-10-06 13:49:48 +00:00
|
|
|
#include "cpu.h"
|
2010-07-25 14:44:29 +00:00
|
|
|
#include "gcc_extensions.h" /* for LIKELY/UNLIKELY */
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2004-02-25 13:00:36 +00:00
|
|
|
extern void system_reboot (void);
|
2009-01-08 10:15:32 +00:00
|
|
|
/* Called from any UIE handler and panicf - wait for a key and return
|
|
|
|
* to reboot system. */
|
|
|
|
extern void system_exception_wait(void);
|
2004-02-25 13:00:36 +00:00
|
|
|
extern void system_init(void);
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
extern long cpu_frequency;
|
|
|
|
|
2006-08-05 20:19:10 +00:00
|
|
|
struct flash_header {
|
|
|
|
unsigned long magic;
|
|
|
|
unsigned long length;
|
|
|
|
char version[32];
|
|
|
|
};
|
|
|
|
|
2007-01-12 18:34:00 +00:00
|
|
|
bool detect_flashed_romimage(void);
|
|
|
|
bool detect_flashed_ramimage(void);
|
|
|
|
bool detect_original_firmware(void);
|
2006-08-05 20:19:10 +00:00
|
|
|
|
2007-01-22 10:41:25 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) \
|
2007-03-26 16:55:17 +00:00
|
|
|
&& defined(ROCKBOX_HAS_LOGF) && (NUM_CORES == 1)
|
2007-01-22 10:41:25 +00:00
|
|
|
#define CPU_BOOST_LOGGING
|
|
|
|
#endif
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2007-10-16 01:25:17 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
extern struct spinlock boostctrl_spin;
|
|
|
|
#endif
|
|
|
|
void cpu_boost_init(void);
|
2005-03-01 14:35:10 +00:00
|
|
|
#define FREQ cpu_frequency
|
2005-03-03 16:29:02 +00:00
|
|
|
void set_cpu_frequency(long frequency);
|
2007-01-22 10:41:25 +00:00
|
|
|
#ifdef CPU_BOOST_LOGGING
|
|
|
|
char * cpu_boost_log_getlog_first(void);
|
|
|
|
char * cpu_boost_log_getlog_next(void);
|
|
|
|
int cpu_boost_log_getcount(void);
|
|
|
|
void cpu_boost_(bool on_off, char* location, int line);
|
|
|
|
#else
|
2005-03-03 16:29:02 +00:00
|
|
|
void cpu_boost(bool on_off);
|
2007-01-22 10:41:25 +00:00
|
|
|
#endif
|
2005-07-05 07:58:19 +00:00
|
|
|
void cpu_idle_mode(bool on_off);
|
2006-10-05 10:07:03 +00:00
|
|
|
int get_cpu_boost_counter(void);
|
2010-04-23 15:32:50 +00:00
|
|
|
#else /* ndef HAVE_ADJUSTABLE_CPU_FREQ */
|
|
|
|
#ifndef FREQ
|
2003-02-07 09:41:57 +00:00
|
|
|
#define FREQ CPU_FREQ
|
2010-04-23 15:32:50 +00:00
|
|
|
#endif
|
2005-09-12 10:34:27 +00:00
|
|
|
#define set_cpu_frequency(frequency)
|
2007-01-22 10:58:40 +00:00
|
|
|
#define cpu_boost(on_off)
|
2006-10-05 10:07:03 +00:00
|
|
|
#define cpu_boost_id(on_off, id)
|
2005-07-05 07:58:19 +00:00
|
|
|
#define cpu_idle_mode(on_off)
|
2006-10-05 10:07:03 +00:00
|
|
|
#define get_cpu_boost_counter()
|
|
|
|
#define get_cpu_boost_tracker()
|
2010-04-23 15:32:50 +00:00
|
|
|
#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
|
2005-03-03 16:29:02 +00:00
|
|
|
|
2007-01-22 10:41:25 +00:00
|
|
|
#ifdef CPU_BOOST_LOGGING
|
|
|
|
#define cpu_boost(on_off) cpu_boost_(on_off,__FILE__, __LINE__)
|
|
|
|
#endif
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#define BAUDRATE 9600
|
|
|
|
|
2013-12-04 16:06:17 +00:00
|
|
|
/* wrap-safe macros for tick comparison */
|
|
|
|
#define TIME_AFTER(a,b) ((long)(b) - (long)(a) < 0)
|
|
|
|
#define TIME_BEFORE(a,b) TIME_AFTER(b,a)
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#ifndef NULL
|
|
|
|
#define NULL ((void*)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) (((a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* return number of elements in array a */
|
|
|
|
#define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0]))
|
|
|
|
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
/* is the given pointer "p" inside the said bounds of array "a"? */
|
|
|
|
#define PTR_IN_ARRAY(a, p, numelem) \
|
|
|
|
((uintptr_t)(p) - (uintptr_t)(a) < (uintptr_t)(numelem)*sizeof ((a)[0]))
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* return p incremented by specified number of bytes */
|
|
|
|
#define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count)))
|
|
|
|
|
|
|
|
#define P2_M1(p2) ((1 << (p2))-1)
|
|
|
|
|
|
|
|
/* align up or down to nearest 2^p2 */
|
|
|
|
#define ALIGN_DOWN_P2(n, p2) ((n) & ~P2_M1(p2))
|
|
|
|
#define ALIGN_UP_P2(n, p2) ALIGN_DOWN_P2((n) + P2_M1(p2),p2)
|
|
|
|
|
|
|
|
/* align up or down to nearest integer multiple of a */
|
2014-03-24 08:32:51 +00:00
|
|
|
#define ALIGN_DOWN(n, a) ((typeof(n))((uintptr_t)(n)/(a)*(a)))
|
2006-11-06 18:07:30 +00:00
|
|
|
#define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
|
|
|
|
|
2009-01-13 13:48:26 +00:00
|
|
|
/* align start and end of buffer to nearest integer multiple of a */
|
2014-08-08 10:33:51 +00:00
|
|
|
#define ALIGN_BUFFER(ptr, size, align) \
|
|
|
|
({ \
|
|
|
|
size_t __sz = (size); \
|
|
|
|
size_t __ali = (align); \
|
|
|
|
uintptr_t __a1 = (uintptr_t)(ptr); \
|
|
|
|
uintptr_t __a2 = __a1 + __sz; \
|
|
|
|
__a1 = ALIGN_UP(__a1, __ali); \
|
|
|
|
__a2 = ALIGN_DOWN(__a2, __ali); \
|
|
|
|
(ptr) = (typeof (ptr))__a1; \
|
|
|
|
(size) = __a2 > __a1 ? __a2 - __a1 : 0; \
|
|
|
|
})
|
2009-01-13 13:48:26 +00:00
|
|
|
|
2014-11-29 17:42:22 +00:00
|
|
|
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
|
|
|
|
|
2011-10-07 19:29:18 +00:00
|
|
|
#define PTR_ADD(ptr, x) ((typeof(ptr))((char*)(ptr) + (x)))
|
|
|
|
#define PTR_SUB(ptr, x) ((typeof(ptr))((char*)(ptr) - (x)))
|
2009-09-01 14:53:37 +00:00
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
/* Get the byte offset of a type's member */
|
2014-08-08 10:33:51 +00:00
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(type, member) __builtin_offsetof(type, member)
|
|
|
|
#endif
|
2008-03-25 02:34:12 +00:00
|
|
|
|
2014-08-08 10:33:51 +00:00
|
|
|
/* Get the containing item of *ptr in type */
|
|
|
|
#ifndef container_of
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
const typeof (((type *)0)->member) *__mptr = (ptr); \
|
|
|
|
(type *)((void *)(__mptr) - offsetof(type, member)); })
|
|
|
|
#endif
|
2008-03-25 02:34:12 +00:00
|
|
|
|
2009-12-16 16:39:24 +00:00
|
|
|
/* returns index of first set bit or 32 if no bits are set */
|
2014-08-06 01:19:07 +00:00
|
|
|
#if defined(CPU_ARM) && ARM_ARCH >= 5 && !defined(__thumb__)
|
|
|
|
static inline int find_first_set_bit(uint32_t val)
|
|
|
|
{ return LIKELY(val) ? __builtin_ctz(val) : 32; }
|
|
|
|
#else
|
2008-03-25 02:34:12 +00:00
|
|
|
int find_first_set_bit(uint32_t val);
|
2014-08-06 01:19:07 +00:00
|
|
|
#endif
|
2008-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
static inline __attribute__((always_inline))
|
|
|
|
uint32_t isolate_first_bit(uint32_t val)
|
|
|
|
{ return val & -val; }
|
|
|
|
|
2010-06-30 02:02:46 +00:00
|
|
|
/* Functions to set and clear register or variable bits atomically */
|
2011-02-06 19:43:45 +00:00
|
|
|
void bitmod16(volatile uint16_t *addr, uint16_t bits, uint16_t mask);
|
|
|
|
void bitset16(volatile uint16_t *addr, uint16_t mask);
|
|
|
|
void bitclr16(volatile uint16_t *addr, uint16_t mask);
|
|
|
|
|
2010-06-30 02:02:46 +00:00
|
|
|
void bitmod32(volatile uint32_t *addr, uint32_t bits, uint32_t mask);
|
|
|
|
void bitset32(volatile uint32_t *addr, uint32_t mask);
|
|
|
|
void bitclr32(volatile uint32_t *addr, uint32_t mask);
|
|
|
|
|
2004-07-24 11:39:17 +00:00
|
|
|
/* gcc 3.4 changed the format of the constraints */
|
2005-04-22 19:34:01 +00:00
|
|
|
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ > 3) || (__GNUC__ >= 4)
|
2004-07-24 11:39:17 +00:00
|
|
|
#define I_CONSTRAINT "I08"
|
|
|
|
#else
|
|
|
|
#define I_CONSTRAINT "I"
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 21:45:56 +00:00
|
|
|
/* Utilize the user break controller to catch invalid memory accesses. */
|
|
|
|
int system_memory_guard(int newmode);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MEMGUARD_KEEP = -1, /* don't change the mode; for reading */
|
|
|
|
MEMGUARD_NONE = 0, /* catch nothing */
|
|
|
|
MEMGUARD_FLASH_WRITES, /* catch writes to area 02 (flash ROM) */
|
|
|
|
MEMGUARD_ZERO_AREA, /* catch all accesses to areas 00 and 01 */
|
|
|
|
MAXMEMGUARD
|
|
|
|
};
|
|
|
|
|
2009-10-06 22:02:06 +00:00
|
|
|
#if !defined(SIMULATOR) && !defined(__PCTOOL__)
|
2006-10-30 14:17:14 +00:00
|
|
|
#include "system-target.h"
|
2010-06-21 16:53:00 +00:00
|
|
|
#elif defined(HAVE_SDL) /* SDL build */
|
2010-05-15 21:02:47 +00:00
|
|
|
#include "system-sdl.h"
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
#include "system-sim.h"
|
|
|
|
#endif
|
2012-03-03 17:54:47 +00:00
|
|
|
#elif defined(__PCTOOL__)
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
#include "system-hosted.h"
|
2010-06-21 16:53:00 +00:00
|
|
|
#endif
|
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2013-08-06 02:02:45 +00:00
|
|
|
|
2011-08-30 14:38:16 +00:00
|
|
|
#include "bitswap.h"
|
2014-08-24 23:46:43 +00:00
|
|
|
#include "rbendian.h"
|
2011-01-30 00:58:45 +00:00
|
|
|
|
2009-06-06 00:11:41 +00:00
|
|
|
#ifndef BIT_N
|
2009-06-06 00:58:57 +00:00
|
|
|
#define BIT_N(n) (1U << (n))
|
2009-06-06 00:00:58 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
#ifndef MASK_N
|
|
|
|
/* Make a mask of n contiguous bits, shifted left by 'shift' */
|
|
|
|
#define MASK_N(type, n, shift) \
|
|
|
|
((type)((((type)1 << (n)) - (type)1) << (shift)))
|
|
|
|
#endif
|
|
|
|
|
2007-05-12 05:20:04 +00:00
|
|
|
/* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */
|
|
|
|
#ifndef DISABLE_INTERRUPTS
|
|
|
|
#define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL
|
|
|
|
#endif
|
|
|
|
|
2010-11-21 12:27:01 +00:00
|
|
|
/* Define this, if the CPU may take advantage of cache aligment. Is enabled
|
|
|
|
* for all ARM CPUs. */
|
|
|
|
#ifdef CPU_ARM
|
|
|
|
#define HAVE_CPU_CACHE_ALIGN
|
2014-08-08 10:33:51 +00:00
|
|
|
#define MIN_STACK_ALIGN 8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN_STACK_ALIGN
|
|
|
|
#define MIN_STACK_ALIGN (sizeof (uintptr_t))
|
2010-11-21 12:27:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Calculate CACHEALIGN_SIZE from CACHEALIGN_BITS */
|
|
|
|
#ifdef CACHEALIGN_SIZE
|
|
|
|
/* undefine, if defined. always calculate from CACHEALIGN_BITS */
|
|
|
|
#undef CACHEALIGN_SIZE
|
|
|
|
#endif
|
2010-03-26 00:11:50 +00:00
|
|
|
#ifdef CACHEALIGN_BITS
|
2010-11-22 18:43:22 +00:00
|
|
|
/* CACHEALIGN_SIZE = 2 ^ CACHEALIGN_BITS */
|
2010-11-21 12:27:01 +00:00
|
|
|
#define CACHEALIGN_SIZE (1u << CACHEALIGN_BITS)
|
|
|
|
#else
|
|
|
|
/* FIXME: set to maximum known cache alignment of supported CPUs */
|
|
|
|
#define CACHEALIGN_BITS 5
|
|
|
|
#define CACHEALIGN_SIZE 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CPU_CACHE_ALIGN
|
|
|
|
/* Cache alignment attributes and sizes are enabled */
|
|
|
|
#define CACHEALIGN_ATTR __attribute__((aligned(CACHEALIGN_SIZE)))
|
|
|
|
/* Aligns x up to a CACHEALIGN_SIZE boundary */
|
|
|
|
#define CACHEALIGN_UP(x) \
|
|
|
|
((typeof (x))ALIGN_UP_P2((uintptr_t)(x), CACHEALIGN_BITS))
|
|
|
|
/* Aligns x down to a CACHEALIGN_SIZE boundary */
|
|
|
|
#define CACHEALIGN_DOWN(x) \
|
|
|
|
((typeof (x))ALIGN_DOWN_P2((uintptr_t)(x), CACHEALIGN_BITS))
|
|
|
|
/* Aligns at least to the greater of size x or CACHEALIGN_SIZE */
|
|
|
|
#define CACHEALIGN_AT_LEAST_ATTR(x) \
|
|
|
|
__attribute__((aligned(CACHEALIGN_UP(x))))
|
|
|
|
/* Aligns a buffer pointer and size to proper boundaries */
|
|
|
|
#define CACHEALIGN_BUFFER(start, size) \
|
|
|
|
ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE)
|
|
|
|
#else
|
|
|
|
/* Cache alignment attributes and sizes are not enabled */
|
|
|
|
#define CACHEALIGN_ATTR
|
|
|
|
#define CACHEALIGN_AT_LEAST_ATTR(x) __attribute__((aligned(x)))
|
|
|
|
#define CACHEALIGN_UP(x) (x)
|
|
|
|
#define CACHEALIGN_DOWN(x) (x)
|
|
|
|
/* Make no adjustments */
|
|
|
|
#define CACHEALIGN_BUFFER(start, size)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Define MEM_ALIGN_ATTR which may be used to align e.g. buffers for faster
|
|
|
|
* access. */
|
2012-03-27 23:52:15 +00:00
|
|
|
#if defined(CPU_ARM)
|
2010-11-21 12:27:01 +00:00
|
|
|
/* Use ARMs cache alignment. */
|
|
|
|
#define MEM_ALIGN_ATTR CACHEALIGN_ATTR
|
2011-08-28 07:45:35 +00:00
|
|
|
#define MEM_ALIGN_SIZE CACHEALIGN_SIZE
|
2010-11-21 12:27:01 +00:00
|
|
|
#elif defined(CPU_COLDFIRE)
|
|
|
|
/* Use fixed alignment of 16 bytes. Speed up only for 'movem' in DRAM. */
|
|
|
|
#define MEM_ALIGN_ATTR __attribute__((aligned(16)))
|
2011-08-28 07:45:35 +00:00
|
|
|
#define MEM_ALIGN_SIZE 16
|
2010-05-14 08:44:07 +00:00
|
|
|
#else
|
2011-08-28 07:45:35 +00:00
|
|
|
/* Align pointer size */
|
2012-03-27 23:52:15 +00:00
|
|
|
#define MEM_ALIGN_ATTR __attribute__((aligned(sizeof(intptr_t))))
|
2011-08-28 07:45:35 +00:00
|
|
|
#define MEM_ALIGN_SIZE sizeof(intptr_t)
|
2010-03-26 00:11:50 +00:00
|
|
|
#endif
|
2007-11-08 05:17:20 +00:00
|
|
|
|
2012-03-27 23:52:15 +00:00
|
|
|
#define MEM_ALIGN_UP(x) \
|
|
|
|
((typeof (x))ALIGN_UP((uintptr_t)(x), MEM_ALIGN_SIZE))
|
|
|
|
#define MEM_ALIGN_DOWN(x) \
|
|
|
|
((typeof (x))ALIGN_DOWN((uintptr_t)(x), MEM_ALIGN_SIZE))
|
|
|
|
|
2010-03-26 00:11:50 +00:00
|
|
|
#ifdef STORAGE_WANTS_ALIGN
|
2010-11-21 12:27:01 +00:00
|
|
|
#define STORAGE_ALIGN_ATTR __attribute__((aligned(CACHEALIGN_SIZE)))
|
|
|
|
#define STORAGE_ALIGN_DOWN(x) \
|
|
|
|
((typeof (x))ALIGN_DOWN_P2((uintptr_t)(x), CACHEALIGN_BITS))
|
|
|
|
/* Pad a size so the buffer can be aligned later */
|
|
|
|
#define STORAGE_PAD(x) ((x) + CACHEALIGN_SIZE - 1)
|
|
|
|
/* Number of bytes in the last cacheline assuming buffer of size x is aligned */
|
|
|
|
#define STORAGE_OVERLAP(x) ((x) & (CACHEALIGN_SIZE - 1))
|
2011-02-09 09:30:09 +00:00
|
|
|
#define STORAGE_ALIGN_BUFFER(start, size) \
|
|
|
|
ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE)
|
2010-03-26 00:11:50 +00:00
|
|
|
#else
|
2010-11-21 12:27:01 +00:00
|
|
|
#define STORAGE_ALIGN_ATTR
|
|
|
|
#define STORAGE_ALIGN_DOWN(x) (x)
|
|
|
|
#define STORAGE_PAD(x) (x)
|
|
|
|
#define STORAGE_OVERLAP(x) 0
|
2011-02-09 09:30:09 +00:00
|
|
|
#define STORAGE_ALIGN_BUFFER(start, size)
|
2010-03-25 23:01:56 +00:00
|
|
|
#endif
|
|
|
|
|
2007-12-29 19:46:35 +00:00
|
|
|
/* Double-cast to avoid 'dereferencing type-punned pointer will
|
|
|
|
* break strict aliasing rules' B.S. */
|
|
|
|
#define PUN_PTR(type, p) ((type)(intptr_t)(p))
|
|
|
|
|
2012-01-04 05:21:44 +00:00
|
|
|
#ifndef SIMULATOR
|
|
|
|
bool dbg_ports(void);
|
|
|
|
#endif
|
2012-01-04 05:29:22 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
|
|
|
bool dbg_hw_info(void);
|
|
|
|
#endif
|
2012-01-04 05:21:44 +00:00
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
#endif /* __SYSTEM_H__ */
|