netlist: Force invalidation of save states. [Couriersud]

Added netlist version information. This is used to enforce the
invalidation of save states when the major/minor netlist version
changes.

This catches edge cases for which neither the size or names of saved
items changes during releases.
This commit is contained in:
couriersud 2019-12-30 16:50:32 +01:00
parent 01d4b2d02e
commit 018830967a
5 changed files with 47 additions and 17 deletions

View File

@ -7,6 +7,7 @@
#include "plib/palloc.h"
#include "plib/pmempool.h"
#include "plib/putil.h"
#include "plib/pfmtlog.h"
#include "devices/nlid_proxy.h"
#include "devices/nlid_system.h"
@ -202,6 +203,7 @@ namespace netlist
, m_callbacks(std::move(callbacks)) // Order is important here
, m_log(*m_callbacks)
, m_extended_validation(false)
, m_dummy_version(1)
{
pstring libpath = plib::util::environment("NL_BOOSTLIB", plib::util::buildpath({".", "nlboost.so"}));
m_lib = plib::make_unique<plib::dynlib>(libpath);
@ -210,6 +212,11 @@ namespace netlist
// create the run interface
m_netlist = m_pool.make_unique<netlist_t>(*this);
// Make sure save states are invalidated when a new version is deployed
m_state.save_item(this, m_dummy_version, pstring("V") + version());
// Initialize factory
devices::initialize_factory(m_setup->factory());
NETLIST_NAME(base)(*m_setup);
}
@ -241,19 +248,19 @@ namespace netlist
return std::numeric_limits<std::size_t>::max();
}
void netlist_state_t::rebuild_lists()
{
for (auto & net : m_nets)
net->rebuild_list();
}
void netlist_state_t::compile_defines(std::vector<std::pair<pstring, pstring>> &defs)
{
#define ENTRY(x) if (pstring(#x) != PSTRINGIFY(x)) defs.emplace_back(std::pair<pstring, pstring>(#x, PSTRINGIFY(x)));
ENTRY(PHAS_RDTSCP)
ENTRY(NL_VERSION_MAJOR)
ENTRY(NL_VERSION_MINOR)
ENTRY(NL_VERSION_PATCHLEVEL)
ENTRY(PUSE_ACCURATE_STATS)
ENTRY(PHAS_INT128)
ENTRY(PUSE_ALIGNED_OPTIMIZATIONS)
@ -300,6 +307,16 @@ namespace netlist
#undef ENTRY
}
pstring netlist_state_t::version()
{
return plib::pfmt("{1}.{2}")(NL_VERSION_MAJOR, NL_VERSION_MINOR);
}
pstring netlist_state_t::version_patchlevel()
{
return plib::pfmt("{1}.{2}.{3}")(NL_VERSION_MAJOR, NL_VERSION_MINOR, NL_VERSION_PATCHLEVEL);
}
void netlist_t::reset()
{
log().debug("Searching for mainclock\n");

View File

@ -1304,11 +1304,9 @@ namespace netlist
using timed_queue = plib::timed_queue_linear<T, TS>;
// Use timed_queue_heap to use stdc++ heap functions instead of linear processing.
/// This slows down processing by about 25% on a Kaby Lake.
//template <class T, bool TS>
//using timed_queue = timed_queue_heap<T, TS>;
// This slows down processing by about 25% on a Kaby Lake.
// template <class T, bool TS>
// using timed_queue = plib::timed_queue_heap<T, TS>;
// -----------------------------------------------------------------------------
// queue_t
@ -1521,6 +1519,8 @@ namespace netlist
void rebuild_lists(); // must be called after post_load !
static void compile_defines(std::vector<std::pair<pstring, pstring>> &defs);
static pstring version();
static pstring version_patchlevel();
nets_collection_type & nets() noexcept { return m_nets; }
const nets_collection_type & nets() const noexcept { return m_nets; }
@ -1575,6 +1575,9 @@ namespace netlist
// sole use is to manage lifetime of net objects
devices_collection_type m_devices;
bool m_extended_validation;
// dummy version
int m_dummy_version;
};
namespace devices
@ -1705,7 +1708,6 @@ namespace netlist
PALIGNAS_CACHELINE()
detail::queue_t m_queue;
bool m_use_stats;
// performance
plib::pperftime_t<true> m_stat_mainloop;
plib::pperfcount_t<true> m_perf_out_processed;

View File

@ -10,6 +10,20 @@
#include "plib/pconfig.h"
#include "plib/pexception.h"
///
/// \brief Version - Major.
///
#define NL_VERSION_MAJOR 0
///
/// \brief Version - Minor.
///
#define NL_VERSION_MINOR 4
///
/// \brief Version - Patch level.
///
#define NL_VERSION_PATCHLEVEL 1
///
/// \addtogroup compiledefine
/// \{

View File

@ -461,8 +461,7 @@ namespace plib {
if (*i == elem)
{
m_end--;
for (;i < m_end; i++)
*i = std::move(*(i+1));
*i = *m_end;
std::make_heap(&m_list[0], m_end, compare());
return;
}

View File

@ -23,8 +23,6 @@
#include <ios>
#include <iostream> // scanf
#define NLTOOL_VERSION 20190420
class tool_app_t : public plib::app
{
public:
@ -1008,12 +1006,12 @@ int tool_app_t::execute()
if (opt_version())
{
pout(
"nltool (netlist) " PSTRINGIFY(NLTOOL_VERSION) "\n"
"nltool (netlist) {1}\n"
"Copyright (C) 2019 Couriersud\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n\n"
"Written by Couriersud.\n");
"Written by Couriersud.\n", netlist::netlist_state_t::version());
if (opt_verb())
{
std::vector<std::pair<pstring, pstring>> defs;
@ -1027,7 +1025,7 @@ int tool_app_t::execute()
}
m_defines = opt_defines();
m_defines.emplace_back("NLTOOL_VERSION=" PSTRINGIFY(NLTOOL_VERSION));
m_defines.emplace_back("NLTOOL_VERSION=" + netlist::netlist_state_t::version());
if (opt_prepro())
m_defines.emplace_back("__PREPROCESSOR_DEBUG__=1");