Skip to content

Commit

Permalink
Backport fix for wrong struct selection for C table parks.
Browse files Browse the repository at this point in the history
An error where the wrong struct with the same name would be selected for C
table writing in diskplot and ramplot would cause corruption of data.
  • Loading branch information
harold-b committed Nov 5, 2022
1 parent d647918 commit 5ee2b81
Showing 1 changed file with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions src/plotting/TableWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "threading/MTJob.h"
#include "plotting/CTables.h"

struct TableWriter
namespace TableWriter
{
/// P7
// Table 7's indices into the Table 6's entries.
Expand Down Expand Up @@ -37,43 +37,51 @@ struct TableWriter

static void WriteC3Parks( const uint64 parkCount, uint32* f7Entries, byte* writeBuffer, uint32 jobId = 0 );
static void WriteC3Park( const uint64 length, uint32* f7Entries, byte* parkBuffer, uint32 jobId = 0 );
};

struct P7Job : MTJob<P7Job>
{
uint64 parkCount;
const uint32* indices;
byte* parkBuffer;
/// Jobs
struct P7Job : MTJob<P7Job>
{
uint64 parkCount;
const uint32* indices;
byte* parkBuffer;

void Run() override;
};
void Run() override;
};

template<uint CInterval>
struct C12Job : MTJob<C12Job<CInterval>>
{
uint64 length;
const uint32* f7Entries;
uint32* writeBuffer;
template<uint CInterval>
struct C12Job : MTJob<C12Job<CInterval>>
{
uint64 length;
const uint32* f7Entries;
uint32* writeBuffer;

void Run() override;
};
void Run() override;
};

struct C3Job : MTJob<C3Job>
{
uint64 parkCount;
uint32* f7Entries;
byte* writeBuffer;

void Run() override;
};
struct C3Job : MTJob<C3Job>
{
uint64 parkCount;
uint32* f7Entries;
byte* writeBuffer;

void Run() override;
};
} // End NS


///
/// Implementation
///

namespace TableWriter
{

///
/// P7
///
//-----------------------------------------------------------
template<uint MAX_JOBS>
inline size_t TableWriter::WriteP7( ThreadPool& threadPool, uint32 threadCount, const uint64 length,
inline size_t WriteP7( ThreadPool& threadPool, uint32 threadCount, const uint64 length,
const uint32* indices, byte* parkBuffer )
{
threadCount = std::min( threadCount, MAX_JOBS );
Expand Down Expand Up @@ -137,7 +145,7 @@ inline size_t TableWriter::WriteP7( ThreadPool& threadPool, uint32 threadCount,
}

//-----------------------------------------------------------
inline void TableWriter::WriteP7Parks( const uint64 parkCount, const uint32* indices, byte* parkBuffer, uint32 jobId )
inline void WriteP7Parks( const uint64 parkCount, const uint32* indices, byte* parkBuffer, uint32 jobId )
{
const size_t parkSize = CDiv( (_K + 1) * kEntriesPerPark, 8 );

Expand All @@ -151,7 +159,7 @@ inline void TableWriter::WriteP7Parks( const uint64 parkCount, const uint32* ind

//-----------------------------------------------------------
template<typename TIdx>
inline void TableWriter::WriteP7Entries( const uint64 length, const TIdx* indices, byte* parkBuffer, uint32 jobId )
inline void WriteP7Entries( const uint64 length, const TIdx* indices, byte* parkBuffer, uint32 jobId )
{
ASSERT( length <= kEntriesPerPark );
ASSERT( ((uintptr_t)parkBuffer & 7 ) == 0 );
Expand Down Expand Up @@ -219,7 +227,7 @@ inline void P7Job::Run()
///
//-----------------------------------------------------------
template<uint MAX_JOBS, uint CInterval>
inline size_t TableWriter::WriteC12Parallel(
inline size_t WriteC12Parallel(
ThreadPool& pool, uint32 threadCount, const uint64 length,
const uint32* f7Entries, uint32* parkBuffer )
{
Expand Down Expand Up @@ -280,7 +288,7 @@ inline size_t TableWriter::WriteC12Parallel(

//-----------------------------------------------------------
template<uint CInterval>
inline void TableWriter::WriteC12Entries( const uint64 length, const uint32* f7Entries, uint32* c1Buffer )
inline void WriteC12Entries( const uint64 length, const uint32* f7Entries, uint32* c1Buffer )
{
uint64 f7Src = 0;
for( uint64 i = 0; i < length; i++, f7Src += CInterval )
Expand All @@ -298,7 +306,7 @@ inline void C12Job<CInterval>::Run()
/// C3
///
//-----------------------------------------------------------
inline uint64 TableWriter::GetC3ParkCount( const uint64 length, uint64& outLastParkRemainder )
inline uint64 GetC3ParkCount( const uint64 length, uint64& outLastParkRemainder )
{
const uint64 c3ParkCount = length / kCheckpoint1Interval;
const uint64 lastParkRemainder = length - ( c3ParkCount * kCheckpoint1Interval );
Expand All @@ -316,15 +324,15 @@ inline uint64 TableWriter::GetC3ParkCount( const uint64 length, uint64& outLastP
}

//-----------------------------------------------------------
inline uint64 TableWriter::GetC3ParkCount( const uint64 length )
inline uint64 GetC3ParkCount( const uint64 length )
{
uint64 remainder;
return GetC3ParkCount( length, remainder );
}

//-----------------------------------------------------------
template<uint MAX_JOBS>
inline size_t TableWriter::WriteC3Parallel( ThreadPool& pool, uint32 threadCount, const uint64 length, uint32* f7Entries, byte* c3Buffer )
inline size_t WriteC3Parallel( ThreadPool& pool, uint32 threadCount, const uint64 length, uint32* f7Entries, byte* c3Buffer )
{
threadCount = std::min( threadCount, MAX_JOBS );

Expand Down Expand Up @@ -377,7 +385,7 @@ inline size_t TableWriter::WriteC3Parallel( ThreadPool& pool, uint32 threadCount
}

//-----------------------------------------------------------
inline void TableWriter::WriteC3Parks( const uint64 parkCount, uint32* f7Entries, byte* writeBuffer, uint32 jobId )
inline void WriteC3Parks( const uint64 parkCount, uint32* f7Entries, byte* writeBuffer, uint32 jobId )
{
const size_t c3Size = CalculateC3Size();

Expand All @@ -391,7 +399,7 @@ inline void TableWriter::WriteC3Parks( const uint64 parkCount, uint32* f7Entries
}

//-----------------------------------------------------------
inline void TableWriter::WriteC3Park( const uint64 length, uint32* f7Entries, byte* parkBuffer, uint32 jobId )
inline void WriteC3Park( const uint64 length, uint32* f7Entries, byte* parkBuffer, uint32 jobId )
{
ASSERT( length <= kCheckpoint1Interval-1 );

Expand Down Expand Up @@ -441,3 +449,4 @@ inline void C3Job::Run()
}


} // End nS

0 comments on commit 5ee2b81

Please sign in to comment.