Menu

#106 XSPICE: double CKTdelta subtraction for ngshared mode

Unstable (example)
open
None
5
2023-10-07
2021-07-07
No

Hi,

A few months ago, I stumbled upon some corner-case bug in ngspice. When I use ngspice as a dynamic library with XSPICE, it may incorrectly subtract CKTdelta from the CKTTime during event backup procedure. The problem is in the sharedsync call and its fallback implementation, responsible for the subtraction in library mode when SHARED_MODULE and XSPICE are enabled, and the analog breakpoint is put between the last accepted time and CKTTime. Incorrect subtraction may make CKTTime less than the previously accepted time. In this case, the result time list may have two or even more points where time[i-1] > time[i].

I've prepared a patch with the fix and attached it to this ticket. During the debugging, I tried to find all preconditions and code execution paths that reproduce this bug. The commit message in the attached patch contains the summary of the research. You can find more information about the bug there.

The patch looks like a hack for me, but I didn't find another way to implement a more elegant fix and not break ngspice public API without changing sharedsync() declaration. So I tried to document all changes to make them as explicit as possible.

Unfortunately, I can't provide the netlist that can reproduce this issue because it contains some models that are not available in the default ngspice build.

If you require any additional information, please, let me know.

1 Attachments

Discussion

  • Holger Vogt

    Holger Vogt - 2021-08-26
    • assigned_to: Holger Vogt
     
  • Holger Vogt

    Holger Vogt - 2021-08-26

    Vyacheslav,

    many thanks for your input.

    I would like to have a look at it, but I am missing any test case for this bug.

    Could you imagine to supply something which allows me to get a better understanding?

    Holger

     
  • Vyacheslav Shevchuk

    Hi Holger,

    I'll try to simplify the netlist and reproduce this issue using ngspice models. Should I also provide an example of the application linked to the ngspice library that interacts with the netlist, or having the netlist is enough? If the test application is required, how should I create it? Is it ok having something like main.c with the Makefile that compiles it and links to the ngspice dynamic library?

     
  • Holger Vogt

    Holger Vogt - 2021-08-26

    Yes, main.c (compilable with any Linux gcc) would be fine.

     
  • Holger Vogt

    Holger Vogt - 2023-10-07

    The patch is applied to git development branch pre-master-42. I have tested it together with the new PWM generator with a simple class D amplifier and with a regulated dc-dc converter, both designed and simulated withing KiCad 7.99 and updated ngspice.dll.

     

    Last edit: Holger Vogt 2023-10-07

Log in to post a comment.