structure memory optimizations.
authorPekka Riikonen <priikone@silcnet.org>
Fri, 29 Mar 2002 20:47:42 +0000 (20:47 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 29 Mar 2002 20:47:42 +0000 (20:47 +0000)
CHANGES
TODO-1.0
lib/silccore/silcpacket.h
lib/silcsftp/sftp_fs_memory.c
lib/silcutil/silcschedule.c
lib/silcutil/silcschedule.h

diff --git a/CHANGES b/CHANGES
index f355f383b75c96deb79d8a47c93865db09602fbd..a668b8109ca39f888602ed2de4be81c68a43c6ff 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Fri Mar 29 21:55:41 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Made some structure optimizations.  SFTP memory FS MemFSEntry
+         entry structure.  Optimized SilcTask structure.  Optimized
+         SilcPacketContext structure.
+
+         Affected files lib/silcsftp/sftp_fs_memory.c,
+         lib/silcutil/silcschedule.c, lib/silccore/silcpacket.h.
+
 Fri Mar 29 10:41:07 EET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * And yet again reverted back the config thing since Johnny
index afda54a93b5b1cba192eff44076874341fab1851..4a0f6e2a558a18f6f5be2148746b4a900ca5bb41 100644 (file)
--- a/TODO-1.0
+++ b/TODO-1.0
@@ -90,23 +90,6 @@ least could be done.
          SILC_BUFFER_LEN macro can do the same.  These would save
          totally 8 bytes of memory per buffer.
 
-       o Scheduler can be optimized for FD tasks by changing the fd_queue
-         to SilcHashTable instead of using linked list.  We need to do
-         one-to-one mapping of FD to task and hash table is more efficient
-         for this usage.
-
-         Also redefine the silc_select to perhaps return a separate
-         structure of the events that actually occurred, instead of
-         returning the events in the fd_list which is then traversed
-         in the generic code to find the changed events.  This can be
-         made faster by having own struct which includes only the
-         changed events, thus the tarversing is faster since the whole
-         fd_list is not traversed anymore (it is still traversed in the
-         silc_select but at least it removes one extra tarversing later
-         for the same list).
-
-         Other task queues should be changed to use SilcList.
-
  o Optimizations in Server
 
        o Remove the big switch statement from the function 
@@ -139,6 +122,8 @@ least could be done.
 
  o Rewrite SilcProtocol to be SilcFSM (see ~/silcfsm).
 
+ o Do some scheduler optimizations (see ~/silcschedule).
+
  o Change SILC_TASK_CALLBACK to non-static, and remove the macro
    SILC_TASK_CALLBACK_GLOBAL.
 
@@ -147,10 +132,6 @@ least could be done.
  o SILC RNG does not implement random seed files, and they should be
    implemented.
 
- o Add SILC scheduler's internal routines into a table of implementation
-   function pointers, that the generic code then takes as extern from
-   implementation.  These are the silc_schedule_internal_* routines.
-
  o Cipher optimizations (asm, that this) at least for i386 would be nice.
 
  o Add builtin SOCKS and HTTP Proxy support, well the SOCKS at least.
index e3c4b6ea6174464585accc969666629a8608c47f..7912362811eed97c2bb208a6bc36c44ddea334cf 100644 (file)
@@ -164,18 +164,20 @@ typedef unsigned char SilcPacketFlags;
  *
  *    Short description of the fields following:
  *
- *    SilcBuffer buffer
- *
- *      The data buffer.
- *
- *    SilcPacketType type
+ *    SilcUInt16 truelen
  *
- *      Type of the packet. Types are defined below.
+ *      True length of the packet.  This may be set by the caller before
+ *      calling any of the silc_packet_* routines.  If not provided the
+ *      library will calculate the values.
  *
  *    SilcPacketFlags flags
  *
  *      Packet flags. Flags are defined above.
  *
+ *    SilcPacketType type
+ *
+ *      Type of the packet. Types are defined below.
+ *
  *    unsigned char *src_id
  *    SilcUInt8 src_id_len
  *    unsigned char src_id_type
@@ -190,15 +192,19 @@ typedef unsigned char SilcPacketFlags;
  *      Destination ID, its length and type. On packet reception retuned
  *      ID's are always the hash values of the ID's from the packet.
  *
- *    SilcUInt16 truelen
  *    SilcUInt8 padlen
  *
- *      The true lenght of the packet and the padded length of the packet.
- *      These may be set by the caller before calling any of the 
- *      silc_packet_* routines. If not provided the library will calculate
- *      the values.
+ *      The padded length of the packet.  This may be set by the caller
+ *      before calling any of the silc_packet_* routines. If not provided
+ *      the library will calculate the values.
+ *
+ *    unsigned int long_pad
+ * 
+ *      If set to TRUE the packet will include the maximum padding allowed
+ *      in SILC packet, which is 128 bytes.  If FALSE only the amount of
+ *      padding needed will be applied.
  *
- *    int users;
+ *    unsigned int users;
  *
  *      Reference counter for this context. The context is freed only 
  *      after the reference counter hits zero. The counter is added
@@ -209,28 +215,29 @@ typedef unsigned char SilcPacketFlags;
  *
  *      Packet sequence number.
  *
+ *    SilcBuffer buffer
+ *
+ *      The actual packet data.
+ *
  ***/
 typedef struct {
-  SilcBuffer buffer;
-
   SilcUInt16 truelen;
   SilcPacketFlags flags;
   SilcPacketType type;
-  SilcUInt8 padlen;
 
   unsigned char *src_id;
+  unsigned char *dst_id;
   SilcUInt8 src_id_len;
   SilcUInt8 src_id_type;
-
-  unsigned char *dst_id;
   SilcUInt8 dst_id_len;
   SilcUInt8 dst_id_type;
 
-  int users;
-  bool long_pad;               /* Set to TRUE to use maximum padding
-                                  in packet (up to 256 bytes). */
+  SilcUInt8 padlen;
+  unsigned int long_pad : 1;   /* Set when maximum padding in packet */
+  unsigned int users : 23;     /* Reference counter */
 
   SilcUInt32 sequence;
+  SilcBuffer buffer;
 } SilcPacketContext;
 
 /****s* silccore/SilcPacketAPI/SilcPacketParserContext
index 621fdee7873e14973c1f5cbead303870674adbee..5ac53706a16739180c30dcf3fb4c145f09dd030b 100644 (file)
 
 const struct SilcSFTPFilesystemOpsStruct silc_sftp_fs_memory;
 
-/* Memory filesystem entry */
 typedef struct MemFSEntryStruct {
-  char *name;                       /* Name of the entry */
-  char *data;                      /* Data of the entry */
-  bool directory;                  /* TRUE if this is directory */
-  SilcSFTPFSMemoryPerm perm;       /* Permissions */
   struct MemFSEntryStruct **entry;  /* Files and sub-directories */
-  SilcUInt32 entry_count;                  /* Number of files and sub-directories */
+  SilcUInt32 entry_count;                  /* Number of files and sub-directories */
   struct MemFSEntryStruct *parent;  /* non-NULL if `directory' is TRUE,
                                       includes parent directory. */
   unsigned long created;           /* Time of creation */
+  char *name;                       /* Name of the entry */
+  char *data;                      /* Data of the entry */
+  unsigned int directory : 1;      /* Set if this is directory */
+  unsigned int perm : 7;           /* Permissions */
 } *MemFSEntry;
 
 /* File handle. */
index 345381094e3036c94a160edc6afd38e2fa263505..828e78748e639167b95b043064312d28656fb5c7 100644 (file)
@@ -109,12 +109,12 @@ do {                                                              \
 /* SILC Task object. Represents one task in the scheduler. */
 struct SilcTaskStruct {
   SilcUInt32 fd;
-  struct timeval timeout;
-  SilcTaskCallback callback;
-  void *context;
-  bool valid;
-  SilcTaskPriority priority;
-  SilcTaskType type;
+  SilcTaskCallback callback;      /* Task callback */
+  void *context;                  /* Task callback context */
+  struct timeval timeout;         /* Set for timeout tasks */
+  unsigned int valid : 1;         /* Set when task is valid */
+  unsigned int priority : 2;      /* Priority of the task */
+  unsigned int type : 5;           /* Type of the task */
 
   /* Pointers forming doubly linked circular list */
   struct SilcTaskStruct *next;
index 1bc5d4a85d522788bde172967937c41cc1b3cc0f..f10bd8306ad34e373993902c470732f122164ace 100644 (file)
@@ -119,7 +119,7 @@ typedef struct SilcTaskStruct *SilcTask;
 typedef enum {
   /* File descriptor task that performs some event over file descriptors.
      These tasks are for example network connections. */
-  SILC_TASK_FD,
+  SILC_TASK_FD           = 0,
 
   /* Timeout tasks are tasks that are executed after the specified 
      time has elapsed. After the task is executed the task is removed
@@ -190,7 +190,7 @@ typedef enum {
      has expired only and only when every other task with higher priority 
      has already been run. For non-timeout tasks this priority behaves
      same way. Life is not fair for tasks with this priority. */
-  SILC_TASK_PRI_LOW,
+  SILC_TASK_PRI_LOW      = 0,
 
   /* Normal priority that is used mostly in SILC. This is priority that
      should always be used unless you specificly need some other priority.