-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
87 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// XM6i | ||
// Copyright (C) 2010-2015 [email protected] | ||
// Copyright (C) 2010 Y.Sugahara | ||
// Copyright (C) 2022-2024 Uwe Seimet | ||
// Copyright (C) 2022-2025 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
|
@@ -577,7 +577,7 @@ tuple<bool, uint64_t, uint32_t> Disk::CheckAndGetStartAndCount(AccessMode mode) | |
} | ||
|
||
// Do not process 0 blocks | ||
return tuple(count || mode == SEEK6 || mode == SEEK10, start, count); | ||
return {count || mode == SEEK6 || mode == SEEK10, start, count}; | ||
} | ||
|
||
vector<PbStatistics> Disk::GetStatistics() const | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// XM6i | ||
// Copyright (C) 2010-2015 [email protected] | ||
// Copyright (C) 2010 Y.Sugahara | ||
// Copyright (C) 2022-2024 Uwe Seimet | ||
// Copyright (C) 2022-2025 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
|
@@ -46,7 +46,7 @@ shared_ptr<DiskTrack> DiskCache::GetTrack(uint32_t block) | |
int track = block >> 8; | ||
|
||
// Get track data | ||
return Assign(track); | ||
return AssignTrack(track); | ||
} | ||
|
||
int DiskCache::ReadSectors(data_in_t buf, uint64_t sector, uint32_t count) | ||
|
@@ -81,12 +81,9 @@ int DiskCache::WriteSectors(data_out_t buf, uint64_t sector, uint32_t count) | |
return disktrk->WriteSector(buf, sector & 0xff); | ||
} | ||
|
||
// Track Assignment | ||
shared_ptr<DiskTrack> DiskCache::Assign(int track) | ||
shared_ptr<DiskTrack> DiskCache::AssignTrack(int track) | ||
{ | ||
assert(track >= 0); | ||
|
||
// First, check if it is already assigned | ||
// Check if it is already assigned | ||
for (CacheData &c : cache) { | ||
if (c.disktrk && c.disktrk->GetTrack() == track) { | ||
// Track match | ||
|
@@ -95,54 +92,29 @@ shared_ptr<DiskTrack> DiskCache::Assign(int track) | |
} | ||
} | ||
|
||
// Next, check for empty | ||
for (size_t i = 0; i < cache.size(); ++i) { | ||
if (!cache[i].disktrk) { | ||
// Try loading | ||
if (Load(static_cast<int>(i), track, nullptr)) { | ||
// Success loading | ||
cache[i].serial = serial; | ||
return cache[i].disktrk; | ||
} | ||
|
||
// Load failed | ||
return nullptr; | ||
// Check for an empty cache slot | ||
for (CacheData &c : cache) { | ||
if (!c.disktrk && Load(static_cast<int>(&c - &cache[0]), track, nullptr)) { | ||
c.serial = serial; | ||
return c.disktrk; | ||
} | ||
} | ||
|
||
// Finally, find the youngest serial number and delete it | ||
|
||
// Set index 0 as candidate c | ||
uint32_t s = cache[0].serial; | ||
size_t c = 0; | ||
// Find the cache entry with the smallest serial number, i.e. the oldest entry and save this track | ||
if (auto c = ranges::min_element(cache, | ||
[](const CacheData &d1, const CacheData &d2) {return d1.serial < d2.serial;}) | ||
- cache.begin(); cache[c].disktrk->Save(sec_path, cache_miss_write_count)) { | ||
// Delete this track | ||
auto disktrk = std::move(cache[c].disktrk); | ||
|
||
// Compare candidate with serial and update to smaller one | ||
for (size_t i = 0; i < cache.size(); ++i) { | ||
assert(cache[i].disktrk); | ||
|
||
// Compare and update the existing serial | ||
if (cache[i].serial < s) { | ||
s = cache[i].serial; | ||
c = i; | ||
if (Load(static_cast<int>(c), track, disktrk)) { | ||
// Successful loading | ||
cache[c].serial = serial; | ||
return cache[c].disktrk; | ||
} | ||
} | ||
|
||
// Save this track | ||
if (!cache[c].disktrk->Save(sec_path, cache_miss_write_count)) { | ||
return nullptr; | ||
} | ||
|
||
// Delete this track | ||
shared_ptr<DiskTrack> disktrk = cache[c].disktrk; | ||
cache[c].disktrk.reset(); | ||
|
||
if (Load(static_cast<int>(c), track, disktrk)) { | ||
// Successful loading | ||
cache[c].serial = serial; | ||
return cache[c].disktrk; | ||
} | ||
|
||
// Load failed | ||
// Save or load failed | ||
return nullptr; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
// Copyright (C) 2001-2006 PI.([email protected]) | ||
// Copyright (C) 2014-2020 GIMONS | ||
// | ||
// Copyright (C) 2022-2024 Uwe Seimet | ||
// Copyright (C) 2022-2025 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
|
@@ -37,7 +37,7 @@ class DiskCache : public Cache | |
uint32_t serial; | ||
}; | ||
|
||
shared_ptr<DiskTrack> Assign(int); | ||
shared_ptr<DiskTrack> AssignTrack(int); | ||
shared_ptr<DiskTrack> GetTrack(uint32_t); | ||
bool Load(int index, int track, shared_ptr<DiskTrack>); | ||
void UpdateSerial(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
// Copyright (C) 2001-2006 PI.([email protected]) | ||
// Copyright (C) 2014-2020 GIMONS | ||
// | ||
// Copyright (C) 2022-2024 Uwe Seimet | ||
// Copyright (C) 2022-2025 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
|
@@ -16,7 +16,7 @@ | |
|
||
DiskTrack::~DiskTrack() | ||
{ | ||
free(buffer); // NOSONAR free() must be used here because of allocation with posix_memalign | ||
free(buffer); // NOSONAR free() must be used here due to posix_memalign | ||
} | ||
|
||
void DiskTrack::Init(int track, int size, int sectors) | ||
|
@@ -41,27 +41,18 @@ bool DiskTrack::Load(const string &path, uint64_t &cache_miss_read_count) | |
|
||
++cache_miss_read_count; | ||
|
||
// Calculate offset (previous tracks are considered to hold 256 sectors) | ||
off_t offset = (off_t)track_number << 8; | ||
offset <<= shift_count; | ||
|
||
const int size = sector_count << shift_count; | ||
|
||
if (!buffer && !posix_memalign((void**)&buffer, 512, ((size + 511) / 512) * 512)) { | ||
buffer_size = size; | ||
} | ||
|
||
// Reallocate if the buffer length is different | ||
if (buffer && buffer_size != static_cast<uint32_t>(size)) { | ||
free(buffer); // NOSONAR free() must be used here because of allocation with posix_memalign | ||
// Allocate or reallocate the buffer | ||
if (!buffer || buffer_size != static_cast<uint32_t>(size)) { | ||
free(buffer); // NOSONAR free() must be used here due to posix_memalign | ||
buffer = nullptr; | ||
if (!posix_memalign((void**)&buffer, 512, ((size + 511) / 512) * 512)) { | ||
buffer_size = size; | ||
|
||
if (posix_memalign((void**)&buffer, 512, (size + 511) & ~511)) { | ||
return false; | ||
} | ||
} | ||
|
||
if (!buffer) { | ||
return false; | ||
buffer_size = size; | ||
} | ||
|
||
modified_flags.resize(sector_count); | ||
|
@@ -74,6 +65,10 @@ bool DiskTrack::Load(const string &path, uint64_t &cache_miss_read_count) | |
return false; | ||
} | ||
|
||
// Calculate offset (previous tracks are considered to hold 256 sectors) | ||
off_t offset = static_cast<off_t>(track_number) << 8; | ||
offset <<= shift_count; | ||
|
||
in.seekg(offset); | ||
in.read((char*)buffer, size); | ||
return in.good(); | ||
|
@@ -102,18 +97,16 @@ bool DiskTrack::Save(const string &path, uint64_t &cache_miss_write_count) | |
} | ||
|
||
// Write consecutive sectors | ||
for (int i = 0; i < sector_count;) { | ||
int i = 0; | ||
while (i < sector_count) { | ||
if (modified_flags[i]) { | ||
int total = 0; | ||
|
||
// Determine consecutive sector range | ||
int j; | ||
for (j = i; j < sector_count; ++j) { | ||
if (!modified_flags[j]) { | ||
break; | ||
} | ||
|
||
int j = i; | ||
while (j < sector_count && modified_flags[j]) { | ||
total += size; | ||
++j; | ||
} | ||
|
||
out.seekp(offset + (i << shift_count)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.