Is there a way to lookup for a specific value in the entire BPF map? - ebpf

Hi I'm doing some experiments with eBPF.
I need to iterate through all the values in the BPF map and check if such value exists in the map from the kernel space.
However, to my understanding eBPF verifier wouldn't load programs into the kernel if it has a loop inside.
So I think iterating through all the keys and looking up the values for every key is out of option (Maybe I could try to hard-code it but I wish to avoid it if possible?).
Is there a method you guys would suggest?
Thanks!

Related

Does anyone have an example of how to use IQueue in codesys?

I'm trying to get the median value of an array in codesys, however the array is fifo, so as a new value is added to the array the first value is deleted and the median is rechecked. The array is always going to be odd in size and I think IQueue will be useful but the codesys sp16 documentation are not very descriptive about how to use it. Any ideas?
The functionblock Queue implements the interface iqueue. See here for more documentation: https://content.helpme-codesys.com/en/libs/Element%20Collections/Current/ElementCollections/Function-Blocks/Queue/Queue.html
In my opinion the Queue could be used to manage adding and removing values with fifo. However to calculate the median value a seperate function is needed that just iterates over all the values in my opinion. The library 'ElementCollections' does not facilitate automatic median value calculation.

Working with many inputs (Matlab)

I'm new to Matlab and I need some suggestions on how to deal with having many inputs to a function.
The program reads data from multiple elements and stores them in an array, which I'm doing in a loop. The problem is that if I input the wrong information about one element, I must re-input the data all over again. I believe that there must exist a better way to input these data, like reading it from a external file, for example.
The problem with the external file would be, as far as I know, with the reading of multiple arrays from a single file, hence the need of multiple external files - and I believe also that must exist some better way.
As noted by #beaker, you can use save and load to store the data. You can store multiple variables in a given file without a problem.

Determine Remaining Bytes

I'm working on a project where I need to send a value between two pieces of hardware using CoDeSys. The comms system in use is CAN and is only capable of transmitting in Bytes, making the maximum value 255.
I need to send a value higher than 255, I'm capable of splitting this over more than one byte and reconstructing it on the receiving machine to get the original value.
I'm thinking I can divide the REAL value by 255 and if the result is over 1 then deconstruct the value in to one byte holding the remainders and one byte holding the amount of 255's in the whole number.
For example 355 would amount to one byte of 100 and another of 1.
Whilst I can describe this, I'm having a really hard time figuring out how to actually write this in logic.
Can anyone help here?
This is all handled for you in CoDeSys if I understand you correctly.
1. CAN - Yes it's in byte but you must not be using CANopen you are using the low level FB that ask you to send a CAN frame of an 8 byte array?
If it is your own two custom controllers ( you are programming both of them in CoDeSys) just use netvariables. Netvariables allows you to transfer any type of variable and you can take the variable list from one controller and import it to another controller and all the data will show up. You don't have to do any variable manipulation it's handle under the hood for you. But I don't know the specifics of your system and what you are trying to do.
If you are trying to deconstruct construct variables from one size to another that is easy and I can share that code with you.

Is it possible to assign a number to a lists with the same name to be differentiated?

A part of my program relies on recording the lengths of roads within my user interface as they are drawn out. As this requires looping , and as I want to be able to keep the name of the list all the data is stored in the same, is it possible to create lists thusly :
set list road-length X
(where X is a counter that is incremented every time a condition is met). Essentially can I tag numbers on to the ends of lists so that I can tell them apart when they need to be read later on in my program?
You can, but it is almost surely the wrong approach. (For one thing, the names will not be global unless you declare them all ahead of time.) Instead, use the table extension, create a global to hold your table, and use the table to map your id numbers to your lists. This will prove much more useful.

Is it possible to use ArrayBuilder without trimming the result?

The ArrayBuilder result() method usually has to perform a copy of the internal array, just to trim off any unused slots at the end. But copying is not guaranteed - when the internal array is exactly the right size, it is returned without copying.
Can anyone see a way to use ArrayBuilder without incurring this cost, in applications where an independent size variable makes trimming unnecessary?
Update: I don't know the size before-hand, and thus don't don't want to pre-allocate. It is an integer array, and I want to avoid the boxing overhead of ArrayBuffer.
Arrays are mutable, there's no need to use a builder, you can just insert into the Array directly.
As you know the size in advance, use Array.ofDim() to create the Array with exactly the right size before you start.