Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite: Initial port #417

Open
wants to merge 22 commits into
base: loader
Choose a base branch
from
Open

sqlite: Initial port #417

wants to merge 22 commits into from

Conversation

msdx321
Copy link
Member

@msdx321 msdx321 commented Mar 18, 2021

Summary of this Pull Request (PR)

Add description here.

Intent for your PR

Choose one (Mandatory):

  • This PR is for a code-review and is intended to get feedback, but not to be pulled yet.
  • This PR is mature, and ready to be integrated into the repo.

Reviewers (Mandatory):

(Specify @<github.com username(s)> of the reviewers. Ex: @user1, @user2)

Code Quality

As part of this pull request, I've considered the following:

Style:

  • Comments adhere to the Style Guide (SG)
  • Spacing adhere's to the SG
  • Naming adhere's to the SG
  • All other aspects of the SG are adhered to, or exceptions are justified in this pull request
  • I have run the auto formatter on my code before submitting this PR (see doc/auto_formatter.md for instructions)

Code Craftsmanship:

  • I've made an attempt to remove all redundant code
  • I've considered ways in which my changes might impact existing code, and cleaned it up
  • I've formatted the code in an effort to make it easier to read (proper error handling, function use, etc...)
  • I've commented appropriately where code is tricky
  • I agree that there is no "throw-away" code, and that code in this PR is of high quality

Testing

I've tested the code using the following test programs (provide list here):

  • micro_booter
  • unit_pingpong
  • unit_schedtests
  • ...(add others here)

Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
@@ -31,7 +34,7 @@ libc_syscall_override(cos_syscall_t fn, int syscall_num)
cos_syscalls[syscall_num] = fn;
}

struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT();
//struct sl_lock stdout_lock = SL_LOCK_STATIC_INIT();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there demand for a single threaded version of this? Removing all this synchronization logic is going to lead to weird bugs as soon as you have more than one thread. Why doesn't it work as-is? Too tight coupling to SL?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question, and good intuition. We revamping libposix right now to use a generic interface that can either be co-located (via library) with sl, or accessed in another component. Given this, most of the synchronization facilities (and sl dependencies) in posix need to change backing APIs.

As such, Bite is trying to get sqlite working for a comparison case, and is not trying to solve other problems for now. As we update posix, I'm hoping we can add back in those features.

A lot of the cruft assuming single-component runtimes has been removed, but we have more to do, and libposix is one of the big places more love needs to be applied.

Copy link
Collaborator

@gparmer gparmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that a lot of your changes are in the sqlite repo. How do you want to proceed with that. See my comment about having a main branch that tracks sqlite's upstream.

Some comments about how to avoid losing all of the sync and futex code.

@@ -4,3 +4,6 @@
[submodule "src/components/lib/ck/ck"]
path = src/components/lib/ck/ck
url = https://github.com/gwsystems/ck.git
[submodule "src/components/lib/sqlite/sqlite"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to move this into gwsystems. Remember, we want the main branch of the repo be unmodifed, and have a cos branch that we pull in as a submodule. That way we have a path for updating the code as upstream changes.

@@ -0,0 +1,9 @@
## tests

This is the skeleton interface used by the `mkcomponent.sh` script to aid in the creation of a new component.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation here, or remove the file.

{
}

int result_print(void *v, int argc, char **argv,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your line width wraparound seems too aggressive. I don't think that the argument needs to be on another line.

#include <cos_defkernel_api.h>

void
cos_init(void)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove this function, it should still work. If you don't have code in it, remove it!

int
main(void)
{
printc("Calling sqlite functions\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent indentation styules. likely mixing spaces and tabs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable definitions should be at the top of the block.

completed_successfully = sl_thd_block_timeout(0, wakeup_deadline);
wakeup_time = sl_now();
//wakeup_deadline = sl_now() + sl_usec2cyc(time_to_microsec(req));
wakeup_deadline = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that silently failing is the best policy here. We should probably fail loudly if a function that we don't support is called. BUG(), assert(0), after a printc to explain. etc...

I don't trust client checking for ENOTSUP which would be the normal solution. Failure is more appropriate if it isn't supported here.

@@ -263,23 +272,27 @@ cos_set_tid_address(int *tidptr)
* };
*/

void* backing_data[SL_MAX_NUM_THDS];
//void* backing_data[SL_MAX_NUM_THDS];
void* backing_data[1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COS_NUM_THREADS, I think???

@@ -291,11 +304,13 @@ cos_clone(int (*func)(void *), void *stack, int flags, void *arg, pid_t *ptid, v
return -1;
}

struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg);
//struct sl_thd * thd = sl_thd_alloc((cos_thd_fn_t) func, arg);
struct sl_thd * thd = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't compile, right? Where is the defn of sl_thd coming from here?

assert(0);
}

/* TODO: Cleanup empty futexes */

struct sl_lock futex_lock = SL_LOCK_STATIC_INIT();
//struct sl_lock futex_lock = SL_LOCK_STATIC_INIT();

/*
* precondition: futex_lock is taken
*/
int
cos_futex_wait(struct futex_data *futex, int *uaddr, int val, const struct timespec *timeout)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all pretty challenging logic that Gregor spent a lot of time on. What I'd like: create an issue with a link to the commit in which this is removed, so that we can know how to easily bring back this code when hook up posix to the rest of the system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there have to be ways to do this that don't sacrifice correctness. (ie that fault instead of being unsafe concurrently) I'm always nervous leaving things in a subtly broken state--it's easy to forget the exact brokenness and put yourself in debugging hell for no reason later

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point.

Perhaps we replace the current lock implementation with something that simply errors out on contention:

struct lock {
        unsigned long owner;
};
struct lock global_lock = (struct lock) { .owner = 0 };
void
lock_take(void) {
        // failure here indicates that you're using concurrency/parallelism, which posix doesn't yet support!
        if (!ps_cas(&global_lock.owner, 0, cos_thdid())) assert(0);
}
void
lock_release(void) {
        // failure here indicates unpaired take and release.
        assert(global_lock.owner == cos_thdid());
        ps_store(&global_lock.owner, 0);
}

Replace normal lock behavior which requires contention management with simple "error out".

@@ -0,0 +1,9 @@
## sqlite

This is the skeleton library used by the `mklib.sh` script to aid in the creation of a new library.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation or remove.

Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Signed-off-by: msdx321 <msdx321@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants